Search in sources :

Example 1 with JSNewExpression

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

the class AddImportECMAScriptClassOrFunctionAction method getCandidates.

private Collection<JSQualifiedNamedElement> getCandidates(Editor editor, PsiFile file) {
    final Collection<JSQualifiedNamedElement> candidates;
    if (myReference instanceof JSReferenceExpression && ((JSReferenceExpression) myReference).getQualifier() == null) {
        Collection<JSQualifiedNamedElement> c = getCandidates(editor, file, myReference.getCanonicalText());
        filterCandidates(c);
        candidates = new THashSet<>(c, JSPsiImplUtils.QUALIFIED_NAME_HASHING_STRATEGY);
    } else {
        JSQualifiedNamedElement invalidResult = null;
        for (ResolveResult r : myReference.multiResolve(false)) {
            PsiElement element = r.getElement();
            if (element instanceof JSQualifiedNamedElement) {
                invalidResult = (JSQualifiedNamedElement) element;
            }
        }
        if (invalidResult != null) {
            if (myReference.getElement().getParent() instanceof JSNewExpression && invalidResult instanceof JSFunction && ((JSFunction) invalidResult).isConstructor()) {
                invalidResult = (JSClass) invalidResult.getParent();
            }
            candidates = new SmartList<>();
            candidates.add(invalidResult);
        } else {
            candidates = Collections.emptyList();
        }
    }
    return candidates;
}
Also used : JSReferenceExpression(com.intellij.lang.javascript.psi.JSReferenceExpression) JSFunction(com.intellij.lang.javascript.psi.JSFunction) JSQualifiedNamedElement(com.intellij.lang.javascript.psi.ecmal4.JSQualifiedNamedElement) JSNewExpression(com.intellij.lang.javascript.psi.JSNewExpression)

Aggregations

JSFunction (com.intellij.lang.javascript.psi.JSFunction)1 JSNewExpression (com.intellij.lang.javascript.psi.JSNewExpression)1 JSReferenceExpression (com.intellij.lang.javascript.psi.JSReferenceExpression)1 JSQualifiedNamedElement (com.intellij.lang.javascript.psi.ecmal4.JSQualifiedNamedElement)1