Search in sources :

Example 1 with JSDefinitionExpression

use of com.intellij.lang.javascript.psi.JSDefinitionExpression in project oxy-template-support-plugin by mutant-industries.

the class InnerJsReferenceExpressionResolver method superResolveInPsiClassModified.

/**
 * modified supertype method, fixes the following issue: https://youtrack.jetbrains.com/issue/IDEA-138078
 *
 * @param aClass
 * @param isStatic
 * @return
 */
@NotNull
private List<ResolveResult> superResolveInPsiClassModified(PsiClass aClass, boolean isStatic) {
    SmartList<ResolveResult> results = new SmartList<>();
    Object candidates;
    Object field;
    if (myParent instanceof JSCallExpression) {
        candidates = aClass.findMethodsByName(myReferencedName, true);
    } else {
        field = aClass.findInnerClassByName(myReferencedName, true);
        if (field == null) {
            boolean inDefinitionExpr = myParent instanceof JSDefinitionExpression;
            String prefix = inDefinitionExpr ? "set" : "get";
            String candidate = prefix + StringUtil.capitalize(myReferencedName);
            PsiMethod[] hasStaticModifier = aClass.findMethodsByName(candidate, true);
            PsiMethod[] resolveProblem = hasStaticModifier;
            int resolveResult = hasStaticModifier.length;
            for (int i$1 = 0; i$1 < resolveResult; ++i$1) {
                PsiMethod accessor = resolveProblem[i$1];
                int parametersCount = accessor.getParameterList().getParametersCount();
                if (parametersCount == (inDefinitionExpr ? 1 : 0)) {
                    field = accessor;
                    break;
                }
            }
            if (field == null && !inDefinitionExpr) {
                prefix = "is";
                candidate = prefix + StringUtil.capitalize(myReferencedName);
                hasStaticModifier = aClass.findMethodsByName(candidate, true);
                resolveProblem = hasStaticModifier;
                resolveResult = hasStaticModifier.length;
                for (int i$1 = 0; i$1 < resolveResult; ++i$1) {
                    PsiMethod accessor = resolveProblem[i$1];
                    int parametersCount = accessor.getParameterList().getParametersCount();
                    if (parametersCount == 0) {
                        field = accessor;
                        break;
                    }
                }
            }
        }
        if (field == null) {
            field = aClass.findFieldByName(myReferencedName, true);
        }
        candidates = field != null ? new PsiModifierListOwner[] { (PsiModifierListOwner) field } : PsiMember.EMPTY_ARRAY;
    }
    int candidatesLength = ((Object[]) candidates).length;
    for (int var16 = 0; var16 < candidatesLength; ++var16) {
        Object var17 = ((Object[]) candidates)[var16];
        boolean var18 = ((PsiModifierListOwner) var17).hasModifierProperty("static");
        String var19 = isStatic && !var18 ? "javascript.instance.member.is.not.accessible.message" : (!((PsiModifierListOwner) var17).hasModifierProperty("public") ? "javascript.element.is.not.accessible.message" : null);
        JSResolveResult var20 = var19 == null ? new JSResolveResult((PsiElement) var17) : new JSResolveResult((PsiElement) var17, null, var19);
        results.add(var20);
    }
    return results;
}
Also used : PsiMethod(com.intellij.psi.PsiMethod) JSCallExpression(com.intellij.lang.javascript.psi.JSCallExpression) JSResolveResult(com.intellij.lang.javascript.psi.resolve.JSResolveResult) PsiModifierListOwner(com.intellij.psi.PsiModifierListOwner) JSDefinitionExpression(com.intellij.lang.javascript.psi.JSDefinitionExpression) SmartList(com.intellij.util.SmartList) JSTaggedResolveResult(com.intellij.lang.javascript.psi.resolve.JSTaggedResolveResult) JSResolveResult(com.intellij.lang.javascript.psi.resolve.JSResolveResult) ResolveResult(com.intellij.psi.ResolveResult) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with JSDefinitionExpression

use of com.intellij.lang.javascript.psi.JSDefinitionExpression in project intellij-plugins by JetBrains.

the class AngularJSReferenceExpressionResolver method resolve.

@NotNull
@Override
public ResolveResult[] resolve(@NotNull JSReferenceExpressionImpl expression, boolean incompleteCode) {
    if (myReferencedName == null)
        return ResolveResult.EMPTY_ARRAY;
    if (myRef.getParent() instanceof JSDefinitionExpression) {
        final PsiElement sibling = PsiTreeUtil.prevVisibleLeaf(myRef);
        if (sibling != null && sibling.getNode().getElementType() == JSTokenTypes.LET_KEYWORD) {
            return new JSResolveResult[] { new JSResolveResult(myRef) };
        }
        final AngularJSRepeatExpression repeat = PsiTreeUtil.getParentOfType(myRef, AngularJSRepeatExpression.class);
        if (repeat != null) {
            for (JSDefinitionExpression def : repeat.getDefinitions()) {
                if (PsiTreeUtil.isAncestor(def, myRef, true))
                    return new JSResolveResult[] { new JSResolveResult(myRef) };
            }
        }
        final AngularJSAsExpression as = PsiTreeUtil.getParentOfType(myRef, AngularJSAsExpression.class);
        if (as != null) {
            if (PsiTreeUtil.isAncestor(as.getDefinition(), myRef, true))
                return new JSResolveResult[] { new JSResolveResult(myRef) };
        }
        JSClass clazz = myRef.getQualifier() == null ? AngularJS2IndexingHandler.findDirectiveClass(myRef) : null;
        if (clazz != null && DialectDetector.isTypeScript(clazz)) {
            final TypeScriptResolveProcessor localProcessor = new TypeScriptResolveProcessor(myReferencedName, myContainingFile, myRef, incompleteCode);
            localProcessor.setToProcessHierarchy(true);
            JSReferenceExpressionImpl.doProcessLocalDeclarations(clazz, myQualifier, localProcessor, false, false, null);
            return localProcessor.getResultsAsResolveResults();
        }
    }
    if (AngularJSAsExpression.isAsControllerRef(myRef, myRef.getParent())) {
        final PsiElement resolve = AngularIndexUtil.resolve(myParent.getProject(), AngularControllerIndex.KEY, myReferencedName);
        if (resolve != null) {
            return new JSResolveResult[] { new JSResolveResult(resolve) };
        }
    } else if (AngularJSFilterExpression.isFilterNameRef(myRef, myParent)) {
        final PsiElement resolve = AngularIndexUtil.resolve(myParent.getProject(), AngularFilterIndex.KEY, myReferencedName);
        if (resolve != null) {
            return new JSResolveResult[] { new JSResolveResult(resolve) };
        }
    } else if (myQualifier == null) {
        final Collection<JSPsiElementBase> localVariables = getItemsByName(myReferencedName, myRef);
        if (!localVariables.isEmpty()) {
            return ContainerUtil.map2Array(localVariables, JSResolveResult.class, item -> new JSResolveResult(item));
        }
    }
    return super.resolve(expression, incompleteCode);
}
Also used : JSPsiElementBase(com.intellij.lang.javascript.psi.JSPsiElementBase) AngularJSRepeatExpression(org.angularjs.lang.psi.AngularJSRepeatExpression) JSDefinitionExpression(com.intellij.lang.javascript.psi.JSDefinitionExpression) JSResolveResult(com.intellij.lang.javascript.psi.resolve.JSResolveResult) TypeScriptResolveProcessor(com.intellij.lang.javascript.ecmascript6.TypeScriptResolveProcessor) JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass) PsiElement(com.intellij.psi.PsiElement) AngularJSAsExpression(org.angularjs.lang.psi.AngularJSAsExpression) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with JSDefinitionExpression

use of com.intellij.lang.javascript.psi.JSDefinitionExpression in project intellij-plugins by JetBrains.

the class JstdTestFileStructure method postProcess.

void postProcess() {
    myNameByPsiElementMap = Collections.emptyMap();
    myPrototypeBasedTestElements = Collections.emptyMap();
    if (myTestCaseStructures.isEmpty()) {
        return;
    }
    int totalCount = 0;
    int prototypeBasedTestCount = 0;
    for (JstdTestCaseStructure testCaseStructure : myTestCaseStructures) {
        totalCount += testCaseStructure.getTestCount() + 1;
        for (JstdTestStructure testStructure : testCaseStructure.getTestStructures()) {
            if (testStructure.getWholeLeftDefExpr() != null) {
                prototypeBasedTestCount++;
            }
        }
    }
    myNameByPsiElementMap = new IdentityHashMap<>(totalCount);
    if (prototypeBasedTestCount > 0) {
        myPrototypeBasedTestElements = new IdentityHashMap<>(prototypeBasedTestCount);
    }
    for (JstdTestCaseStructure testCaseStructure : myTestCaseStructures) {
        JSExpression testCaseMethodExpr = testCaseStructure.getEnclosingCallExpression().getMethodExpression();
        if (testCaseMethodExpr != null) {
            myNameByPsiElementMap.put(testCaseMethodExpr, testCaseStructure.getName());
        }
        for (JstdTestStructure testStructure : testCaseStructure.getTestStructures()) {
            PsiElement anchor = testStructure.getTestMethodNameDeclaration();
            myNameByPsiElementMap.put(anchor, testStructure.getName());
            JSDefinitionExpression wholeLeftDefExpr = testStructure.getWholeLeftDefExpr();
            if (wholeLeftDefExpr != null) {
                myPrototypeBasedTestElements.put(wholeLeftDefExpr, null);
            }
        }
    }
}
Also used : JSDefinitionExpression(com.intellij.lang.javascript.psi.JSDefinitionExpression) JSExpression(com.intellij.lang.javascript.psi.JSExpression) PsiElement(com.intellij.psi.PsiElement)

Example 4 with JSDefinitionExpression

use of com.intellij.lang.javascript.psi.JSDefinitionExpression in project oxy-template-support-plugin by mutant-industries.

the class JsMacroNameDataIndexer method map.

@Override
@NotNull
public Map<String, JsMacroNameIndexedElement> map(@NotNull final FileContent inputData) {
    PsiFile jsFile = inputData.getPsiFile().getViewProvider().getPsi(OxyTemplateInnerJs.INSTANCE);
    Map<String, JsMacroNameIndexedElement> result = new HashMap<>();
    for (PsiElement psiElement : jsFile.getChildren()) {
        if (psiElement instanceof JSExpressionStatement && (psiElement = PsiTreeUtil.getChildOfAnyType(psiElement, JSAssignmentExpression.class)) != null && psiElement.getFirstChild() instanceof JSDefinitionExpression) {
            String rootNamespace = psiElement.getFirstChild().getText().replace(MACRO_REGISTRY_NAMESPACE + ".", "");
            boolean firstIteration = true;
            for (JSReferenceExpression ref : PsiTreeUtil.findChildrenOfType(psiElement.getFirstChild(), JSReferenceExpression.class)) {
                String namespace = ref.getText().replace(MACRO_REGISTRY_NAMESPACE + ".", "");
                if (!namespace.equals(DEFAULT_NAMESPACE) && !namespace.equals(MACRO_REGISTRY_NAMESPACE)) {
                    result.put(ref.getText().replace(MACRO_REGISTRY_NAMESPACE + ".", ""), new JsMacroNameIndexedElement(firstIteration && psiElement.getLastChild() instanceof JSFunctionExpression, ref.getTextOffset() + ref.getTextLength() - 1));
                }
                firstIteration = false;
            }
            if (psiElement.getLastChild() instanceof JSObjectLiteralExpression) {
                processObjectLiteralExpression((JSObjectLiteralExpression) psiElement.getLastChild(), rootNamespace, result);
            }
        }
    }
    return result;
}
Also used : HashMap(java.util.HashMap) JSFunctionExpression(com.intellij.lang.javascript.psi.JSFunctionExpression) JSReferenceExpression(com.intellij.lang.javascript.psi.JSReferenceExpression) JSDefinitionExpression(com.intellij.lang.javascript.psi.JSDefinitionExpression) PsiFile(com.intellij.psi.PsiFile) JSObjectLiteralExpression(com.intellij.lang.javascript.psi.JSObjectLiteralExpression) PsiElement(com.intellij.psi.PsiElement) JSExpressionStatement(com.intellij.lang.javascript.psi.JSExpressionStatement) JSAssignmentExpression(com.intellij.lang.javascript.psi.JSAssignmentExpression) NotNull(org.jetbrains.annotations.NotNull)

Example 5 with JSDefinitionExpression

use of com.intellij.lang.javascript.psi.JSDefinitionExpression in project oxy-template-support-plugin by mutant-industries.

the class MacroIndex method isInMacroDefinition.

public static boolean isInMacroDefinition(@NotNull JSReferenceExpression expression) {
    String referenceText = expression.getText();
    JSReferenceExpression topReference = !(expression.getParent() instanceof JSReferenceExpression) ? expression : PsiTreeUtil.getTopmostParentOfType(expression, JSReferenceExpression.class);
    return topReference != null && topReference.getParent() instanceof JSDefinitionExpression && !MacroIndex.isMacroRootNamespace(referenceText, true);
}
Also used : JSReferenceExpression(com.intellij.lang.javascript.psi.JSReferenceExpression) JSDefinitionExpression(com.intellij.lang.javascript.psi.JSDefinitionExpression)

Aggregations

JSDefinitionExpression (com.intellij.lang.javascript.psi.JSDefinitionExpression)5 PsiElement (com.intellij.psi.PsiElement)4 NotNull (org.jetbrains.annotations.NotNull)3 JSReferenceExpression (com.intellij.lang.javascript.psi.JSReferenceExpression)2 JSResolveResult (com.intellij.lang.javascript.psi.resolve.JSResolveResult)2 TypeScriptResolveProcessor (com.intellij.lang.javascript.ecmascript6.TypeScriptResolveProcessor)1 JSAssignmentExpression (com.intellij.lang.javascript.psi.JSAssignmentExpression)1 JSCallExpression (com.intellij.lang.javascript.psi.JSCallExpression)1 JSExpression (com.intellij.lang.javascript.psi.JSExpression)1 JSExpressionStatement (com.intellij.lang.javascript.psi.JSExpressionStatement)1 JSFunctionExpression (com.intellij.lang.javascript.psi.JSFunctionExpression)1 JSObjectLiteralExpression (com.intellij.lang.javascript.psi.JSObjectLiteralExpression)1 JSPsiElementBase (com.intellij.lang.javascript.psi.JSPsiElementBase)1 JSClass (com.intellij.lang.javascript.psi.ecmal4.JSClass)1 JSTaggedResolveResult (com.intellij.lang.javascript.psi.resolve.JSTaggedResolveResult)1 PsiFile (com.intellij.psi.PsiFile)1 PsiMethod (com.intellij.psi.PsiMethod)1 PsiModifierListOwner (com.intellij.psi.PsiModifierListOwner)1 ResolveResult (com.intellij.psi.ResolveResult)1 SmartList (com.intellij.util.SmartList)1