use of com.intellij.lang.injection.ConcatenationAwareInjector in project intellij-community by JetBrains.
the class JavaConcatenationInjectorManager method doCompute.
private static MultiHostRegistrarImpl doCompute(@NotNull PsiFile containingFile, @NotNull Project project, @NotNull PsiElement anchor, @NotNull PsiElement[] operands) {
MultiHostRegistrarImpl registrar = new MultiHostRegistrarImpl(project, containingFile, anchor);
JavaConcatenationInjectorManager concatenationInjectorManager = getInstance(project);
for (ConcatenationAwareInjector concatenationInjector : concatenationInjectorManager.myConcatenationInjectors) {
concatenationInjector.getLanguagesToInject(registrar, operands);
if (registrar.getResult() != null)
break;
}
if (registrar.getResult() == null) {
registrar = null;
}
return registrar;
}
use of com.intellij.lang.injection.ConcatenationAwareInjector in project intellij-community by JetBrains.
the class MyTestInjector method registerForStringVarInitializer.
private static void registerForStringVarInitializer(@NotNull Disposable parent, @NotNull final Project project, final Language language, @NotNull @NonNls final String varName, @NonNls final String prefix, @NonNls final String suffix) {
if (language == null)
return;
final ConcatenationAwareInjector injector = new ConcatenationAwareInjector() {
@Override
public void getLanguagesToInject(@NotNull MultiHostRegistrar injectionPlacesRegistrar, @NotNull PsiElement... operands) {
PsiVariable variable = PsiTreeUtil.getParentOfType(operands[0], PsiVariable.class);
if (variable == null)
return;
if (!varName.equals(variable.getName()))
return;
if (!(operands[0] instanceof PsiLiteralExpression))
return;
boolean started = false;
String prefixFromPrev = "";
for (int i = 0; i < operands.length; i++) {
PsiElement operand = operands[i];
if (!(operand instanceof PsiLiteralExpression)) {
continue;
}
Object value = ((PsiLiteralExpression) operand).getValue();
if (!(value instanceof String)) {
prefixFromPrev += value;
continue;
}
TextRange textRange = textRangeToInject((PsiLanguageInjectionHost) operand);
if (!started) {
injectionPlacesRegistrar.startInjecting(language);
started = true;
}
injectionPlacesRegistrar.addPlace(prefixFromPrev + (i == 0 ? "" : prefix == null ? "" : prefix), i == operands.length - 1 ? null : suffix, (PsiLanguageInjectionHost) operand, textRange);
prefixFromPrev = "";
}
if (started) {
injectionPlacesRegistrar.doneInjecting();
}
}
};
final JavaConcatenationInjectorManager injectorManager = JavaConcatenationInjectorManager.getInstance(project);
injectorManager.registerConcatenationInjector(injector);
Disposer.register(parent, new Disposable() {
@Override
public void dispose() {
boolean b = injectorManager.unregisterConcatenationInjector(injector);
assert b;
}
});
}
use of com.intellij.lang.injection.ConcatenationAwareInjector in project intellij-community by JetBrains.
the class MyTestInjector method registerForParameterValue.
private static void registerForParameterValue(Disposable parent, final Project project, final Language language, final String paramName) {
if (language == null)
return;
final ConcatenationAwareInjector injector = new ConcatenationAwareInjector() {
@Override
public void getLanguagesToInject(@NotNull MultiHostRegistrar injectionPlacesRegistrar, @NotNull PsiElement... operands) {
PsiElement operand = operands[0];
if (!(operand instanceof PsiLiteralExpression))
return;
if (!(operand.getParent() instanceof PsiExpressionList))
return;
PsiExpressionList expressionList = (PsiExpressionList) operand.getParent();
int i = ArrayUtil.indexOf(expressionList.getExpressions(), operand);
if (!(operand.getParent().getParent() instanceof PsiMethodCallExpression))
return;
PsiMethodCallExpression methodCallExpression = (PsiMethodCallExpression) operand.getParent().getParent();
PsiMethod method = methodCallExpression.resolveMethod();
if (method == null)
return;
PsiParameter[] parameters = method.getParameterList().getParameters();
if (i >= parameters.length)
return;
PsiParameter parameter = parameters[i];
if (!paramName.equals(parameter.getName()))
return;
TextRange textRange = textRangeToInject((PsiLanguageInjectionHost) operand);
injectionPlacesRegistrar.startInjecting(language).addPlace(null, null, (PsiLanguageInjectionHost) operand, textRange).doneInjecting();
}
};
final JavaConcatenationInjectorManager injectorManager = JavaConcatenationInjectorManager.getInstance(project);
injectorManager.registerConcatenationInjector(injector);
Disposer.register(parent, new Disposable() {
@Override
public void dispose() {
boolean b = injectorManager.unregisterConcatenationInjector(injector);
assert b;
}
});
}
Aggregations