Java Code Examples for org.eclipse.jdt.core.IClasspathEntry#getSourceAttachmentPath()
The following examples show how to use
org.eclipse.jdt.core.IClasspathEntry#getSourceAttachmentPath() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SourceJarLocations.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
public static File getSourceJarPath(IJavaElement element) throws JavaModelException { IPackageFragmentRoot root = JavaModelUtil.getPackageFragmentRoot(element); if (root == null) { return null; } IClasspathEntry entry = root.getResolvedClasspathEntry(); IPath sourceAttachment = entry.getSourceAttachmentPath(); if (sourceAttachment == null) { return null; //No source jar could be found } return sourceAttachment.toFile(); }
Example 2
Source File: LibraryClasspathContainerInitializer.java From google-cloud-eclipse with Apache License 2.0 | 5 votes |
private static boolean jarPathsAreValid(LibraryClasspathContainer container) { IClasspathEntry[] classpathEntries = container.getClasspathEntries(); for (IClasspathEntry classpathEntry : classpathEntries) { if (!classpathEntry.getPath().toFile().exists() || (classpathEntry.getSourceAttachmentPath() != null && !classpathEntry.getSourceAttachmentPath().toFile().exists())) { return false; } } return true; }
Example 3
Source File: BuildPathSupport.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * Finds a source attachment for a new archive in the existing classpaths. * @param elem The new classpath entry * @return A path to be taken for the source attachment or <code>null</code> */ public static IPath guessSourceAttachment(CPListElement elem) { if (elem.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { return null; } IJavaProject currProject= elem.getJavaProject(); // can be null try { IJavaModel jmodel= JavaCore.create(ResourcesPlugin.getWorkspace().getRoot()); IJavaProject[] jprojects= jmodel.getJavaProjects(); for (int i= 0; i < jprojects.length; i++) { IJavaProject curr= jprojects[i]; if (!curr.equals(currProject)) { IClasspathEntry[] entries= curr.getRawClasspath(); for (int k= 0; k < entries.length; k++) { IClasspathEntry entry= entries[k]; if (entry.getEntryKind() == elem.getEntryKind() && entry.getPath().equals(elem.getPath())) { IPath attachPath= entry.getSourceAttachmentPath(); if (attachPath != null && !attachPath.isEmpty()) { return attachPath; } } } } } } catch (JavaModelException e) { JavaPlugin.log(e.getStatus()); } return null; }
Example 4
Source File: JavaProject.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private void addToResult(IClasspathEntry rawEntry, IClasspathEntry resolvedEntry, ResolvedClasspath result, LinkedHashSet resolvedEntries, ExternalFoldersManager externalFoldersManager, Map oldChainedEntriesMap, boolean addAsChainedEntry, Map knownDrives) { IPath resolvedPath; // If it's already been resolved, do not add to resolvedEntries if (result.rawReverseMap.get(resolvedPath = resolvedEntry.getPath()) == null) { result.rawReverseMap.put(resolvedPath, rawEntry); result.rootPathToResolvedEntries.put(resolvedPath, resolvedEntry); resolvedEntries.add(resolvedEntry); if (addAsChainedEntry) { IClasspathEntry chainedEntry = null; chainedEntry = (ClasspathEntry) oldChainedEntriesMap.get(resolvedPath); if (chainedEntry != null) { // This is required to keep the attributes if any added by the user in // the previous session such as source attachment path etc. copyFromOldChainedEntry((ClasspathEntry) resolvedEntry, (ClasspathEntry) chainedEntry); } } } if (resolvedEntry.getEntryKind() == IClasspathEntry.CPE_LIBRARY && ExternalFoldersManager.isExternalFolderPath(resolvedPath)) { externalFoldersManager.addFolder(resolvedPath, true/*scheduleForCreation*/); // no-op if not an external folder or if already registered } // https://bugs.eclipse.org/bugs/show_bug.cgi?id=336046 // The source attachment path could be external too and in which case, must be added. IPath sourcePath = resolvedEntry.getSourceAttachmentPath(); if (sourcePath != null && driveExists(sourcePath, knownDrives) && ExternalFoldersManager.isExternalFolderPath(sourcePath)) { externalFoldersManager.addFolder(sourcePath, true); } }
Example 5
Source File: ClassFileEditor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
private void createSourceAttachmentControls(Composite composite, IPackageFragmentRoot root) throws JavaModelException { IClasspathEntry entry; try { entry= JavaModelUtil.getClasspathEntry(root); } catch (JavaModelException ex) { if (ex.isDoesNotExist()) entry= null; else throw ex; } IPath containerPath= null; if (entry == null || root.getKind() != IPackageFragmentRoot.K_BINARY) { createLabel(composite, Messages.format(JavaEditorMessages.SourceAttachmentForm_message_noSource, BasicElementLabels.getFileName( fFile))); return; } IJavaProject jproject= root.getJavaProject(); boolean canEditEncoding= true; if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { containerPath= entry.getPath(); ClasspathContainerInitializer initializer= JavaCore.getClasspathContainerInitializer(containerPath.segment(0)); IClasspathContainer container= JavaCore.getClasspathContainer(containerPath, jproject); if (initializer == null || container == null) { createLabel(composite, Messages.format(JavaEditorMessages.ClassFileEditor_SourceAttachmentForm_cannotconfigure, BasicElementLabels.getPathLabel(containerPath, false))); return; } String containerName= container.getDescription(); IStatus status= initializer.getSourceAttachmentStatus(containerPath, jproject); if (status.getCode() == ClasspathContainerInitializer.ATTRIBUTE_NOT_SUPPORTED) { createLabel(composite, Messages.format(JavaEditorMessages.ClassFileEditor_SourceAttachmentForm_notsupported, containerName)); return; } if (status.getCode() == ClasspathContainerInitializer.ATTRIBUTE_READ_ONLY) { createLabel(composite, Messages.format(JavaEditorMessages.ClassFileEditor_SourceAttachmentForm_readonly, containerName)); return; } IStatus attributeStatus= initializer.getAttributeStatus(containerPath, jproject, IClasspathAttribute.SOURCE_ATTACHMENT_ENCODING); canEditEncoding= !(attributeStatus.getCode() == ClasspathContainerInitializer.ATTRIBUTE_NOT_SUPPORTED || attributeStatus.getCode() == ClasspathContainerInitializer.ATTRIBUTE_READ_ONLY); entry= JavaModelUtil.findEntryInContainer(container, root.getPath()); Assert.isNotNull(entry); } Button button; IPath path= entry.getSourceAttachmentPath(); if (path == null || path.isEmpty()) { String rootLabel= JavaElementLabels.getElementLabel(root, JavaElementLabels.ALL_DEFAULT); createLabel(composite, Messages.format(JavaEditorMessages.SourceAttachmentForm_message_noSourceAttachment, rootLabel)); createLabel(composite, JavaEditorMessages.SourceAttachmentForm_message_pressButtonToAttach); createLabel(composite, null); button= createButton(composite, JavaEditorMessages.SourceAttachmentForm_button_attachSource); } else { createLabel(composite, Messages.format(JavaEditorMessages.SourceAttachmentForm_message_noSourceInAttachment, BasicElementLabels.getFileName(fFile))); createLabel(composite, JavaEditorMessages.SourceAttachmentForm_message_pressButtonToChange); createLabel(composite, null); button= createButton(composite, JavaEditorMessages.SourceAttachmentForm_button_changeAttachedSource); } button.addSelectionListener(getButtonListener(entry, containerPath, jproject, canEditEncoding)); }