List of usage examples for org.eclipse.jdt.core IClasspathEntry getContentKind
int getContentKind();
From source file:org.key_project.util.jdt.JDTUtil.java
License:Open Source License
/** * Returns the {@link IResource}s of the given {@link IClasspathEntry}. * @param javaProject The actual {@link IJavaProject} that provides the {@link IClasspathEntry}. * @param entry The given {@link IClasspathEntry}. * @param alreadyHandledProjects The already handled {@link IProject} that don't need to be analysed again. * @return The found {@link IResource}s. * @throws JavaModelException //from w w w .jav a2 s . c om */ private static List<IResource> getResourceFor(IJavaProject javaProject, IClasspathEntry entry, int expectedKind, Set<IProject> alreadyHandledProjects) throws JavaModelException { if (entry != null) { if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER || entry.getEntryKind() == IClasspathEntry.CPE_SOURCE || entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY || entry.getEntryKind() == IClasspathEntry.CPE_VARIABLE) { List<IResource> result = new LinkedList<IResource>(); IPackageFragmentRoot[] roots = javaProject.findPackageFragmentRoots(entry); for (IPackageFragmentRoot root : roots) { if (root.getKind() == expectedKind) { if (root.getResource() != null) { if (root.getResource().getLocationURI() != null) { result.add(root.getResource()); } } else if (root.getPath() != null) { IResource resource = ResourcesPlugin.getWorkspace().getRoot() .findMember(root.getPath()); if (resource != null && resource.exists()) { result.add(resource); } } } } return result; // Ignore containers } else if (entry.getEntryKind() == IClasspathEntry.CPE_PROJECT) { Assert.isNotNull(entry.getPath()); IResource project = ResourcesPlugin.getWorkspace().getRoot().findMember(entry.getPath()); Assert.isTrue(project instanceof IProject); if (!alreadyHandledProjects.contains(project)) { return getSourceResources((IProject) project, alreadyHandledProjects); } else { return null; // Project was already analyzed, no need to do it again. } } else { Assert.isTrue(false, "Unknown content kind \"" + entry.getContentKind() + "\" of class path entry \"" + entry + "\"."); return null; } } else { return null; } }
From source file:org.key_project.util.jdt.JDTUtil.java
License:Open Source License
/** * Returns the locations of the given {@link IClasspathEntry}. * @param javaProject The actual {@link IJavaProject} that provides the {@link IClasspathEntry}. * @param entry The given {@link IClasspathEntry}. * @param alreadyHandledProjects The already handled {@link IProject} that don't need to be analysed again. * @return The found locations.//from ww w . j a v a 2 s . c o m * @throws JavaModelException */ private static List<File> getLocationFor(IJavaProject javaProject, IClasspathEntry entry, int expectedKind, Set<IProject> alreadyHandledProjects) throws JavaModelException { if (entry != null) { if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER || entry.getEntryKind() == IClasspathEntry.CPE_SOURCE || entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY || entry.getEntryKind() == IClasspathEntry.CPE_VARIABLE) { List<File> result = new LinkedList<File>(); IPackageFragmentRoot[] roots = javaProject.findPackageFragmentRoots(entry); for (IPackageFragmentRoot root : roots) { if (root.getKind() == expectedKind) { if (root.getResource() != null) { if (root.getResource().getLocationURI() != null) { result.add(ResourceUtil.getLocation(root.getResource())); } } else if (root.getPath() != null) { File location = new File(root.getPath().toString()); if (location.exists()) { result.add(location); } } } } return result; // Ignore containers } else if (entry.getEntryKind() == IClasspathEntry.CPE_PROJECT) { Assert.isNotNull(entry.getPath()); IResource project = ResourcesPlugin.getWorkspace().getRoot().findMember(entry.getPath()); Assert.isTrue(project instanceof IProject); if (!alreadyHandledProjects.contains(project)) { return getSourceLocations((IProject) project, alreadyHandledProjects); } else { return null; // Project was already analyzed, no need to do it again. } } else { Assert.isTrue(false, "Unknown content kind \"" + entry.getContentKind() + "\" of class path entry \"" + entry + "\"."); return null; } } else { return null; } }
From source file:org.springframework.ide.eclipse.boot.properties.editor.StsConfigMetadataRepositoryJsonLoader.java
License:Open Source License
/** * Load the {@link ConfigMetadataRepository} with the metadata of the current * classpath using the {@link #DEFAULT_LOCATION_PATTERN}. If the same config * metadata items is held within different resources, the first that is * loaded is kept which means the result is not deterministic. *///from ww w . ja v a 2s. com public ConfigurationMetadataRepository load(IJavaProject project) throws Exception { debug(">> load ConfigurationMetadataRepository for " + project.getElementName()); IClasspathEntry[] classpath = project.getResolvedClasspath(true); for (IClasspathEntry e : classpath) { int ekind = e.getEntryKind(); int ckind = e.getContentKind(); IPath path = e.getPath(); if (ekind == IClasspathEntry.CPE_LIBRARY && ckind == IPackageFragmentRoot.K_BINARY) { //jar file dependency File jarFile = path.toFile(); if (FileUtil.isJarFile(jarFile)) { loadFromJar(jarFile); } } else if (ekind == IClasspathEntry.CPE_PROJECT) { loadFromProjectDependency(e); } else { debug("Skipped: " + ekind(ekind) + " " + ckind(ckind) + ": " + path); } } loadFromOutputFolder(project); debug("<< load ConfigurationMetadataRepository for " + project.getElementName() + ": " + repository.getAllProperties().size() + " properties"); return repository; }
From source file:org.springframework.tooling.jdt.ls.commons.classpath.ClasspathUtil.java
License:Open Source License
private static String toContentKind(IClasspathEntry entry) { switch (entry.getContentKind()) { case IPackageFragmentRoot.K_BINARY: return ENTRY_KIND_BINARY; case IPackageFragmentRoot.K_SOURCE: return ENTRY_KIND_SOURCE; default:/* w w w . ja v a 2 s . c o m*/ return "unknown: " + entry.getContentKind(); } }