Search in sources :

Example 1 with QUnitFileStructureBuilder

use of com.intellij.javascript.testFramework.qunit.QUnitFileStructureBuilder in project intellij-plugins by JetBrains.

the class KarmaTestLocationProvider method findQUnitElement.

@Nullable
private static PsiElement findQUnitElement(Project project, @NotNull String moduleName, @Nullable String testName) {
    String key = JsTestFileByTestNameIndex.createQUnitKey(moduleName, testName);
    GlobalSearchScope scope = GlobalSearchScope.projectScope(project);
    List<VirtualFile> jsTestVirtualFiles = JsTestFileByTestNameIndex.findJsTestFilesByNameInScope(key, scope);
    QUnitFileStructureBuilder builder = QUnitFileStructureBuilder.getInstance();
    for (VirtualFile file : jsTestVirtualFiles) {
        PsiFile psiFile = PsiManager.getInstance(project).findFile(file);
        if (psiFile instanceof JSFile) {
            QUnitFileStructure qunitFileStructure = builder.fetchCachedTestFileStructure((JSFile) psiFile);
            PsiElement element = qunitFileStructure.findPsiElement(moduleName, testName);
            if (element != null && element.isValid()) {
                return element;
            }
        }
    }
    return null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) PsiFile(com.intellij.psi.PsiFile) JSFile(com.intellij.lang.javascript.psi.JSFile) QUnitFileStructure(com.intellij.javascript.testFramework.qunit.QUnitFileStructure) PsiElement(com.intellij.psi.PsiElement) QUnitFileStructureBuilder(com.intellij.javascript.testFramework.qunit.QUnitFileStructureBuilder) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with QUnitFileStructureBuilder

use of com.intellij.javascript.testFramework.qunit.QUnitFileStructureBuilder in project intellij-plugins by JetBrains.

the class JstdTestLocationProvider method findTestFromQUnitDefaultModule.

@Nullable
private static PsiElement findTestFromQUnitDefaultModule(@NotNull Project project, @NotNull String testMethodName) {
    GlobalSearchScope scope = GlobalSearchScope.projectScope(project);
    testMethodName = StringUtil.trimStart(testMethodName, "test ");
    String key = JsTestFileByTestNameIndex.createQUnitKeyForTestFromDefaultModule(testMethodName);
    List<VirtualFile> jsTestVirtualFiles = JsTestFileByTestNameIndex.findJsTestFilesByNameInScope(key, scope);
    List<VirtualFile> validJsTestVirtualFiles = filterVirtualFiles(jsTestVirtualFiles);
    for (VirtualFile jsTestVirtualFile : validJsTestVirtualFiles) {
        PsiFile psiFile = PsiManager.getInstance(project).findFile(jsTestVirtualFile);
        if (psiFile instanceof JSFile) {
            JSFile jsFile = (JSFile) psiFile;
            QUnitFileStructureBuilder builder = QUnitFileStructureBuilder.getInstance();
            QUnitFileStructure qunitFileStructure = builder.fetchCachedTestFileStructure(jsFile);
            PsiElement element = qunitFileStructure.findPsiElement(DefaultQUnitModuleStructure.NAME, testMethodName);
            if (element != null && element.isValid()) {
                return element;
            }
        }
    }
    return null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) PsiFile(com.intellij.psi.PsiFile) JSFile(com.intellij.lang.javascript.psi.JSFile) QUnitFileStructure(com.intellij.javascript.testFramework.qunit.QUnitFileStructure) PsiElement(com.intellij.psi.PsiElement) QUnitFileStructureBuilder(com.intellij.javascript.testFramework.qunit.QUnitFileStructureBuilder) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

QUnitFileStructure (com.intellij.javascript.testFramework.qunit.QUnitFileStructure)2 QUnitFileStructureBuilder (com.intellij.javascript.testFramework.qunit.QUnitFileStructureBuilder)2 JSFile (com.intellij.lang.javascript.psi.JSFile)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 PsiElement (com.intellij.psi.PsiElement)2 PsiFile (com.intellij.psi.PsiFile)2 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)2 Nullable (org.jetbrains.annotations.Nullable)2