Skip to content

Commit

Permalink
#819 | Inject FlexibleSearch language into the `FlexibleSearchQuery…
Browse files Browse the repository at this point in the history
…` and its descendants in Java code
  • Loading branch information
mlytvyn authored Dec 3, 2023
1 parent 1316d58 commit 95c537b
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

### Features
- Rely on `intelliLang` plugin to inject `FlexibleSearch` and `Polyglot Query` languages into the Java code [#817](https://github.com/epam/sap-commerce-intellij-idea-plugin/pull/817)
- Inject `FlexibleSearch` language into the `FlexibleSearchQuery` and its descendants in Java code [#819](https://github.com/epam/sap-commerce-intellij-idea-plugin/pull/819)
- Added navigation to the `items.xml` Ordering Attribute from the generated classes [#818](https://github.com/epam/sap-commerce-intellij-idea-plugin/pull/818)

### `Polyglot Query` enhancements
Expand Down
2 changes: 0 additions & 2 deletions resources/injection/languageInjections.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,10 @@
<display-name>[y] FlexibleSearch</display-name>
<ignore-pattern>(\\s|.)*GET(\\s|.)*\{(.*)}</ignore-pattern>
<place><![CDATA[psiModifierListOwner().withText(string().matches("(\\s|.)*=(\\s|.)*SELECT(\\s|.)+FROM(\\s|.)+\\{(\\s|.)*"))]]></place>
<place><![CDATA[psiParameter()]]></place>
</injection>
<injection language="Polyglot Query" injector-id="java">
<display-name>[y] Polyglot Query</display-name>
<ignore-pattern>(\\s|.)*SELECT(\\s|.)*FROM(\\s|.)*\{(\\s|.)*</ignore-pattern>
<place><![CDATA[psiModifierListOwner().withText(string().matches("(\\s|.)*=(\\s|.)*GET(\\s|.)+\\{(\\s|.)*"))]]></place>
<place><![CDATA[psiParameter()]]></place>
</injection>
</component>
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,6 @@ object HybrisConstants {
const val CLASS_FQN_ITEM_ROOT = "de.hybris.platform.core.model.ItemModel"
const val CLASS_FQN_ENUM_ROOT = "de.hybris.platform.core.HybrisEnumValue"
const val CLASS_NAME_ENUM = "HybrisEnumValue"
const val CLASS_NAME_FLEXIBLE_SEARCH_SERVICE = "FlexibleSearchService"
const val CLASS_FQN_INTERCEPTOR_MAPPING = "de.hybris.platform.servicelayer.interceptor.impl.InterceptorMapping"
const val CLASS_FQN_ANNOTATION_ACCESSOR = "de.hybris.bootstrap.annotations.Accessor"
const val CLASS_FQN_CONFIG_IMPORT_PROCESSOR = "de.hybris.platform.commerceservices.impex.impl.ConfigPropertyImportProcessor"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,20 @@
package com.intellij.idea.plugin.hybris.startup

import com.intellij.idea.plugin.hybris.common.HybrisConstants
import com.intellij.idea.plugin.hybris.flexibleSearch.FlexibleSearchLanguage
import com.intellij.idea.plugin.hybris.polyglotQuery.PolyglotQueryLanguage
import com.intellij.idea.plugin.hybris.settings.HybrisProjectSettingsComponent
import com.intellij.openapi.project.DumbService
import com.intellij.openapi.project.Project
import com.intellij.openapi.startup.ProjectActivity
import com.intellij.patterns.PsiJavaPatterns
import com.intellij.psi.JavaPsiFacade
import com.intellij.psi.search.GlobalSearchScope
import com.intellij.psi.search.searches.ClassInheritorsSearch
import org.intellij.plugins.intelliLang.Configuration
import org.intellij.plugins.intelliLang.inject.config.InjectionPlace
import org.intellij.plugins.intelliLang.inject.java.InjectionCache
import org.intellij.plugins.intelliLang.inject.java.JavaLanguageInjectionSupport

/**
* TODO: reset Injection Cache on CRUD operation on classes related to FlexibleSearchQuery
Expand All @@ -40,6 +46,24 @@ class HybrisIntelliLangStartupActivity : ProjectActivity {
add(HybrisConstants.CLASS_NAME_FLEXIBLE_SEARCH_QUERY)
addAll(findCustomExtensionsOfTheFlexibleSearch(project))
}

val targetLanguages = setOf(FlexibleSearchLanguage.INSTANCE.id, PolyglotQueryLanguage.instance.id)

// TODO: replace with pattern declared in the XML file once https://youtrack.jetbrains.com/issue/IDEA-339624/ will be resolved.
// com.intellij.patterns.compiler.PatternCompiler cannot parse primitive booleans required by the pattern
Configuration.getInstance().getInjections(JavaLanguageInjectionSupport.JAVA_SUPPORT_ID)
.filter { targetLanguages.contains(it.injectedLanguageId) }
.forEach {
val injectionPlaces = it.injectionPlaces.toMutableSet()
val psiParameterInjectionPlace = InjectionPlace(
PsiJavaPatterns.psiParameter().ofMethod(
PsiJavaPatterns.psiMethod().definedInClass(PsiJavaPatterns.psiClass().inheritorOf(false, HybrisConstants.CLASS_FQN_FLEXIBLE_SEARCH_QUERY))
),
true
)
injectionPlaces.add(psiParameterInjectionPlace)
it.setInjectionPlaces(*injectionPlaces.toTypedArray())
}
}
}

Expand Down

0 comments on commit 95c537b

Please sign in to comment.