Search in sources :

Example 1 with MacroNameVisitor

use of ool.intellij.plugin.psi.visitor.MacroNameVisitor in project oxy-template-support-plugin by mutant-industries.

the class OxyTemplateHelper method getUsedJsMacros.

@NotNull
public static Map<PsiElement, JSElement> getUsedJsMacros(@NotNull PsiFile psiFile) {
    final Map<PsiElement, JSElement> usedMacros = new HashMap<>();
    new MacroNameVisitor() {

        @Override
        public void visitMacroName(@NotNull MacroName macroName) {
            PsiElement reference;
            if (macroName.getReference() != null && (reference = macroName.getReference().resolve()) != null && OxyTemplateIndexUtil.getJsMacroNameReferences(macroName.getName(), macroName.getProject()).size() > 0) {
                usedMacros.put(macroName, (JSElement) reference);
            }
        }
    }.visitFile(psiFile);
    new JSRecursiveElementVisitor() {

        @Override
        public void visitJSCallExpression(@NotNull JSCallExpression node) {
            if (node.getFirstChild() instanceof JSReferenceExpression) {
                JSReferenceExpression referenceExpression = (JSReferenceExpression) node.getFirstChild();
                PsiElement reference;
                if (referenceExpression.getReference() != null && (reference = referenceExpression.getReference().resolve()) != null && reference instanceof JSProperty && OxyTemplateIndexUtil.isMacro(reference)) {
                    usedMacros.put(referenceExpression, (JSElement) reference);
                }
            }
            super.visitJSCallExpression(node);
        }
    }.visitFile(psiFile.getViewProvider().getPsi(OxyTemplateInnerJs.INSTANCE));
    return usedMacros;
}
Also used : JSReferenceExpression(com.intellij.lang.javascript.psi.JSReferenceExpression) HashMap(java.util.HashMap) JSElement(com.intellij.lang.javascript.psi.JSElement) JSCallExpression(com.intellij.lang.javascript.psi.JSCallExpression) MacroNameVisitor(ool.intellij.plugin.psi.visitor.MacroNameVisitor) JSProperty(com.intellij.lang.javascript.psi.JSProperty) PsiElement(com.intellij.psi.PsiElement) JSRecursiveElementVisitor(com.intellij.lang.javascript.psi.JSRecursiveElementVisitor) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

JSCallExpression (com.intellij.lang.javascript.psi.JSCallExpression)1 JSElement (com.intellij.lang.javascript.psi.JSElement)1 JSProperty (com.intellij.lang.javascript.psi.JSProperty)1 JSRecursiveElementVisitor (com.intellij.lang.javascript.psi.JSRecursiveElementVisitor)1 JSReferenceExpression (com.intellij.lang.javascript.psi.JSReferenceExpression)1 PsiElement (com.intellij.psi.PsiElement)1 HashMap (java.util.HashMap)1 MacroNameVisitor (ool.intellij.plugin.psi.visitor.MacroNameVisitor)1 NotNull (org.jetbrains.annotations.NotNull)1