Search in sources :

Example 16 with JSFile

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

the class AbstractMethodBasedInspection method createVisitor.

@NotNull
@Override
protected final JSElementVisitor createVisitor(final ProblemsHolder holder, LocalInspectionToolSession session) {
    if (holder == null) {
        return JSElementVisitor.NOP_ELEMENT_VISITOR;
    }
    Project project = holder.getProject();
    if (!ApplicationManager.getApplication().isUnitTestMode()) {
        if (!JstdSettingsUtil.areJstdConfigFilesInProjectCached(project)) {
            return JSElementVisitor.NOP_ELEMENT_VISITOR;
        }
    }
    return new JSElementVisitor() {

        @Override
        public void visitJSCallExpression(final JSCallExpression jsCallExpression) {
            JSFile jsFile = null;
            if (jsCallExpression != null) {
                jsFile = ObjectUtils.tryCast(jsCallExpression.getContainingFile(), JSFile.class);
            }
            if (jsFile == null) {
                return;
            }
            JSReferenceExpression methodExpression = ObjectUtils.tryCast(jsCallExpression.getMethodExpression(), JSReferenceExpression.class);
            if (methodExpression == null) {
                return;
            }
            boolean suitableSymbol = isSuitableElement(jsFile, jsCallExpression);
            if (suitableSymbol) {
                boolean resolved = isResolved(methodExpression);
                if (!resolved) {
                    TextRange rangeInElement = TextRange.create(0, methodExpression.getTextLength());
                    HintWrapperQuickFix fix = new HintWrapperQuickFix(methodExpression, rangeInElement, getFix());
                    holder.registerProblem(methodExpression, getProblemDescription(), ProblemHighlightType.GENERIC_ERROR_OR_WARNING, rangeInElement, fix);
                }
            }
        }
    };
}
Also used : Project(com.intellij.openapi.project.Project) JSReferenceExpression(com.intellij.lang.javascript.psi.JSReferenceExpression) JSCallExpression(com.intellij.lang.javascript.psi.JSCallExpression) TextRange(com.intellij.openapi.util.TextRange) JSFile(com.intellij.lang.javascript.psi.JSFile) JSElementVisitor(com.intellij.lang.javascript.psi.JSElementVisitor) NotNull(org.jetbrains.annotations.NotNull)

Example 17 with JSFile

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

the class JstdAssertionFrameworkLineMarkerProvider method getLineMarkerInfo.

@Override
public LineMarkerInfo getLineMarkerInfo(@NotNull PsiElement element) {
    Project project = element.getProject();
    JSFile jsFile = ObjectUtils.tryCast(element.getContainingFile(), JSFile.class);
    if (jsFile == null) {
        return null;
    }
    if (!JstdSettingsUtil.areJstdConfigFilesInProjectCached(project)) {
        return null;
    }
    LineMarkerInfo lineMarkerInfo = getJstdLineMarkerInfo(project, jsFile, element);
    if (lineMarkerInfo == null) {
        lineMarkerInfo = getQUnitLineMarkerInfo(jsFile, element);
    }
    return lineMarkerInfo;
}
Also used : Project(com.intellij.openapi.project.Project) LineMarkerInfo(com.intellij.codeInsight.daemon.LineMarkerInfo) JSFile(com.intellij.lang.javascript.psi.JSFile)

Example 18 with JSFile

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

the class JstdImplicitUsageProvider method isImplicitUsage.

@Override
public boolean isImplicitUsage(PsiElement element) {
    JSFile jsFile = ObjectUtils.tryCast(element.getContainingFile(), JSFile.class);
    if (jsFile == null) {
        return false;
    }
    VirtualFile virtualFile = jsFile.getVirtualFile();
    if (virtualFile == null) {
        return false;
    }
    boolean isInScope = JstdLibraryUtil.isFileInJstdLibScope(element.getProject(), virtualFile);
    if (!isInScope) {
        return false;
    }
    JstdTestFileStructureBuilder builder = JstdTestFileStructureBuilder.getInstance();
    JstdTestFileStructure fileStructure = builder.fetchCachedTestFileStructure(jsFile);
    return fileStructure.isPrototypeTestElement(element);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) JSFile(com.intellij.lang.javascript.psi.JSFile)

Example 19 with JSFile

use of com.intellij.lang.javascript.psi.JSFile 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 20 with JSFile

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

the class FlexCssPropertyDescriptor method getDeclarations.

@NotNull
@Override
public PsiElement[] getDeclarations(@NotNull PsiElement context) {
    Map<PsiElement, PairInfo> navElement2pairInfo = new HashMap<>();
    final Project project = context.getProject();
    GlobalSearchScope scope = FlexCssUtil.getResolveScope(context);
    Set<JSClass> visited = ContainerUtil.newLinkedHashSet();
    for (String className : myClassNames) {
        Collection<JSQualifiedNamedElement> candidates = StubIndex.getElements(JSQualifiedElementIndex.KEY, className.hashCode(), project, scope, JSQualifiedNamedElement.class);
        findStyleAttributes(candidates, visited, navElement2pairInfo);
        // search in MXML files
        PsiElement jsClass = ActionScriptClassResolver.findClassByQNameStatic(className, scope);
        if (jsClass instanceof JSClass) {
            findStyleAttributesInClassOrSuper((JSClass) jsClass, visited, navElement2pairInfo);
        }
    }
    Set<JSFile> visitedFiles = ContainerUtil.newLinkedHashSet();
    for (String fileName : myFileNames) {
        Collection<VirtualFile> files = FilenameIndex.getVirtualFilesByName(project, fileName, scope);
        for (final VirtualFile file : files) {
            PsiFile psiFile = ReadAction.compute(() -> PsiManager.getInstance(project).findFile(file));
            if (psiFile instanceof JSFile) {
                findStyleAttributesInFile((JSFile) psiFile, visitedFiles, navElement2pairInfo);
            }
        }
    }
    Set<PsiElement> navPairs = navElement2pairInfo.keySet();
    Map<String, PsiElement> qName2ResultElement = new HashMap<>();
    for (PsiElement navPair : navPairs) {
        PairInfo pairInfo = navElement2pairInfo.get(navPair);
        String jsClassQName = pairInfo.myJsClassQName;
        PsiElement navPairInOtherClassWithSameQName = jsClassQName != null ? qName2ResultElement.get(jsClassQName) : null;
        if (navPairInOtherClassWithSameQName == null || navPairInOtherClassWithSameQName == navElement2pairInfo.get(navPairInOtherClassWithSameQName) && pairInfo.myPair != navPair) {
            qName2ResultElement.put(jsClassQName, navPair);
        }
    }
    Collection<PsiElement> result = qName2ResultElement.values();
    return PsiUtilCore.toPsiElementArray(result);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) HashMap(com.intellij.util.containers.HashMap) JSQualifiedNamedElement(com.intellij.lang.javascript.psi.ecmal4.JSQualifiedNamedElement) Project(com.intellij.openapi.project.Project) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) PsiFile(com.intellij.psi.PsiFile) JSFile(com.intellij.lang.javascript.psi.JSFile) JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

JSFile (com.intellij.lang.javascript.psi.JSFile)39 PsiElement (com.intellij.psi.PsiElement)18 VirtualFile (com.intellij.openapi.vfs.VirtualFile)16 PsiFile (com.intellij.psi.PsiFile)16 Nullable (org.jetbrains.annotations.Nullable)10 XmlFile (com.intellij.psi.xml.XmlFile)9 JSReferenceExpression (com.intellij.lang.javascript.psi.JSReferenceExpression)6 TestFileStructurePack (com.intellij.javascript.testFramework.TestFileStructurePack)5 JSClass (com.intellij.lang.javascript.psi.ecmal4.JSClass)5 Project (com.intellij.openapi.project.Project)5 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)5 NotNull (org.jetbrains.annotations.NotNull)5 JSQualifiedNamedElement (com.intellij.lang.javascript.psi.ecmal4.JSQualifiedNamedElement)4 LogicalPosition (com.intellij.openapi.editor.LogicalPosition)4 TextRange (com.intellij.openapi.util.TextRange)4 PsiReference (com.intellij.psi.PsiReference)4 PsiMultiReference (com.intellij.psi.impl.source.resolve.reference.impl.PsiMultiReference)4 XmlTag (com.intellij.psi.xml.XmlTag)4 JasmineFileStructure (com.intellij.javascript.testFramework.jasmine.JasmineFileStructure)3 QUnitFileStructure (com.intellij.javascript.testFramework.qunit.QUnitFileStructure)3