Search in sources :

Example 1 with MacroReferenceSet

use of ool.intellij.plugin.psi.reference.MacroReferenceSet 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;
        }
    });
}
Also used : ProcessingContext(com.intellij.util.ProcessingContext) MacroReferenceSet(ool.intellij.plugin.psi.reference.MacroReferenceSet) PsiExpression(com.intellij.psi.PsiExpression) PsiReferenceExpression(com.intellij.psi.PsiReferenceExpression) NotNull(org.jetbrains.annotations.NotNull) PsiNewExpression(com.intellij.psi.PsiNewExpression) PsiMethodCallExpression(com.intellij.psi.PsiMethodCallExpression) PsiLiteralExpression(com.intellij.psi.PsiLiteralExpression) PsiReferenceProvider(com.intellij.psi.PsiReferenceProvider) PsiNewExpressionImpl(com.intellij.psi.impl.source.tree.java.PsiNewExpressionImpl) PsiElement(com.intellij.psi.PsiElement)

Aggregations

PsiElement (com.intellij.psi.PsiElement)1 PsiExpression (com.intellij.psi.PsiExpression)1 PsiLiteralExpression (com.intellij.psi.PsiLiteralExpression)1 PsiMethodCallExpression (com.intellij.psi.PsiMethodCallExpression)1 PsiNewExpression (com.intellij.psi.PsiNewExpression)1 PsiReferenceExpression (com.intellij.psi.PsiReferenceExpression)1 PsiReferenceProvider (com.intellij.psi.PsiReferenceProvider)1 PsiNewExpressionImpl (com.intellij.psi.impl.source.tree.java.PsiNewExpressionImpl)1 ProcessingContext (com.intellij.util.ProcessingContext)1 MacroReferenceSet (ool.intellij.plugin.psi.reference.MacroReferenceSet)1 NotNull (org.jetbrains.annotations.NotNull)1