List of usage examples for org.eclipse.jdt.core IPackageFragmentRoot getResolvedClasspathEntry
IClasspathEntry getResolvedClasspathEntry() throws JavaModelException;
From source file:at.bestsolution.fxide.jdt.corext.javadoc.JavaDocLocations.java
License:Open Source License
public static URL getJavadocBaseLocation(IJavaElement element) throws JavaModelException { if (element.getElementType() == IJavaElement.JAVA_PROJECT) { return getProjectJavadocLocation((IJavaProject) element); }/*from w w w. java 2s .c o m*/ IPackageFragmentRoot root = JavaModelUtil.getPackageFragmentRoot(element); if (root == null) { return null; } if (root.getKind() == IPackageFragmentRoot.K_BINARY) { IClasspathEntry entry = root.getResolvedClasspathEntry(); URL javadocLocation = getLibraryJavadocLocation(entry); if (javadocLocation != null) { return getLibraryJavadocLocation(entry); } entry = root.getRawClasspathEntry(); switch (entry.getEntryKind()) { case IClasspathEntry.CPE_LIBRARY: case IClasspathEntry.CPE_VARIABLE: return getLibraryJavadocLocation(entry); default: return null; } } else { return getProjectJavadocLocation(root.getJavaProject()); } }
From source file:at.bestsolution.fxide.jdt.corext.util.JavaModelUtil.java
License:Open Source License
/** * Returns the classpath entry of the given package fragment root. This is the raw entry, except * if the root is a referenced library, in which case it's the resolved entry. * * @param root a package fragment root/*from ww w . ja va 2s . c o m*/ * @return the corresponding classpath entry * @throws JavaModelException if accessing the entry failed * @since 3.6 */ public static IClasspathEntry getClasspathEntry(IPackageFragmentRoot root) throws JavaModelException { IClasspathEntry rawEntry = root.getRawClasspathEntry(); int rawEntryKind = rawEntry.getEntryKind(); switch (rawEntryKind) { case IClasspathEntry.CPE_LIBRARY: case IClasspathEntry.CPE_VARIABLE: case IClasspathEntry.CPE_CONTAINER: // should not happen, see https://bugs.eclipse.org/bugs/show_bug.cgi?id=305037 if (root.isArchive() && root.getKind() == IPackageFragmentRoot.K_BINARY) { IClasspathEntry resolvedEntry = root.getResolvedClasspathEntry(); if (resolvedEntry.getReferencingEntry() != null) return resolvedEntry; else return rawEntry; } } return rawEntry; }
From source file:com.codenvy.ide.ext.java.server.internal.core.DeltaProcessor.java
License:Open Source License
private void addPackageFragmentRoot(OpenableElementInfo parent, IPackageFragmentRoot child) throws JavaModelException { IJavaElement[] roots = parent.getChildren(); if (roots.length > 0) { IClasspathEntry[] resolvedClasspath = ((JavaProject) child.getJavaProject()).getResolvedClasspath(); IPath currentEntryPath = child.getResolvedClasspathEntry().getPath(); int indexToInsert = -1; int lastComparedIndex = -1; int i = 0, j = 0; for (; i < roots.length && j < resolvedClasspath.length;) { IClasspathEntry classpathEntry = resolvedClasspath[j]; if (lastComparedIndex != j && currentEntryPath.equals(classpathEntry.getPath())) { indexToInsert = i;/*from w ww .j a v a 2s .c o m*/ break; } lastComparedIndex = j; IClasspathEntry rootEntry = ((IPackageFragmentRoot) roots[i]).getResolvedClasspathEntry(); if (rootEntry.getPath().equals(classpathEntry.getPath())) i++; else j++; } for (; i < roots.length; i++) { // If the new root is already among the children, no need to proceed further. Just return. if (roots[i].equals(child)) { return; } // If we start seeing root's classpath entry different from the child's entry, then the child can't // be present further down the roots array. if (!((IPackageFragmentRoot) roots[i]).getResolvedClasspathEntry().getPath() .equals(currentEntryPath)) break; } if (indexToInsert >= 0) { int newSize = roots.length + 1; IPackageFragmentRoot[] newChildren = new IPackageFragmentRoot[newSize]; if (indexToInsert > 0) System.arraycopy(roots, 0, newChildren, 0, indexToInsert); newChildren[indexToInsert] = child; System.arraycopy(roots, indexToInsert, newChildren, indexToInsert + 1, (newSize - indexToInsert - 1)); parent.setChildren(newChildren); return; } } parent.addChild(child); }
From source file:com.codenvy.ide.ext.java.server.internal.core.JavaElement.java
License:Open Source License
protected URL getJavadocBaseLocation() throws JavaModelException { IPackageFragmentRoot root = (IPackageFragmentRoot) getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT); if (root == null) { return null; }// www . j av a 2 s. c o m if (root.getKind() == IPackageFragmentRoot.K_BINARY) { IClasspathEntry entry = null; try { entry = root.getResolvedClasspathEntry(); URL url = getLibraryJavadocLocation(entry); if (url != null) { return url; } } catch (JavaModelException jme) { // Proceed with raw classpath } entry = root.getRawClasspathEntry(); switch (entry.getEntryKind()) { case IClasspathEntry.CPE_LIBRARY: case IClasspathEntry.CPE_VARIABLE: return getLibraryJavadocLocation(entry); default: return null; } } return null; }
From source file:com.microsoft.javapkgsrv.JavaElementLabelComposer.java
License:Open Source License
private static IClasspathEntry getClasspathEntry(IPackageFragmentRoot root) throws JavaModelException { IClasspathEntry rawEntry = root.getRawClasspathEntry(); int rawEntryKind = rawEntry.getEntryKind(); switch (rawEntryKind) { case IClasspathEntry.CPE_LIBRARY: case IClasspathEntry.CPE_VARIABLE: case IClasspathEntry.CPE_CONTAINER: // should not happen, see https://bugs.eclipse.org/bugs/show_bug.cgi?id=305037 if (root.isArchive() && root.getKind() == IPackageFragmentRoot.K_BINARY) { IClasspathEntry resolvedEntry = root.getResolvedClasspathEntry(); if (resolvedEntry.getReferencingEntry() != null) return resolvedEntry; else/*from w ww . ja v a 2 s . c o m*/ return rawEntry; } } return rawEntry; }
From source file:com.redhat.ceylon.eclipse.core.model.JDTModuleManager.java
License:Open Source License
@Override protected JDTModule createModule(List<String> moduleName, String version) { JDTModule module = null;//from w ww . j a v a 2 s .c o m String moduleNameString = Util.getName(moduleName); List<IPackageFragmentRoot> roots = new ArrayList<IPackageFragmentRoot>(); if (javaProject != null) { try { if (moduleNameString.equals(Module.DEFAULT_MODULE_NAME)) { // Add the list of source package fragment roots for (IPackageFragmentRoot root : javaProject.getPackageFragmentRoots()) { if (root.exists() && javaProject.isOnClasspath(root)) { IClasspathEntry entry = root.getResolvedClasspathEntry(); if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE && !root.isExternal()) { roots.add(root); } } } } else { for (IPackageFragmentRoot root : javaProject.getPackageFragmentRoots()) { if (root.exists() && javaProject.isOnClasspath(root)) { if (JDKUtils.isJDKModule(moduleNameString)) { // find the first package that exists in this root for (String pkg : JDKUtils.getJDKPackagesByModule(moduleNameString)) { if (root.getPackageFragment(pkg).exists()) { roots.add(root); break; } } } else if (JDKUtils.isOracleJDKModule(moduleNameString)) { // find the first package that exists in this root for (String pkg : JDKUtils.getOracleJDKPackagesByModule(moduleNameString)) { if (root.getPackageFragment(pkg).exists()) { roots.add(root); break; } } } else if (!(root instanceof JarPackageFragmentRoot) && !CeylonBuilder.isInCeylonClassesOutputFolder(root.getPath())) { String packageToSearch = moduleNameString; if (root.getPackageFragment(packageToSearch).exists()) { roots.add(root); } } } } } } catch (JavaModelException e) { e.printStackTrace(); } } module = new JDTModule(this, roots); module.setName(moduleName); module.setVersion(version); setupIfJDKModule(module); return module; }
From source file:com.redhat.ceylon.eclipse.core.model.loader.JDTModuleManager.java
License:Open Source License
@Override protected Module createModule(List<String> moduleName, String version) { JDTModule module = null;//from ww w.ja v a 2 s .c o m String moduleNameString = Util.getName(moduleName); List<IPackageFragmentRoot> roots = new ArrayList<IPackageFragmentRoot>(); try { if (moduleNameString.equals(Module.DEFAULT_MODULE_NAME)) { // Add the list of source package fragment roots for (IPackageFragmentRoot root : javaProject.getPackageFragmentRoots()) { IClasspathEntry entry = root.getResolvedClasspathEntry(); if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE && !root.isExternal()) { roots.add(root); } } } else { for (IPackageFragmentRoot root : javaProject.getPackageFragmentRoots()) { if (JDKUtils.isJDKModule(moduleNameString)) { // find the first package that exists in this root for (String pkg : JDKUtils.getJDKPackagesByModule(moduleNameString)) { if (root.getPackageFragment(pkg).exists()) { roots.add(root); break; } } } else if (JDKUtils.isOracleJDKModule(moduleNameString)) { // find the first package that exists in this root for (String pkg : JDKUtils.getOracleJDKPackagesByModule(moduleNameString)) { if (root.getPackageFragment(pkg).exists()) { roots.add(root); break; } } } else if (!(root instanceof JarPackageFragmentRoot)) { String packageToSearch = moduleNameString; if (root.getPackageFragment(packageToSearch).exists()) { roots.add(root); } } } } } catch (JavaModelException e) { e.printStackTrace(); } module = new JDTModule(this, roots); module.setName(moduleName); module.setVersion(version); setupIfJDKModule(module); return module; }
From source file:es.bsc.servicess.ide.editors.CommonFormPage.java
License:Apache License
/** Get the eclipse compilation unit for the orchestration class * @param serviceClass Name of the orchestration class * @param project Service implementation project * @param prMetadata Project Metadata/*from w w w . j a v a 2 s . c o m*/ * @return Compilation unit of the orchetration class * @throws Exception */ public static IType getExternalOrchestrationClass(String serviceClass, IJavaProject project, ProjectMetadata prMetadata) throws Exception { String libraryLocation = (prMetadata.getOrchestrationClass(serviceClass).getLibraryLocation()); IType type = null; for (IPackageFragmentRoot r : project.getAllPackageFragmentRoots()) { /*log.debug("PFR: " + r.getElementName()+ " entry: " + r.getResolvedClasspathEntry().getPath() + "(Looking for: "+ libraryLocation+")");*/ if (r.getResolvedClasspathEntry().getPath().toOSString().trim().equals(libraryLocation.trim())) { IPackageFragment frag = r.getPackageFragment(Signature.getQualifier(serviceClass)); return frag.getClassFile(Signature.getSimpleName(serviceClass) + ".class").getType(); } } throw new PartInitException("Type not found"); }
From source file:es.bsc.servicess.ide.wizards.coretypes.ExistingMethodSpecificTreatment.java
License:Apache License
private IJavaElement[] findElementsToSerach(IJavaProject project, String libraryLoc) throws CoreException { project.getProject().refreshLocal(IResource.DEPTH_INFINITE, null); ArrayList<IPackageFragmentRoot> pfrs = new ArrayList<IPackageFragmentRoot>(); for (IPackageFragmentRoot r : project.getAllPackageFragmentRoots()) { log.debug("PFR: " + r.getElementName() + " entry: " + r.getResolvedClasspathEntry().getPath()); if (r.getResolvedClasspathEntry().getPath().toOSString().trim().equals(libraryLoc.trim())) { pfrs.add(r);//w w w .j a v a 2 s . c o m } } return pfrs.toArray(new IPackageFragmentRoot[pfrs.size()]); }
From source file:es.bsc.servicess.ide.wizards.ServiceSsImportOrchestrationClassPage.java
License:Apache License
private void selectOEClass() { IJavaElement[] elements;//from w w w .ja v a 2 s. c o m if (project == null) { MessageDialog.openError(this.getShell(), "Error", "Project is not selected"); return; } try { // project.getProject().refreshLocal(IResource.DEPTH_INFINITE, null); ArrayList<IPackageFragmentRoot> pfrs = new ArrayList<IPackageFragmentRoot>(); String packLoc; if (libraryLocation != null && libraryLocation.getText().trim().length() > 0) { packLoc = libraryLocation.getText().trim(); } else if (warPath.endsWith(".jar")) { packLoc = warPath.trim(); } else { packLoc = project.getProject().getFolder(ProjectMetadata.IMPORT_FOLDER) .getFolder(PackagingUtils.getPackageName(warPath)).getFolder("WEB-INF").getFolder("classes") .getFullPath().toOSString().trim(); } for (IPackageFragmentRoot r : project.getAllPackageFragmentRoots()) { log.debug("PFR: " + r.getElementName() + " entry: " + r.getResolvedClasspathEntry().getPath().toOSString()); log.debug("Looking for " + packLoc); if (r.getResolvedClasspathEntry().getPath().toOSString().trim().equals(packLoc)) { pfrs.add(r); } } elements = pfrs.toArray(new IPackageFragmentRoot[pfrs.size()]); } catch (Exception e) { e.printStackTrace(); ErrorDialog.openError(this.getShell(), "Error", "Error opening package location", new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e)); return; } if (elements == null || elements.length <= 0) { ErrorDialog.openError(this.getShell(), "Error", "Getting java elements", new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Java elements not found")); return; } IJavaSearchScope scope = SearchEngine.createJavaSearchScope(elements); FilteredTypesSelectionDialog dialog = new FilteredTypesSelectionDialog(this.getShell(), false, this.getWizard().getContainer(), scope, IJavaSearchConstants.CLASS); dialog.setTitle("Class Selection"); dialog.setMessage("Select a Class"); dialog.setInitialPattern(declaringClass.getText().trim()); if (declaringClass.getText().trim().length() > 0) { dialog.setInitialPattern(declaringClass.getText().trim()); } else dialog.setInitialPattern("?"); if (dialog.open() == Window.OK) { oeClass = (IType) dialog.getFirstResult(); if (!declaringClass.getText().trim().equals(oeClass.getElementName())) { declaringClass.setText(oeClass.getFullyQualifiedName()); } } else { /* * TODO if (libraryAdded){ cont.removeEntry(entry); libraryAdded = * false; cont = null; entry = null; } */ } }