use of org.intellij.plugins.intelliLang.inject.config.BaseInjection in project intellij-community by JetBrains.
the class JavaLanguageInjectionSupport method doEditInjection.
private static void doEditInjection(final Project project, final MethodParameterInjection template, final PsiMethod contextMethod) {
final Configuration configuration = InjectorUtils.getEditableInstance(project);
final BaseInjection baseTemplate = new BaseInjection(template.getSupportId()).copyFrom(template);
final MethodParameterInjection allMethodParameterInjection = createFrom(project, baseTemplate, contextMethod, true);
// find existing injection for this class.
final BaseInjection originalInjection = configuration.findExistingInjection(allMethodParameterInjection);
final MethodParameterInjection methodParameterInjection;
if (originalInjection == null) {
methodParameterInjection = template;
} else {
final BaseInjection originalCopy = originalInjection.copy();
final InjectionPlace currentPlace = template.getInjectionPlaces()[0];
originalCopy.mergeOriginalPlacesFrom(template, true);
originalCopy.setPlaceEnabled(currentPlace.getText(), true);
methodParameterInjection = createFrom(project, originalCopy, contextMethod, false);
}
mergePlacesAndAddToConfiguration(project, configuration, methodParameterInjection, originalInjection);
}
use of org.intellij.plugins.intelliLang.inject.config.BaseInjection in project intellij-community by JetBrains.
the class XmlLanguageInjector method getXmlAnnotatedElementsValue.
private Trinity<Long, Pattern, Collection<String>> getXmlAnnotatedElementsValue() {
Trinity<Long, Pattern, Collection<String>> index = myXmlIndex;
if (index == null || myConfiguration.getModificationCount() != index.first.longValue()) {
final Map<ElementPattern<?>, BaseInjection> map = new THashMap<>();
for (BaseInjection injection : myConfiguration.getInjections(XmlLanguageInjectionSupport.XML_SUPPORT_ID)) {
for (InjectionPlace place : injection.getInjectionPlaces()) {
if (!place.isEnabled() || place.getElementPattern() == null)
continue;
map.put(place.getElementPattern(), injection);
}
}
final Collection<String> stringSet = PatternValuesIndex.buildStringIndex(map.keySet());
index = Trinity.create(myConfiguration.getModificationCount(), buildPattern(stringSet), stringSet);
myXmlIndex = index;
}
return index;
}
use of org.intellij.plugins.intelliLang.inject.config.BaseInjection in project intellij-community by JetBrains.
the class CommentLanguageInjector method getLanguagesToInject.
public void getLanguagesToInject(@NotNull final MultiHostRegistrar registrar, @NotNull final PsiElement context) {
if (!(context instanceof PsiLanguageInjectionHost) || context instanceof PsiComment)
return;
if (!((PsiLanguageInjectionHost) context).isValidHost())
return;
PsiLanguageInjectionHost host = (PsiLanguageInjectionHost) context;
boolean applicableFound = false;
for (LanguageInjectionSupport support : mySupports) {
if (!support.isApplicableTo(host))
continue;
if (support == myInjectorSupport && applicableFound)
continue;
applicableFound = true;
if (!support.useDefaultCommentInjector())
continue;
BaseInjection injection = support.findCommentInjection(host, null);
if (injection == null)
continue;
if (!InjectorUtils.registerInjectionSimple(host, injection, support, registrar))
continue;
return;
}
}
use of org.intellij.plugins.intelliLang.inject.config.BaseInjection in project intellij-community by JetBrains.
the class PatternEditorContextMembersProvider method processDynamicElements.
@Override
public void processDynamicElements(@NotNull PsiType qualifierType, @NotNull final PsiScopeProcessor scopeProcessor, @NotNull final PsiElement place, @NotNull final ResolveState state) {
final PsiFile file = place.getContainingFile().getOriginalFile();
final BaseInjection injection = file.getUserData(BaseInjection.INJECTION_KEY);
Processor<PsiElement> processor = element -> element.processDeclarations(scopeProcessor, state, null, place);
if (injection == null) {
processDevContext(file, processor);
} else {
processPatternContext(injection, file, processor);
}
}
use of org.intellij.plugins.intelliLang.inject.config.BaseInjection in project intellij-community by JetBrains.
the class Configuration method setHostInjectionEnabled.
public boolean setHostInjectionEnabled(final PsiLanguageInjectionHost host, final Collection<String> languages, final boolean enabled) {
List<BaseInjection> originalInjections = new ArrayList<>();
List<BaseInjection> newInjections = new ArrayList<>();
for (LanguageInjectionSupport support : InjectorUtils.getActiveInjectionSupports()) {
for (BaseInjection injection : getInjections(support.getId())) {
if (!languages.contains(injection.getInjectedLanguageId()))
continue;
boolean replace = false;
final ArrayList<InjectionPlace> newPlaces = new ArrayList<>();
for (InjectionPlace place : injection.getInjectionPlaces()) {
if (place.isEnabled() != enabled && place.getElementPattern() != null && (place.getElementPattern().accepts(host) || place.getElementPattern().accepts(host.getParent()))) {
newPlaces.add(place.enabled(enabled));
replace = true;
} else
newPlaces.add(place);
}
if (replace) {
originalInjections.add(injection);
final BaseInjection newInjection = injection.copy();
newInjection.setInjectionPlaces(newPlaces.toArray(new InjectionPlace[newPlaces.size()]));
newInjections.add(newInjection);
}
}
}
if (!originalInjections.isEmpty()) {
replaceInjectionsWithUndo(host.getProject(), newInjections, originalInjections, Collections.emptyList());
return true;
}
return false;
}
Aggregations