@JSTestOptions({JSTestOption.WithFlexFacet, JSTestOption.WithLineMarkers})
  public void testLineMarkersInSwf() throws Exception {
    myAfterCommitRunnable =
        () ->
            FlexTestUtils.addLibrary(
                myModule,
                "lib",
                getTestDataPath() + getBasePath() + "/",
                getTestName(false) + ".swc",
                null,
                null);
    configureByFiles((String) null);
    VirtualFile vFile =
        LocalFileSystem.getInstance()
            .findFileByPath(getTestDataPath() + getBasePath() + "/" + getTestName(false) + ".swc");
    vFile = JarFileSystem.getInstance().getJarRootForLocalFile(vFile).findChild("library.swf");
    myEditor =
        FileEditorManager.getInstance(myProject)
            .openTextEditor(new OpenFileDescriptor(myProject, vFile, 0), false);
    PsiDocumentManager.getInstance(getProject()).commitAllDocuments();

    myFile = myPsiManager.findFile(vFile);
    ((EditorImpl) myEditor).setCaretActive();

    vFile =
        LocalFileSystem.getInstance()
            .findFileByPath(getTestDataPath() + getBasePath() + "/" + getTestName(false) + ".as");
    myFile = myPsiManager.findFile(vFile);
    checkHighlighting(
        new ExpectedHighlightingData(
            new DocumentImpl(StreamUtil.convertSeparators(VfsUtil.loadText(vFile))),
            false,
            false,
            true,
            myFile));
  }
예제 #2
0
  public static VirtualFile[] configureByFiles(
      @Nullable VirtualFile rawProjectRoot,
      VirtualFile[] files,
      @Nullable VirtualFile[] auxiliaryFiles,
      Module module,
      @Nullable
          TripleFunction<ModifiableRootModel, VirtualFile, List<String>, Void> moduleInitializer)
      throws Exception {
    return WriteAction.compute(
        () -> {
          VirtualFile dummyRoot = VirtualFileManager.getInstance().findFileByUrl("temp:///");
          //noinspection ConstantConditions
          dummyRoot.refresh(false, false);
          final VirtualFile sourceDir = dummyRoot.createChildDirectory(DesignerTests.class, "s");
          assert sourceDir != null;

          final IndexableFileSet indexableFileSet =
              new IndexableFileSet() {
                @Override
                public boolean isInSet(@NotNull final VirtualFile file) {
                  return file.getFileSystem() == sourceDir.getFileSystem();
                }

                @Override
                public void iterateIndexableFilesIn(
                    @NotNull final VirtualFile file, @NotNull final ContentIterator iterator) {
                  if (file.isDirectory()) {
                    for (VirtualFile child : file.getChildren()) {
                      iterateIndexableFilesIn(child, iterator);
                    }
                  } else {
                    iterator.processFile(file);
                  }
                }
              };
          FileBasedIndex.getInstance().registerIndexableSet(indexableFileSet, module.getProject());

          Disposer.register(
              module,
              new Disposable() {
                @Override
                public void dispose() {
                  FileBasedIndex.getInstance().removeIndexableSet(indexableFileSet);
                  ApplicationManager.getApplication()
                      .runWriteAction(
                          () -> {
                            try {
                              sourceDir.delete(null);
                            } catch (IOException e) {
                              throw new RuntimeException(e);
                            }
                          });
                }
              });

          final ModifiableRootModel rootModel =
              ModuleRootManager.getInstance(module).getModifiableModel();

          VirtualFile[] toFiles = copyFiles(files, sourceDir, rawProjectRoot);
          if (auxiliaryFiles != null) {
            copyFiles(auxiliaryFiles, sourceDir, rawProjectRoot);
          }

          rootModel.addContentEntry(sourceDir).addSourceFolder(sourceDir, false);
          final List<String> libs = new ArrayList<>();
          if (moduleInitializer != null) {
            moduleInitializer.fun(rootModel, sourceDir, libs);
          }
          rootModel.commit();

          for (String path : libs) {
            VirtualFile virtualFile = path.charAt(0) != '/' ? getFile("lib", path) : getFile(path);
            FlexTestUtils.addLibrary(
                module, path, virtualFile.getParent().getPath(), virtualFile.getName(), null, null);
          }
          return toFiles;
        });
  }