Search in sources :

Example 16 with BaseInjection

use of org.intellij.plugins.intelliLang.inject.config.BaseInjection in project intellij-community by JetBrains.

the class JavaLanguageInjectionSupport method editInjectionInPlace.

public boolean editInjectionInPlace(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 BaseInjection originalInjection = injectionsMap.keySet().iterator().next();
    final MethodParameterInjection methodParameterInjection = createFrom(psiElement.getProject(), originalInjection, injectionsMap.get(originalInjection).first, false);
    final MethodParameterInjection copy = methodParameterInjection.copy();
    final BaseInjection newInjection = showInjectionUI(project, methodParameterInjection);
    if (newInjection != null) {
        newInjection.mergeOriginalPlacesFrom(copy, false);
        newInjection.mergeOriginalPlacesFrom(originalInjection, true);
        configuration.replaceInjectionsWithUndo(project, Collections.singletonList(newInjection), Collections.singletonList(originalInjection), Collections.<PsiAnnotation>emptyList());
    }
    return true;
}
Also used : Project(com.intellij.openapi.project.Project) Configuration(org.intellij.plugins.intelliLang.Configuration) MethodParameterInjection(org.intellij.plugins.intelliLang.inject.config.MethodParameterInjection) BaseInjection(org.intellij.plugins.intelliLang.inject.config.BaseInjection) Pair(com.intellij.openapi.util.Pair)

Example 17 with BaseInjection

use of org.intellij.plugins.intelliLang.inject.config.BaseInjection 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 18 with BaseInjection

use of org.intellij.plugins.intelliLang.inject.config.BaseInjection in project intellij-community by JetBrains.

the class InjectorUtils method findCommentInjection.

@Nullable
public static BaseInjection findCommentInjection(@NotNull PsiElement context, @NotNull String supportId, @Nullable Ref<PsiElement> causeRef) {
    CommentInjectionData data = findCommentInjectionData(context, causeRef);
    if (data == null)
        return null;
    BaseInjection injection = new BaseInjection(supportId);
    injection.setPrefix(data.getPrefix());
    injection.setSuffix(data.getSuffix());
    injection.setInjectedLanguageId(data.getInjectedLanguageId());
    injection.setDisplayName(data.getDisplayName());
    return injection;
}
Also used : BaseInjection(org.intellij.plugins.intelliLang.inject.config.BaseInjection) Nullable(org.jetbrains.annotations.Nullable)

Example 19 with BaseInjection

use of org.intellij.plugins.intelliLang.inject.config.BaseInjection in project intellij-community by JetBrains.

the class JavaLanguageInjectionSupport method createEditAction.

@Override
public AnAction createEditAction(final Project project, final Factory<BaseInjection> producer) {
    return new AnAction() {

        @Override
        public void actionPerformed(final AnActionEvent e) {
            final BaseInjection originalInjection = producer.create();
            final MethodParameterInjection injection = createFrom(project, originalInjection, null, false);
            if (injection != null) {
                final boolean mergeEnabled = !project.isInitialized() || JavaPsiFacade.getInstance(project).findClass(injection.getClassName(), GlobalSearchScope.allScope(project)) == null;
                final BaseInjection newInjection = showInjectionUI(project, injection);
                if (newInjection != null) {
                    newInjection.mergeOriginalPlacesFrom(originalInjection, mergeEnabled);
                    originalInjection.copyFrom(newInjection);
                }
            } else {
                createDefaultEditAction(project, producer).actionPerformed(null);
            }
        }
    };
}
Also used : MethodParameterInjection(org.intellij.plugins.intelliLang.inject.config.MethodParameterInjection) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) AnAction(com.intellij.openapi.actionSystem.AnAction) BaseInjection(org.intellij.plugins.intelliLang.inject.config.BaseInjection)

Example 20 with BaseInjection

use of org.intellij.plugins.intelliLang.inject.config.BaseInjection in project intellij-community by JetBrains.

the class JavaLanguageInjectionSupport method mergePlacesAndAddToConfiguration.

private static void mergePlacesAndAddToConfiguration(@NotNull Project project, @NotNull Configuration configuration, @NotNull MethodParameterInjection injection, @Nullable BaseInjection originalInjection) {
    BaseInjection newInjection = new BaseInjection(injection.getSupportId()).copyFrom(injection);
    if (originalInjection != null) {
        newInjection.mergeOriginalPlacesFrom(originalInjection, true);
    }
    configuration.replaceInjectionsWithUndo(project, Collections.singletonList(newInjection), ContainerUtil.createMaybeSingletonList(originalInjection), Collections.<PsiElement>emptyList());
}
Also used : 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