List of usage examples for org.eclipse.jdt.core IClasspathEntry CPE_CONTAINER
int CPE_CONTAINER
To view the source code for org.eclipse.jdt.core IClasspathEntry CPE_CONTAINER.
Click Source Link
From source file:com.codenvy.ide.ext.java.server.internal.core.ClasspathEntry.java
License:Open Source License
/** * Answers an ID which is used to distinguish entries during package * fragment root computations/*from www. j av a2 s .co m*/ */ public String rootID() { if (this.rootID == null) { switch (this.entryKind) { case IClasspathEntry.CPE_LIBRARY: this.rootID = "[LIB]" + this.path; //$NON-NLS-1$ break; case IClasspathEntry.CPE_PROJECT: this.rootID = "[PRJ]" + this.path; //$NON-NLS-1$ break; case IClasspathEntry.CPE_SOURCE: this.rootID = "[SRC]" + this.path; //$NON-NLS-1$ break; case IClasspathEntry.CPE_VARIABLE: this.rootID = "[VAR]" + this.path; //$NON-NLS-1$ break; case IClasspathEntry.CPE_CONTAINER: this.rootID = "[CON]" + this.path; //$NON-NLS-1$ break; default: this.rootID = ""; //$NON-NLS-1$ break; } } return this.rootID; }
From source file:com.codenvy.ide.ext.java.server.internal.core.search.JavaSearchScope.java
License:Open Source License
/** * Add a path to current java search scope or all project fragment roots if null. * Use project resolved classpath to retrieve and store access restriction on each classpath entry. * Recurse if dependent projects are found. * * @param javaProject// w w w . j a v a 2 s.co m * Project used to get resolved classpath entries * @param pathToAdd * Path to add in case of single element or null if user want to add all project package fragment roots * @param includeMask * Mask to apply on classpath entries * @param projectsToBeAdded * Set to avoid infinite recursion * @param visitedProjects * Set to avoid adding twice the same project * @param referringEntry * Project raw entry in referring project classpath * @throws org.eclipse.jdt.core.JavaModelException * May happen while getting java model info */ void add(JavaProject javaProject, IPath pathToAdd, int includeMask, HashSet projectsToBeAdded, HashSet visitedProjects, IClasspathEntry referringEntry) throws JavaModelException { // IProject project = javaProject.getProject(); // if (!project.isAccessible() || !visitedProjects.add(project)) return; IPath projectPath = javaProject.getFullPath(); String projectPathString = projectPath.toString(); addEnclosingProjectOrJar(projectPath); IClasspathEntry[] entries = javaProject.getResolvedClasspath(); // IJavaModel model = javaProject.getJavaModel(); // JavaModelManager.PerProjectInfo perProjectInfo = javaProject.getPerProjectInfo(); for (int i = 0, length = entries.length; i < length; i++) { IClasspathEntry entry = entries[i]; AccessRuleSet access = null; ClasspathEntry cpEntry = (ClasspathEntry) entry; if (referringEntry != null) { // Add only exported entries. // Source folder are implicitly exported. if (!entry.isExported() && entry.getEntryKind() != IClasspathEntry.CPE_SOURCE) { continue; } cpEntry = cpEntry.combineWith((ClasspathEntry) referringEntry); // cpEntry = ((ClasspathEntry)referringEntry).combineWith(cpEntry); } access = cpEntry.getAccessRuleSet(); switch (entry.getEntryKind()) { case IClasspathEntry.CPE_LIBRARY: IClasspathEntry rawEntry = null; // Map rootPathToRawEntries = perProjectInfo.rootPathToRawEntries; // if (rootPathToRawEntries != null) { // rawEntry = (IClasspathEntry)rootPathToRawEntries.get(entry.getPath()); // } // if (rawEntry == null) break; rawKind: switch (cpEntry.getEntryKind()) { case IClasspathEntry.CPE_LIBRARY: case IClasspathEntry.CPE_VARIABLE: if ((includeMask & APPLICATION_LIBRARIES) != 0) { IPath path = entry.getPath(); if (pathToAdd == null || pathToAdd.equals(path)) { // Object target = JavaModel.getTarget(path, false/*don't check existence*/); // if (target instanceof IFolder) // case of an external folder // path = ((IFolder)target).getFullPath(); String pathToString = path.getDevice() == null ? path.toString() : path.toOSString(); add(projectPath.toString(), "", pathToString, false/*not a package*/, access); //$NON-NLS-1$ addEnclosingProjectOrJar(entry.getPath()); } } break; case IClasspathEntry.CPE_CONTAINER: IClasspathContainer container = JavaCore.getClasspathContainer(rawEntry.getPath(), javaProject); if (container == null) break; switch (container.getKind()) { case IClasspathContainer.K_APPLICATION: if ((includeMask & APPLICATION_LIBRARIES) == 0) break rawKind; break; case IClasspathContainer.K_SYSTEM: case IClasspathContainer.K_DEFAULT_SYSTEM: if ((includeMask & SYSTEM_LIBRARIES) == 0) break rawKind; break; default: break rawKind; } IPath path = entry.getPath(); if (pathToAdd == null || pathToAdd.equals(path)) { Object target = JavaModel.getTarget(path, false/*don't check existence*/); if (target instanceof IFolder) // case of an external folder path = ((IFolder) target).getFullPath(); String pathToString = path.getDevice() == null ? path.toString() : path.toOSString(); add(projectPath.toString(), "", pathToString, false/*not a package*/, access); //$NON-NLS-1$ addEnclosingProjectOrJar(entry.getPath()); } break; } break; case IClasspathEntry.CPE_PROJECT: // if ((includeMask & REFERENCED_PROJECTS) != 0) { // IPath path = entry.getPath(); // if (pathToAdd == null || pathToAdd.equals(path)) { // JavaProject referencedProject = (JavaProject)model.getJavaProject(path.lastSegment()); // if (!projectsToBeAdded // .contains(referencedProject)) { // do not recurse if depending project was used to create the scope // add(referencedProject, null, includeMask, projectsToBeAdded, visitedProjects, cpEntry); // } // } // } break; case IClasspathEntry.CPE_SOURCE: if ((includeMask & SOURCES) != 0) { IPath path = entry.getPath(); if (pathToAdd == null || pathToAdd.equals(path)) { add(projectPath.toString(), Util.relativePath(path, 1/*remove project segment*/), projectPathString, false/*not a package*/, access); } } break; } } }
From source file:com.drgarbage.bytecodevisualizer.editors.NoSourceViewer.java
License:Apache License
private void createSourceAttachmentControls(Composite composite, IPackageFragmentRoot root) throws JavaModelException { IClasspathEntry entry;/*from ww w.java 2 s.c om*/ try { entry = root.getRawClasspathEntry(); } catch (JavaModelException ex) { if (ex.isDoesNotExist()) entry = null; else throw ex; } IPath containerPath = null; if (entry == null || root.getKind() != IPackageFragmentRoot.K_BINARY) { String s = CoreMessages.SourceAttachmentForm_message_noSource; createLabel(composite, MessageFormat.format(s, new Object[] { fFile.getElementName() })); return; } IJavaProject jproject = root.getJavaProject(); 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, MessageFormat.format(CoreMessages.SourceAttachmentForm_cannotconfigure, new Object[] { containerPath.toString() })); return; } String containerName = container.getDescription(); IStatus status = initializer.getSourceAttachmentStatus(containerPath, jproject); if (status.getCode() == ClasspathContainerInitializer.ATTRIBUTE_NOT_SUPPORTED) { createLabel(composite, MessageFormat.format(CoreMessages.SourceAttachmentForm_notsupported, new Object[] { containerName })); return; } if (status.getCode() == ClasspathContainerInitializer.ATTRIBUTE_READ_ONLY) { createLabel(composite, MessageFormat.format(CoreMessages.SourceAttachmentForm_readonly, new Object[] { containerName })); return; } entry = JavaModelUtil.findEntryInContainer(container, root.getPath()); Assert.isNotNull(entry); } Button button; String msg = null; String btnText = null; IPath path = entry.getSourceAttachmentPath(); if (path == null || path.isEmpty()) { msg = MessageFormat.format(CoreMessages.SourceAttachmentForm_message_noSourceAttachment, new Object[] { root.getElementName() }); btnText = CoreMessages.SourceAttachmentForm_button_attachSource; } else { msg = MessageFormat.format(CoreMessages.SourceAttachmentForm_message_noSourceInAttachment, new Object[] { fFile.getElementName() }); btnText = CoreMessages.SourceAttachmentForm_button_changeAttachedSource; } createLabel(composite, msg); createLabel(composite, CoreMessages.SourceAttachmentForm_message_pressButtonToAttach); createLabel(composite, null); button = createButton(composite, btnText); button.addSelectionListener(createButtonListener(entry, containerPath, jproject)); }
From source file:com.google.appengine.eclipse.core.sdk.AppEngineUpdateProjectSdkCommandTest.java
License:Open Source License
/** * Tests that an expanded SDK gets replaced with the specified SDK container. *//*ww w . jav a 2 s . c om*/ public void testExecute() throws CoreException { final GaeSdk defaultSdk = GaePreferences.getDefaultSdk(); // Set the project's classpath contain the expanded container ClasspathUtilities.setRawClasspath(javaProject, defaultSdk.getClasspathEntries()); PluginTestUtils.waitForIdle(); final GaeSdk oldSdk = GaeSdk.findSdkFor(javaProject); ResourcesPlugin.getWorkspace().run(new IWorkspaceRunnable() { public void run(IProgressMonitor monitor) throws CoreException { try { AppEngineUpdateProjectSdkCommand command = new AppEngineUpdateProjectSdkCommand(javaProject, oldSdk, defaultSdk, UpdateType.DEFAULT_CONTAINER, null); command.execute(); } catch (FileNotFoundException e) { throw new CoreException(StatusUtilities.newErrorStatus(e, AppEngineCorePlugin.PLUGIN_ID)); } catch (BackingStoreException e) { throw new CoreException(StatusUtilities.newErrorStatus(e, AppEngineCorePlugin.PLUGIN_ID)); } } }, null); PluginTestUtils.waitForIdle(); IClasspathEntry[] rawClasspath = javaProject.getRawClasspath(); // Ensure that the entries were collapsed back into a single container entry assertEquals(1, rawClasspath.length); assertEquals(GaeSdkContainer.CONTAINER_PATH, rawClasspath[0].getPath()); assertEquals(IClasspathEntry.CPE_CONTAINER, rawClasspath[0].getEntryKind()); }
From source file:com.google.devtools.bazel.e4b.BazelProjectSupport.java
License:Open Source License
/** * Convert an Eclipse JDT project into an IntelliJ project view *///from w w w . ja v a2 s . c o m public static ProjectView getProjectView(IProject project) throws BackingStoreException, JavaModelException { com.google.devtools.bazel.e4b.projectviews.Builder builder = ProjectView.builder(); IScopeContext projectScope = new ProjectScope(project); Preferences projectNode = projectScope.getNode(Activator.PLUGIN_ID); for (String s : projectNode.keys()) { if (s.startsWith("buildArgs")) { builder.addBuildFlag(projectNode.get(s, "")); } else if (s.startsWith("target")) { builder.addTarget(projectNode.get(s, "")); } } IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); for (IClasspathEntry entry : ((IJavaProject) project).getRawClasspath()) { switch (entry.getEntryKind()) { case IClasspathEntry.CPE_SOURCE: IResource res = root.findMember(entry.getPath()); if (res != null) { builder.addDirectory(res.getProjectRelativePath().removeFirstSegments(1).toOSString()); } break; case IClasspathEntry.CPE_CONTAINER: String path = entry.getPath().toOSString(); if (path.startsWith(STANDARD_VM_CONTAINER_PREFIX)) { builder.setJavaLanguageLevel( Integer.parseInt(path.substring(STANDARD_VM_CONTAINER_PREFIX.length()))); } break; } } return builder.build(); }
From source file:com.google.gdt.eclipse.appengine.rpc.wizards.helpers.RpcServiceLayerCreator.java
License:Open Source License
private String getGwtContainerPath(IJavaProject javaProject) throws CoreException { IClasspathEntry[] entries = null;// ww w. j ava2s . c o m entries = javaProject.getRawClasspath(); for (IClasspathEntry entry : entries) { if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER && entry.getPath().toString().equals("com.google.gwt.eclipse.core.GWT_CONTAINER")) { //$NON-NLS-N$ IClasspathContainer container = JavaCore.getClasspathContainer(entry.getPath(), javaProject); if (container instanceof GWTRuntimeContainer) { IPath path = ((GWTRuntimeContainer) container).getSdk().getInstallationPath(); return path.toString(); } } } // gwt not on classpath, add to it, set nature GWTRuntime gwt = GWTPreferences.getDefaultRuntime(); IPath containerPath = SdkClasspathContainer.computeContainerPath(GWTRuntimeContainer.CONTAINER_ID, gwt, SdkClasspathContainer.Type.DEFAULT); if (GaeNature.isGaeProject(javaProject.getProject())) { addClasspathContainer(javaProject, containerPath); GWTNature.addNatureToProject(javaProject.getProject()); } return gwt.getInstallationPath().toString(); }
From source file:com.google.gdt.eclipse.core.ClasspathUtilities.java
License:Open Source License
/** * Finds all the classpath containers in the specified project that match the * provided container ID./*from w ww .j a v a 2 s.c o m*/ * * @param javaProject the project to query * @param containerId The container ID we are trying to match. * @return an array of matching classpath containers. */ public static IClasspathEntry[] findClasspathContainersWithContainerId(IJavaProject javaProject, final String containerId) throws JavaModelException { Predicate<IClasspathEntry> matchPredicate = new Predicate<IClasspathEntry>() { public boolean apply(IClasspathEntry entry) { if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { IPath containerPath = entry.getPath(); if (containerPath.segmentCount() > 0 && containerPath.segment(0).equals(containerId)) { return true; } } return false; } }; IClasspathEntry[] classpathEntries = javaProject.getRawClasspath(); int matchCount = 0; for (int i = 0; i < classpathEntries.length; i++) { if (matchPredicate.apply(classpathEntries[i])) { matchCount++; } } IClasspathEntry[] matchingClasspathEntries = new IClasspathEntry[matchCount]; int matchingClasspathEntriesIdx = 0; for (int i = 0; i < classpathEntries.length; i++) { if (matchPredicate.apply(classpathEntries[i])) { matchingClasspathEntries[matchingClasspathEntriesIdx] = classpathEntries[i]; matchingClasspathEntriesIdx++; } } return matchingClasspathEntries; }
From source file:com.google.gdt.eclipse.core.ClasspathUtilities.java
License:Open Source License
/** * Returns the first index of the specified * {@link IClasspathEntry#CPE_CONTAINER} entry with the specified container ID * or -1 if one could not be found./*from w w w. j a v a2s . com*/ * * @param classpathEntries array of classpath entries * @param containerId container ID * @return index of the specified {@link IClasspathEntry#CPE_CONTAINER} entry * with the specified container ID or -1 */ public static int indexOfClasspathEntryContainer(IClasspathEntry[] classpathEntries, String containerId) { for (int i = 0; i < classpathEntries.length; ++i) { IClasspathEntry classpathEntry = classpathEntries[i]; if (classpathEntry.getEntryKind() != IClasspathEntry.CPE_CONTAINER) { // Skip anything that is not a container continue; } IPath containerPath = classpathEntry.getPath(); if (containerPath.segmentCount() > 0 && containerPath.segment(0).equals(containerId)) { return i; } } return -1; }
From source file:com.google.gdt.eclipse.core.sdk.ClasspathContainerUpdateJob.java
License:Open Source License
@Override protected IStatus run(IProgressMonitor jobMonitor) { try {// www .java 2 s.c om IWorkspaceRunnable runnable = new IWorkspaceRunnable() { public void run(IProgressMonitor runnableMonitor) throws CoreException { IJavaProject[] projects = JavaCore.create(ResourcesPlugin.getWorkspace().getRoot()) .getJavaProjects(); runnableMonitor.beginTask(LaunchingMessages.LaunchingPlugin_0, projects.length + 1); rebindContainers(runnableMonitor, projects); runnableMonitor.done(); } /** * Rebind all of the classpath containers whose comparison ID matches * the expected ID. */ private void rebindContainers(IProgressMonitor runnableMonitor, IJavaProject[] projects) throws CoreException { for (IJavaProject project : projects) { // Update the progress monitor runnableMonitor.worked(1); IClasspathEntry[] rawClasspathEntries = project.getRawClasspath(); for (IClasspathEntry rawClasspathEntry : rawClasspathEntries) { if (rawClasspathEntry.getEntryKind() != IClasspathEntry.CPE_CONTAINER) { continue; } IPath path = rawClasspathEntry.getPath(); if (path == null || path.segmentCount() == 0) { continue; } Object actualComparisonId = classpathContainerInitializer.getComparisonID(path, project); if (!actualComparisonId.equals(expectedComparisonId)) { continue; } classpathContainerInitializer.initialize(path, project); } } } }; JavaCore.run(runnable, null, jobMonitor); return Status.OK_STATUS; } catch (CoreException e) { return e.getStatus(); } }
From source file:com.google.gdt.eclipse.core.sdk.SdkClasspathContainer.java
License:Open Source License
/** * Returns <code>true</code> if the classpath entry is an * {@link IClasspathEntry#CPE_CONTAINER} and it has the specified container * ID./*from w w w. jav a 2 s . com*/ * * @param containerId * @param classpathEntry * @return whether the classpathEntry is a container and has the containerId */ public static boolean isContainerClasspathEntry(String containerId, IClasspathEntry classpathEntry) { if (classpathEntry.getEntryKind() != IClasspathEntry.CPE_CONTAINER) { return false; } return isContainerPath(containerId, classpathEntry.getPath()); }