List of usage examples for org.eclipse.jdt.core IClasspathEntry getReferencingEntry
IClasspathEntry getReferencingEntry();
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 . j av a 2s .c om*/ * @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:at.bestsolution.fxide.jdt.text.viewersupport.JavaElementLabelComposer.java
License:Open Source License
private boolean appendVariableLabel(IPackageFragmentRoot root, long flags) { try {/* ww w . j a va2s . c o m*/ 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 appendExternalArchiveLabel(IPackageFragmentRoot root, long flags) { IPath path;// w w w . ja va 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:com.drgarbage.bytecodevisualizer.editors.NoSourceViewer.java
License:Apache License
private SelectionListener createButtonListener(final IClasspathEntry entry, final IPath containerPath, final IJavaProject jproject) { return new SelectionListener() { public void widgetSelected(SelectionEvent event) { Shell shell = fSite.getShell(); try { IClasspathEntry result = BuildPathDialogAccess.configureSourceAttachment(shell, entry); if (result != null) { /* 3.4, 3.5 version */ // applySourceAttachment(shell, result, jproject, containerPath); /* 3.6 version */ applySourceAttachment(shell, result, jproject, containerPath, entry.getReferencingEntry() != null); if (fSourceCodeViewer != null) { fSourceCodeViewer.verifyInput(); }//from w ww. j a va 2s .c om com.drgarbage.utils.Messages.info(CoreMessages.RestartEditorMessage); } } catch (Throwable e) { BytecodeVisualizerPlugin.log(e); } } public void widgetDefaultSelected(SelectionEvent e) { } }; }
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 w w . ja va 2 s . c om*/ return rawEntry; } } return rawEntry; }
From source file:com.microsoft.javapkgsrv.JavaElementLabelComposer.java
License:Open Source License
private boolean appendVariableLabel(IPackageFragmentRoot root, long flags) { try {/*from w ww . j a v a 2 s . co m*/ IClasspathEntry rawEntry = root.getRawClasspathEntry(); if (rawEntry.getEntryKind() == IClasspathEntry.CPE_VARIABLE) { IClasspathEntry entry = 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, 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(CONCAT_STRING); fBuffer.append(path.removeLastSegments(1).toOSString()); } } else { fBuffer.append(path.toString()); } } else { fBuffer.append(path.toString()); } int offset = fBuffer.length(); fBuffer.append(CONCAT_STRING); if (root.isExternal()) fBuffer.append(root.getPath().toOSString()); else fBuffer.append(root.getPath().makeRelative().toString()); return true; } } catch (JavaModelException e) { // problems with class path, ignore (bug 202792) return false; } return false; }
From source file:com.microsoft.javapkgsrv.JavaElementLabelComposer.java
License:Open Source License
private void appendExternalArchiveLabel(IPackageFragmentRoot root, long flags) { IPath path;// w w w. j ava 2 s . com IClasspathEntry classpathEntry = null; try { classpathEntry = 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, 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(CONCAT_STRING); fBuffer.append(path.removeLastSegments(1).toOSString()); } if (classpathEntry != null) { IClasspathEntry referencingEntry = classpathEntry.getReferencingEntry(); if (referencingEntry != null) { fBuffer.append(" (from "); fBuffer.append(Name.CLASS_PATH.toString()); fBuffer.append(" of "); fBuffer.append(referencingEntry.getPath().lastSegment()); fBuffer.append(")"); } } } else { fBuffer.append(path.toOSString()); } } else { fBuffer.append(path.toOSString()); } }
From source file:org.eclipse.e4.demo.simpleide.jdt.internal.editor.viewer.JavaElementLabelComposer.java
License:Open Source License
private void appendExternalArchiveLabel(IPackageFragmentRoot root, long flags) { IPath path;/* ww w .j a va 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.JavaElementLabels_onClassPathOf(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:org.eclipse.e4.demo.simpleide.jdt.internal.editor.viewer.JavaElementLabelComposer.java
License:Open Source License
private boolean appendVariableLabel(IPackageFragmentRoot root, long flags) { try {/* ww w . ja v a 2 s.com*/ 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:org.eclipse.jdt.internal.core.JavaProject.java
License:Open Source License
public String encodeClasspathEntry(IClasspathEntry classpathEntry) { try {/*from w ww . ja va2s . c om*/ ByteArrayOutputStream s = new ByteArrayOutputStream(); OutputStreamWriter writer = new OutputStreamWriter(s, "UTF8"); //$NON-NLS-1$ XMLWriter xmlWriter = new XMLWriter(writer, this, false/*don't print XML version*/); ((ClasspathEntry) classpathEntry).elementEncode(xmlWriter, this.project.getFullPath(), true/*indent*/, true/*insert new line*/, null/*not interested in unknown elements*/, (classpathEntry.getReferencingEntry() != null)); writer.flush(); writer.close(); return s.toString("UTF8");//$NON-NLS-1$ } catch (IOException e) { return null; // never happens since all is done in memory } }