Java 类com.intellij.openapi.projectRoots.impl.ProjectRootUtil 实例源码

项目:intellij-ce-playground    文件:SrcRepositoryUseTest.java   
public void testGetFields(){
  setupLoadingFilter();

  PsiDirectory root = ProjectRootUtil.getAllContentRoots(myProject) [0];
  VirtualFile child = root.getVirtualFile().findChild("pack").findChild("MyClass2.java");
  assertNotNull(child);
  PsiJavaFile file = (PsiJavaFile)myPsiManager.findFile(child);
  PsiClass[] classes = file.getClasses();
  assertEquals(1, classes.length);

  PsiClass aClass = classes[0];
  PsiField[] fields = aClass.getFields();
  assertEquals(3, fields.length);
  assertEquals(aClass, fields[0].getParent());

  teardownLoadingFilter();
}
项目:intellij-ce-playground    文件:SrcRepositoryUseTest.java   
public void testGetMethods(){
  setupLoadingFilter();

  PsiDirectory root = ProjectRootUtil.getAllContentRoots(myProject) [0];
  VirtualFile child = root.getVirtualFile().findChild("pack").findChild("MyClass2.java");
  assertNotNull(child);
  PsiJavaFile file = (PsiJavaFile)myPsiManager.findFile(child);
  PsiClass[] classes = file.getClasses();
  assertEquals(1, classes.length);

  PsiClass aClass = classes[0];
  PsiMethod[] methods = aClass.getMethods();
  assertEquals(3, methods.length);
  assertEquals(aClass, methods[0].getParent());

  teardownLoadingFilter();
}
项目:intellij-ce-playground    文件:SrcRepositoryUseTest.java   
public void testGetInnerClasses(){
  setupLoadingFilter();

  PsiDirectory root = ProjectRootUtil.getAllContentRoots(myProject) [0];
  VirtualFile child = root.getVirtualFile().findChild("pack").findChild("MyClass2.java");
  assertNotNull(child);
  PsiJavaFile file = (PsiJavaFile)myPsiManager.findFile(child);
  PsiClass[] classes = file.getClasses();
  assertEquals(1, classes.length);

  PsiClass aClass = classes[0];
  PsiClass[] inners = aClass.getInnerClasses();
  assertEquals(1, inners.length);
  assertEquals(aClass, inners[0].getParent());

  teardownLoadingFilter();
}
项目:intellij-ce-playground    文件:SrcRepositoryUseTest.java   
public void testResolveSuperClass(){
  setupLoadingFilter();

  PsiDirectory root = ProjectRootUtil.getAllContentRoots(myProject) [0];
  VirtualFile child = root.getVirtualFile().findChild("pack").findChild("MyClass2.java");
  assertNotNull(child);
  PsiJavaFile file = (PsiJavaFile)myPsiManager.findFile(child);
  PsiClass[] classes = file.getClasses();
  assertEquals(1, classes.length);

  PsiClass aClass = classes[0];
  PsiClass[] superTypes = aClass.getSupers();
  LOG.assertTrue(superTypes.length == 2);
  LOG.assertTrue(superTypes[0].getQualifiedName().equals(CommonClassNames.JAVA_LANG_STRING));
  LOG.assertTrue(superTypes[1].getQualifiedName().equals(CommonClassNames.JAVA_LANG_RUNNABLE));

  teardownLoadingFilter();
}
项目:intellij-ce-playground    文件:SrcRepositoryUseTest.java   
public void testImportList(){
  setupLoadingFilter();

  PsiDirectory root = ProjectRootUtil.getAllContentRoots(myProject) [0];
  VirtualFile child = root.getVirtualFile().findChild("MyClass1.java");
  assertNotNull(child);
  PsiJavaFile file = (PsiJavaFile)myPsiManager.findFile(child);
  PsiImportList list = file.getImportList();
  assertEquals(file, list.getParent());

  PsiImportStatement[] imports = list.getImportStatements();
  assertEquals(3, imports.length);
  assertFalse(imports[0].isOnDemand());
  assertTrue(imports[1].isOnDemand());
  imports[2].isOnDemand();

  String ref1 = imports[0].getQualifiedName();
  String ref2 = imports[1].getQualifiedName();
  String ref3 = imports[2].getQualifiedName();

  assertEquals("a.b", ref1);
  assertEquals("c", ref2);
  assertNull(ref3);

  teardownLoadingFilter();
}
项目:tools-idea    文件:SrcRepositoryUseTest.java   
public void testGetFields(){
  setupLoadingFilter();

  PsiDirectory root = ProjectRootUtil.getAllContentRoots(myProject) [0];
  VirtualFile child = root.getVirtualFile().findChild("pack").findChild("MyClass2.java");
  assertNotNull(child);
  PsiJavaFile file = (PsiJavaFile)myPsiManager.findFile(child);
  PsiClass[] classes = file.getClasses();
  assertEquals(1, classes.length);

  PsiClass aClass = classes[0];
  PsiField[] fields = aClass.getFields();
  assertEquals(3, fields.length);
  assertEquals(aClass, fields[0].getParent());

  teardownLoadingFilter();
}
项目:tools-idea    文件:SrcRepositoryUseTest.java   
public void testGetMethods(){
  setupLoadingFilter();

  PsiDirectory root = ProjectRootUtil.getAllContentRoots(myProject) [0];
  VirtualFile child = root.getVirtualFile().findChild("pack").findChild("MyClass2.java");
  assertNotNull(child);
  PsiJavaFile file = (PsiJavaFile)myPsiManager.findFile(child);
  PsiClass[] classes = file.getClasses();
  assertEquals(1, classes.length);

  PsiClass aClass = classes[0];
  PsiMethod[] methods = aClass.getMethods();
  assertEquals(3, methods.length);
  assertEquals(aClass, methods[0].getParent());

  teardownLoadingFilter();
}
项目:tools-idea    文件:SrcRepositoryUseTest.java   
public void testGetInnerClasses(){
  setupLoadingFilter();

  PsiDirectory root = ProjectRootUtil.getAllContentRoots(myProject) [0];
  VirtualFile child = root.getVirtualFile().findChild("pack").findChild("MyClass2.java");
  assertNotNull(child);
  PsiJavaFile file = (PsiJavaFile)myPsiManager.findFile(child);
  PsiClass[] classes = file.getClasses();
  assertEquals(1, classes.length);

  PsiClass aClass = classes[0];
  PsiClass[] inners = aClass.getInnerClasses();
  assertEquals(1, inners.length);
  assertEquals(aClass, inners[0].getParent());

  teardownLoadingFilter();
}
项目:tools-idea    文件:SrcRepositoryUseTest.java   
public void testResolveSuperClass(){
  setupLoadingFilter();

  PsiDirectory root = ProjectRootUtil.getAllContentRoots(myProject) [0];
  VirtualFile child = root.getVirtualFile().findChild("pack").findChild("MyClass2.java");
  assertNotNull(child);
  PsiJavaFile file = (PsiJavaFile)myPsiManager.findFile(child);
  PsiClass[] classes = file.getClasses();
  assertEquals(1, classes.length);

  PsiClass aClass = classes[0];
  PsiClass[] superTypes = aClass.getSupers();
  LOG.assertTrue(superTypes.length == 2);
  LOG.assertTrue(superTypes[0].getQualifiedName().equals(CommonClassNames.JAVA_LANG_STRING));
  LOG.assertTrue(superTypes[1].getQualifiedName().equals(CommonClassNames.JAVA_LANG_RUNNABLE));

  teardownLoadingFilter();
}
项目:tools-idea    文件:SrcRepositoryUseTest.java   
public void testImportList(){
  setupLoadingFilter();

  PsiDirectory root = ProjectRootUtil.getAllContentRoots(myProject) [0];
  VirtualFile child = root.getVirtualFile().findChild("MyClass1.java");
  assertNotNull(child);
  PsiJavaFile file = (PsiJavaFile)myPsiManager.findFile(child);
  PsiImportList list = file.getImportList();
  assertEquals(file, list.getParent());

  PsiImportStatement[] imports = list.getImportStatements();
  assertEquals(3, imports.length);
  assertFalse(imports[0].isOnDemand());
  assertTrue(imports[1].isOnDemand());
  imports[2].isOnDemand();

  String ref1 = imports[0].getQualifiedName();
  String ref2 = imports[1].getQualifiedName();
  String ref3 = imports[2].getQualifiedName();

  assertEquals("a.b", ref1);
  assertEquals("c", ref2);
  assertNull(ref3);

  teardownLoadingFilter();
}
项目:consulo-java    文件:SrcRepositoryUseTest.java   
public void testGetFields(){
  setupLoadingFilter();

  PsiDirectory root = ProjectRootUtil.getAllContentRoots(myProject) [0];
  VirtualFile child = root.getVirtualFile().findChild("pack").findChild("MyClass2.java");
  assertNotNull(child);
  PsiJavaFile file = (PsiJavaFile)myPsiManager.findFile(child);
  PsiClass[] classes = file.getClasses();
  assertEquals(1, classes.length);

  PsiClass aClass = classes[0];
  PsiField[] fields = aClass.getFields();
  assertEquals(3, fields.length);
  assertEquals(aClass, fields[0].getParent());

  teardownLoadingFilter();
}
项目:consulo-java    文件:SrcRepositoryUseTest.java   
public void testGetMethods(){
  setupLoadingFilter();

  PsiDirectory root = ProjectRootUtil.getAllContentRoots(myProject) [0];
  VirtualFile child = root.getVirtualFile().findChild("pack").findChild("MyClass2.java");
  assertNotNull(child);
  PsiJavaFile file = (PsiJavaFile)myPsiManager.findFile(child);
  PsiClass[] classes = file.getClasses();
  assertEquals(1, classes.length);

  PsiClass aClass = classes[0];
  PsiMethod[] methods = aClass.getMethods();
  assertEquals(3, methods.length);
  assertEquals(aClass, methods[0].getParent());

  teardownLoadingFilter();
}
项目:consulo-java    文件:SrcRepositoryUseTest.java   
public void testGetInnerClasses(){
  setupLoadingFilter();

  PsiDirectory root = ProjectRootUtil.getAllContentRoots(myProject) [0];
  VirtualFile child = root.getVirtualFile().findChild("pack").findChild("MyClass2.java");
  assertNotNull(child);
  PsiJavaFile file = (PsiJavaFile)myPsiManager.findFile(child);
  PsiClass[] classes = file.getClasses();
  assertEquals(1, classes.length);

  PsiClass aClass = classes[0];
  PsiClass[] inners = aClass.getInnerClasses();
  assertEquals(1, inners.length);
  assertEquals(aClass, inners[0].getParent());

  teardownLoadingFilter();
}
项目:consulo-java    文件:SrcRepositoryUseTest.java   
public void testResolveSuperClass(){
  setupLoadingFilter();

  PsiDirectory root = ProjectRootUtil.getAllContentRoots(myProject) [0];
  VirtualFile child = root.getVirtualFile().findChild("pack").findChild("MyClass2.java");
  assertNotNull(child);
  PsiJavaFile file = (PsiJavaFile)myPsiManager.findFile(child);
  PsiClass[] classes = file.getClasses();
  assertEquals(1, classes.length);

  PsiClass aClass = classes[0];
  PsiClass[] superTypes = aClass.getSupers();
  LOG.assertTrue(superTypes.length == 2);
  LOG.assertTrue(superTypes[0].getQualifiedName().equals(CommonClassNames.JAVA_LANG_STRING));
  LOG.assertTrue(superTypes[1].getQualifiedName().equals(CommonClassNames.JAVA_LANG_RUNNABLE));

  teardownLoadingFilter();
}
项目:consulo-java    文件:SrcRepositoryUseTest.java   
public void testImportList(){
  setupLoadingFilter();

  PsiDirectory root = ProjectRootUtil.getAllContentRoots(myProject) [0];
  VirtualFile child = root.getVirtualFile().findChild("MyClass1.java");
  assertNotNull(child);
  PsiJavaFile file = (PsiJavaFile)myPsiManager.findFile(child);
  PsiImportList list = file.getImportList();
  assertEquals(file, list.getParent());

  PsiImportStatement[] imports = list.getImportStatements();
  assertEquals(3, imports.length);
  assertFalse(imports[0].isOnDemand());
  assertTrue(imports[1].isOnDemand());
  imports[2].isOnDemand();

  String ref1 = imports[0].getQualifiedName();
  String ref2 = imports[1].getQualifiedName();
  String ref3 = imports[2].getQualifiedName();

  assertEquals("a.b", ref1);
  assertEquals("c", ref2);
  assertNull(ref3);

  teardownLoadingFilter();
}
项目:intellij-ce-playground    文件:SrcRepositoryUseTest.java   
public void testGetClasses(){
  setupLoadingFilter();

  PsiDirectory root = ProjectRootUtil.getAllContentRoots(myProject) [0];
  VirtualFile child = root.getVirtualFile().findChild("MyClass1.java");
  assertNotNull(child);
  PsiJavaFile file = (PsiJavaFile)myPsiManager.findFile(child);
  PsiClass[] classes = file.getClasses();
  assertEquals(2, classes.length);
  assertEquals(file, classes[0].getParent());

  teardownLoadingFilter();
}
项目:intellij-ce-playground    文件:SrcRepositoryUseTest.java   
public void testGetClassName(){
  setupLoadingFilter();

  PsiDirectory root = ProjectRootUtil.getAllContentRoots(myProject) [0];
  VirtualFile child = root.getVirtualFile().findChild("MyClass1.java");
  assertNotNull(child);
  PsiJavaFile file = (PsiJavaFile)myPsiManager.findFile(child);
  PsiClass[] classes = file.getClasses();
  assertEquals(2, classes.length);

  assertEquals("MyClass1", classes[0].getName());
  assertEquals("Class2", classes[1].getName());

  teardownLoadingFilter();
}
项目:intellij-ce-playground    文件:SrcRepositoryUseTest.java   
public void testGetClassQName(){
  setupLoadingFilter();

  PsiDirectory root = ProjectRootUtil.getAllContentRoots(myProject) [0];
  VirtualFile child = root.getVirtualFile().findChild("pack").findChild("MyClass2.java");
  assertNotNull(child);
  PsiJavaFile file = (PsiJavaFile)myPsiManager.findFile(child);
  PsiClass[] classes = file.getClasses();
  assertEquals(1, classes.length);

  assertEquals("pack.MyClass2", classes[0].getQualifiedName());

  teardownLoadingFilter();
}
项目:intellij-ce-playground    文件:SrcRepositoryUseTest.java   
public void testGetContainingFile(){
  setupLoadingFilter();

  PsiDirectory root = ProjectRootUtil.getAllContentRoots(myProject) [0];
  VirtualFile child = root.getVirtualFile().findChild("pack").findChild("MyClass2.java");
  assertNotNull(child);
  PsiJavaFile file = (PsiJavaFile)myPsiManager.findFile(child);
  PsiClass[] classes = file.getClasses();
  assertEquals(1, classes.length);

  assertEquals(file, classes[0].getContainingFile());

  teardownLoadingFilter();
}
项目:intellij-ce-playground    文件:SrcRepositoryUseTest.java   
public void testParentIdAssertOnExternalChange() throws Exception {
  PsiDirectory root = ProjectRootUtil.getAllContentRoots(myProject) [0];
  VirtualFile vFile = root.getVirtualFile().findChild("MyClass1.java");

  PsiJavaFile psiFile = (PsiJavaFile) myPsiManager.findFile(vFile);
  psiFile.getClasses();

  rewriteFileExternally(vFile, "import a . b;\n" +
                               "import c.*;\n" +
                               "import\n" +
                               "\n" +
                               "class MyClass1{\n" +
                               "  {\n" +
                               "    class Local{\n" +
                               "      public void foo(){\n" +
                               "        new Runnable(){\n" +
                               "          public void run(){\n" +
                               "            new Throwable(){\n" +
                               "            };\n" +
                               "          };\n" +
                               "        }\n" +
                               "      }\n" +
                               "    };\n" +
                               "  }\n" +
                               "}\n" +
                               "\n" +
                               "class Class2{\n" +
                               "}\n");

  PsiClass myClass = myJavaFacade.findClass("MyClass1", GlobalSearchScope.allScope(myProject));
  myClass.getChildren();
}
项目:intellij-ce-playground    文件:UpdateCacheTest.java   
public void testFileCreation() throws Exception {
  PsiDirectory root = ProjectRootUtil.getAllContentRoots(myProject) [0];

  PsiFile file = PsiFileFactory.getInstance(myProject).createFileFromText("New.java", JavaFileType.INSTANCE, "class A{ Object o;}");
  file = (PsiFile)root.add(file);
  assertNotNull(file);

  PsiClass objectClass = myJavaFacade.findClass(CommonClassNames.JAVA_LANG_OBJECT, GlobalSearchScope.allScope(getProject()));
  assertNotNull(objectClass);
  checkUsages(objectClass, new String[]{"New.java"});
}
项目:tools-idea    文件:SrcRepositoryUseTest.java   
public void testGetClasses(){
  setupLoadingFilter();

  PsiDirectory root = ProjectRootUtil.getAllContentRoots(myProject) [0];
  VirtualFile child = root.getVirtualFile().findChild("MyClass1.java");
  assertNotNull(child);
  PsiJavaFile file = (PsiJavaFile)myPsiManager.findFile(child);
  PsiClass[] classes = file.getClasses();
  assertEquals(2, classes.length);
  assertEquals(file, classes[0].getParent());

  teardownLoadingFilter();
}
项目:tools-idea    文件:SrcRepositoryUseTest.java   
public void testGetClassName(){
  setupLoadingFilter();

  PsiDirectory root = ProjectRootUtil.getAllContentRoots(myProject) [0];
  VirtualFile child = root.getVirtualFile().findChild("MyClass1.java");
  assertNotNull(child);
  PsiJavaFile file = (PsiJavaFile)myPsiManager.findFile(child);
  PsiClass[] classes = file.getClasses();
  assertEquals(2, classes.length);

  assertEquals("MyClass1", classes[0].getName());
  assertEquals("Class2", classes[1].getName());

  teardownLoadingFilter();
}
项目:tools-idea    文件:SrcRepositoryUseTest.java   
public void testGetClassQName(){
  setupLoadingFilter();

  PsiDirectory root = ProjectRootUtil.getAllContentRoots(myProject) [0];
  VirtualFile child = root.getVirtualFile().findChild("pack").findChild("MyClass2.java");
  assertNotNull(child);
  PsiJavaFile file = (PsiJavaFile)myPsiManager.findFile(child);
  PsiClass[] classes = file.getClasses();
  assertEquals(1, classes.length);

  assertEquals("pack.MyClass2", classes[0].getQualifiedName());

  teardownLoadingFilter();
}
项目:tools-idea    文件:SrcRepositoryUseTest.java   
public void testGetContainingFile(){
  setupLoadingFilter();

  PsiDirectory root = ProjectRootUtil.getAllContentRoots(myProject) [0];
  VirtualFile child = root.getVirtualFile().findChild("pack").findChild("MyClass2.java");
  assertNotNull(child);
  PsiJavaFile file = (PsiJavaFile)myPsiManager.findFile(child);
  PsiClass[] classes = file.getClasses();
  assertEquals(1, classes.length);

  assertEquals(file, classes[0].getContainingFile());

  teardownLoadingFilter();
}
项目:tools-idea    文件:SrcRepositoryUseTest.java   
public void testParentIdAssertOnExternalChange() throws Exception {
  PsiDirectory root = ProjectRootUtil.getAllContentRoots(myProject) [0];
  VirtualFile vFile = root.getVirtualFile().findChild("MyClass1.java");

  PsiJavaFile psiFile = (PsiJavaFile) myPsiManager.findFile(vFile);
  psiFile.getClasses();

  rewriteFileExternally(vFile, "import a . b;\n" +
                               "import c.*;\n" +
                               "import\n" +
                               "\n" +
                               "class MyClass1{\n" +
                               "  {\n" +
                               "    class Local{\n" +
                               "      public void foo(){\n" +
                               "        new Runnable(){\n" +
                               "          public void run(){\n" +
                               "            new Throwable(){\n" +
                               "            };\n" +
                               "          };\n" +
                               "        }\n" +
                               "      }\n" +
                               "    };\n" +
                               "  }\n" +
                               "}\n" +
                               "\n" +
                               "class Class2{\n" +
                               "}\n");

  PsiClass myClass = myJavaFacade.findClass("MyClass1", GlobalSearchScope.allScope(myProject));
  myClass.getChildren();
}
项目:tools-idea    文件:UpdateCacheTest.java   
public void testFileCreation() throws Exception {
  PsiDirectory root = ProjectRootUtil.getAllContentRoots(myProject) [0];

  PsiFile file = PsiFileFactory.getInstance(myProject).createFileFromText("New.java", JavaFileType.INSTANCE, "class A{ Object o;}");
  file = (PsiFile)root.add(file);
  assertNotNull(file);

  PsiClass objectClass = myJavaFacade.findClass(CommonClassNames.JAVA_LANG_OBJECT, GlobalSearchScope.allScope(getProject()));
  assertNotNull(objectClass);
  checkUsages(objectClass, new String[]{"New.java"});
}
项目:tools-idea    文件:Convertor34.java   
@SuppressWarnings({"HardCodedStringLiteral"})
private static void processRoot(Element root, RootElementProcessor processor) {
  LOG.assertTrue("root".equals(root.getName()));
  final String type = root.getAttributeValue("type");
  LOG.assertTrue(type != null);
  if (ProjectRootUtil.SIMPLE_ROOT.equals(type)) {
    processor.processSimpleRoot(root);
  }
  else if (ProjectRootUtil.OUTPUT_ROOT.equals(type)) {
    processor.processOutputRoot(root);
  }
  else if (ProjectRootUtil.JDK_ROOT.equals(type)) {
    processor.processJdkRoot(root);
  }
  else if (ProjectRootUtil.EXCLUDED_OUTPUT.equals(type)) {
    processor.processExcludedOutputRoot(root);
  }
  else if (ProjectRootUtil.LIBRARY_ROOT.equals(type)) {
    processor.processLibraryRoot(root);
  }
  else if (ProjectRootUtil.EJB_ROOT.equals(type)) {
    processor.processEjbRoot(root);
  }
  else if (ProjectRootUtil.COMPOSITE_ROOT.equals(type)) {
    final List children = root.getChildren("root");
    for (int i = 0; i < children.size(); i++) {
      Element element = (Element)children.get(i);
      processRoot(element, processor);
    }
  }
  else {
    LOG.error("Unknown root type: " + type);
  }
}
项目:consulo-java    文件:SrcRepositoryUseTest.java   
public void testGetClasses(){
  setupLoadingFilter();

  PsiDirectory root = ProjectRootUtil.getAllContentRoots(myProject) [0];
  VirtualFile child = root.getVirtualFile().findChild("MyClass1.java");
  assertNotNull(child);
  PsiJavaFile file = (PsiJavaFile)myPsiManager.findFile(child);
  PsiClass[] classes = file.getClasses();
  assertEquals(2, classes.length);
  assertEquals(file, classes[0].getParent());

  teardownLoadingFilter();
}
项目:consulo-java    文件:SrcRepositoryUseTest.java   
public void testGetClassName(){
  setupLoadingFilter();

  PsiDirectory root = ProjectRootUtil.getAllContentRoots(myProject) [0];
  VirtualFile child = root.getVirtualFile().findChild("MyClass1.java");
  assertNotNull(child);
  PsiJavaFile file = (PsiJavaFile)myPsiManager.findFile(child);
  PsiClass[] classes = file.getClasses();
  assertEquals(2, classes.length);

  assertEquals("MyClass1", classes[0].getName());
  assertEquals("Class2", classes[1].getName());

  teardownLoadingFilter();
}
项目:consulo-java    文件:SrcRepositoryUseTest.java   
public void testGetClassQName(){
  setupLoadingFilter();

  PsiDirectory root = ProjectRootUtil.getAllContentRoots(myProject) [0];
  VirtualFile child = root.getVirtualFile().findChild("pack").findChild("MyClass2.java");
  assertNotNull(child);
  PsiJavaFile file = (PsiJavaFile)myPsiManager.findFile(child);
  PsiClass[] classes = file.getClasses();
  assertEquals(1, classes.length);

  assertEquals("pack.MyClass2", classes[0].getQualifiedName());

  teardownLoadingFilter();
}
项目:consulo-java    文件:SrcRepositoryUseTest.java   
public void testGetContainingFile(){
  setupLoadingFilter();

  PsiDirectory root = ProjectRootUtil.getAllContentRoots(myProject) [0];
  VirtualFile child = root.getVirtualFile().findChild("pack").findChild("MyClass2.java");
  assertNotNull(child);
  PsiJavaFile file = (PsiJavaFile)myPsiManager.findFile(child);
  PsiClass[] classes = file.getClasses();
  assertEquals(1, classes.length);

  assertEquals(file, classes[0].getContainingFile());

  teardownLoadingFilter();
}
项目:consulo-java    文件:SrcRepositoryUseTest.java   
public void testParentIdAssertOnExternalChange() throws Exception {
  PsiDirectory root = ProjectRootUtil.getAllContentRoots(myProject) [0];
  VirtualFile vFile = root.getVirtualFile().findChild("MyClass1.java");

  PsiJavaFile psiFile = (PsiJavaFile) myPsiManager.findFile(vFile);
  psiFile.getClasses();

  rewriteFileExternally(vFile, "import a . b;\n" +
                               "import c.*;\n" +
                               "import\n" +
                               "\n" +
                               "class MyClass1{\n" +
                               "  {\n" +
                               "    class Local{\n" +
                               "      public void foo(){\n" +
                               "        new Runnable(){\n" +
                               "          public void run(){\n" +
                               "            new Throwable(){\n" +
                               "            };\n" +
                               "          };\n" +
                               "        }\n" +
                               "      }\n" +
                               "    };\n" +
                               "  }\n" +
                               "}\n" +
                               "\n" +
                               "class Class2{\n" +
                               "}\n");

  PsiClass myClass = myJavaFacade.findClass("MyClass1", GlobalSearchScope.allScope(myProject));
  myClass.getChildren();
}
项目:consulo-java    文件:UpdateCacheTest.java   
public void testFileCreation() throws Exception {
  PsiDirectory root = ProjectRootUtil.getAllContentRoots(myProject) [0];

  PsiFile file = PsiFileFactory.getInstance(myProject).createFileFromText("New.java", JavaFileType.INSTANCE, "class A{ Object o;}");
  file = (PsiFile)root.add(file);
  assertNotNull(file);

  PsiClass objectClass = myJavaFacade.findClass(CommonClassNames.JAVA_LANG_OBJECT, GlobalSearchScope.allScope(getProject()));
  assertNotNull(objectClass);
  checkUsages(objectClass, new String[]{"New.java"});
}
项目:intellij-ce-playground    文件:PackageUtil.java   
/**
 * @deprecated
 */
@Nullable
public static PsiDirectory findOrCreateDirectoryForPackage(Project project,
                                                           String packageName,
                                                           PsiDirectory baseDir,
                                                           boolean askUserToCreate, boolean filterSourceDirsForTestBaseDir) throws IncorrectOperationException {

  PsiDirectory psiDirectory = null;

  if (!"".equals(packageName)) {
    PsiPackage rootPackage = findLongestExistingPackage(project, packageName);
    if (rootPackage != null) {
      int beginIndex = rootPackage.getQualifiedName().length() + 1;
      packageName = beginIndex < packageName.length() ? packageName.substring(beginIndex) : "";
      String postfixToShow = packageName.replace('.', File.separatorChar);
      if (packageName.length() > 0) {
        postfixToShow = File.separatorChar + postfixToShow;
      }
      PsiDirectory[] directories = rootPackage.getDirectories();
      if (filterSourceDirsForTestBaseDir) {
        directories = filterSourceDirectories(baseDir, project, directories);
      }
      psiDirectory = DirectoryChooserUtil.selectDirectory(project, directories, baseDir, postfixToShow);
      if (psiDirectory == null) return null;
    }
  }

  if (psiDirectory == null) {
    PsiDirectory[] sourceDirectories = ProjectRootUtil.getSourceRootDirectories(project);
    psiDirectory = DirectoryChooserUtil.selectDirectory(project, sourceDirectories, baseDir,
                                   File.separatorChar + packageName.replace('.', File.separatorChar));
    if (psiDirectory == null) return null;
  }

  String restOfName = packageName;
  boolean askedToCreate = false;
  while (restOfName.length() > 0) {
    final String name = getLeftPart(restOfName);
    PsiDirectory foundExistingDirectory = psiDirectory.findSubdirectory(name);
    if (foundExistingDirectory == null) {
      if (!askedToCreate && askUserToCreate) {
        int toCreate = Messages.showYesNoDialog(project,
                                                IdeBundle.message("prompt.create.non.existing.package", packageName),
                                                IdeBundle.message("title.package.not.found"),
                                                Messages.getQuestionIcon());
        if (toCreate != Messages.YES) {
          return null;
        }
        askedToCreate = true;
      }
      psiDirectory = createSubdirectory(psiDirectory, name, project);
    }
    else {
      psiDirectory = foundExistingDirectory;
    }
    restOfName = cutLeftPart(restOfName);
  }
  return psiDirectory;
}
项目:tools-idea    文件:PackageUtil.java   
/**
 * @deprecated
 */
@Nullable
public static PsiDirectory findOrCreateDirectoryForPackage(Project project,
                                                           String packageName,
                                                           PsiDirectory baseDir,
                                                           boolean askUserToCreate, boolean filterSourceDirsForTestBaseDir) throws IncorrectOperationException {

  PsiDirectory psiDirectory = null;

  if (!"".equals(packageName)) {
    PsiPackage rootPackage = findLongestExistingPackage(project, packageName);
    if (rootPackage != null) {
      int beginIndex = rootPackage.getQualifiedName().length() + 1;
      packageName = beginIndex < packageName.length() ? packageName.substring(beginIndex) : "";
      String postfixToShow = packageName.replace('.', File.separatorChar);
      if (packageName.length() > 0) {
        postfixToShow = File.separatorChar + postfixToShow;
      }
      PsiDirectory[] directories = rootPackage.getDirectories();
      if (filterSourceDirsForTestBaseDir) {
        directories = filterSourceDirectories(baseDir, project, directories);
      }
      psiDirectory = DirectoryChooserUtil.selectDirectory(project, directories, baseDir, postfixToShow);
      if (psiDirectory == null) return null;
    }
  }

  if (psiDirectory == null) {
    PsiDirectory[] sourceDirectories = ProjectRootUtil.getSourceRootDirectories(project);
    psiDirectory = DirectoryChooserUtil.selectDirectory(project, sourceDirectories, baseDir,
                                   File.separatorChar + packageName.replace('.', File.separatorChar));
    if (psiDirectory == null) return null;
  }

  String restOfName = packageName;
  boolean askedToCreate = false;
  while (restOfName.length() > 0) {
    final String name = getLeftPart(restOfName);
    PsiDirectory foundExistingDirectory = psiDirectory.findSubdirectory(name);
    if (foundExistingDirectory == null) {
      if (!askedToCreate && askUserToCreate) {
        int toCreate = Messages.showYesNoDialog(project,
                                                IdeBundle.message("prompt.create.non.existing.package", packageName),
                                                IdeBundle.message("title.package.not.found"),
                                                Messages.getQuestionIcon());
        if (toCreate != 0) {
          return null;
        }
        askedToCreate = true;
      }
      psiDirectory = createSubdirectory(psiDirectory, name, project);
    }
    else {
      psiDirectory = foundExistingDirectory;
    }
    restOfName = cutLeftPart(restOfName);
  }
  return psiDirectory;
}