List of usage examples for org.eclipse.jdt.core IPackageFragmentRoot getPath
IPath getPath();
From source file:ar.com.fluxit.jqa.JQAEclipseRunner.java
License:Open Source License
private Collection<File> getClassPath(IJavaProject javaProject) throws JavaModelException { Collection<File> result = new ArrayList<File>(); for (IPackageFragmentRoot classpathEntry : javaProject.getAllPackageFragmentRoots()) { if (classpathEntry.isExternal()) { result.add(classpathEntry.getPath().toFile()); } else {/*from w ww . j a v a2s. com*/ result.add(Utils.getAbsolutePath(((IJavaProject) classpathEntry.getParent()).getOutputLocation())); } } return result; }
From source file:at.bestsolution.fxide.jdt.text.viewersupport.JavaElementLabelComposer.java
License:Open Source License
private boolean appendVariableLabel(IPackageFragmentRoot root, long flags) { try {/*ww w.jav a 2 s . c om*/ IClasspathEntry rawEntry = root.getRawClasspathEntry(); if (rawEntry.getEntryKind() == IClasspathEntry.CPE_VARIABLE) { IClasspathEntry entry = JavaModelUtil.getClasspathEntry(root); if (entry.getReferencingEntry() != null) { return false; // not the variable entry itself, but a referenced entry } IPath path = rawEntry.getPath().makeRelative(); if (getFlag(flags, JavaElementLabels.REFERENCED_ROOT_POST_QUALIFIED)) { int segements = path.segmentCount(); if (segements > 0) { fBuffer.append(path.segment(segements - 1)); if (segements > 1) { int offset = fBuffer.length(); fBuffer.append(JavaElementLabels.CONCAT_STRING); fBuffer.append(path.removeLastSegments(1).toOSString()); // if (getFlag(flags, JavaElementLabels.COLORIZE)) { // fBuffer.setStyle(offset, fBuffer.length() - offset, QUALIFIER_STYLE); // } } } else { fBuffer.append(path.toString()); } } else { fBuffer.append(path.toString()); } int offset = fBuffer.length(); fBuffer.append(JavaElementLabels.CONCAT_STRING); if (root.isExternal()) fBuffer.append(root.getPath().toOSString()); else fBuffer.append(root.getPath().makeRelative().toString()); // if (getFlag(flags, JavaElementLabels.COLORIZE)) { // fBuffer.setStyle(offset, fBuffer.length() - offset, QUALIFIER_STYLE); // } return true; } } catch (JavaModelException e) { // problems with class path, ignore (bug 202792) return false; } return false; }
From source file:at.bestsolution.fxide.jdt.text.viewersupport.JavaElementLabelComposer.java
License:Open Source License
private void appendFolderLabel(IPackageFragmentRoot root, long flags) { IResource resource = root.getResource(); if (resource == null) { appendExternalArchiveLabel(root, flags); return;// w w w . j a va 2 s . c om } boolean rootQualified = getFlag(flags, JavaElementLabels.ROOT_QUALIFIED); boolean referencedQualified = getFlag(flags, JavaElementLabels.REFERENCED_ROOT_POST_QUALIFIED) && isReferenced(root); if (rootQualified) { fBuffer.append(root.getPath().makeRelative().toString()); } else { IPath projectRelativePath = resource.getProjectRelativePath(); if (projectRelativePath.segmentCount() == 0) { fBuffer.append(resource.getName()); referencedQualified = false; } else { fBuffer.append(projectRelativePath.toString()); } int offset = fBuffer.length(); if (referencedQualified) { fBuffer.append(JavaElementLabels.CONCAT_STRING); fBuffer.append(resource.getProject().getName()); } else if (getFlag(flags, JavaElementLabels.ROOT_POST_QUALIFIED)) { fBuffer.append(JavaElementLabels.CONCAT_STRING); fBuffer.append(root.getParent().getElementName()); } else { return; } // if (getFlag(flags, JavaElementLabels.COLORIZE)) { // fBuffer.setStyle(offset, fBuffer.length() - offset, QUALIFIER_STYLE); // } } }
From source file:at.bestsolution.fxide.jdt.text.viewersupport.JavaElementLabelComposer.java
License:Open Source License
private void appendExternalArchiveLabel(IPackageFragmentRoot root, long flags) { IPath path;/*from w w w .java 2 s . c o m*/ IClasspathEntry classpathEntry = null; try { classpathEntry = JavaModelUtil.getClasspathEntry(root); IPath rawPath = classpathEntry.getPath(); if (classpathEntry.getEntryKind() != IClasspathEntry.CPE_CONTAINER && !rawPath.isAbsolute()) path = rawPath; else path = root.getPath(); } catch (JavaModelException e) { path = root.getPath(); } if (getFlag(flags, JavaElementLabels.REFERENCED_ROOT_POST_QUALIFIED)) { int segements = path.segmentCount(); if (segements > 0) { fBuffer.append(path.segment(segements - 1)); int offset = fBuffer.length(); if (segements > 1 || path.getDevice() != null) { fBuffer.append(JavaElementLabels.CONCAT_STRING); fBuffer.append(path.removeLastSegments(1).toOSString()); } if (classpathEntry != null) { IClasspathEntry referencingEntry = classpathEntry.getReferencingEntry(); if (referencingEntry != null) { fBuffer.append( Messages.format(JavaUIMessages.JavaElementLabels_onClassPathOf, new Object[] { Name.CLASS_PATH.toString(), referencingEntry.getPath().lastSegment() })); } } // if (getFlag(flags, JavaElementLabels.COLORIZE)) { // fBuffer.setStyle(offset, fBuffer.length() - offset, QUALIFIER_STYLE); // } } else { fBuffer.append(path.toOSString()); } } else { fBuffer.append(path.toOSString()); } }
From source file:at.bestsolution.fxide.jdt.text.viewersupport.JavaElementLabelComposer.java
License:Open Source License
private void appendInternalArchiveLabel(IPackageFragmentRoot root, long flags) { IResource resource = root.getResource(); boolean rootQualified = getFlag(flags, JavaElementLabels.ROOT_QUALIFIED); if (rootQualified) { fBuffer.append(root.getPath().makeRelative().toString()); } else {//w w w .j a v a 2s.com fBuffer.append(root.getElementName()); int offset = fBuffer.length(); boolean referencedPostQualified = getFlag(flags, JavaElementLabels.REFERENCED_ROOT_POST_QUALIFIED); if (referencedPostQualified && isReferenced(root)) { fBuffer.append(JavaElementLabels.CONCAT_STRING); fBuffer.append(resource.getParent().getFullPath().makeRelative().toString()); } else if (getFlag(flags, JavaElementLabels.ROOT_POST_QUALIFIED)) { fBuffer.append(JavaElementLabels.CONCAT_STRING); fBuffer.append(root.getParent().getPath().makeRelative().toString()); } if (referencedPostQualified) { try { IClasspathEntry referencingEntry = JavaModelUtil.getClasspathEntry(root).getReferencingEntry(); if (referencingEntry != null) { fBuffer.append( Messages.format(JavaUIMessages.JavaElementLabels_onClassPathOf, new Object[] { Name.CLASS_PATH.toString(), referencingEntry.getPath().lastSegment() })); } } catch (JavaModelException e) { // ignore } } // if (getFlag(flags, JavaElementLabels.COLORIZE)) { // fBuffer.setStyle(offset, fBuffer.length() - offset, QUALIFIER_STYLE); // } } }
From source file:byke.tests.workspaceutils.JavaProject.java
License:Open Source License
private IPackageFragmentRoot createSourceFolder(final String path) throws CoreException, JavaModelException { IFolder folder = safeGetFolder(path); IPackageFragmentRoot root = _javaProject.getPackageFragmentRoot(folder); IClasspathEntry newSourceEntry = JavaCore.newSourceEntry(root.getPath(), new IPath[] {}); addClasspathEntry(newSourceEntry);/*w w w.j a va 2s. c om*/ return root; }
From source file:ca.mcgill.sable.soot.launching.SootFileLauncher.java
License:Open Source License
public void handleFiles(Object toProcess) { setDoNotContinue(false);// w w w . ja va2 s . c om if (toProcess instanceof IClassFile) { IClassFile cf = (IClassFile) toProcess; IPackageFragmentRoot pfr = (IPackageFragmentRoot) cf.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT); IPackageFragment pf = (IPackageFragment) cf.getAncestor(IJavaElement.PACKAGE_FRAGMENT); if (pfr.getResource() != null) { setClasspathAppend(platform_location + pfr.getPath().toOSString()); } else { setClasspathAppend(pfr.getPath().toOSString()); } addJars(); if (pf.isDefaultPackage()) { getToProcessList().add(removeFileExt(cf.getElementName())); } else { getToProcessList().add(pf.getElementName() + "." + removeFileExt(cf.getElementName())); } } else if (toProcess instanceof IFile) { IFile file = (IFile) toProcess; if (file.getFileExtension().compareTo("jimple") == 0) { setClasspathAppend(platform_location + file.getParent().getFullPath().toOSString()); addJars(); setIsSrcPrec(true); setSrcPrec(LaunchCommands.JIMPLE_IN); getToProcessList().add(removeFileExt(file.getName())); } else if (file.getFileExtension().equals("java")) { try { handleSourceFile(JavaCore.createCompilationUnitFrom(file)); } catch (Exception e) { System.out.println("problem creating CompilationUnit"); } } else if (file.getFileExtension().equals("class")) { try { handleClassFile(file); } catch (Exception e) { System.out.println("not a class file"); } } } else if (toProcess instanceof ICompilationUnit) { ICompilationUnit cu = (ICompilationUnit) toProcess; handleSourceFile(cu); } }
From source file:ca.mcgill.sable.soot.launching.SootFileLauncher.java
License:Open Source License
private void handleSourceFile(ICompilationUnit cu) { IPackageFragmentRoot pfr = (IPackageFragmentRoot) cu.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT); IPackageFragment pf = (IPackageFragment) cu.getAncestor(IJavaElement.PACKAGE_FRAGMENT); if (isSrcPrec() && getSrcPrec().equals("java")) { setClasspathAppend(platform_location + pfr.getPath().toOSString()); } else {// w w w. j a va 2 s .c om try { IProject proj = cu.getJavaProject().getProject(); IFolder output = proj.getFolder(cu.getJavaProject().getOutputLocation().lastSegment()); IPackageFragment pkf = (IPackageFragment) cu.getAncestor(IJavaElement.PACKAGE_FRAGMENT); IFile exists = null; if (pkf.isDefaultPackage()) { exists = output.getFile(removeFileExt(cu.getElementName()) + ".class"); } else { IFolder pkg = output.getFolder(dotsToSlashes(pf.getElementName())); exists = pkg.getFile(removeFileExt(cu.getElementName()) + ".class"); } if (!exists.exists()) { window = SootPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow(); MessageDialog noClassFound = new MessageDialog(window.getShell(), "Soot Information", null, "No underlying class file was found, maybe build project.", 0, new String[] { "OK" }, 0); noClassFound.open(); setDoNotContinue(true); } setClasspathAppend(platform_location + cu.getJavaProject().getOutputLocation().toOSString()); } catch (CoreException e) { } } addJars(); if (pf.isDefaultPackage()) { getToProcessList().add(removeFileExt(cu.getElementName())); } else { getToProcessList().add(pf.getElementName() + "." + removeFileExt(cu.getElementName())); } }
From source file:ca.ubc.cs.ferret.tests.support.TestProject.java
License:Open Source License
private IPackageFragmentRoot createSourceFolder() throws CoreException { IFolder folder = project.getFolder("src"); folder.create(false, true, null);/*from ww w. jav a 2s . c o m*/ IPackageFragmentRoot root = javaProject.getPackageFragmentRoot(folder); IClasspathEntry[] oldEntries = javaProject.getRawClasspath(); IClasspathEntry[] newEntries = new IClasspathEntry[oldEntries.length + 1]; System.arraycopy(oldEntries, 0, newEntries, 0, oldEntries.length); newEntries[oldEntries.length] = JavaCore.newSourceEntry(root.getPath()); javaProject.setRawClasspath(newEntries, null); return root; }
From source file:ccw.ClojureCore.java
License:Open Source License
/** * Get the file's namespace name if the file is a lib. * <p>//from www . jav a2s .c om * Checks: * <ul> * <li>if the file is in the classpath</li> * <li>if the file ends with .clj</li> * <li>if the file contains a ns call(*)</li> * </ul> * If check is ko, returns nil, the file does not correspond to a 'lib' * <br/> * If check is ok, deduce the 'lib' name from the file path, e.g. a file * path such as <code>/projectName/src/foo/bar_baz/core.clj</code> will * return "foo.bar-baz.core". * </p> * <p> * (*): based on a simplistic regex based heuristic for maximum speed * </p> * @param file * @return null if not a lib, String with lib namespace name if a lib */ public static String findMaybeLibNamespace(IFile file) { try { IJavaProject jProject = JavaCore.create(file.getProject()); IPackageFragmentRoot[] froots = jProject.getAllPackageFragmentRoots(); for (IPackageFragmentRoot froot : froots) { if (froot.getPath().isPrefixOf(file.getFullPath())) { String ret = findMaybeLibNamespace(file, froot.getPath()); if (ret != null) { return ret; } else { continue; } } } } catch (JavaModelException e) { CCWPlugin.logError("unable to determine the fragment root of the file " + file, e); } return null; }