Search in sources :

Example 1 with JSCallExpression

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

the class AngularModulesProvider method getDependencies.

@Override
public List<Link> getDependencies(@NotNull PsiFile file) {
    final Project project = file.getProject();
    if (!AngularIndexUtil.hasAngularJS(project))
        return null;
    if (!(file instanceof JSFile))
        return null;
    final SmartPointerManager spm = SmartPointerManager.getInstance(project);
    final List<Link> result = new ArrayList<>();
    final CommonProcessors.CollectProcessor<String> processor = new CommonProcessors.CollectProcessor<>();
    final GlobalSearchScope fileScope = GlobalSearchScope.fileScope(file);
    final int fileId = FileBasedIndex.getFileId(file.getVirtualFile());
    StubIndex.getInstance().processAllKeys(AngularModuleIndex.KEY, processor, fileScope, new IdFilter() {

        @Override
        public boolean containsFileId(int id) {
            return id == fileId;
        }
    });
    for (String key : processor.getResults()) {
        AngularIndexUtil.multiResolve(project, AngularModuleIndex.KEY, key, element -> {
            if (!file.equals(element.getContainingFile()))
                return true;
            final JSCallExpression expression = PsiTreeUtil.getParentOfType(element, JSCallExpression.class);
            if (expression != null) {
                final List<String> dependencies = AngularModuleIndex.findDependenciesInModuleDeclaration(expression);
                if (dependencies != null) {
                    for (String dependency : dependencies) {
                        final JSImplicitElement resolve = AngularIndexUtil.resolve(project, AngularModuleIndex.KEY, dependency);
                        if (resolve != null) {
                            result.add(new Link(spm.createSmartPsiElementPointer(element.getNavigationElement()), spm.createSmartPsiElementPointer(resolve.getNavigationElement()), key, resolve.getName(), AngularJSIcons.AngularJS));
                        }
                    }
                }
            }
            return true;
        });
    }
    return result;
}
Also used : IdFilter(com.intellij.util.indexing.IdFilter) JSCallExpression(com.intellij.lang.javascript.psi.JSCallExpression) ArrayList(java.util.ArrayList) Project(com.intellij.openapi.project.Project) SmartPointerManager(com.intellij.psi.SmartPointerManager) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) JSFile(com.intellij.lang.javascript.psi.JSFile) CommonProcessors(com.intellij.util.CommonProcessors) JSImplicitElement(com.intellij.lang.javascript.psi.stubs.JSImplicitElement)

Example 2 with JSCallExpression

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

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

the class JsTestDriverTestCaseWithoutTestsInspection method createVisitor.

@NotNull
@Override
protected PsiElementVisitor createVisitor(ProblemsHolder holder, LocalInspectionToolSession session) {
    JSFile jsFile = ObjectUtils.tryCast(holder.getFile(), JSFile.class);
    if (jsFile == null) {
        return JSElementVisitor.NOP_ELEMENT_VISITOR;
    }
    Project project = holder.getProject();
    if (!ApplicationManager.getApplication().isUnitTestMode()) {
        if (!JstdSettingsUtil.areJstdConfigFilesInProjectCached(project)) {
            return JSElementVisitor.NOP_ELEMENT_VISITOR;
        }
    }
    VirtualFile virtualFile = jsFile.getVirtualFile();
    if (virtualFile != null) {
        boolean inScope = JstdLibraryUtil.isFileInJstdLibScope(project, virtualFile);
        if (!inScope) {
            return JSElementVisitor.NOP_ELEMENT_VISITOR;
        }
    }
    JstdTestFileStructure testFileStructure = JstdTestFileStructureBuilder.getInstance().fetchCachedTestFileStructure(jsFile);
    for (JstdTestCaseStructure structure : testFileStructure.getTestCaseStructures()) {
        if (structure.getTestCount() == 0) {
            JSCallExpression callExpression = structure.getEnclosingCallExpression();
            if (callExpression.isValid()) {
                JSReferenceExpression methodExpression = ObjectUtils.tryCast(callExpression.getMethodExpression(), JSReferenceExpression.class);
                if (methodExpression != null) {
                    int startOffset = methodExpression.getStartOffsetInParent();
                    TextRange rangeInElement = TextRange.create(startOffset, startOffset + methodExpression.getTextLength());
                    holder.registerProblem(callExpression, "TestCase has no tests. Tests names should have 'test' prefix.", ProblemHighlightType.GENERIC_ERROR_OR_WARNING, rangeInElement, LocalQuickFix.EMPTY_ARRAY);
                }
            }
        }
    }
    return JSElementVisitor.NOP_ELEMENT_VISITOR;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) 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) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with JSCallExpression

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

the class JstdAssertionFrameworkLineMarkerProvider method getQUnitLineMarkerInfo.

@Nullable
private static LineMarkerInfo getQUnitLineMarkerInfo(@NotNull JSFile jsFile, @NotNull PsiElement element) {
    QUnitFileStructure qunitFileStructure = QUnitFileStructureBuilder.getInstance().fetchCachedTestFileStructure(jsFile);
    if (element instanceof JSCallExpression) {
        JSCallExpression callExpression = (JSCallExpression) element;
        String testElementName = qunitFileStructure.getNameByPsiElement(callExpression);
        if (testElementName == null) {
            return null;
        }
        return createLineMarkerFromElement(element, testElementName);
    }
    return null;
}
Also used : JSCallExpression(com.intellij.lang.javascript.psi.JSCallExpression) QUnitFileStructure(com.intellij.javascript.testFramework.qunit.QUnitFileStructure) Nullable(org.jetbrains.annotations.Nullable)

Example 5 with JSCallExpression

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

the class JstdGenerateNewTestAction method buildGenerator.

@Nullable
private static Runnable buildGenerator(@NotNull JstdTestFileStructure fileStructure, @NotNull GenerateActionContext context) {
    int caretOffset = context.getDocumentCaretOffset();
    JstdTestCaseStructure jstdTestCaseStructure = fileStructure.findEnclosingTestCaseByOffset(caretOffset);
    if (jstdTestCaseStructure != null) {
        JSObjectLiteralExpression testsObjectLiteral = jstdTestCaseStructure.getTestsObjectsLiteral();
        if (testsObjectLiteral != null) {
            return new TestGeneratorOnObjectLiteral(testsObjectLiteral, context);
        } else {
            if (jstdTestCaseStructure.getTestCount() == 0) {
                JSCallExpression callExpression = jstdTestCaseStructure.getEnclosingCallExpression();
                JSArgumentList argumentList = callExpression.getArgumentList();
                JSExpression[] arguments = JsPsiUtils.getArguments(argumentList);
                if (arguments.length == 1 && arguments[0] != null) {
                    return new TestGeneratorOnNewlyCreatedObjectLiteral(argumentList, context);
                }
            }
        }
    } else {
        for (JstdTestCaseStructure testCaseStructure : fileStructure.getTestCaseStructures()) {
            JSObjectLiteralExpression testsObjectLiteral = testCaseStructure.getTestsObjectsLiteral();
            if (testsObjectLiteral != null && JsPsiUtils.containsOffsetStrictly(testsObjectLiteral.getTextRange(), caretOffset)) {
                return new TestGeneratorOnObjectLiteral(testsObjectLiteral, context);
            }
        }
    }
    return null;
}
Also used : JSCallExpression(com.intellij.lang.javascript.psi.JSCallExpression) JSArgumentList(com.intellij.lang.javascript.psi.JSArgumentList) JstdTestCaseStructure(com.google.jstestdriver.idea.assertFramework.jstd.JstdTestCaseStructure) JSObjectLiteralExpression(com.intellij.lang.javascript.psi.JSObjectLiteralExpression) JSExpression(com.intellij.lang.javascript.psi.JSExpression) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

JSCallExpression (com.intellij.lang.javascript.psi.JSCallExpression)7 JSFile (com.intellij.lang.javascript.psi.JSFile)3 JSReferenceExpression (com.intellij.lang.javascript.psi.JSReferenceExpression)3 Project (com.intellij.openapi.project.Project)3 Nullable (org.jetbrains.annotations.Nullable)3 JSExpression (com.intellij.lang.javascript.psi.JSExpression)2 TextRange (com.intellij.openapi.util.TextRange)2 NotNull (org.jetbrains.annotations.NotNull)2 JstdTestCaseStructure (com.google.jstestdriver.idea.assertFramework.jstd.JstdTestCaseStructure)1 QUnitFileStructure (com.intellij.javascript.testFramework.qunit.QUnitFileStructure)1 JSArgumentList (com.intellij.lang.javascript.psi.JSArgumentList)1 JSElementVisitor (com.intellij.lang.javascript.psi.JSElementVisitor)1 JSExpressionStatement (com.intellij.lang.javascript.psi.JSExpressionStatement)1 JSObjectLiteralExpression (com.intellij.lang.javascript.psi.JSObjectLiteralExpression)1 JSTextReference (com.intellij.lang.javascript.psi.impl.JSTextReference)1 JSImplicitElement (com.intellij.lang.javascript.psi.stubs.JSImplicitElement)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 PsiElement (com.intellij.psi.PsiElement)1 SmartPointerManager (com.intellij.psi.SmartPointerManager)1 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)1