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