List of usage examples for org.eclipse.jdt.core IJavaProject getPackageFragmentRoots
IPackageFragmentRoot[] getPackageFragmentRoots() throws JavaModelException;
From source file:com.redhat.ceylon.eclipse.ui.test.headless.ModelAndPhasedUnitsTests.java
License:Open Source License
@Test public void checkReferencedProjectJavaCeylonUnits() throws CoreException { if (compilationError != null) { throw compilationError; }//from ww w. j a v a2s . com IJavaProject javaProject = JavaCore.create(referencedCeylonProject); String rootPath = null; ICompilationUnit javaClassElement = null; ICompilationUnit javaObjectElement = null; ICompilationUnit javaMethodElement = null; for (IPackageFragmentRoot root : javaProject.getPackageFragmentRoots()) { IPackageFragment pkg = root.getPackageFragment("referencedCeylonProject"); if (pkg.exists() && pkg.getCompilationUnit("JavaCeylonTopLevelClass_Referenced_Ceylon_Project.java").exists()) { javaClassElement = pkg.getCompilationUnit("JavaCeylonTopLevelClass_Referenced_Ceylon_Project.java"); javaObjectElement = pkg .getCompilationUnit("javaCeylonTopLevelObject_Referenced_Ceylon_Project_.java"); javaMethodElement = pkg .getCompilationUnit("javaCeylonTopLevelMethod_Referenced_Ceylon_Project_.java"); rootPath = root.getPath().toOSString(); break; } } Module module = modelLoader.findModule("referencedCeylonProject", "1.0.0"); JavaCompilationUnit javaClassCompilationUnit = checkDeclarationUnit(module, "referencedCeylonProject.JavaCeylonTopLevelClass_Referenced_Ceylon_Project", JavaCompilationUnit.class, rootPath + "/" + "referencedCeylonProject/JavaCeylonTopLevelClass_Referenced_Ceylon_Project.java", "referencedCeylonProject/JavaCeylonTopLevelClass_Referenced_Ceylon_Project.java", "JavaCeylonTopLevelClass_Referenced_Ceylon_Project.java"); Assert.assertEquals("Wrong Java Element for Class : ", javaClassElement, javaClassCompilationUnit.getTypeRoot()); Assert.assertNotNull("Project Resource for Class should not be null :", javaClassCompilationUnit.getProjectResource()); Assert.assertNotNull("Root Folder Resource for Class should not be null :", javaClassCompilationUnit.getRootFolderResource()); Assert.assertNotNull("File Resource should for Class not be null :", javaClassCompilationUnit.getFileResource()); JavaCompilationUnit javaObjectCompilationUnit = checkDeclarationUnit(module, "referencedCeylonProject.javaCeylonTopLevelObject_Referenced_Ceylon_Project", JavaCompilationUnit.class, rootPath + "/" + "referencedCeylonProject/javaCeylonTopLevelObject_Referenced_Ceylon_Project_.java", "referencedCeylonProject/javaCeylonTopLevelObject_Referenced_Ceylon_Project_.java", "javaCeylonTopLevelObject_Referenced_Ceylon_Project_.java"); Assert.assertEquals("Wrong Java Element for Object : ", javaObjectElement, javaObjectCompilationUnit.getTypeRoot()); Assert.assertNotNull("Project Resource for Object should not be null :", javaObjectCompilationUnit.getProjectResource()); Assert.assertNotNull("Root Folder Resource for Object should not be null :", javaObjectCompilationUnit.getRootFolderResource()); Assert.assertNotNull("File Resource should for Object not be null :", javaObjectCompilationUnit.getFileResource()); JavaCompilationUnit javaMethodCompilationUnit = checkDeclarationUnit(module, "referencedCeylonProject.javaCeylonTopLevelMethod_Referenced_Ceylon_Project_", JavaCompilationUnit.class, rootPath + "/" + "referencedCeylonProject/javaCeylonTopLevelMethod_Referenced_Ceylon_Project_.java", "referencedCeylonProject/javaCeylonTopLevelMethod_Referenced_Ceylon_Project_.java", "javaCeylonTopLevelMethod_Referenced_Ceylon_Project_.java"); Assert.assertEquals("Wrong Java Element for Method : ", javaMethodElement, javaMethodCompilationUnit.getTypeRoot()); Assert.assertNotNull("Project Resource for Method should not be null :", javaMethodCompilationUnit.getProjectResource()); Assert.assertNotNull("Root Folder Resource for Method should not be null :", javaMethodCompilationUnit.getRootFolderResource()); Assert.assertNotNull("File Resource should for Method not be null :", javaMethodCompilationUnit.getFileResource()); }
From source file:com.redhat.ceylon.eclipse.ui.test.headless.ModelAndPhasedUnitsTests.java
License:Open Source License
@Test public void checkReferencedProjectPureJavaUnits() throws CoreException { if (compilationError != null) { throw compilationError; }/*from w w w. jav a 2 s .com*/ IJavaProject javaProject = JavaCore.create(referencedCeylonProject); String rootPath = null; ICompilationUnit javaElement = null; for (IPackageFragmentRoot root : javaProject.getPackageFragmentRoots()) { IPackageFragment pkg = root.getPackageFragment("referencedCeylonProject"); if (pkg.exists() && pkg.getCompilationUnit("JavaClassInCeylonModule_Referenced_Ceylon_Project.java").exists()) { javaElement = pkg.getCompilationUnit("JavaClassInCeylonModule_Referenced_Ceylon_Project.java"); rootPath = root.getPath().toOSString(); break; } } Module module = modelLoader.findModule("referencedCeylonProject", "1.0.0"); JavaCompilationUnit javaClassCompilationUnit = checkDeclarationUnit(module, "referencedCeylonProject.JavaClassInCeylonModule_Referenced_Ceylon_Project", JavaCompilationUnit.class, rootPath + "/" + "referencedCeylonProject/JavaClassInCeylonModule_Referenced_Ceylon_Project.java", "referencedCeylonProject/JavaClassInCeylonModule_Referenced_Ceylon_Project.java", "JavaClassInCeylonModule_Referenced_Ceylon_Project.java"); Assert.assertEquals("Wrong Java Element for Pure Java Class : ", javaElement, javaClassCompilationUnit.getTypeRoot()); Assert.assertNotNull("Project Resource for Pure Java Class should not be null :", javaClassCompilationUnit.getProjectResource()); Assert.assertNotNull("Root Folder Resource Pure Java for Class should not be null :", javaClassCompilationUnit.getRootFolderResource()); Assert.assertNotNull("File Resource should Pure Java for Class not be null :", javaClassCompilationUnit.getFileResource()); }
From source file:com.redhat.ceylon.eclipse.ui.test.ModelAndPhasedUnitsTests.java
License:Open Source License
@SuppressWarnings("restriction") @Test/*from ww w. j av a 2 s . co m*/ public void checkJavaLibrayrUnits() throws CoreException { if (compilationError != null) { throw compilationError; } IJavaProject javaProject = JavaCore.create(mainProject); String jarName = null; IClassFile javaElement = null; for (IPackageFragmentRoot root : javaProject.getPackageFragmentRoots()) { if (root instanceof JarPackageFragmentRoot) { JarPackageFragmentRoot jarRoot = (JarPackageFragmentRoot) root; IPackageFragment pkg = root.getPackageFragment("java.util.logging"); if (pkg.exists()) { javaElement = pkg.getClassFile("Logger.class"); jarName = jarRoot.getJar().getName(); break; } } } Module module = modelLoader.findModule(AbstractModelLoader.JAVA_BASE_MODULE_NAME, AbstractModelLoader.JDK_MODULE_VERSION); JavaClassFile javaClass = checkDeclarationUnit(module, "java.util.logging.Logger", JavaClassFile.class, jarName + "!/" + "java/util/logging/Logger.class", "java/util/logging/Logger.class", "Logger.class"); Assert.assertEquals("Wrong Java Element : ", javaElement, javaClass.getJavaElement()); Assert.assertNull("Project Resource should be null :", javaClass.getProjectResource()); Assert.assertNull("Root Folder Resource should be null :", javaClass.getRootFolderResource()); Assert.assertNull("File Resource should be null :", javaClass.getFileResource()); }
From source file:com.redhat.ceylon.eclipse.ui.test.ModelAndPhasedUnitsTests.java
License:Open Source License
@Test public void checkMainProjectJavaCeylonUnits() throws CoreException { if (compilationError != null) { throw compilationError; }//from ww w. ja va2 s .c o m IJavaProject javaProject = JavaCore.create(mainProject); String rootPath = null; ICompilationUnit javaClassElement = null; ICompilationUnit javaObjectElement = null; ICompilationUnit javaMethodElement = null; for (IPackageFragmentRoot root : javaProject.getPackageFragmentRoots()) { IPackageFragment pkg = root.getPackageFragment("mainModule"); if (pkg.exists() && pkg.getCompilationUnit("JavaCeylonTopLevelClass_Main_Ceylon_Project.java").exists()) { javaClassElement = pkg.getCompilationUnit("JavaCeylonTopLevelClass_Main_Ceylon_Project.java"); javaObjectElement = pkg.getCompilationUnit("javaCeylonTopLevelObject_Main_Ceylon_Project_.java"); javaMethodElement = pkg.getCompilationUnit("javaCeylonTopLevelMethod_Main_Ceylon_Project_.java"); rootPath = root.getPath().toOSString(); break; } } Module module = modelLoader.findModule("mainModule", "1.0.0"); JavaCompilationUnit javaClassCompilationUnit = checkDeclarationUnit(module, "mainModule.JavaCeylonTopLevelClass_Main_Ceylon_Project", JavaCompilationUnit.class, rootPath + "/" + "mainModule/JavaCeylonTopLevelClass_Main_Ceylon_Project.java", "mainModule/JavaCeylonTopLevelClass_Main_Ceylon_Project.java", "JavaCeylonTopLevelClass_Main_Ceylon_Project.java"); Assert.assertEquals("Wrong Java Element for Class : ", javaClassElement, javaClassCompilationUnit.getJavaElement()); Assert.assertNotNull("Project Resource for Class should not be null :", javaClassCompilationUnit.getProjectResource()); Assert.assertNotNull("Root Folder Resource for Class should not be null :", javaClassCompilationUnit.getRootFolderResource()); Assert.assertNotNull("File Resource should for Class not be null :", javaClassCompilationUnit.getFileResource()); JavaCompilationUnit javaObjectCompilationUnit = checkDeclarationUnit(module, "mainModule.javaCeylonTopLevelObject_Main_Ceylon_Project", JavaCompilationUnit.class, rootPath + "/" + "mainModule/javaCeylonTopLevelObject_Main_Ceylon_Project_.java", "mainModule/javaCeylonTopLevelObject_Main_Ceylon_Project_.java", "javaCeylonTopLevelObject_Main_Ceylon_Project_.java"); Assert.assertEquals("Wrong Java Element for Object : ", javaObjectElement, javaObjectCompilationUnit.getJavaElement()); Assert.assertNotNull("Project Resource for Object should not be null :", javaObjectCompilationUnit.getProjectResource()); Assert.assertNotNull("Root Folder Resource for Object should not be null :", javaObjectCompilationUnit.getRootFolderResource()); Assert.assertNotNull("File Resource should for Object not be null :", javaObjectCompilationUnit.getFileResource()); JavaCompilationUnit javaMethodCompilationUnit = checkDeclarationUnit(module, "mainModule.javaCeylonTopLevelMethod_Main_Ceylon_Project_", JavaCompilationUnit.class, rootPath + "/" + "mainModule/javaCeylonTopLevelMethod_Main_Ceylon_Project_.java", "mainModule/javaCeylonTopLevelMethod_Main_Ceylon_Project_.java", "javaCeylonTopLevelMethod_Main_Ceylon_Project_.java"); Assert.assertEquals("Wrong Java Element for Method : ", javaMethodElement, javaMethodCompilationUnit.getJavaElement()); Assert.assertNotNull("Project Resource for Method should not be null :", javaMethodCompilationUnit.getProjectResource()); Assert.assertNotNull("Root Folder Resource for Method should not be null :", javaMethodCompilationUnit.getRootFolderResource()); Assert.assertNotNull("File Resource should for Method not be null :", javaMethodCompilationUnit.getFileResource()); }
From source file:com.redhat.ceylon.eclipse.ui.test.ModelAndPhasedUnitsTests.java
License:Open Source License
@Test public void checkMainProjectPureJavaUnits() throws CoreException { if (compilationError != null) { throw compilationError; }//w w w . j av a 2 s. c om IJavaProject javaProject = JavaCore.create(mainProject); String rootPath = null; ICompilationUnit javaElement = null; for (IPackageFragmentRoot root : javaProject.getPackageFragmentRoots()) { IPackageFragment pkg = root.getPackageFragment("mainModule"); if (pkg.exists() && pkg.getCompilationUnit("JavaClassInCeylonModule_Main_Ceylon_Project.java").exists()) { javaElement = pkg.getCompilationUnit("JavaClassInCeylonModule_Main_Ceylon_Project.java"); rootPath = root.getPath().toOSString(); break; } } Module module = modelLoader.findModule("mainModule", "1.0.0"); JavaCompilationUnit javaClassCompilationUnit = checkDeclarationUnit(module, "mainModule.JavaClassInCeylonModule_Main_Ceylon_Project", JavaCompilationUnit.class, rootPath + "/" + "mainModule/JavaClassInCeylonModule_Main_Ceylon_Project.java", "mainModule/JavaClassInCeylonModule_Main_Ceylon_Project.java", "JavaClassInCeylonModule_Main_Ceylon_Project.java"); Assert.assertEquals("Wrong Java Element for Pure Java Class : ", javaElement, javaClassCompilationUnit.getJavaElement()); Assert.assertNotNull("Project Resource for Pure Java Class should not be null :", javaClassCompilationUnit.getProjectResource()); Assert.assertNotNull("Root Folder Resource Pure Java for Class should not be null :", javaClassCompilationUnit.getRootFolderResource()); Assert.assertNotNull("File Resource should Pure Java for Class not be null :", javaClassCompilationUnit.getFileResource()); }
From source file:com.redhat.ceylon.eclipse.ui.test.ModelAndPhasedUnitsTests.java
License:Open Source License
@Test public void checkReferencedProjectJavaCeylonUnits() throws CoreException { if (compilationError != null) { throw compilationError; }//from w ww . j a va 2s. c o m IJavaProject javaProject = JavaCore.create(referencedCeylonProject); String rootPath = null; ICompilationUnit javaClassElement = null; ICompilationUnit javaObjectElement = null; ICompilationUnit javaMethodElement = null; for (IPackageFragmentRoot root : javaProject.getPackageFragmentRoots()) { IPackageFragment pkg = root.getPackageFragment("referencedCeylonProject"); if (pkg.exists() && pkg.getCompilationUnit("JavaCeylonTopLevelClass_Referenced_Ceylon_Project.java").exists()) { javaClassElement = pkg.getCompilationUnit("JavaCeylonTopLevelClass_Referenced_Ceylon_Project.java"); javaObjectElement = pkg .getCompilationUnit("javaCeylonTopLevelObject_Referenced_Ceylon_Project_.java"); javaMethodElement = pkg .getCompilationUnit("javaCeylonTopLevelMethod_Referenced_Ceylon_Project_.java"); rootPath = root.getPath().toOSString(); break; } } Module module = modelLoader.findModule("referencedCeylonProject", "1.0.0"); JavaCompilationUnit javaClassCompilationUnit = checkDeclarationUnit(module, "referencedCeylonProject.JavaCeylonTopLevelClass_Referenced_Ceylon_Project", JavaCompilationUnit.class, rootPath + "/" + "referencedCeylonProject/JavaCeylonTopLevelClass_Referenced_Ceylon_Project.java", "referencedCeylonProject/JavaCeylonTopLevelClass_Referenced_Ceylon_Project.java", "JavaCeylonTopLevelClass_Referenced_Ceylon_Project.java"); Assert.assertEquals("Wrong Java Element for Class : ", javaClassElement, javaClassCompilationUnit.getJavaElement()); Assert.assertNotNull("Project Resource for Class should not be null :", javaClassCompilationUnit.getProjectResource()); Assert.assertNotNull("Root Folder Resource for Class should not be null :", javaClassCompilationUnit.getRootFolderResource()); Assert.assertNotNull("File Resource should for Class not be null :", javaClassCompilationUnit.getFileResource()); JavaCompilationUnit javaObjectCompilationUnit = checkDeclarationUnit(module, "referencedCeylonProject.javaCeylonTopLevelObject_Referenced_Ceylon_Project", JavaCompilationUnit.class, rootPath + "/" + "referencedCeylonProject/javaCeylonTopLevelObject_Referenced_Ceylon_Project_.java", "referencedCeylonProject/javaCeylonTopLevelObject_Referenced_Ceylon_Project_.java", "javaCeylonTopLevelObject_Referenced_Ceylon_Project_.java"); Assert.assertEquals("Wrong Java Element for Object : ", javaObjectElement, javaObjectCompilationUnit.getJavaElement()); Assert.assertNotNull("Project Resource for Object should not be null :", javaObjectCompilationUnit.getProjectResource()); Assert.assertNotNull("Root Folder Resource for Object should not be null :", javaObjectCompilationUnit.getRootFolderResource()); Assert.assertNotNull("File Resource should for Object not be null :", javaObjectCompilationUnit.getFileResource()); JavaCompilationUnit javaMethodCompilationUnit = checkDeclarationUnit(module, "referencedCeylonProject.javaCeylonTopLevelMethod_Referenced_Ceylon_Project_", JavaCompilationUnit.class, rootPath + "/" + "referencedCeylonProject/javaCeylonTopLevelMethod_Referenced_Ceylon_Project_.java", "referencedCeylonProject/javaCeylonTopLevelMethod_Referenced_Ceylon_Project_.java", "javaCeylonTopLevelMethod_Referenced_Ceylon_Project_.java"); Assert.assertEquals("Wrong Java Element for Method : ", javaMethodElement, javaMethodCompilationUnit.getJavaElement()); Assert.assertNotNull("Project Resource for Method should not be null :", javaMethodCompilationUnit.getProjectResource()); Assert.assertNotNull("Root Folder Resource for Method should not be null :", javaMethodCompilationUnit.getRootFolderResource()); Assert.assertNotNull("File Resource should for Method not be null :", javaMethodCompilationUnit.getFileResource()); }
From source file:com.redhat.ceylon.eclipse.ui.test.ModelAndPhasedUnitsTests.java
License:Open Source License
@Test public void checkReferencedProjectPureJavaUnits() throws CoreException { if (compilationError != null) { throw compilationError; }/*w w w .ja va 2s . c o m*/ IJavaProject javaProject = JavaCore.create(referencedCeylonProject); String rootPath = null; ICompilationUnit javaElement = null; for (IPackageFragmentRoot root : javaProject.getPackageFragmentRoots()) { IPackageFragment pkg = root.getPackageFragment("referencedCeylonProject"); if (pkg.exists() && pkg.getCompilationUnit("JavaClassInCeylonModule_Referenced_Ceylon_Project.java").exists()) { javaElement = pkg.getCompilationUnit("JavaClassInCeylonModule_Referenced_Ceylon_Project.java"); rootPath = root.getPath().toOSString(); break; } } Module module = modelLoader.findModule("referencedCeylonProject", "1.0.0"); JavaCompilationUnit javaClassCompilationUnit = checkDeclarationUnit(module, "referencedCeylonProject.JavaClassInCeylonModule_Referenced_Ceylon_Project", JavaCompilationUnit.class, rootPath + "/" + "referencedCeylonProject/JavaClassInCeylonModule_Referenced_Ceylon_Project.java", "referencedCeylonProject/JavaClassInCeylonModule_Referenced_Ceylon_Project.java", "JavaClassInCeylonModule_Referenced_Ceylon_Project.java"); Assert.assertEquals("Wrong Java Element for Pure Java Class : ", javaElement, javaClassCompilationUnit.getJavaElement()); Assert.assertNotNull("Project Resource for Pure Java Class should not be null :", javaClassCompilationUnit.getProjectResource()); Assert.assertNotNull("Root Folder Resource Pure Java for Class should not be null :", javaClassCompilationUnit.getRootFolderResource()); Assert.assertNotNull("File Resource should Pure Java for Class not be null :", javaClassCompilationUnit.getFileResource()); }
From source file:com.sabre.buildergenerator.TestHelper.java
License:Open Source License
public static IPackageFragmentRoot getSourceRoot(IJavaProject javaProject) throws JavaModelException { IPackageFragmentRoot sourceRoot = null; for (IPackageFragmentRoot pfr : javaProject.getPackageFragmentRoots()) { if (pfr.getKind() == IPackageFragmentRoot.K_SOURCE) { sourceRoot = pfr;/*ww w . j av a2s . c om*/ } } return sourceRoot; }
From source file:com.sabre.buildergenerator.ui.wizard.SourceFolderSelectDialog.java
License:Open Source License
private void initElements(IJavaProject javaProject) { List<IPackageFragmentRoot> roots = new LinkedList<IPackageFragmentRoot>(); try {/*from w w w.jav a2 s . co m*/ for (IPackageFragmentRoot root : javaProject.getPackageFragmentRoots()) { if (root.getKind() == IPackageFragmentRoot.K_SOURCE) { roots.add(root); } } } catch (JavaModelException e) { throw new RuntimeException(e); } setElements(roots.toArray(new IPackageFragmentRoot[roots.size()])); }
From source file:com.siteview.mde.internal.core.builders.BundleErrorReporter.java
License:Open Source License
private void addProjectPackages(IProject proj) { try {/*from w w w . j ava 2 s . c o m*/ if (proj.hasNature(JavaCore.NATURE_ID)) { IJavaProject jp = JavaCore.create(proj); IPackageFragmentRoot[] roots = jp.getPackageFragmentRoots(); for (int i = 0; i < roots.length; i++) { if (roots[i].getKind() == IPackageFragmentRoot.K_SOURCE || (roots[i].getKind() == IPackageFragmentRoot.K_BINARY && !roots[i].isExternal())) { IJavaElement[] children = roots[i].getChildren(); for (int j = 0; j < children.length; j++) { IPackageFragment f = (IPackageFragment) children[j]; String name = f.getElementName(); if (name.equals("")) //$NON-NLS-1$ name = "."; //$NON-NLS-1$ if (f.hasChildren() || f.getNonJavaResources().length > 0) fProjectPackages.add(name); } } } } } catch (CoreException ce) { } }