List of usage examples for org.eclipse.jdt.core IClasspathEntry CPE_VARIABLE
int CPE_VARIABLE
To view the source code for org.eclipse.jdt.core IClasspathEntry CPE_VARIABLE.
Click Source Link
From source file:com.redhat.ceylon.eclipse.code.explorer.PackageExplorerContentProvider.java
License:Open Source License
@Override protected Object internalGetParent(Object element) { if (!fIsFlatLayout && element instanceof IPackageFragment) { return getHierarchicalPackageParent((IPackageFragment) element); } else if (element instanceof IPackageFragmentRoot) { // since we insert logical package containers we have to fix // up the parent for package fragment roots so that they refer // to the container and containers refer to the project IPackageFragmentRoot root = (IPackageFragmentRoot) element; try {// w w w . j a v a2s . c o m IClasspathEntry entry = root.getRawClasspathEntry(); int entryKind = entry.getEntryKind(); if (entryKind == IClasspathEntry.CPE_CONTAINER) { return new ClassPathContainer(root.getJavaProject(), entry); } else if (fShowLibrariesNode && (entryKind == IClasspathEntry.CPE_LIBRARY || entryKind == IClasspathEntry.CPE_VARIABLE)) { return new LibraryContainer(root.getJavaProject()); } } catch (JavaModelException e) { // fall through } } else if (element instanceof PackageFragmentRootContainer) { return ((PackageFragmentRootContainer) element).getJavaProject(); } return super.internalGetParent(element); }
From source file:com.redhat.ceylon.eclipse.code.preferences.CeylonBuildPathsBlock.java
License:Open Source License
private int getPageIndex(int entryKind) { switch (entryKind) { case IClasspathEntry.CPE_CONTAINER: case IClasspathEntry.CPE_LIBRARY: case IClasspathEntry.CPE_VARIABLE: return 2; case IClasspathEntry.CPE_PROJECT: return 1; case IClasspathEntry.CPE_SOURCE: return 0; }/* ww w.j av a 2s . co m*/ return 0; }
From source file:com.redhat.ceylon.eclipse.code.preferences.ResourceListLabelProvider.java
License:Open Source License
public String getCPListElementAttributeText(CPListElementAttribute attrib) { String notAvailable = NewWizardMessages.CPListLabelProvider_none; String key = attrib.getKey(); if (key.equals(CPListElement.SOURCEATTACHMENT)) { String arg;//from w w w .j av a2s . c om IPath path = (IPath) attrib.getValue(); if (path != null && !path.isEmpty()) { if (attrib.getParent().getEntryKind() == IClasspathEntry.CPE_VARIABLE) { arg = getVariableString(path); } else { arg = getPathString(path, path.getDevice() != null); } } else { arg = notAvailable; } return Messages.format(NewWizardMessages.CPListLabelProvider_source_attachment_label, new String[] { arg }); } else if (key.equals(CPListElement.OUTPUT)) { String arg = null; IPath path = (IPath) attrib.getValue(); if (path != null) { arg = BasicElementLabels.getPathLabel(path, false); } else { arg = NewWizardMessages.CPListLabelProvider_default_output_folder_label; } return Messages.format(NewWizardMessages.CPListLabelProvider_output_folder_label, new String[] { arg }); } else if (key.equals(CPListElement.EXCLUSION)) { String arg = null; IPath[] patterns = (IPath[]) attrib.getValue(); if (patterns != null && patterns.length > 0) { int patternsCount = 0; StringBuffer buf = new StringBuffer(); for (int i = 0; i < patterns.length; i++) { if (patterns[i].segmentCount() > 0) { String pattern = BasicElementLabels.getPathLabel(patterns[i], false); if (patternsCount > 0) { buf.append(NewWizardMessages.CPListLabelProvider_exclusion_filter_separator); } buf.append(pattern); patternsCount++; } } if (patternsCount > 0) { arg = buf.toString(); } else { arg = notAvailable; } } else { arg = notAvailable; } return Messages.format(NewWizardMessages.CPListLabelProvider_exclusion_filter_label, new String[] { arg }); } else if (key.equals(CPListElement.INCLUSION)) { String arg = null; IPath[] patterns = (IPath[]) attrib.getValue(); if (patterns != null && patterns.length > 0) { int patternsCount = 0; StringBuffer buf = new StringBuffer(); for (int i = 0; i < patterns.length; i++) { if (patterns[i].segmentCount() > 0) { String pattern = BasicElementLabels.getPathLabel(patterns[i], false); if (patternsCount > 0) { buf.append(NewWizardMessages.CPListLabelProvider_inclusion_filter_separator); } buf.append(pattern); patternsCount++; } } if (patternsCount > 0) { arg = buf.toString(); } else { arg = notAvailable; } } else { arg = NewWizardMessages.CPListLabelProvider_all; } return Messages.format(NewWizardMessages.CPListLabelProvider_inclusion_filter_label, new String[] { arg }); } else if (key.equals(CPListElement.ACCESSRULES)) { IAccessRule[] rules = (IAccessRule[]) attrib.getValue(); int nRules = rules != null ? rules.length : 0; int parentKind = attrib.getParent().getEntryKind(); if (parentKind == IClasspathEntry.CPE_PROJECT) { Boolean combined = (Boolean) attrib.getParent().getAttribute(CPListElement.COMBINE_ACCESSRULES); if (nRules > 0) { if (combined.booleanValue()) { if (nRules == 1) { return NewWizardMessages.CPListLabelProvider_project_access_rules_combined_singular; } else { return Messages.format( NewWizardMessages.CPListLabelProvider_project_access_rules_combined_plural, String.valueOf(nRules)); } } else { if (nRules == 1) { return NewWizardMessages.CPListLabelProvider_project_access_rules_not_combined_singular; } else { return Messages.format( NewWizardMessages.CPListLabelProvider_project_access_rules_not_combined_plural, String.valueOf(nRules)); } } } else { return NewWizardMessages.CPListLabelProvider_project_access_rules_no_rules; } } else if (parentKind == IClasspathEntry.CPE_CONTAINER) { if (nRules > 1) { return Messages.format(NewWizardMessages.CPListLabelProvider_container_access_rules_plural, String.valueOf(nRules)); } else if (nRules == 1) { return NewWizardMessages.CPListLabelProvider_container_access_rules_singular; } else { return NewWizardMessages.CPListLabelProvider_container_no_access_rules; } } else { if (nRules > 1) { return Messages.format(NewWizardMessages.CPListLabelProvider_access_rules_enabled_plural, String.valueOf(nRules)); } else if (nRules == 1) { return NewWizardMessages.CPListLabelProvider_access_rules_enabled_singular; } else { return NewWizardMessages.CPListLabelProvider_access_rules_disabled; } } } else if (key.equals(CPListElement.IGNORE_OPTIONAL_PROBLEMS)) { String arg; if ("true".equals(attrib.getValue())) { //$NON-NLS-1$ arg = NewWizardMessages.CPListLabelProvider_ignore_optional_problems_yes; } else { arg = NewWizardMessages.CPListLabelProvider_ignore_optional_problems_no; } return Messages.format(NewWizardMessages.CPListLabelProvider_ignore_optional_problems_label, arg); } else { ClasspathAttributeConfiguration config = fAttributeDescriptors.get(key); if (config != null) { ClasspathAttributeAccess access = attrib.getClasspathAttributeAccess(); String nameLabel = config.getNameLabel(access); String valueLabel = config.getValueLabel(access); // should be LTR marked return Messages.format(NewWizardMessages.CPListLabelProvider_attribute_label, new String[] { nameLabel, valueLabel }); } String arg = (String) attrib.getValue(); if (arg == null) { arg = notAvailable; } return Messages.format(NewWizardMessages.CPListLabelProvider_attribute_label, new String[] { key, arg }); } }
From source file:com.redhat.ceylon.eclipse.core.classpath.CeylonClasspathUtil.java
License:Apache License
/** * Just a verbatim copy of the internal Eclipse function: * org.eclipse.jdt.internal.corext.javadoc * .JavaDocLocations#getLibraryJavadocLocation(IClasspathEntry) * /* w ww . j a v a 2 s.c om*/ * @param entry * @return */ public static URL getLibraryJavadocLocation(IClasspathEntry entry) { if (entry == null) { throw new IllegalArgumentException("Entry must not be null"); //$NON-NLS-1$ } int kind = entry.getEntryKind(); if (kind != IClasspathEntry.CPE_LIBRARY && kind != IClasspathEntry.CPE_VARIABLE) { throw new IllegalArgumentException("Entry must be of kind CPE_LIBRARY or " + "CPE_VARIABLE"); //$NON-NLS-1$ } IClasspathAttribute[] extraAttributes = entry.getExtraAttributes(); for (int i = 0; i < extraAttributes.length; i++) { IClasspathAttribute attrib = extraAttributes[i]; if (IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME.equals(attrib.getName())) { try { return new URL(attrib.getValue()); } catch (MalformedURLException e) { return null; } } } return null; }
From source file:com.redhat.ceylon.eclipse.core.model.JDTModelLoader.java
License:Open Source License
@Override public synchronized boolean loadPackage(Module module, String packageName, boolean loadDeclarations) { packageName = Util.quoteJavaKeywords(packageName); if (loadDeclarations && !loadedPackages.add(cacheKeyByModule(module, packageName))) { return true; }// w w w .j a va2 s . com if (module instanceof JDTModule) { JDTModule jdtModule = (JDTModule) module; List<IPackageFragmentRoot> roots = jdtModule.getPackageFragmentRoots(); IPackageFragment packageFragment = null; for (IPackageFragmentRoot root : roots) { // skip packages that are not present if (!root.exists() || !javaProject.isOnClasspath(root)) continue; try { IClasspathEntry entry = root.getRawClasspathEntry(); //TODO: is the following really necessary? //Note that getContentKind() returns an undefined //value for a classpath container or variable if (entry.getEntryKind() != IClasspathEntry.CPE_CONTAINER && entry.getEntryKind() != IClasspathEntry.CPE_VARIABLE && entry.getContentKind() == IPackageFragmentRoot.K_SOURCE && !CeylonBuilder.isCeylonSourceEntry(entry)) { continue; } packageFragment = root.getPackageFragment(packageName); if (!packageFragment.exists()) { continue; } } catch (JavaModelException e) { if (!e.isDoesNotExist()) { e.printStackTrace(); } continue; } if (!loadDeclarations) { // we found the package return true; } // we have a few virtual types in java.lang that we need to load but they are not listed from class files if (module.getNameAsString().equals(JAVA_BASE_MODULE_NAME) && packageName.equals("java.lang")) { loadJavaBaseArrays(); } IClassFile[] classFiles = new IClassFile[] {}; org.eclipse.jdt.core.ICompilationUnit[] compilationUnits = new org.eclipse.jdt.core.ICompilationUnit[] {}; try { classFiles = packageFragment.getClassFiles(); } catch (JavaModelException e) { e.printStackTrace(); } try { compilationUnits = packageFragment.getCompilationUnits(); } catch (JavaModelException e) { e.printStackTrace(); } List<IType> typesToLoad = new LinkedList<>(); for (IClassFile classFile : classFiles) { IType type = classFile.getType(); typesToLoad.add(type); } for (org.eclipse.jdt.core.ICompilationUnit compilationUnit : compilationUnits) { // skip removed CUs if (!compilationUnit.exists()) continue; try { for (IType type : compilationUnit.getTypes()) { typesToLoad.add(type); } } catch (JavaModelException e) { e.printStackTrace(); } } for (IType type : typesToLoad) { String typeFullyQualifiedName = type.getFullyQualifiedName(); String[] nameParts = typeFullyQualifiedName.split("\\."); String typeQualifiedName = nameParts[nameParts.length - 1]; // only top-levels are added in source declarations if (typeQualifiedName.indexOf('$') > 0) { continue; } if (type.exists() && !sourceDeclarations.containsKey(getToplevelQualifiedName( type.getPackageFragment().getElementName(), typeFullyQualifiedName)) && !isTypeHidden(module, typeFullyQualifiedName)) { convertToDeclaration(module, typeFullyQualifiedName, DeclarationType.VALUE); } } } } return false; }
From source file:com.redhat.ceylon.eclipse.core.model.loader.JDTModelLoader.java
License:Open Source License
@Override public synchronized boolean loadPackage(String packageName, boolean loadDeclarations) { packageName = Util.quoteJavaKeywords(packageName); if (loadDeclarations && !loadedPackages.add(packageName)) { return true; }/*from w w w . j a v a 2 s. c o m*/ Module module = lookupModuleInternal(packageName); if (module instanceof JDTModule) { JDTModule jdtModule = (JDTModule) module; List<IPackageFragmentRoot> roots = jdtModule.getPackageFragmentRoots(); IPackageFragment packageFragment = null; for (IPackageFragmentRoot root : roots) { // skip packages that are not present if (!root.exists()) continue; try { IClasspathEntry entry = root.getRawClasspathEntry(); //TODO: is the following really necessary? //Note that getContentKind() returns an undefined //value for a classpath container or variable if (entry.getEntryKind() != IClasspathEntry.CPE_CONTAINER && entry.getEntryKind() != IClasspathEntry.CPE_VARIABLE && entry.getContentKind() == IPackageFragmentRoot.K_SOURCE && !CeylonBuilder.isCeylonSourceEntry(entry)) { continue; } packageFragment = root.getPackageFragment(packageName); if (packageFragment.exists()) { if (!loadDeclarations) { // we found the package return true; } else { try { for (IClassFile classFile : packageFragment.getClassFiles()) { // skip removed class files if (!classFile.exists()) continue; IType type = classFile.getType(); if (type.exists() && !type.isMember() && !sourceDeclarations.containsKey( getQualifiedName(type.getPackageFragment().getElementName(), type.getTypeQualifiedName()))) { convertToDeclaration(type.getFullyQualifiedName(), DeclarationType.VALUE); } } for (org.eclipse.jdt.core.ICompilationUnit compilationUnit : packageFragment .getCompilationUnits()) { // skip removed CUs if (!compilationUnit.exists()) continue; for (IType type : compilationUnit.getTypes()) { if (type.exists() && !type.isMember() && !sourceDeclarations.containsKey( getQualifiedName(type.getPackageFragment().getElementName(), type.getTypeQualifiedName()))) { convertToDeclaration(type.getFullyQualifiedName(), DeclarationType.VALUE); } } } } catch (JavaModelException e) { e.printStackTrace(); } } } } catch (JavaModelException e) { e.printStackTrace(); } } } return false; }
From source file:com.tasktop.dropwizard.launcher.DropwizardRuntimeClasspathProvider.java
License:Open Source License
protected void addProjectEntries(Set<IRuntimeClasspathEntry> resolved, IPath path, int scope, String classifier, ILaunchConfiguration launchConfiguration, final IProgressMonitor monitor) throws CoreException { IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); IProject project = root.getProject(path.segment(0)); IMavenProjectFacade projectFacade = projectManager.create(project, monitor); if (projectFacade == null) { return;//from ww w. j a va 2 s . c o m } ResolverConfiguration configuration = projectFacade.getResolverConfiguration(); if (configuration == null) { return; } IJavaProject javaProject = JavaCore.create(project); boolean projectResolved = false; for (IClasspathEntry entry : javaProject.getRawClasspath()) { IRuntimeClasspathEntry rce = null; switch (entry.getEntryKind()) { case IClasspathEntry.CPE_SOURCE: if (!projectResolved) { IMavenClassifierManager mavenClassifierManager = MavenJdtPlugin.getDefault() .getMavenClassifierManager(); IClassifierClasspathProvider classifierClasspathProvider = mavenClassifierManager .getClassifierClasspathProvider(projectFacade, classifier); if (IClasspathManager.CLASSPATH_TEST == scope) { classifierClasspathProvider.setTestClasspath(resolved, projectFacade, monitor); } else { classifierClasspathProvider.setRuntimeClasspath(resolved, projectFacade, monitor); } projectResolved = true; } break; case IClasspathEntry.CPE_CONTAINER: IClasspathContainer container = JavaCore.getClasspathContainer(entry.getPath(), javaProject); if (container != null && !MavenClasspathHelpers.isMaven2ClasspathContainer(entry.getPath())) { switch (container.getKind()) { case IClasspathContainer.K_APPLICATION: rce = JavaRuntime.newRuntimeContainerClasspathEntry(container.getPath(), IRuntimeClasspathEntry.USER_CLASSES, javaProject); break; default: break; } } break; case IClasspathEntry.CPE_LIBRARY: rce = JavaRuntime.newArchiveRuntimeClasspathEntry(entry.getPath()); break; case IClasspathEntry.CPE_VARIABLE: if (!JavaRuntime.JRELIB_VARIABLE.equals(entry.getPath().segment(0))) { rce = JavaRuntime.newVariableRuntimeClasspathEntry(entry.getPath()); } break; case IClasspathEntry.CPE_PROJECT: IProject res = root.getProject(entry.getPath().segment(0)); if (res != null) { IJavaProject otherProject = JavaCore.create(res); if (otherProject != null) { rce = JavaRuntime.newDefaultProjectClasspathEntry(otherProject); } } break; default: break; } if (rce != null) { addStandardClasspathEntries(resolved, rce, launchConfiguration); } } }
From source file:com.windowtester.eclipse.ui.convert.WTAPIUsage.java
License:Open Source License
private void collectPluginsReferencedByClasspathEntry(PrintWriter writer, Collection<String> pluginIds, IJavaProject proj, IClasspathEntry entry) throws IOException { IPath path = entry.getPath();//from w w w .jav a2 s . c om switch (entry.getEntryKind()) { case IClasspathEntry.CPE_LIBRARY: case IClasspathEntry.CPE_VARIABLE: for (int i = path.segmentCount() - 1; i >= 0; i--) { String segment = path.segment(i); if (segment.startsWith("com.windowtester.")) { String id = segment; i++; while (i < path.segmentCount()) id += "/" + path.segment(i++); pluginIds.add(id); break; } } break; case IClasspathEntry.CPE_CONTAINER: if (path.segmentCount() >= 1 && path.segment(0).equals("org.eclipse.pde.core.requiredPlugins")) collectPluginsReferencedInManifest(pluginIds, proj); break; case IClasspathEntry.CPE_SOURCE: case IClasspathEntry.CPE_PROJECT: // ignored break; default: pluginIds.add("unknown " + entry.getEntryKind() + " - " + entry); break; } }
From source file:com.windowtester.eclipse.ui.wizard.NewExampleProjectWizard.java
License:Open Source License
private void importProject(String projectName, IProgressMonitor monitor) throws CoreException { final IWorkspace workspace = ResourcesPlugin.getWorkspace(); final IProject project = workspace.getRoot().getProject(projectName); IProjectDescription description = workspace.newProjectDescription(projectName); description.setLocation(null);//from w ww.java 2 s .c o m project.create(description, new SubProgressMonitor(monitor, 1)); project.open(new SubProgressMonitor(monitor, 1)); // Direct ECLIPSE_HOME references are different each Eclipse installation // so adjust the classpath accordingly IJavaProject javaProject = JavaCore.create(project); IClasspathEntry[] classpath = javaProject.getRawClasspath(); boolean modified = false; for (int i = 0; i < classpath.length; i++) { IClasspathEntry entry = classpath[i]; if (entry.getEntryKind() != IClasspathEntry.CPE_VARIABLE) continue; IPath path = entry.getPath(); if (path.segmentCount() != 3) continue; if (!path.segment(0).equals("ECLIPSE_HOME")) continue; if (!path.segment(1).equals("plugins")) continue; String jarName = path.segment(2); path = path.removeLastSegments(1); IPath pluginsPath = JavaCore.getResolvedVariablePath(path); if (pluginsPath == null) { Logger.log("Failed to resolve " + path); continue; } File pluginsDir = pluginsPath.toFile(); String jarPrefix = jarName.substring(0, jarName.indexOf('_') + 1); String[] childNames = pluginsDir.list(); if (childNames == null) { Logger.log("Failed to obtain children for " + pluginsDir.getPath()); continue; } for (int j = 0; j < childNames.length; j++) { String name = childNames[j]; if (name.startsWith(jarPrefix)) { modified = true; classpath[i] = JavaCore.newVariableEntry(path.append(name), null, null); break; } } } if (modified) javaProject.setRawClasspath(classpath, new NullProgressMonitor()); }
From source file:de.tobject.findbugs.builder.PDEClassPathGenerator.java
License:Open Source License
private static void resolveInWorkspace(IClasspathEntry classpathEntry, Set<String> classPath, Set<IProject> projectOnCp) { int entryKind = classpathEntry.getEntryKind(); switch (entryKind) { case IClasspathEntry.CPE_PROJECT: Set<String> cp = resolveProjectClassPath(classpathEntry.getPath(), projectOnCp); classPath.addAll(cp);/* w w w . ja va 2 s . c o m*/ break; case IClasspathEntry.CPE_VARIABLE: classpathEntry = JavaCore.getResolvedClasspathEntry(classpathEntry); if (classpathEntry == null) { return; } //$FALL-THROUGH$ case IClasspathEntry.CPE_LIBRARY: String lib = resolveLibrary(classpathEntry.getPath()); if (lib != null) { classPath.add(lib); } break; case IClasspathEntry.CPE_SOURCE: // ??? break; default: break; } }