Search in sources :

Example 1 with GrLiteralContainer

use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.literals.GrLiteralContainer in project intellij-community by JetBrains.

the class GroovyLanguageInjectionSupport method removeInjectionInPlace.

@Override
public boolean removeInjectionInPlace(@Nullable final PsiLanguageInjectionHost psiElement) {
    if (!isStringLiteral(psiElement))
        return false;
    GrLiteralContainer host = (GrLiteralContainer) psiElement;
    final HashMap<BaseInjection, Pair<PsiMethod, Integer>> injectionsMap = ContainerUtil.newHashMap();
    final ArrayList<PsiElement> annotations = new ArrayList<>();
    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 = JavaLanguageInjectionSupport.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) GrLiteralImpl(org.jetbrains.plugins.groovy.lang.psi.impl.statements.expressions.literals.GrLiteralImpl) IElementType(com.intellij.psi.tree.IElementType) GrStringContent(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.literals.GrStringContent) NonNls(org.jetbrains.annotations.NonNls) GrArgumentList(org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList) HashMap(java.util.HashMap) GrLiteral(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.literals.GrLiteral) ContainerUtil(com.intellij.util.containers.ContainerUtil) ControlFlowUtils(org.jetbrains.plugins.groovy.codeInspection.utils.ControlFlowUtils) ArrayList(java.util.ArrayList) GrOpenBlock(org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrOpenBlock) GrReturnStatement(org.jetbrains.plugins.groovy.lang.psi.api.statements.branch.GrReturnStatement) BaseInjection(org.intellij.plugins.intelliLang.inject.config.BaseInjection) GrListOrMap(org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.GrListOrMap) TokenSets(org.jetbrains.plugins.groovy.lang.lexer.TokenSets) Project(com.intellij.openapi.project.Project) GroovyPsiElement(org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement) GrLiteralContainer(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.literals.GrLiteralContainer) AbstractLanguageInjectionSupport(org.intellij.plugins.intelliLang.inject.AbstractLanguageInjectionSupport) InjectorUtils(org.intellij.plugins.intelliLang.inject.InjectorUtils) GrAnnotationNameValuePair(org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.annotation.GrAnnotationNameValuePair) NullableFunction(com.intellij.util.NullableFunction) LightElement(com.intellij.psi.impl.light.LightElement) Nullable(org.jetbrains.annotations.Nullable) Contract(org.jetbrains.annotations.Contract) GrAnnotationArrayInitializer(org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.annotation.GrAnnotationArrayInitializer) List(java.util.List) Configuration(org.intellij.plugins.intelliLang.Configuration) GrControlFlowOwner(org.jetbrains.plugins.groovy.lang.psi.GrControlFlowOwner) Processor(com.intellij.util.Processor) org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions) Pair(com.intellij.openapi.util.Pair) GrMethod(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod) LanguageInjectionSupport(org.intellij.plugins.intelliLang.inject.LanguageInjectionSupport) com.intellij.psi(com.intellij.psi) JavaLanguageInjectionSupport(org.intellij.plugins.intelliLang.inject.java.JavaLanguageInjectionSupport) GrString(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.literals.GrString) NotNull(org.jetbrains.annotations.NotNull) GroovyPatterns(org.jetbrains.plugins.groovy.lang.psi.patterns.GroovyPatterns) Configuration(org.intellij.plugins.intelliLang.Configuration) ArrayList(java.util.ArrayList) GrString(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.literals.GrString) BaseInjection(org.intellij.plugins.intelliLang.inject.config.BaseInjection) Project(com.intellij.openapi.project.Project) GrLiteralContainer(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.literals.GrLiteralContainer) GroovyPsiElement(org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement) GrAnnotationNameValuePair(org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.annotation.GrAnnotationNameValuePair) Pair(com.intellij.openapi.util.Pair)

Aggregations

Language (com.intellij.lang.Language)1 Project (com.intellij.openapi.project.Project)1 Pair (com.intellij.openapi.util.Pair)1 com.intellij.psi (com.intellij.psi)1 LightElement (com.intellij.psi.impl.light.LightElement)1 IElementType (com.intellij.psi.tree.IElementType)1 NullableFunction (com.intellij.util.NullableFunction)1 Processor (com.intellij.util.Processor)1 ContainerUtil (com.intellij.util.containers.ContainerUtil)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Configuration (org.intellij.plugins.intelliLang.Configuration)1 AbstractLanguageInjectionSupport (org.intellij.plugins.intelliLang.inject.AbstractLanguageInjectionSupport)1 InjectorUtils (org.intellij.plugins.intelliLang.inject.InjectorUtils)1 LanguageInjectionSupport (org.intellij.plugins.intelliLang.inject.LanguageInjectionSupport)1 BaseInjection (org.intellij.plugins.intelliLang.inject.config.BaseInjection)1 JavaLanguageInjectionSupport (org.intellij.plugins.intelliLang.inject.java.JavaLanguageInjectionSupport)1 Contract (org.jetbrains.annotations.Contract)1 NonNls (org.jetbrains.annotations.NonNls)1