Search in sources :

Example 1 with JSImportStatement

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

the class FlexRenameTest method testRenameClassTwoTimes.

public void testRenameClassTwoTimes() throws Exception {
    final String name = getTestName(false);
    VirtualFile file = getVirtualFile(getBasePath() + name + "/mytest/foo/" + name + "_2.js2");
    VirtualFile[] files = { getVirtualFile(getBasePath() + name + "/mytest/boo/" + name + ".js2"), file };
    configureByFiles(new File(getTestDataPath() + getBasePath() + name), files);
    int referencesCount = findRenamedRefsToReferencedElementAtCaret().length;
    performAction(name + "_3", true);
    checkResultByFile(getBasePath() + name + "_after.js2");
    assertEquals(referencesCount, findRenamedRefsToReferencedElementAtCaret().length);
    performAction(name + "_4", true);
    checkResultByFile(getBasePath() + name + "_after2.js2");
    PsiReference[] refs = findRenamedRefsToReferencedElementAtCaret();
    assertEquals(referencesCount, refs.length);
    for (PsiReference ref : refs) {
        PsiElement refElement = ref.getElement();
        PsiElement refElementParent = refElement.getParent();
        assertFalse(refElementParent instanceof JSReferenceExpression);
        if (!(refElementParent instanceof JSImportStatement)) {
            assertEquals(name + "_4", refElement.getText());
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) JSReferenceExpression(com.intellij.lang.javascript.psi.JSReferenceExpression) JSImportStatement(com.intellij.lang.javascript.psi.ecmal4.JSImportStatement) PsiReference(com.intellij.psi.PsiReference) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) PsiElement(com.intellij.psi.PsiElement)

Example 2 with JSImportStatement

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

the class ActionScriptCompletionKeywordsContributor method process.

@Override
public boolean process(KeywordCompletionConsumer consumer, PsiElement context) {
    if (JSCompletionContributor.getInstance().isDoingSmartCodeCompleteAction())
        return false;
    final PsiElement parent = context.getParent();
    final PsiElement grandParent = parent != null ? parent.getParent() : null;
    final PsiElement grandGrandParent = grandParent != null ? grandParent.getParent() : null;
    if (parent instanceof JSReferenceExpression && ((JSReferenceExpression) parent).getQualifier() == null && (JSResolveUtil.isExprInTypeContext((JSReferenceExpression) parent) || grandParent instanceof JSExpressionStatement && (JSResolveUtil.isPlaceWhereNsCanBe(grandParent) || grandGrandParent instanceof JSFile && grandGrandParent.getContext() == null) || grandParent instanceof JSAttributeList || parent instanceof JSAttributeNameValuePair)) {
        if (!(grandParent instanceof JSImportStatement) && (grandParent instanceof JSAttributeList || JSResolveUtil.isPlaceWhereNsCanBe(grandParent) || grandGrandParent instanceof JSFile) && (!(grandParent instanceof JSFunction) || ((JSFunction) grandParent).getReturnTypeElement() != parent)) {
            consumer.consume(JSLookupPriority.SMART_KEYWORDS_PRIORITY, true, accessModifiers);
            consumer.consume(JSLookupPriority.SMART_KEYWORDS_PRIORITY, true, "class", "function", "interface", "namespace", "package", "extends", "implements", "import", "override", "static", "dynamic", "var", "const", "use", "final");
        }
        return false;
    }
    if (JSResolveUtil.isInPlaceWhereTypeCanBeDuringCompletion(parent) && JSResolveUtil.isPlaceWhereNsCanBe(grandParent)) {
        consumer.consume(JSLookupPriority.KEYWORDS_PRIORITY, false, JSKeywordsCompletionProvider.TYPE_LITERAL_VALUES);
        consumer.consume(JSLookupPriority.KEYWORDS_PRIORITY, false, "function");
        consumer.consume(JSLookupPriority.KEYWORDS_PRIORITY, true, accessModifiers);
        consumer.consume(JSLookupPriority.KEYWORDS_PRIORITY, true, "extends", "implements", "include", "import", "static", "override", "namespace", "class", "interface", "var", "use");
        return false;
    }
    return true;
}
Also used : JSAttributeList(com.intellij.lang.javascript.psi.ecmal4.JSAttributeList) JSReferenceExpression(com.intellij.lang.javascript.psi.JSReferenceExpression) JSFunction(com.intellij.lang.javascript.psi.JSFunction) JSImportStatement(com.intellij.lang.javascript.psi.ecmal4.JSImportStatement) JSAttributeNameValuePair(com.intellij.lang.javascript.psi.ecmal4.JSAttributeNameValuePair) JSFile(com.intellij.lang.javascript.psi.JSFile) PsiElement(com.intellij.psi.PsiElement) JSExpressionStatement(com.intellij.lang.javascript.psi.JSExpressionStatement)

Example 3 with JSImportStatement

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

the class ActionScriptReferenceExpressionResolver method resolve.

@NotNull
@Override
public ResolveResult[] resolve(@NotNull JSReferenceExpressionImpl expression, boolean incompleteCode) {
    if (myReferencedName == null)
        return ResolveResult.EMPTY_ARRAY;
    PsiElement currentParent = JSResolveUtil.getTopReferenceParent(myParent);
    if (JSResolveUtil.isSelfReference(currentParent, myRef)) {
        if (!(currentParent instanceof JSPackageStatement) || myParent == currentParent) {
            return new ResolveResult[] { new JSResolveResult(currentParent) };
        }
    }
    if (isConditionalVariableReference(currentParent, myRef)) {
        if (ModuleUtilCore.findModuleForPsiElement(myRef) == null) {
            // do not red highlight conditional compiler definitions in 3rd party library/SDK source code
            return new ResolveResult[] { new JSResolveResult(myRef) };
        } else {
            return resolveConditionalCompilationVariable(myRef);
        }
    }
    if (myRef.isAttributeReference()) {
        return dummyResult(myRef);
    }
    if (JSCommonTypeNames.ANY_TYPE.equals(myReferencedName)) {
        if (currentParent instanceof JSImportStatement && myQualifier instanceof JSReferenceExpression)
            return ((JSReferenceExpression) myQualifier).multiResolve(false);
        if (myParent instanceof JSE4XNamespaceReference)
            return dummyResult(myRef);
    }
    // nonqualified items in implements list in mxml
    if (myParent instanceof JSReferenceListMember && myParent.getParent().getNode().getElementType() == JSStubElementTypes.IMPLEMENTS_LIST && myRef.getQualifier() == null && myContainingFile instanceof JSFile && XmlBackedJSClassImpl.isImplementsAttribute((JSFile) myContainingFile)) {
        PsiElement byQName = ActionScriptClassResolver.findClassByQNameStatic(myRef.getText(), myRef);
        // for some reason Flex compiler allows to implement non-public interface in default package, so let's not check access type here
        if (byQName != null)
            return new ResolveResult[] { new JSResolveResult(byQName) };
        return ResolveResult.EMPTY_ARRAY;
    }
    SinkResolveProcessor<ResolveResultSink> localProcessor;
    if (myLocalResolve) {
        final PsiElement topParent = JSResolveUtil.getTopReferenceParent(myParent);
        localProcessor = new SinkResolveProcessor<ResolveResultSink>(myReferencedName, myRef, new ResolveResultSink(myRef, myReferencedName)) {

            @Override
            public boolean needPackages() {
                if (myParent instanceof JSReferenceExpression && topParent instanceof JSImportStatement) {
                    return true;
                }
                return super.needPackages();
            }
        };
        localProcessor.setToProcessHierarchy(true);
        JSReferenceExpressionImpl.doProcessLocalDeclarations(myRef, myQualifier, localProcessor, true, false, null);
        PsiElement jsElement = localProcessor.getResult();
        if (myQualifier instanceof JSThisExpression && localProcessor.processingEncounteredAnyTypeAccess() && // this is from ecma script closure, proceed it in JavaScript way
        jsElement != null) {
            localProcessor.getResults().clear();
            jsElement = null;
        }
        if (myQualifier == null) {
            final JSReferenceExpression namespaceReference = JSReferenceExpressionImpl.getNamespaceReference(myRef);
            ResolveResult[] resolveResultsAsConditionalCompilationVariable = null;
            if (namespaceReference != null && (namespaceReference == myRef || namespaceReference.resolve() == namespaceReference)) {
                if (jsElement == null && ModuleUtilCore.findModuleForPsiElement(myRef) == null) {
                    // do not red highlight conditional compiler definitions in 3rd party library/SDK source code
                    return new ResolveResult[] { new JSResolveResult(myRef) };
                }
                resolveResultsAsConditionalCompilationVariable = resolveConditionalCompilationVariable(myRef);
            }
            if (resolveResultsAsConditionalCompilationVariable != null && resolveResultsAsConditionalCompilationVariable.length > 0 && (jsElement == null || resolveResultsAsConditionalCompilationVariable[0].isValidResult())) {
                return resolveResultsAsConditionalCompilationVariable;
            }
        }
        if (jsElement != null || localProcessor.isEncounteredDynamicClasses() && myQualifier == null || !localProcessor.processingEncounteredAnyTypeAccess() && !localProcessor.isEncounteredDynamicClasses()) {
            return localProcessor.getResultsAsResolveResults();
        }
    } else {
        final QualifiedItemProcessor<ResolveResultSink> processor = new QualifiedItemProcessor<>(new ResolveResultSink(myRef, myReferencedName), myContainingFile);
        processor.setTypeContext(JSResolveUtil.isExprInTypeContext(myRef));
        JSTypeEvaluator.evaluateTypes(myQualifier, myContainingFile, processor);
        if (processor.resolved == QualifiedItemProcessor.TypeResolveState.PrefixUnknown) {
            return dummyResult(myRef);
        }
        if (processor.resolved == QualifiedItemProcessor.TypeResolveState.Resolved || processor.resolved == QualifiedItemProcessor.TypeResolveState.Undefined || processor.getResult() != null) {
            return processor.getResultsAsResolveResults();
        } else {
            localProcessor = processor;
        }
    }
    ResolveResult[] results = resolveFromIndices(localProcessor);
    if (results.length == 0 && localProcessor.isEncounteredXmlLiteral()) {
        return dummyResult(myRef);
    }
    return results;
}
Also used : JSPackageStatement(com.intellij.lang.javascript.psi.ecmal4.JSPackageStatement) JSE4XNamespaceReference(com.intellij.lang.javascript.psi.e4x.JSE4XNamespaceReference) JSReferenceListMember(com.intellij.lang.javascript.psi.ecmal4.JSReferenceListMember) JSImportStatement(com.intellij.lang.javascript.psi.ecmal4.JSImportStatement) ResolveResult(com.intellij.psi.ResolveResult) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

JSImportStatement (com.intellij.lang.javascript.psi.ecmal4.JSImportStatement)3 PsiElement (com.intellij.psi.PsiElement)3 JSReferenceExpression (com.intellij.lang.javascript.psi.JSReferenceExpression)2 JSExpressionStatement (com.intellij.lang.javascript.psi.JSExpressionStatement)1 JSFile (com.intellij.lang.javascript.psi.JSFile)1 JSFunction (com.intellij.lang.javascript.psi.JSFunction)1 JSE4XNamespaceReference (com.intellij.lang.javascript.psi.e4x.JSE4XNamespaceReference)1 JSAttributeList (com.intellij.lang.javascript.psi.ecmal4.JSAttributeList)1 JSAttributeNameValuePair (com.intellij.lang.javascript.psi.ecmal4.JSAttributeNameValuePair)1 JSPackageStatement (com.intellij.lang.javascript.psi.ecmal4.JSPackageStatement)1 JSReferenceListMember (com.intellij.lang.javascript.psi.ecmal4.JSReferenceListMember)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 PsiReference (com.intellij.psi.PsiReference)1 ResolveResult (com.intellij.psi.ResolveResult)1 File (java.io.File)1 NotNull (org.jetbrains.annotations.NotNull)1