Search in sources :

Example 6 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 7 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)

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