public void testContentWrite() throws Exception {
    File content = getTestRoot();
    File source = new File(content, "source");
    File testSource = new File(content, "testSource");
    File exclude = new File(content, "exclude");
    File classes = new File(content, "classes");
    File testClasses = new File(content, "testClasses");
    final VirtualFile contentFile = LocalFileSystem.getInstance().findFileByIoFile(content);
    assertNotNull(contentFile);
    final VirtualFile sourceFile = LocalFileSystem.getInstance().findFileByIoFile(source);
    assertNotNull(sourceFile);
    final VirtualFile testSourceFile = LocalFileSystem.getInstance().findFileByIoFile(testSource);
    assertNotNull(testSourceFile);
    final VirtualFile excludeFile = LocalFileSystem.getInstance().findFileByIoFile(exclude);

    assertNotNull(excludeFile);
    final VirtualFile classesFile = LocalFileSystem.getInstance().findFileByIoFile(classes);

    assertNotNull(classesFile);
    final VirtualFile testClassesFile = LocalFileSystem.getInstance().findFileByIoFile(testClasses);

    assertNotNull(testClassesFile);

    final File moduleFile = new File(content, "test.iml");
    final Module module = createModule(moduleFile);
    final ModuleRootManagerImpl moduleRootManager =
        (ModuleRootManagerImpl) ModuleRootManager.getInstance(module);

    PsiTestUtil.addContentRoot(module, contentFile);
    PsiTestUtil.addSourceRoot(module, sourceFile);
    PsiTestUtil.addSourceRoot(module, testSourceFile, true);
    ModuleRootModificationUtil.setModuleSdk(module, JavaSdkImpl.getMockJdk17());
    PsiTestUtil.addExcludedRoot(module, excludeFile);
    PsiTestUtil.setCompilerOutputPath(module, classesFile.getUrl(), false);
    PsiTestUtil.setCompilerOutputPath(module, testClassesFile.getUrl(), true);

    final Element element = new Element("root");
    moduleRootManager.getState().writeExternal(element);
    assertElementEquals(
        element,
        "<root inherit-compiler-output=\"false\">"
            + "<output url=\"file://$MODULE_DIR$/classes\" />"
            + "<output-test url=\"file://$MODULE_DIR$/testClasses\" />"
            + "<exclude-output />"
            + "<content url=\"file://$MODULE_DIR$\">"
            + "<sourceFolder url=\"file://$MODULE_DIR$/source\" isTestSource=\"false\" />"
            + "<sourceFolder url=\"file://$MODULE_DIR$/testSource\" isTestSource=\"true\" />"
            + "<excludeFolder url=\"file://$MODULE_DIR$/exclude\" />"
            + "</content>"
            + "<orderEntry type=\"jdk\" jdkName=\"java 1.7\" jdkType=\"JavaSDK\" />"
            + "<orderEntry type=\"sourceFolder\" forTests=\"false\" />"
            + "</root>",
        module);
  }
コード例 #2
0
  public void testAddSourceRoot() throws Exception {
    File dir = createTempDirectory();

    final VirtualFile root =
        LocalFileSystem.getInstance()
            .refreshAndFindFileByPath(dir.getCanonicalPath().replace(File.separatorChar, '/'));

    new WriteCommandAction.Simple(getProject()) {
      @Override
      protected void run() throws Throwable {
        PsiTestUtil.addContentRoot(myModule, root);

        VirtualFile newFile = createChildData(root, "New.java");
        setFileText(newFile, "class A{ Exception e;} //todo");
      }
    }.execute().throwException();

    PsiDocumentManager.getInstance(myProject).commitAllDocuments();

    PsiTodoSearchHelper.SERVICE
        .getInstance(myProject)
        .findFilesWithTodoItems(); // to initialize caches

    PsiTestUtil.addSourceRoot(myModule, root);

    PsiClass exceptionClass =
        myJavaFacade.findClass("java.lang.Exception", GlobalSearchScope.allScope(getProject()));
    assertNotNull(exceptionClass);
    checkUsages(exceptionClass, new String[] {"1.java", "2.java", "New.java"});
    checkTodos(new String[] {"2.java", "New.java"});
  }
コード例 #3
0
  public void testAnnotated() throws Throwable {
    PsiFile psiFile = myFixture.configureByFile("lib/p/TestAnnotated.java");
    PsiTestUtil.addSourceRoot(myModule, psiFile.getVirtualFile().getParent());
    final PsiFile file = myFixture.getFile();
    final Editor editor = myFixture.getEditor();
    assertNotAvailable("Annotate method 'get' as @NotNull");
    assertNotAvailable("Annotate method 'get' as @Nullable");

    final DeannotateIntentionAction deannotateFix = new DeannotateIntentionAction();
    assertFalse(deannotateFix.isAvailable(myProject, editor, file));
  }
コード例 #4
0
  public void testModuleConflicts() throws Exception {
    final Module module2 = doCreateRealModule("module2");
    final VirtualFile contentRoot =
        LocalFileSystem.getInstance()
            .findFileByPath(getTestDataPath() + getTestRoot() + getTestName(false) + "/module2");
    PsiTestUtil.addSourceRoot(module2, contentRoot);
    FlexTestUtils.addFlexModuleDependency(myModule, module2);

    String[] conflicts =
        new String[] {
          "Class A, referenced in method Sub.foo(A), will not be accessible in module module2"
        };
    doTestConflicts("Sub", "ISuper", DocCommentPolicy.ASIS, conflicts, "foo");
  }
コード例 #5
0
 private void doSetUpSourcePath(final String sourcePath, boolean isTestSource) throws IOException {
   final String sourceDirectoryName = isTestSource ? "test" : "src";
   final VirtualFile moduleFile = myModule.getModuleFile();
   assertNotNull(moduleFile);
   VirtualFile moduleSourceDir =
       ApplicationManager.getApplication()
           .runWriteAction(
               new ThrowableComputable<VirtualFile, IOException>() {
                 @Override
                 public VirtualFile compute() throws IOException {
                   VirtualFile moduleSourceDir =
                       VfsUtil.createDirectoryIfMissing(
                           moduleFile.getParent(), sourceDirectoryName);
                   FileUtil.copyDirContent(
                       new File(sourcePath), new File(moduleSourceDir.getPath()));
                   VfsUtil.markDirtyAndRefresh(false, true, true, moduleSourceDir);
                   return moduleSourceDir;
                 }
               });
   PsiTestUtil.addSourceRoot(myModule, moduleSourceDir, isTestSource);
 }
コード例 #6
0
 public static <P extends JpsElement> void addSourceRoot(
     Module module, final VirtualFile vDir, @NotNull final JpsModuleSourceRootType<P> rootType) {
   addSourceRoot(module, vDir, rootType, rootType.createDefaultProperties());
 }
コード例 #7
0
 public static void addSourceRoot(
     final Module module, final VirtualFile vDir, final boolean isTestSource) {
   addSourceRoot(
       module, vDir, isTestSource ? JavaSourceRootType.TEST_SOURCE : JavaSourceRootType.SOURCE);
 }
コード例 #8
0
 public static void addSourceRoot(Module module, final VirtualFile vDir) {
   addSourceRoot(module, vDir, false);
 }
コード例 #9
0
 private static void addSourcePath(Module module, String path, boolean testSource) {
   final ContentEntry entry = ModuleRootManager.getInstance(module).getContentEntries()[0];
   VirtualFile child = entry.getFile().findChild(path);
   assertNotNull(child);
   PsiTestUtil.addSourceRoot(module, child, testSource);
 }
コード例 #10
0
  public void testPrimitive() throws Throwable {
    PsiFile psiFile = myFixture.configureByFile("lib/p/TestPrimitive.java");
    PsiTestUtil.addSourceRoot(myModule, psiFile.getVirtualFile().getParent());

    assertNotAvailable("Annotate method 'get' as @NotNull");
  }