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