List of usage examples for org.eclipse.jdt.core IClasspathEntry getEntryKind
int getEntryKind();
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 ww. j a v a2 s.c om*/ 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 CPListElement findElement(IClasspathEntry entry) { CPListElement prefixMatch = null;/*ww w. j a va 2 s . co m*/ int entryKind = entry.getEntryKind(); for (int i = 0, len = fClassPathList.getSize(); i < len; i++) { CPListElement curr = fClassPathList.getElement(i); if (curr.getEntryKind() == entryKind) { IPath entryPath = entry.getPath(); IPath currPath = curr.getPath(); if (currPath.equals(entryPath)) { return curr; } // in case there's no full match, look for a similar container (same ID segment): if (prefixMatch == null && entryKind == IClasspathEntry.CPE_CONTAINER) { int n = entryPath.segmentCount(); if (n > 0) { IPath genericContainerPath = n == 1 ? entryPath : entryPath.removeLastSegments(n - 1); if (n > 1 && genericContainerPath.isPrefixOf(currPath)) { prefixMatch = curr; } } } } } return prefixMatch; }
From source file:com.redhat.ceylon.eclipse.code.preferences.CeylonBuildPathsBlock.java
License:Open Source License
public void setElementToReveal(IClasspathEntry entry, String attributeKey) { int pageIndex = getPageIndex(entry.getEntryKind()); if (fTabFolder == null) { fPageIndex = pageIndex;//from w w w .j av a 2s.co m } else { fTabFolder.setSelection(pageIndex); CPListElement element = findElement(entry); if (element != null) { Object elementToSelect = element; if (attributeKey != null) { Object attrib = element.findAttributeElement(attributeKey); if (attrib != null) { elementToSelect = attrib; } } BuildPathBasePage page = (BuildPathBasePage) fTabFolder.getItem(pageIndex).getData(); List<Object> selection = new ArrayList<Object>(1); selection.add(elementToSelect); page.setSelection(selection, true); } } }
From source file:com.redhat.ceylon.eclipse.code.preferences.CeylonBuildPathsBlock.java
License:Open Source License
public void addElement(IClasspathEntry entry) { int pageIndex = getPageIndex(entry.getEntryKind()); if (fTabFolder == null) { fPageIndex = pageIndex;//w ww.j av a 2 s . c o m } else { fTabFolder.setSelection(pageIndex); // Object page= fTabFolder.getItem(pageIndex).getData(); // if (page instanceof LibrariesWorkbookPage) { // CPListElement element= CPListElement.create(entry, true, fCurrJProject); // ((LibrariesWorkbookPage) page).addElement(element); // } } }
From source file:com.redhat.ceylon.eclipse.code.wizard.AddResourceFolderWizardPage.java
License:Open Source License
private StatusInfo updateRootStatus() { IJavaProject javaProject = fNewElement.getJavaProject(); IProject project = javaProject.getProject(); StatusInfo pathNameStatus = validatePathName(fRootDialogField.getText(), fParent); if (!pathNameStatus.isOK()) return pathNameStatus; if (fLinkedMode) { IStatus linkNameStatus = validateLinkLocation(fRootDialogField.getText()); if (linkNameStatus.matches(IStatus.ERROR)) { StatusInfo result = new StatusInfo(); result.setError(linkNameStatus.getMessage()); return result; }/* w w w. j av a2 s . c o m*/ } StatusInfo result = new StatusInfo(); result.setOK(); IPath projPath = project.getFullPath(); IPath path = fParent.getFullPath().append(fRootDialogField.getText()); restoreCPElements(); int projectEntryIndex = -1; boolean createFolderForExisting = false; IFolder folder = fParent.getFolder(new Path(fRootDialogField.getText())); for (int i = 0; i < fExistingEntries.size(); i++) { IClasspathEntry curr = fExistingEntries.get(i).getClasspathEntry(); if (curr.getEntryKind() == IClasspathEntry.CPE_SOURCE) { if (path.equals(curr.getPath()) && fExistingEntries.get(i) != fNewElement) { if (folder.exists()) { result.setError("The folder is already a source or resource folder."); return result; } else { createFolderForExisting = true; } } if (projPath.equals(curr.getPath())) { projectEntryIndex = i; } } } if (folder.exists() && !folder.getFullPath().equals(fOrginalPath)) return new StatusInfo(IStatus.ERROR, Messages.format(NewWizardMessages.NewFolderDialog_folderNameEmpty_alreadyExists, BasicElementLabels.getPathLabel(folder.getFullPath(), false))); boolean isProjectASourceFolder = projectEntryIndex != -1; fModifiedElements.clear(); updateFilters(fNewElement.getPath(), path); fNewElement.setPath(path); if (fLinkedMode) { fNewElement.setLinkTarget(fLinkFields.getLinkTarget()); } fRemovedElements.clear(); Set<CPListElement> modified = new HashSet<CPListElement>(); boolean isProjectSourceFolderReplaced = false; if (fAddExclusionPatterns.isSelected()) { if (fOrginalPath == null) { addExclusionPatterns(fNewElement, fExistingEntries, modified); fModifiedElements.addAll(modified); if (!createFolderForExisting) CPListElement.insert(fNewElement, fExistingEntries); } } else { if (isProjectASourceFolder) { if (fRemoveProjectFolder.isSelected()) { fOldProjectSourceFolder = fExistingEntries.get(projectEntryIndex); fRemovedElements.add(fOldProjectSourceFolder); fExistingEntries.set(projectEntryIndex, fNewElement); isProjectSourceFolderReplaced = true; } else { if (!createFolderForExisting) CPListElement.insert(fNewElement, fExistingEntries); } } else { if (!createFolderForExisting) CPListElement.insert(fNewElement, fExistingEntries); } } if ((!fAllowConflict && fCanCommitConflictingBuildpath) || createFolderForExisting) return new StatusInfo(); fNewOutputLocation = null; IJavaModelStatus status = JavaConventions.validateClasspath(javaProject, CPListElement.convertToClasspathEntries(fExistingEntries), fOutputLocation); if (!status.isOK()) { if (fOutputLocation.equals(projPath)) { //Try to change the output folder fNewOutputLocation = projPath.append( PreferenceConstants.getPreferenceStore().getString(PreferenceConstants.SRCBIN_BINNAME)); IStatus status2 = JavaConventions.validateClasspath(javaProject, CPListElement.convertToClasspathEntries(fExistingEntries), fNewOutputLocation); if (status2.isOK()) { if (isProjectSourceFolderReplaced) { result.setInfo( Messages.format(NewWizardMessages.NewSourceFolderWizardPage_warning_ReplaceSFandOL, BasicElementLabels.getPathLabel(fNewOutputLocation, false))); } else { result.setInfo( Messages.format(NewWizardMessages.NewSourceFolderWizardPage_warning_ReplaceOL, BasicElementLabels.getPathLabel(fNewOutputLocation, false))); } return result; } } //Don't know what the problem is, report to user fNewOutputLocation = null; if (fCanCommitConflictingBuildpath) { result.setInfo(NewWizardMessages.AddSourceFolderWizardPage_conflictWarning + status.getMessage()); } else { result.setError(status.getMessage()); } return result; } if (!modified.isEmpty()) { //Added exclusion patterns to solve problem if (modified.size() == 1) { CPListElement elem = (CPListElement) modified.toArray()[0]; String changed = BasicElementLabels.getPathLabel(elem.getPath(), false); String excl = BasicElementLabels.getPathLabel(fNewElement.getPath(), false); result.setInfo(Messages.format(NewWizardMessages.AddSourceFolderWizardPage_addSinglePattern, new Object[] { excl, changed })); } else { result.setInfo( Messages.format(NewWizardMessages.NewSourceFolderWizardPage_warning_AddedExclusions_plural, String.valueOf(modified.size()))); } return result; } if (isProjectSourceFolderReplaced) { result.setInfo(NewWizardMessages.AddSourceFolderWizardPage_replaceSourceFolderInfo); return result; } return result; }
From source file:com.redhat.ceylon.eclipse.code.wizard.BuildPathsBlock.java
License:Open Source License
public void addElement(IClasspathEntry entry) { int pageIndex = getPageIndex(entry.getEntryKind()); if (fTabFolder == null) { fPageIndex = pageIndex;// w w w. j av a2 s . co m } else { fTabFolder.setSelection(pageIndex); Object page = fTabFolder.getItem(pageIndex).getData(); if (page instanceof LibrariesWorkbookPage) { CPListElement element = CPListElement.create(entry, true, fCurrJProject); ((LibrariesWorkbookPage) page).addElement(element); } } }
From source file:com.redhat.ceylon.eclipse.core.classpath.CeylonClasspathUtil.java
License:Apache License
/** * Search the Ceylon classpath containers within the specified Java project * //from ww w . j av a2s. c o m * @param javaProject * the project to search into * @return the Ivy classpath container if found */ public static List<CeylonClasspathContainer> getCeylonClasspathContainers(IJavaProject javaProject) { List<CeylonClasspathContainer> containers = new ArrayList<CeylonClasspathContainer>(); if (FakeProjectManager.isFake(javaProject) || !javaProject.exists()) { return containers; } try { IClasspathEntry[] entries = javaProject.getRawClasspath(); for (int i = 0; i < entries.length; i++) { IClasspathEntry entry = entries[i]; if (entry != null && entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { IPath path = entry.getPath(); if (isCeylonClasspathContainer(path)) { IClasspathContainer cp = JavaCore.getClasspathContainer(path, javaProject); if (cp instanceof CeylonClasspathContainer) { containers.add((CeylonClasspathContainer) cp); } } } } } catch (JavaModelException e) { // unless there are issues with the JDT, this should never happen e.printStackTrace(); } return containers; }
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. com * @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.classpath.CeylonClasspathUtil.java
License:Apache License
/** * Search the Ivy classpath entry within the specified Java project with the specific path * //from w w w . jav a2s .c o m * @param containerPath * the path of the container * @param javaProject * the project to search into * @return the Ivy classpath container if found, otherwise return <code>null</code> */ public static IClasspathEntry getCeylonClasspathEntry(IPath containerPath, IJavaProject javaProject) { if (FakeProjectManager.isFake(javaProject) || !javaProject.exists()) { return null; } try { IClasspathEntry[] entries = javaProject.getRawClasspath(); for (int i = 0; i < entries.length; i++) { IClasspathEntry entry = entries[i]; if (entry != null && entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { if (containerPath.equals(entry.getPath())) { return entry; } } } } catch (JavaModelException e) { // unless there are issues with the JDT, this should never happen e.printStackTrace(); } 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; }//from ww w .j ava 2 s. c o m 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; }