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;
}
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;
}
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;
}
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);
}
}
};
}
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());
}
Aggregations