List of usage examples for org.eclipse.jdt.core IJavaProject getPackageFragmentRoots
IPackageFragmentRoot[] getPackageFragmentRoots() throws JavaModelException;
From source file:com.testify.ecfeed.ui.editor.ModelEditor.java
License:Open Source License
@Override public IPackageFragmentRoot getPackageFragmentRoot() { try {/*from w ww . j a v a2 s .com*/ if (getProject().hasNature(JavaCore.NATURE_ID)) { IJavaProject javaProject = JavaCore.create(getProject()); IPath path = getPath(); if (javaProject != null) { for (IPackageFragmentRoot root : javaProject.getPackageFragmentRoots()) { if (root.getPath().isPrefixOf(path)) { return root; } } } } } catch (CoreException e) { } return null; }
From source file:com.windowtester.eclipse.ui.convert.WTAPIUsage.java
License:Open Source License
/** * Recursively iterate over the elements in the specified java element to convert each * compilation to use the new WindowTester API. * //from ww w . j a va 2s. co m * @param proj the java project (not <code>null</code>) * @param monitor the progress monitor (not <code>null</code>) */ private void scanProject(IJavaProject proj, IProgressMonitor monitor) throws JavaModelException { if (visited.contains(proj)) return; visited.add(proj); IPackageFragmentRoot[] roots = proj.getPackageFragmentRoots(); monitor.beginTask("Scanning " + proj.getPath(), roots.length); for (int i = 0; i < roots.length; i++) { scanPackageRoot(roots[i], new SubProgressMonitor(monitor, 1)); monitor.worked(1); } monitor.done(); }
From source file:com.windowtester.eclipse.ui.convert.WTConvertAPIRefactoring.java
License:Open Source License
/** * Recursively iterate over the elements in the specified java element to convert each * compilation to use the new WindowTester API. * /* ww w. j av a 2 s . c om*/ * @param proj the java project (not <code>null</code>) * @param monitor the progress monitor (not <code>null</code>) */ private void convertProject(IJavaProject proj, IProgressMonitor monitor) throws JavaModelException { if (visited.contains(proj)) return; visited.add(proj); IPackageFragmentRoot[] roots = proj.getPackageFragmentRoots(); monitor.beginTask("Converting " + proj.getPath(), roots.length); for (int i = 0; i < roots.length; i++) convertPackageRoot(roots[i], new SubProgressMonitor(monitor, 1)); monitor.done(); }
From source file:com.windowtester.eclipse.ui_tool.WTConvertAPIContextBuilderTool.java
License:Open Source License
/** * Recursively iterate over all elements in the project looking for WindowTester * classes and members.//from ww w . ja va 2s . co m * * @param proj the java project (not <code>null</code>) */ private void scanProject(IProject proj) throws JavaModelException { if (!proj.exists()) return; String projName = proj.getName(); if (!projName.startsWith("com.windowtester.") || projName.indexOf('_') != -1) return; if (projName.endsWith(".recorder") || projName.endsWith(".help") || projName.endsWith(".codegen")) return; if (projName.equals("com.windowtester.eclipse.ui")) return; IJavaProject javaProject = JavaCore.create(proj); if (!javaProject.exists()) return; IPackageFragmentRoot[] roots = javaProject.getPackageFragmentRoots(); for (int i = 0; i < roots.length; i++) scanPackageRoot(roots[i]); }
From source file:com.worldline.awltech.i18ntools.editor.data.model.I18NDataLoader.java
License:Open Source License
private static Map<Locale, IFile> locateResourceBundle(IJavaProject javaProject, String resourceBundlePath) throws CoreException { Map<Locale, IFile> resourceBundles = new LinkedHashMap<>(); for (IPackageFragmentRoot pfr : javaProject.getPackageFragmentRoots()) { if (pfr.getResource() instanceof IContainer) { IContainer container = (IContainer) pfr.getResource(); Path path = new Path(resourceBundlePath); IResource foundMember = container.findMember(path.addFileExtension("properties")); if (foundMember instanceof IFile && foundMember.exists()) { // We have the default resource bundle ! resourceBundles.put(null, (IFile) foundMember); // Now we need to find the other languages... for (IResource resource : container.members()) { // We don't forget to skip the already found default // one. String fileNameBase = path.lastSegment().concat("_"); if (resource != foundMember) { if (resource instanceof IFile && resource.exists()) { // The aim here is to chunk the name of the file // to retrieve the locale and load it. IFile iFile = (IFile) resource; if ("properties".equals(iFile.getFileExtension()) && iFile.getName().startsWith(fileNameBase)) { String localeChunk = iFile.getName().substring(fileNameBase.length(), iFile.getName().length() - ".properties".length()); Locale locale = Locale.forLanguageTag(localeChunk.replace("_", "-")); if (locale != null) { resourceBundles.put(locale, iFile); }// w ww.java 2 s .co m } } } } } } } return resourceBundles; }
From source file:dacapo.eclipse.EclipseTests.java
License:Open Source License
/** * Returns compilation unit with given name in given project and package. * @param projectName/*from w ww. j a v a2 s . c o m*/ * @param packageName * @param unitName * @return org.eclipse.jdt.core.ICompilationUnit */ protected ICompilationUnit getCompilationUnit(String projectName, String packageName, String unitName) throws JavaModelException { IJavaProject javaProject = getProject(projectName); if (javaProject == null) return null; IPackageFragmentRoot[] fragmentRoots = javaProject.getPackageFragmentRoots(); int length = fragmentRoots.length; for (int i = 0; i < length; i++) { if (fragmentRoots[i] instanceof JarPackageFragmentRoot) continue; IJavaElement[] packages = fragmentRoots[i].getChildren(); for (int k = 0; k < packages.length; k++) { IPackageFragment pack = (IPackageFragment) packages[k]; if (pack.getElementName().equals(packageName)) { ICompilationUnit[] units = pack.getCompilationUnits(); for (int u = 0; u < units.length; u++) { if (units[u].getElementName().equals(unitName)) return units[u]; } } } } return null; }
From source file:dacapo.eclipse.EclipseTests.java
License:Open Source License
/** * Returns all compilation units of a given project. * @param javaProject Project to collect units * @return List of org.eclipse.jdt.core.ICompilationUnit *//* w ww . j a v a2 s . c o m*/ protected List getProjectCompilationUnits(IJavaProject javaProject) throws JavaModelException { IPackageFragmentRoot[] fragmentRoots = javaProject.getPackageFragmentRoots(); int length = fragmentRoots.length; List allUnits = new ArrayList(); for (int i = 0; i < length; i++) { if (fragmentRoots[i] instanceof JarPackageFragmentRoot) continue; IJavaElement[] packages = fragmentRoots[i].getChildren(); for (int k = 0; k < packages.length; k++) { IPackageFragment pack = (IPackageFragment) packages[k]; ICompilationUnit[] units = pack.getCompilationUnits(); for (int u = 0; u < units.length; u++) { allUnits.add(units[u]); } } } return allUnits; }
From source file:de.devboost.eclipse.jdtutilities.JDTUtility.java
License:Open Source License
/** * Returns the Java element contained in the resource located at the * given path or <code>null</code> if the resource does not contain a Java * element./*from ww w . jav a 2 s .c o m*/ */ public IJavaElement getJavaElement(String path) throws JavaModelException { IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); IFile file = root.getFile(new Path(path)); IJavaProject javaProject = getJavaProject(file); if (javaProject == null) { return null; } IPackageFragmentRoot[] roots = javaProject.getPackageFragmentRoots(); for (IPackageFragmentRoot packageFragmentRoot : roots) { IPath fragmentPath = packageFragmentRoot.getPath(); String fragmentPathString = fragmentPath.toString(); if (path.startsWith(fragmentPathString + "/")) { // resource is contained in this package fragment root String classPathRelativePath = path.substring(fragmentPathString.length() + 1); IJavaElement element = javaProject.findElement(new Path(classPathRelativePath)); if (element != null) { return element; } } } return null; }
From source file:de.fu_berlin.inf.jtourbus.utility.Utilities.java
License:Open Source License
public static ICompilationUnit[] getCompilationUnits(IJavaProject project) { HashSet<ICompilationUnit> result = new HashSet<ICompilationUnit>(); try {/*from w w w.j a v a2 s. co m*/ IPackageFragmentRoot[] roots = project.getPackageFragmentRoots(); for (int k = 0; k < roots.length; k++) { if (roots[k].getKind() == IPackageFragmentRoot.K_SOURCE) { IJavaElement[] children = roots[k].getChildren(); for (int i = 0; i < children.length; i++) { result.addAll(Arrays.asList(((IPackageFragment) children[i]).getCompilationUnits())); } } } } catch (JavaModelException e) { JTourBusPlugin.log(e); } return result.toArray(new ICompilationUnit[result.size()]); }
From source file:de.fxworld.generationgap.GapEclipseWorkflow.java
License:Open Source License
protected List<String> getSourceFolders(IProject project) { List<String> result = new ArrayList<String>(); IJavaProject javaProject = JavaCore.create(project); IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); try {// www. j a v a2 s. c o m for (IPackageFragmentRoot packageFragmentRoot : javaProject.getPackageFragmentRoots()) { if (packageFragmentRoot.getKind() == IPackageFragmentRoot.K_SOURCE) { IPath path = packageFragmentRoot.getPath(); IFolder folder = root.getFolder(path); String location = folder.getLocation().toString(); if (!location.contains("src-gen")) { result.add(location); } } } for (IProject referencedProject : javaProject.getProject().getReferencedProjects()) { if (referencedProject.isAccessible() && referencedProject.hasNature(JavaCore.NATURE_ID)) { result.addAll(getSourceFolders(referencedProject)); } } } catch (JavaModelException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (CoreException e) { // TODO Auto-generated catch block e.printStackTrace(); } return result; }