protected void runTool(
      final String testDir,
      final String jdkName,
      boolean runDeadCodeFirst,
      final InspectionTool tool,
      InspectionTool... additional) {
    final VirtualFile[] sourceDir = new VirtualFile[1];
    ApplicationManager.getApplication()
        .runWriteAction(
            new Runnable() {
              @Override
              public void run() {
                try {
                  setupRootModel(testDir, sourceDir, jdkName);
                } catch (Exception e) {
                  LOG.error(e);
                }
              }
            });
    AnalysisScope scope = createAnalysisScope(sourceDir[0].getParent());

    InspectionManagerEx inspectionManager =
        (InspectionManagerEx) InspectionManager.getInstance(getProject());
    InspectionTool[] tools =
        runDeadCodeFirst
            ? new InspectionTool[] {new UnusedDeclarationInspection(), tool}
            : new InspectionTool[] {tool};
    tools = ArrayUtil.mergeArrays(tools, additional);
    final GlobalInspectionContextImpl globalContext =
        CodeInsightTestFixtureImpl.createGlobalContextForTool(
            scope, getProject(), inspectionManager, tools);

    InspectionTestUtil.runTool(tool, scope, globalContext, inspectionManager);
  }
  @NotNull
  @Override
  protected List<HighlightInfo> doHighlighting() {
    PsiDocumentManager.getInstance(myProject).commitAllDocuments();

    TIntArrayList toIgnore = new TIntArrayList();
    toIgnore.add(Pass.EXTERNAL_TOOLS);
    toIgnore.add(Pass.LOCAL_INSPECTIONS);
    toIgnore.add(Pass.WHOLE_FILE_LOCAL_INSPECTIONS);
    toIgnore.add(Pass.POPUP_HINTS);
    return CodeInsightTestFixtureImpl.instantiateAndRun(
        getFile(), getEditor(), toIgnore.toNativeArray(), false);
  }
Exemplo n.º 3
0
  public void testFileReferencesInImports() throws Exception {
    myFixture.addFileToProject(
        "pubspec.yaml",
        "name: ProjectName\n"
            + "dependencies:\n"
            + "  PathPackage:\n"
            + "    path: local_package\n");
    myFixture.addFileToProject("local_package/lib/localPackageLib1.dart", "");
    myFixture.addFileToProject("local_package/lib/src/localPackageLib2.dart", "");
    myFixture.addFileToProject(
        "packages/ProjectName/src/file0.dart", ""); // symlink to lib/src/file0.dart
    myFixture.addFileToProject("packages/ProjectName/file1.dart", ""); // symlink to lib/file1.dart
    myFixture.addFileToProject("packages/ProjectName/file2.dart", ""); // symlink to lib/file2.dart
    myFixture.addFileToProject(
        "packages/PathPackage/localPackageLib1.dart",
        ""); // symlink to local_package/lib/localPackageLib1.dart
    myFixture.addFileToProject(
        "packages/PathPackage/src/localPackageLib2.dart",
        ""); // symlink to local_package/lib/src/localPackageLib2.dart
    myFixture.addFileToProject("packages/SomePackage/somePack1.dart", "");
    myFixture.addFileToProject("packages/SomePackage/src/somePack2.dart", "");
    myFixture.addFileToProject("lib/src/file0.dart", "");
    myFixture.addFileToProject("lib/file1.dart", "");
    final PsiFile psiFile =
        myFixture.addFileToProject(
            "lib/file2.dart",
            "import '<caret expected='lib/file1.dart'>file1.dart<caret expected='lib/file1.dart'>';\n"
                + "import '<caret expected='lib'>.<caret expected='lib'>/<caret expected='lib/file1.dart'>file1.dart<caret expected='lib/file1.dart'>';\n"
                + "import '<caret expected='/src'>..<caret expected='/src'>/<caret expected='lib'>lib<caret expected='lib'>/<caret expected='lib/file1.dart'>file1.dart<caret expected='lib/file1.dart'>';\n"
                + "import '<caret expected='lib/src'>src<caret expected='lib/src'>/<caret expected='lib/src/file0.dart'>file0.dart<caret expected='lib/src/file0.dart'>';\n"
                +
                // todo not sure that DartStringLiteralExpression should be here as reference
                "import 'package:ProjectName<caret expected=''>/<caret expected='lib/src'>src<caret expected='lib/src'>/<caret expected='lib/src/file0.dart'>file0.dart<caret expected='lib/src/file0.dart'>';\n"
                + "import 'package:ProjectName<caret expected=''>/<caret expected='lib/file1.dart'>file1.dart<caret expected='lib/file1.dart'>';\n"
                + "import 'package:PathPackage<caret expected=''>/<caret expected='local_package/lib/localPackageLib1.dart'>localPackageLib1.dart<caret expected='local_package/lib/localPackageLib1.dart'>';\n"
                + "import 'package:PathPackage<caret expected=''>/<caret expected='local_package/lib/src'>src<caret expected='local_package/lib/src'>/<caret expected='local_package/lib/src/localPackageLib2.dart'>localPackageLib2.dart<caret expected='local_package/lib/src/localPackageLib2.dart'>';\n"
                + "import 'package<caret expected=''>:<caret expected='packages/SomePackage'>SomePackage<caret expected='packages/SomePackage'>/<caret expected='packages/SomePackage/somePack1.dart'>somePack1.dart<caret expected='packages/SomePackage/somePack1.dart'>';\n"
                + "import 'package<caret expected=''>:<caret expected='packages/SomePackage'>SomePackage<caret expected='packages/SomePackage'>/<caret expected='packages/SomePackage/src'>src<caret expected='packages/SomePackage/src'>/<caret expected='packages/SomePackage/src/somePack2.dart'>somePack2.dart<caret expected='packages/SomePackage/src/somePack2.dart'>';\n"
                + "");
    ((CodeInsightTestFixtureImpl) myFixture).openFileInEditor(psiFile.getVirtualFile());

    doTest();
  }
  @NotNull
  protected List<HighlightInfo> doHighlighting() {
    PsiDocumentManager.getInstance(myProject).commitAllDocuments();

    TIntArrayList toIgnore = new TIntArrayList();
    if (!doTestLineMarkers()) {
      toIgnore.add(Pass.UPDATE_OVERRIDEN_MARKERS);
      toIgnore.add(Pass.VISIBLE_LINE_MARKERS);
      toIgnore.add(Pass.LINE_MARKERS);
    }

    if (!doExternalValidation()) {
      toIgnore.add(Pass.EXTERNAL_TOOLS);
    }
    if (forceExternalValidation()) {
      toIgnore.add(Pass.LINE_MARKERS);
      toIgnore.add(Pass.LOCAL_INSPECTIONS);
      toIgnore.add(Pass.WHOLE_FILE_LOCAL_INSPECTIONS);
      toIgnore.add(Pass.POPUP_HINTS);
      toIgnore.add(Pass.UPDATE_ALL);
      toIgnore.add(Pass.UPDATE_OVERRIDEN_MARKERS);
      toIgnore.add(Pass.VISIBLE_LINE_MARKERS);
    }

    boolean canChange = canChangeDocumentDuringHighlighting();
    List<HighlightInfo> infos =
        CodeInsightTestFixtureImpl.instantiateAndRun(
            getFile(), getEditor(), toIgnore.toNativeArray(), canChange);

    if (!canChange) {
      Document document = getDocument(getFile());
      DaemonCodeAnalyzerEx daemonCodeAnalyzer = DaemonCodeAnalyzerEx.getInstanceEx(myProject);
      daemonCodeAnalyzer.getFileStatusMap().assertAllDirtyScopesAreNull(document);
    }

    return infos;
  }
  @Override
  protected void setUp() throws Exception {
    super.setUp();

    final LocalInspectionTool[] tools = configureLocalInspectionTools();

    CodeInsightTestFixtureImpl.configureInspections(
        tools, getProject(), Collections.<String>emptyList(), getTestRootDisposable());

    DaemonCodeAnalyzerImpl daemonCodeAnalyzer =
        (DaemonCodeAnalyzerImpl) DaemonCodeAnalyzer.getInstance(getProject());
    daemonCodeAnalyzer.prepareForTest();
    final StartupManagerImpl startupManager =
        (StartupManagerImpl) StartupManagerEx.getInstanceEx(getProject());
    startupManager.runStartupActivities();
    startupManager.startCacheUpdate();
    startupManager.runPostStartupActivities();
    DaemonCodeAnalyzerSettings.getInstance().setImportHintEnabled(false);

    if (isPerformanceTest()) {
      IntentionManager.getInstance()
          .getAvailableIntentionActions(); // hack to avoid slowdowns in PyExtensionFactory
      PathManagerEx.getTestDataPath(); // to cache stuff
      ReferenceProvidersRegistry.getInstance(); // pre-load tons of classes
      InjectedLanguageManager.getInstance(getProject()); // zillion of Dom Sem classes
      LanguageAnnotators.INSTANCE.allForLanguage(
          JavaLanguage.INSTANCE); // pile of annotator classes loads
      LanguageAnnotators.INSTANCE.allForLanguage(StdLanguages.XML);
      ProblemHighlightFilter.EP_NAME.getExtensions();
      Extensions.getExtensions(ImplicitUsageProvider.EP_NAME);
      Extensions.getExtensions(XmlSchemaProvider.EP_NAME);
      Extensions.getExtensions(XmlFileNSInfoProvider.EP_NAME);
      Extensions.getExtensions(ExternalAnnotatorsFilter.EXTENSION_POINT_NAME);
      Extensions.getExtensions(IndexPatternBuilder.EP_NAME);
    }
  }
 @Override
 public void setUp() throws Exception {
   super.setUp();
   DartTestUtils.configureDartSdk(myModule, getTestRootDisposable(), true);
   ((CodeInsightTestFixtureImpl) myFixture).canChangeDocumentDuringHighlighting(true);
 }