Search in sources :

Example 6 with Configuration

use of org.intellij.plugins.intelliLang.Configuration in project intellij-community by JetBrains.

the class JavaLanguageInjectionSupport method removeInjectionInPlace.

public boolean removeInjectionInPlace(final PsiLanguageInjectionHost psiElement) {
    if (!isMine(psiElement))
        return false;
    final HashMap<BaseInjection, Pair<PsiMethod, Integer>> injectionsMap = new HashMap<>();
    final ArrayList<PsiElement> annotations = new ArrayList<>();
    final PsiLiteralExpression host = (PsiLiteralExpression) psiElement;
    final Project project = host.getProject();
    final Configuration configuration = Configuration.getProjectInstance(project);
    collectInjections(host, configuration, this, injectionsMap, annotations);
    if (injectionsMap.isEmpty() && annotations.isEmpty())
        return false;
    final ArrayList<BaseInjection> originalInjections = new ArrayList<>(injectionsMap.keySet());
    final List<BaseInjection> newInjections = ContainerUtil.mapNotNull(originalInjections, (NullableFunction<BaseInjection, BaseInjection>) injection -> {
        final Pair<PsiMethod, Integer> pair = injectionsMap.get(injection);
        final String placeText = getPatternStringForJavaPlace(pair.first, pair.second);
        final BaseInjection newInjection = injection.copy();
        newInjection.setPlaceEnabled(placeText, false);
        return InjectorUtils.canBeRemoved(newInjection) ? null : newInjection;
    });
    configuration.replaceInjectionsWithUndo(project, newInjections, originalInjections, annotations);
    return true;
}
Also used : Language(com.intellij.lang.Language) InjectLanguageAction(org.intellij.plugins.intelliLang.inject.InjectLanguageAction) THashSet(gnu.trove.THashSet) PsiTreeUtil(com.intellij.psi.util.PsiTreeUtil) Matcher(java.util.regex.Matcher) WriteCommandAction(com.intellij.openapi.command.WriteCommandAction) Module(com.intellij.openapi.module.Module) SimpleTextAttributes(com.intellij.ui.SimpleTextAttributes) MultiHostRegistrar(com.intellij.lang.injection.MultiHostRegistrar) SimpleColoredText(com.intellij.ui.SimpleColoredText) ModuleUtilCore(com.intellij.openapi.module.ModuleUtilCore) ContextComputationProcessor(org.intellij.plugins.intelliLang.util.ContextComputationProcessor) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) Configurable(com.intellij.openapi.options.Configurable) Nullable(org.jetbrains.annotations.Nullable) Configuration(org.intellij.plugins.intelliLang.Configuration) AnnotationUtil(com.intellij.codeInsight.AnnotationUtil) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) InjectionPlace(org.intellij.plugins.intelliLang.inject.config.InjectionPlace) com.intellij.psi(com.intellij.psi) Pattern(java.util.regex.Pattern) PatternCompiler(com.intellij.patterns.compiler.PatternCompiler) com.intellij.util(com.intellij.util) NotNull(org.jetbrains.annotations.NotNull) Factory(com.intellij.openapi.util.Factory) Ref(com.intellij.openapi.util.Ref) java.util(java.util) NonNls(org.jetbrains.annotations.NonNls) ContainerUtil(com.intellij.util.containers.ContainerUtil) JavaCodeStyleManager(com.intellij.psi.codeStyle.JavaCodeStyleManager) BaseInjection(org.intellij.plugins.intelliLang.inject.config.BaseInjection) DialogWrapper(com.intellij.openapi.ui.DialogWrapper) DialogBuilder(com.intellij.openapi.ui.DialogBuilder) AdvancedSettingsUI(org.intellij.plugins.intelliLang.AdvancedSettingsUI) Project(com.intellij.openapi.project.Project) PsiUtil(com.intellij.psi.util.PsiUtil) PsiJavaPatterns(com.intellij.patterns.PsiJavaPatterns) MethodParameterPanel(org.intellij.plugins.intelliLang.inject.config.ui.MethodParameterPanel) AbstractLanguageInjectionSupport(org.intellij.plugins.intelliLang.inject.AbstractLanguageInjectionSupport) InjectorUtils(org.intellij.plugins.intelliLang.inject.InjectorUtils) StringUtil(com.intellij.openapi.util.text.StringUtil) AnAction(com.intellij.openapi.actionSystem.AnAction) PsiUtilEx(org.intellij.plugins.intelliLang.util.PsiUtilEx) AbstractInjectionPanel(org.intellij.plugins.intelliLang.inject.config.ui.AbstractInjectionPanel) EditInjectionSettingsAction(org.intellij.plugins.intelliLang.inject.EditInjectionSettingsAction) Result(com.intellij.openapi.application.Result) Pair(com.intellij.openapi.util.Pair) MethodParameterInjection(org.intellij.plugins.intelliLang.inject.config.MethodParameterInjection) Element(org.jdom.Element) Configuration(org.intellij.plugins.intelliLang.Configuration) BaseInjection(org.intellij.plugins.intelliLang.inject.config.BaseInjection) Project(com.intellij.openapi.project.Project) Pair(com.intellij.openapi.util.Pair)

Example 7 with Configuration

use of org.intellij.plugins.intelliLang.Configuration in project intellij-community by JetBrains.

the class LanguageReferenceProvider method registerReferenceProviders.

public void registerReferenceProviders(@NotNull PsiReferenceRegistrar registrar) {
    final Configuration configuration = Configuration.getInstance();
    registrar.registerReferenceProvider(literalExpression().annotationParam(StandardPatterns.string().with(new PatternCondition<String>("isLanguageAnnotation") {

        @Override
        public boolean accepts(@NotNull final String s, final ProcessingContext context) {
            return Comparing.equal(configuration.getAdvancedConfiguration().getLanguageAnnotationClass(), s);
        }
    }), "value").and(literalExpression().with(new PatternCondition<PsiLiteralExpression>("isStringLiteral") {

        @Override
        public boolean accepts(@NotNull final PsiLiteralExpression expression, final ProcessingContext context) {
            return PsiUtilEx.isStringOrCharacterLiteral(expression);
        }
    })), new PsiReferenceProvider() {

        @NotNull
        @Override
        public PsiReference[] getReferencesByElement(@NotNull final PsiElement element, @NotNull final ProcessingContext context) {
            return new PsiReference[] { new LanguageReference((PsiLiteralExpression) element) };
        }
    });
    registrar.registerReferenceProvider(literalExpression().with(new PatternCondition<PsiLiteralExpression>("isStringLiteral") {

        @Override
        public boolean accepts(@NotNull final PsiLiteralExpression expression, final ProcessingContext context) {
            return PsiUtilEx.isStringOrCharacterLiteral(expression);
        }
    }), new PsiReferenceProvider() {

        @NotNull
        @Override
        public PsiReference[] getReferencesByElement(@NotNull PsiElement psiElement, @NotNull ProcessingContext context) {
            final PsiLiteralExpression expression = (PsiLiteralExpression) psiElement;
            final PsiModifierListOwner owner = AnnotationUtilEx.getAnnotatedElementFor(expression, AnnotationUtilEx.LookupType.PREFER_DECLARATION);
            if (owner != null && PsiUtilEx.isLanguageAnnotationTarget(owner)) {
                final PsiAnnotation[] annotations = AnnotationUtilEx.getAnnotationFrom(owner, configuration.getAdvancedConfiguration().getPatternAnnotationPair(), true);
                if (annotations.length > 0) {
                    final String pattern = AnnotationUtilEx.calcAnnotationValue(annotations, "value");
                    if (pattern != null) {
                        return new PsiReference[] { new RegExpEnumReference(expression, pattern) };
                    }
                }
            }
            return PsiReference.EMPTY_ARRAY;
        }
    });
}
Also used : ProcessingContext(com.intellij.util.ProcessingContext) Configuration(org.intellij.plugins.intelliLang.Configuration) PatternCondition(com.intellij.patterns.PatternCondition) NotNull(org.jetbrains.annotations.NotNull)

Example 8 with Configuration

use of org.intellij.plugins.intelliLang.Configuration in project intellij-community by JetBrains.

the class XmlLanguageInjectionSupport method removeInjection.

@Override
public boolean removeInjection(PsiElement host) {
    final Project project = host.getProject();
    final Configuration configuration = Configuration.getProjectInstance(project);
    final ArrayList<BaseInjection> injections = collectInjections(host, configuration);
    if (injections.isEmpty())
        return false;
    final ArrayList<BaseInjection> newInjections = new ArrayList<>();
    for (BaseInjection injection : injections) {
        final BaseInjection newInjection = injection.copy();
        newInjection.setPlaceEnabled(null, false);
        if (InjectorUtils.canBeRemoved(newInjection))
            continue;
        newInjections.add(newInjection);
    }
    configuration.replaceInjectionsWithUndo(project, newInjections, injections, Collections.<PsiElement>emptyList());
    return true;
}
Also used : Project(com.intellij.openapi.project.Project) Configuration(org.intellij.plugins.intelliLang.Configuration) ArrayList(java.util.ArrayList)

Example 9 with Configuration

use of org.intellij.plugins.intelliLang.Configuration in project intellij-community by JetBrains.

the class XmlLanguageInjectionSupport method doEditInjection.

private static void doEditInjection(final Project project, final XmlTagInjection template) {
    final Configuration configuration = InjectorUtils.getEditableInstance(project);
    final AbstractTagInjection originalInjection = (AbstractTagInjection) configuration.findExistingInjection(template);
    final XmlTagInjection newInjection = originalInjection == null ? template : new XmlTagInjection().copyFrom(originalInjection);
    configuration.replaceInjectionsWithUndo(project, Collections.singletonList(newInjection), ContainerUtil.createMaybeSingletonList(originalInjection), Collections.<PsiElement>emptyList());
}
Also used : Configuration(org.intellij.plugins.intelliLang.Configuration)

Example 10 with Configuration

use of org.intellij.plugins.intelliLang.Configuration in project intellij-community by JetBrains.

the class GrLanguageReferenceProvider method registerReferenceProviders.

@Override
public void registerReferenceProviders(@NotNull PsiReferenceRegistrar registrar) {
    final Configuration configuration = Configuration.getInstance();
    registrar.registerReferenceProvider(GroovyPatterns.groovyLiteralExpression().annotationParam(StandardPatterns.string().with(isLanguageAnnotation(configuration)), "value").and(GroovyPatterns.groovyLiteralExpression().with(isStringLiteral())), new PsiReferenceProvider() {

        @NotNull
        @Override
        public PsiReference[] getReferencesByElement(@NotNull final PsiElement element, @NotNull final ProcessingContext context) {
            return new PsiReference[] { new LanguageReference((PsiLiteral) element) };
        }
    });
}
Also used : LanguageReference(org.intellij.plugins.intelliLang.inject.java.LanguageReference) ProcessingContext(com.intellij.util.ProcessingContext) Configuration(org.intellij.plugins.intelliLang.Configuration) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

Configuration (org.intellij.plugins.intelliLang.Configuration)11 Project (com.intellij.openapi.project.Project)5 BaseInjection (org.intellij.plugins.intelliLang.inject.config.BaseInjection)4 NotNull (org.jetbrains.annotations.NotNull)4 Pair (com.intellij.openapi.util.Pair)3 MethodParameterInjection (org.intellij.plugins.intelliLang.inject.config.MethodParameterInjection)3 Language (com.intellij.lang.Language)2 Result (com.intellij.openapi.application.Result)2 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)2 com.intellij.psi (com.intellij.psi)2 ProcessingContext (com.intellij.util.ProcessingContext)2 ContainerUtil (com.intellij.util.containers.ContainerUtil)2 ArrayList (java.util.ArrayList)2 AbstractLanguageInjectionSupport (org.intellij.plugins.intelliLang.inject.AbstractLanguageInjectionSupport)2 InjectorUtils (org.intellij.plugins.intelliLang.inject.InjectorUtils)2 NonNls (org.jetbrains.annotations.NonNls)2 Nullable (org.jetbrains.annotations.Nullable)2 AnnotationUtil (com.intellij.codeInsight.AnnotationUtil)1 MultiHostRegistrar (com.intellij.lang.injection.MultiHostRegistrar)1 AnAction (com.intellij.openapi.actionSystem.AnAction)1