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.google.gdt.eclipse.managedapis.impl.ManagedApiProjectImpl.java
License:Open Source License
public static String getAndroidSdk(IProject androidProject) throws JavaModelException { if (androidProject == null) { return null; }//from w ww. j ava2 s . com IJavaProject androidJavaProject = JavaCore.create(androidProject); List<IClasspathEntry> rawClasspathList = new ArrayList<IClasspathEntry>(); rawClasspathList.addAll(Arrays.asList(androidJavaProject.getRawClasspath())); for (IClasspathEntry e : rawClasspathList) { if (e.getEntryKind() != IClasspathEntry.CPE_CONTAINER) { continue; } IClasspathContainer c = JavaCore.getClasspathContainer(e.getPath(), androidJavaProject); if (c.getDescription().contains(ANDROID_2_CLASSPATH_CONTAINER)) { return ANDROID2_ENVIRONMENT; } else if (c.getDescription().contains(ANDROID_3_CLASSPATH_CONTAINER) || c.getDescription().contains(ANDROID_4_CLASSPATH_CONTAINER)) { return ANDROID3_ENVIRONMENT; } } return null; }
From source file:com.google.gdt.eclipse.managedapis.impl.ManagedApiProjectImpl.java
License:Open Source License
public ManagedApi[] getManagedApis() { List<ManagedApi> installedApis = new ArrayList<ManagedApi>(); if (eProject != null) { IJavaProject project = eProject.getJavaProject(); if (project != null) { try { IClasspathEntry[] rawClasspath = project.getRawClasspath(); for (IClasspathEntry entry : rawClasspath) { if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { if (ManagedApiPlugin.API_CONTAINER_PATH.isPrefixOf(entry.getPath())) { IClasspathContainer container = JavaCore.getClasspathContainer(entry.getPath(), project); if (container instanceof ManagedApiContainer) { ManagedApiContainer managedApiContainer = (ManagedApiContainer) container; installedApis.add(managedApiContainer.getManagedApi()); }//from w ww . ja va 2 s . c o m } } } } catch (JavaModelException e) { ManagedApiLogger.warn(e, "Error reading classpath"); } } } return installedApis.toArray(new ManagedApi[installedApis.size()]); }
From source file:com.google.gdt.eclipse.managedapis.ui.ManagedApiContainerFilter.java
License:Open Source License
/** * @return false if the Java element is a file that is contained in a * SimpleDirContainer that is in the classpath of the owning Java * project (non-Javadoc)//from w w w . j a v a2 s. com * * @see org.eclipse.jface.viewers.ViewerFilter#select(org.eclipse.jface.viewers.Viewer, * java.lang.Object, java.lang.Object) */ @Override public boolean select(Viewer viewer, Object parentElement, Object element) { if (element instanceof IResource) { IResource resource = (IResource) element; if (resource.getType() == IResource.FILE || resource.getType() == IResource.FOLDER) { IProject project = resource.getProject(); try { if (project != null && project.exists() && NatureUtils.hasNature(project, JavaCore.NATURE_ID)) { IJavaProject jp = JavaCore.create(resource.getProject()); // lets see if this file is included within a ManagedApiRoot IClasspathEntry[] entries = jp.getRawClasspath(); for (IClasspathEntry entry : entries) { if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { if (ManagedApiPlugin.API_CONTAINER_PATH.isPrefixOf(entry.getPath())) { // this is likely a ManagedApiContainer, but the container // could be a ghost, and thus unmapped to a // ManagedApiContainer - check below IClasspathContainer container = JavaCore.getClasspathContainer(entry.getPath(), jp); if (container instanceof ManagedApiContainer) { ManagedApiContainer managedApiContainer = (ManagedApiContainer) container; if (managedApiContainer.contains(resource)) { // this file will is included in the container, so hide it return false; } } } } } } } catch (JavaModelException e) { ManagedApiLogger.warn(e, "Error reading the classpath"); } catch (CoreException e) { ManagedApiLogger.warn(e, "Error accessing Java Project"); } } } return true; }
From source file:com.google.gwt.eclipse.core.runtime.AbstractGWTRuntimeTest.java
License:Open Source License
protected boolean assertGWTRuntimeEntry(IPath runtimePath, IClasspathEntry[] entries) { boolean hasGWTRuntime = false; for (IClasspathEntry entry : entries) { IPath entryPath = entry.getPath(); if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { if (GWTRuntimeContainer.isPathForGWTRuntimeContainer(entryPath)) { // Make sure we have only one GWT runtime if (hasGWTRuntime) { return false; }/* www . jav a2 s . c o m*/ // We found at a GWT runtime hasGWTRuntime = true; // Make sure it's the one we're looking for if (!entryPath.equals(runtimePath)) { return false; } } } // Make sure we don't have any gwt-user.jar dependencies if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { String jarName = entryPath.lastSegment(); if (jarName.equals(GWTRuntime.GWT_USER_JAR)) { return false; } } } return hasGWTRuntime; }
From source file:com.google.gwt.eclipse.core.runtime.AbstractGWTRuntimeTest.java
License:Open Source License
protected void removeGWTRuntimeFromTestProject() throws Exception { IJavaProject project = getTestProject(); // Replace GWT runtime classpath entry with gwt-user.jar and // gwt-dev-PLAT.jar List<IClasspathEntry> newEntries = new ArrayList<IClasspathEntry>(); for (IClasspathEntry entry : project.getRawClasspath()) { if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { if (GWTRuntimeContainer.isPathForGWTRuntimeContainer(entry.getPath())) { GWTJarsRuntime defaultSdk = GwtRuntimeTestUtilities.getDefaultRuntime(); IPath gwtUserJar = defaultSdk.getInstallationPath().append(GWTRuntime.GWT_USER_JAR); newEntries.add(JavaCore.newLibraryEntry(gwtUserJar, null, null)); IPath gwtDevJar = defaultSdk.getInstallationPath() .append(Util.getDevJarName(defaultSdk.getInstallationPath())); newEntries.add(JavaCore.newLibraryEntry(gwtDevJar, null, null)); continue; }/*from ww w . j a v a 2 s . c o m*/ } // Leave non-GWT runtime entries on the classpath as is newEntries.add(entry); } ClasspathUtilities.setRawClasspath(project, newEntries); JobsUtilities.waitForIdle(); }
From source file:com.google.gwt.eclipse.core.validators.java.JsniJavaRef.java
License:Open Source License
public IJavaElement resolveJavaElement(IJavaProject project) throws UnresolvedJsniJavaRefException { IJavaElement element = null;/*w w w. jav a 2s . c om*/ // 0. Ignore the magic null reference if (className().equals("null")) { throw new UnresolvedJsniJavaRefException(null, this); } // 1. Try to find the type in the project's classpath IType type = JavaModelSearch.findType(project, dottedClassName()); if (type == null) { throw new UnresolvedJsniJavaRefException(GWTProblemType.JSNI_JAVA_REF_UNRESOLVED_TYPE, this); } // TODO: remove this check once we can validate against super source // 1A. Do not validate JRE types (they could contain references to members // which are only defined in the emulated versions in super source) if (type.isBinary()) { IPackageFragmentRoot pkgRoot = (IPackageFragmentRoot) type .getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT); try { IClasspathEntry cpEntry = pkgRoot.getRawClasspathEntry(); if (cpEntry.getEntryKind() == IClasspathEntry.CPE_CONTAINER && cpEntry.getPath().segment(0).equals(JavaRuntime.JRE_CONTAINER)) { throw new UnresolvedJsniJavaRefException(null, this); } } catch (JavaModelException e) { GWTPluginLog.logError(e); throw new UnresolvedJsniJavaRefException(null, this); } } // 2. Create a super-type hierarchy for the type, which we'll use for // finding its super classes and implemented interfaces ITypeHierarchy hierarchy; try { hierarchy = type.newSupertypeHierarchy(null); } catch (JavaModelException e) { GWTPluginLog.logError(e, "Error creating type hierarchy for " + className()); throw new UnresolvedJsniJavaRefException(GWTProblemType.JSNI_JAVA_REF_UNRESOLVED_TYPE, this); } if (isMethod()) { if (isConstructor()) { if (matchesAnyOverload()) { element = JavaModelSearch.findFirstCtor(type); } else { String[] ctorParamTypes = paramTypes(); try { /* * If the constructor is on a non-static inner class, the reference * will have an extra parameter that specifies the enclosing type. * We'll need to check that type and then remove the parameter * before using JavaModelSearch to find the constructor. */ IJavaElement typeParent = type.getParent(); if (typeParent.getElementType() == IJavaElement.TYPE && !Flags.isStatic(type.getFlags())) { // Make sure we do have the enclosing type as the first parameter if (ctorParamTypes.length == 0) { throw new UnresolvedJsniJavaRefException( GWTProblemType.JSNI_JAVA_REF_NO_MATCHING_CTOR, this); } // Now verify that the type of the first parameter is actually the // the same type as the enclosing type IType parentType = (IType) typeParent; String enclosingTypeName = parentType.getFullyQualifiedName('.'); String enclosingTypeParam = JavaModelSearch.getQualifiedTypeName(ctorParamTypes[0]); if (!enclosingTypeName.equals(enclosingTypeParam)) { throw new UnresolvedJsniJavaRefException( GWTProblemType.JSNI_JAVA_REF_NO_MATCHING_CTOR, this); } // Drop the first parameter (the enclosing type) ctorParamTypes = new String[paramTypes().length - 1]; System.arraycopy(paramTypes(), 1, ctorParamTypes, 0, ctorParamTypes.length); } } catch (JavaModelException e) { GWTPluginLog.logError(e); // Continue on and try to resolve the reference anyway } // 3A. Find a constructor for this type with matching parameter types element = JavaModelSearch.findCtorInHierarchy(hierarchy, type, ctorParamTypes); if (element == null) { throw new UnresolvedJsniJavaRefException(GWTProblemType.JSNI_JAVA_REF_NO_MATCHING_CTOR, this); } } } else { // 3B. Find a method for this type with the same name element = JavaModelSearch.findMethodInHierarchy(hierarchy, type, memberName()); if (element == null) { try { if (type.isEnum()) { // Ignore the magic Enum::values() method if (memberName().equals("values") && !matchesAnyOverload() && paramTypes().length == 0) { // Throwing this exception with a null GWTProblemType indicates // that the ref doesn't resolve, but can be ignored anyway. throw new UnresolvedJsniJavaRefException(null, this); } } } catch (JavaModelException e) { GWTPluginLog.logError(e); } throw new UnresolvedJsniJavaRefException(GWTProblemType.JSNI_JAVA_REF_MISSING_METHOD, this); } if (!matchesAnyOverload()) { // Now try to match the method's parameter types element = JavaModelSearch.findMethodInHierarchy(hierarchy, type, memberName(), paramTypes()); if (element == null) { try { if (type.isEnum()) { // Ignore the synthetic Enum::valueOf(String) method. // Note that valueOf(Class,String) is not synthetic. if (memberName().equals("valueOf") && paramTypes().length == 1 && paramTypes()[0].equals("Ljava/lang/String;")) { // Throwing this exception with a null GWTProblemType // indicates that the ref doesn't resolve, but can be ignored // anyway. throw new UnresolvedJsniJavaRefException(null, this); } } } catch (JavaModelException e) { GWTPluginLog.logError(e); } throw new UnresolvedJsniJavaRefException(GWTProblemType.JSNI_JAVA_REF_NO_MATCHING_METHOD, this); } } } } else { // 3C. Find a field with the same name assert (isField()); element = JavaModelSearch.findFieldInHierarchy(hierarchy, type, memberName()); if (element == null) { throw new UnresolvedJsniJavaRefException(GWTProblemType.JSNI_JAVA_REF_MISSING_FIELD, this); } } assert (element != null); return element; }
From source file:com.google.inject.tools.ideplugin.eclipse.EclipseJavaProject.java
License:Apache License
private List<String> expandClasspath(IClasspathEntry[] entries, String projectName, String projectLocation) throws Exception { final List<String> args = new ArrayList<String>(); IResource presource;/*from w w w . ja v a2s . c o m*/ String resourceLocation; String path; for (IClasspathEntry entry : entries) { switch (entry.getEntryKind()) { case IClasspathEntry.CPE_CONTAINER: IClasspathContainer container = JavaCore.getClasspathContainer(entry.getPath(), project); args.addAll(expandClasspath(container.getClasspathEntries(), projectName, projectLocation)); break; case IClasspathEntry.CPE_SOURCE: IResource resource = ResourcesPlugin.getWorkspace().getRoot().findMember(entry.getPath()); path = resource.getLocation().makeAbsolute().toOSString(); if (path.startsWith("/" + projectName)) { args.add(path.replaceFirst("/" + projectName, projectLocation)); } else { args.add(path); } break; case IClasspathEntry.CPE_LIBRARY: path = entry.getPath().makeAbsolute().toOSString(); if (path.startsWith("/" + projectName)) { args.add(path.replaceFirst("/" + projectName, projectLocation)); } else { args.add(path); } break; case IClasspathEntry.CPE_PROJECT: presource = ResourcesPlugin.getWorkspace().getRoot().findMember(entry.getPath()); resourceLocation = presource.getLocation().makeAbsolute().toOSString(); String outputLocation = resourceLocation; args.add(outputLocation.replaceFirst(presource.getName(), resourceLocation)); break; case IClasspathEntry.CPE_VARIABLE: break; default: //never happens } } return args; }
From source file:com.ibm.wala.ide.util.JavaEclipseProjectPath.java
License:Open Source License
@Override protected void resolveClasspathEntry(IJavaProject project, IClasspathEntry entry, ILoader loader, boolean includeSource, boolean cpeFromMainProject) { entry = JavaCore.getResolvedClasspathEntry(entry); switch (entry.getEntryKind()) { case IClasspathEntry.CPE_SOURCE: { resolveSourcePathEntry(includeSource ? JavaSourceLoader.SOURCE : Loader.APPLICATION, includeSource, cpeFromMainProject, entry.getPath(), entry.getOutputLocation(), entry.getExclusionPatterns(), "java"); break;// w ww.ja v a2 s. c om } case IClasspathEntry.CPE_LIBRARY: { resolveLibraryPathEntry(loader, entry.getPath()); break; } case IClasspathEntry.CPE_PROJECT: { resolveProjectPathEntry(loader, includeSource, entry.getPath()); break; } case IClasspathEntry.CPE_CONTAINER: { try { IClasspathContainer cont = JavaCore.getClasspathContainer(entry.getPath(), project); IClasspathEntry[] entries = cont.getClasspathEntries(); resolveClasspathEntries(project, Arrays.asList(entries), cont.getKind() == IClasspathContainer.K_APPLICATION ? loader : Loader.PRIMORDIAL, includeSource, false); } catch (CoreException e) { System.err.println(e); Assertions.UNREACHABLE(); } } } }
From source file:com.iw.plugins.spindle.ant.AntScriptGenerator.java
License:Mozilla Public License
/** * We need to collect and filter the list of classpath roots, src and binary. * We need to separate jars containing javax.servet.* classes and ignore the * JRE classpath container setting altogether. * /*from w w w . j a va 2s .c o m*/ * @param monitor a progress monitor */ private void resolveProjectClasspath(IProgressMonitor monitor) { ArrayList resolvedEntries = new ArrayList(); IJavaProject jproject = null; try { jproject = fTapestryProject.getJavaProject(); IClasspathEntry[] entries = jproject.getRawClasspath(); // we need to ignore JRE entires and collect all of the other entries! // don't separate src from binary roots at this time. for (int i = 0; i < entries.length; i++) { switch (entries[i].getEntryKind()) { case IClasspathEntry.CPE_VARIABLE: IClasspathEntry resolvedEntry = null; try { resolvedEntry = JavaCore.getResolvedClasspathEntry(entries[i]); } catch (org.eclipse.jdt.internal.core.Assert.AssertionFailedException e) { UIPlugin.log(e); } if (resolvedEntry != null) resolvedEntries.add(resolvedEntry); break; case IClasspathEntry.CPE_CONTAINER: //We don't care about the JRE! if ("".equals(entries[i].getPath())) break; IClasspathContainer container = JavaCore.getClasspathContainer(entries[i].getPath(), jproject); if (container == null) break; IClasspathEntry[] containerEntries = container.getClasspathEntries(); if (containerEntries == null) break; // container was bound for (int j = 0, containerLength = containerEntries.length; j < containerLength; j++) { IClasspathEntry cEntry = containerEntries[j]; // if (generateMarkerOnError) // { // IJavaModelStatus containerStatus = // ClasspathEntry.validateClasspathEntry( // jproject, // cEntry, // false, // true /* recurse */); // if (!containerStatus.isOK()) // createClasspathProblemMarker(containerStatus); // } // if container is exported, then its nested entries must in turn // be exported (21749) resolvedEntries.add(cEntry); } break; default: resolvedEntries.add(entries[i]); } } } catch (CoreException e) { UIPlugin.log(e); } if (jproject == null) return; }
From source file:com.iw.plugins.spindle.ui.widgets.TypeChooserWidget.java
License:Mozilla Public License
public void configure(final IJavaProject project, final IRunnableContext context) { try {//from w ww . j av a2 s. co m final boolean baseIsInterface = fHierarchyRoot.isInterface(); fSearchResults = new ArrayList(); IRunnableWithProgress runnable = new IRunnableWithProgress() { public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { IJavaSearchScope scope = null; try { // we want to rip out the JRE entry as there's no chance of finding a tapestry class there. ArrayList roots = new ArrayList(); IClasspathEntry[] classpath = project.getRawClasspath(); for (int i = 0; i < classpath.length; i++) { if (classpath[i].getEntryKind() == IClasspathEntry.CPE_CONTAINER) { IPath cpPath = classpath[i].getPath(); if (JavaRuntime.JRE_CONTAINER.equals(cpPath.segment(0))) continue; } roots.add(project.findPackageFragmentRoots(classpath[i])); } scope = SearchEngine.createJavaSearchScope( (IJavaElement[]) roots.toArray(new IJavaElement[roots.size()]), true); } catch (JavaModelException e1) { scope = SearchEngine.createJavaSearchScope(new IJavaElement[] { project }, true); } ISearchPattern pattern = SearchEngine.createSearchPattern("*", IJavaSearchConstants.TYPE, IJavaSearchConstants.DECLARATIONS, true); SearchEngine engine = new SearchEngine(); IJavaSearchResultCollector collector = new IJavaSearchResultCollector() { public void aboutToStart() { } public void accept(IResource resource, int start, int end, IJavaElement enclosingElement, int accuracy) throws CoreException { if (accuracy != EXACT_MATCH) return; if (enclosingElement.getElementType() != IJavaElement.TYPE) return; IType type = (IType) enclosingElement; System.out.println(type.getFullyQualifiedName()); if (baseIsInterface) { if (!CoreUtils.implementsInterface(type, fHierarchyRoot.getElementName())) return; } else { if (!CoreUtils.extendsType(type, fHierarchyRoot)) return; } System.out.println(type.getFullyQualifiedName()); fSearchResults.add(type); } public void done() { } public IProgressMonitor getProgressMonitor() { return monitor; } }; try { engine.search(ResourcesPlugin.getWorkspace(), pattern, scope, collector); } catch (JavaModelException e) { UIPlugin.log(e); } } }; context.run(false, true, runnable); } catch (InvocationTargetException e) { UIPlugin.log(e); } catch (InterruptedException e) { //do nothing; } catch (JavaModelException e) { UIPlugin.log(e); } }