Search in sources :

Example 6 with BaseInjection

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);
}
Also used : Configuration(org.intellij.plugins.intelliLang.Configuration) MethodParameterInjection(org.intellij.plugins.intelliLang.inject.config.MethodParameterInjection) InjectionPlace(org.intellij.plugins.intelliLang.inject.config.InjectionPlace) BaseInjection(org.intellij.plugins.intelliLang.inject.config.BaseInjection)

Example 7 with BaseInjection

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;
}
Also used : ElementPattern(com.intellij.patterns.ElementPattern) Pattern(java.util.regex.Pattern) THashMap(gnu.trove.THashMap) ElementPattern(com.intellij.patterns.ElementPattern) InjectionPlace(org.intellij.plugins.intelliLang.inject.config.InjectionPlace) BaseInjection(org.intellij.plugins.intelliLang.inject.config.BaseInjection)

Example 8 with BaseInjection

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;
    }
}
Also used : PsiComment(com.intellij.psi.PsiComment) PsiLanguageInjectionHost(com.intellij.psi.PsiLanguageInjectionHost) BaseInjection(org.intellij.plugins.intelliLang.inject.config.BaseInjection)

Example 9 with BaseInjection

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);
    }
}
Also used : ArrayUtil(com.intellij.util.ArrayUtil) PatternClassBean(com.intellij.patterns.compiler.PatternClassBean) ContainerUtil(com.intellij.util.containers.ContainerUtil) LowLevelSearchUtil(com.intellij.psi.impl.search.LowLevelSearchUtil) FileContextUtil(com.intellij.psi.impl.source.resolve.FileContextUtil) StringSearcher(com.intellij.util.text.StringSearcher) NonCodeMembersContributor(org.jetbrains.plugins.groovy.lang.resolve.NonCodeMembersContributor) BaseInjection(org.intellij.plugins.intelliLang.inject.config.BaseInjection) PatternCompilerFactory(com.intellij.patterns.compiler.PatternCompilerFactory) CacheManager(com.intellij.psi.impl.cache.CacheManager) Project(com.intellij.openapi.project.Project) TextOccurenceProcessor(com.intellij.psi.search.TextOccurenceProcessor) XmlTag(com.intellij.psi.xml.XmlTag) PsiScopeProcessor(com.intellij.psi.scope.PsiScopeProcessor) InjectorUtils(org.intellij.plugins.intelliLang.inject.InjectorUtils) GroovyFileType(org.jetbrains.plugins.groovy.GroovyFileType) StdFileTypes(com.intellij.openapi.fileTypes.StdFileTypes) StringUtil(com.intellij.openapi.util.text.StringUtil) com.intellij.psi.util(com.intellij.psi.util) Key(com.intellij.openapi.util.Key) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) Set(java.util.Set) XmlText(com.intellij.psi.xml.XmlText) UsageSearchContext(com.intellij.psi.search.UsageSearchContext) EmptyProgressIndicator(com.intellij.openapi.progress.EmptyProgressIndicator) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) Processor(com.intellij.util.Processor) com.intellij.psi(com.intellij.psi) NotNull(org.jetbrains.annotations.NotNull) SoftFactoryMap(com.intellij.util.containers.SoftFactoryMap) BaseInjection(org.intellij.plugins.intelliLang.inject.config.BaseInjection)

Example 10 with BaseInjection

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;
}
Also used : LanguageInjectionSupport(org.intellij.plugins.intelliLang.inject.LanguageInjectionSupport) InjectionPlace(org.intellij.plugins.intelliLang.inject.config.InjectionPlace) BaseInjection(org.intellij.plugins.intelliLang.inject.config.BaseInjection)

Aggregations

BaseInjection (org.intellij.plugins.intelliLang.inject.config.BaseInjection)23 InjectionPlace (org.intellij.plugins.intelliLang.inject.config.InjectionPlace)7 Nullable (org.jetbrains.annotations.Nullable)7 Language (com.intellij.lang.Language)6 Project (com.intellij.openapi.project.Project)6 LanguageInjectionSupport (org.intellij.plugins.intelliLang.inject.LanguageInjectionSupport)6 InjectorUtils (org.intellij.plugins.intelliLang.inject.InjectorUtils)5 NotNull (org.jetbrains.annotations.NotNull)5 AnAction (com.intellij.openapi.actionSystem.AnAction)4 AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)4 ContainerUtil (com.intellij.util.containers.ContainerUtil)4 THashSet (gnu.trove.THashSet)4 Pair (com.intellij.openapi.util.Pair)3 PsiElement (com.intellij.psi.PsiElement)3 IOException (java.io.IOException)3 Configuration (org.intellij.plugins.intelliLang.Configuration)3 MethodParameterInjection (org.intellij.plugins.intelliLang.inject.config.MethodParameterInjection)3 Element (org.jdom.Element)3 NonNls (org.jetbrains.annotations.NonNls)3 SplitterProportionsDataImpl (com.intellij.ide.ui.SplitterProportionsDataImpl)2