use of com.intellij.psi.PsiReferenceProvider in project oxy-template-support-plugin by mutant-industries.
the class LiteralJsMacroReferenceContributor method registerReferenceProviders.
@Override
public void registerReferenceProviders(@NotNull PsiReferenceRegistrar registrar) {
registrar.registerReferenceProvider(PlatformPatterns.psiElement(PsiLiteralExpression.class), new PsiReferenceProvider() {
@NotNull
@Override
public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull ProcessingContext context) {
PsiLiteralExpression literalExpression = (PsiLiteralExpression) element;
PsiMethodCallExpression callExpression;
PsiNewExpression newMacroCallExpression;
if (!(literalExpression.getValue() instanceof String)) {
return PsiReference.EMPTY_ARRAY;
}
if ((newMacroCallExpression = PsiTreeUtil.getParentOfType(literalExpression, PsiNewExpressionImpl.class)) != null && newMacroCallExpression.getClassReference() != null) {
if (MacroCall.class.getName().equals(newMacroCallExpression.getClassReference().getQualifiedName())) {
return new MacroReferenceSet(literalExpression).getAllReferences();
}
} else if ((callExpression = PsiTreeUtil.getParentOfType(literalExpression, PsiMethodCallExpression.class)) != null) {
PsiExpression[] parameters = callExpression.getArgumentList().getExpressions();
PsiReferenceExpression expression = callExpression.getMethodExpression();
String callText = expression.getText();
if (// TODO type check...
callText.contains("ageUpdater.update")) {
if (parameters.length > 0 && literalExpression.isEquivalentTo(parameters[0])) {
// TODO template path reference
} else if (parameters.length > 1 && literalExpression.isEquivalentTo(parameters[1])) {
return new MacroReferenceSet(literalExpression).getAllReferences();
}
}
}
return PsiReference.EMPTY_ARRAY;
}
});
}
Aggregations