List of usage examples for org.eclipse.jdt.core IJavaElement PACKAGE_FRAGMENT
int PACKAGE_FRAGMENT
To view the source code for org.eclipse.jdt.core IJavaElement PACKAGE_FRAGMENT.
Click Source Link
From source file:org.eclipse.ajdt.internal.ui.wizards.exports.ContainerFilter.java
License:Open Source License
/** * Returns the result of this filter, when applied to the * given inputs./* w ww .ja v a 2 s. com*/ * * @param inputs the set of elements to * @return Returns true if element should be included in filtered set */ public boolean select(Viewer viewer, Object parent, Object element) { boolean isContainer = element instanceof IContainer; if (!isContainer && element instanceof IJavaElement) { int type = ((IJavaElement) element).getElementType(); isContainer = type == IJavaElement.JAVA_MODEL || type == IJavaElement.JAVA_PROJECT || type == IJavaElement.PACKAGE_FRAGMENT || type == IJavaElement.PACKAGE_FRAGMENT_ROOT; } return (fFilterContainers && !isContainer) || (!fFilterContainers && isContainer); }
From source file:org.eclipse.ajdt.internal.ui.wizards.exports.SealPackagesFilter.java
License:Open Source License
/** * Returns the result of this filter, when applied to the * given inputs./*from w w w . jav a 2s .c o m*/ * * @param inputs the set of elements to * @return Returns true if element should be included in filtered set */ public boolean select(Viewer viewer, Object parent, Object element) { if (element instanceof IJavaElement) { int type = ((IJavaElement) element).getElementType(); if (type == IJavaElement.JAVA_MODEL || type == IJavaElement.JAVA_PROJECT || type == IJavaElement.PACKAGE_FRAGMENT_ROOT) return true; return (type == IJavaElement.PACKAGE_FRAGMENT && fAllowedPackages.contains(element)); } else return false; }
From source file:org.eclipse.ajdt.internal.ui.wizards.NewTypeWizardPage.java
License:Open Source License
/** * Initializes all fields provided by the page with a given selection. * // w w w.j av a 2 s . c o m * @param elem the selection used to initialize this page or <code> * null</code> if no selection was available */ protected void initTypePage(IJavaElement elem) { String initSuperclass = "java.lang.Object"; //$NON-NLS-1$ ArrayList initSuperinterfaces = new ArrayList(5); IJavaProject project = null; IPackageFragment pack = null; IType enclosingType = null; if (elem != null) { // evaluate the enclosing type project = elem.getJavaProject(); pack = (IPackageFragment) elem.getAncestor(IJavaElement.PACKAGE_FRAGMENT); IType typeInCU = (IType) elem.getAncestor(IJavaElement.TYPE); if (typeInCU != null) { if (typeInCU.getCompilationUnit() != null) { enclosingType = typeInCU; } } else { ICompilationUnit cu = (ICompilationUnit) elem.getAncestor(IJavaElement.COMPILATION_UNIT); if (cu != null) { enclosingType = cu.findPrimaryType(); } } try { IType type = null; if (elem.getElementType() == IJavaElement.TYPE) { type = (IType) elem; if (type.exists()) { String superName = SuperInterfaceSelectionDialog.getNameWithTypeParameters(type); if (type.isInterface()) { initSuperinterfaces.add(superName); } else { initSuperclass = superName; } } } } catch (JavaModelException e) { JavaPlugin.log(e); // ignore this exception now } } String typeName = ""; //$NON-NLS-1$ ITextSelection selection = getCurrentTextSelection(); if (selection != null) { String text = selection.getText(); if (text != null && validateJavaTypeName(text, project).isOK()) { typeName = text; } } setPackageFragment(pack, true); setEnclosingType(enclosingType, true); setEnclosingTypeSelection(false, true); setTypeName(typeName, true); setSuperClass(initSuperclass, true); setSuperInterfaces(initSuperinterfaces, true); setAddComments(StubUtility.doAddComments(project), true); // from project or workspace }
From source file:org.eclipse.che.jdt.internal.core.DeltaProcessor.java
License:Open Source License
private int elementType(File res, int kind, int parentType, RootInfo rootInfo) { Path path = new Path(res.getAbsolutePath()); switch (parentType) { case IJavaElement.JAVA_MODEL: // case of a movedTo or movedFrom project (other cases are handled in processResourceDelta(...) return IJavaElement.JAVA_PROJECT; case NON_JAVA_RESOURCE: case IJavaElement.JAVA_PROJECT: if (rootInfo == null) { rootInfo = enclosingRootInfo(path, kind); }/*from w w w . ja va 2 s .c o m*/ if (rootInfo != null && rootInfo.isRootOfProject(path)) { return IJavaElement.PACKAGE_FRAGMENT_ROOT; } // not yet in a package fragment root or root of another project // or package fragment to be included (see below) // $FALL-THROUGH$ case IJavaElement.PACKAGE_FRAGMENT_ROOT: case IJavaElement.PACKAGE_FRAGMENT: if (rootInfo == null) { IPath rootPath = externalPath(res); rootInfo = enclosingRootInfo(rootPath, kind); } if (rootInfo == null) { return NON_JAVA_RESOURCE; } if (Util.isExcluded(path, rootInfo.inclusionPatterns, rootInfo.exclusionPatterns, false)) { return NON_JAVA_RESOURCE; } if (res.isDirectory()) { if (parentType == NON_JAVA_RESOURCE && !Util.isExcluded(new Path(res.getParent()), rootInfo.inclusionPatterns, rootInfo.exclusionPatterns, false)) { // parent is a non-Java resource because it doesn't have a valid package name (see https://bugs.eclipse // .org/bugs/show_bug.cgi?id=130982) return NON_JAVA_RESOURCE; } String sourceLevel = rootInfo.project == null ? null : rootInfo.project.getOption(JavaCore.COMPILER_SOURCE, true); String complianceLevel = rootInfo.project == null ? null : rootInfo.project.getOption(JavaCore.COMPILER_COMPLIANCE, true); if (Util.isValidFolderNameForPackage(res.getName(), sourceLevel, complianceLevel)) { return IJavaElement.PACKAGE_FRAGMENT; } return NON_JAVA_RESOURCE; } String fileName = res.getName(); String sourceLevel = rootInfo.project == null ? null : rootInfo.project.getOption(JavaCore.COMPILER_SOURCE, true); String complianceLevel = rootInfo.project == null ? null : rootInfo.project.getOption(JavaCore.COMPILER_COMPLIANCE, true); if (Util.isValidCompilationUnitName(fileName, sourceLevel, complianceLevel)) { return IJavaElement.COMPILATION_UNIT; } else if (Util.isValidClassFileName(fileName, sourceLevel, complianceLevel)) { return IJavaElement.CLASS_FILE; } else { IPath rootPath = externalPath(res); if ((rootInfo = rootInfo(rootPath, kind)) != null && rootInfo.project.getProject().getFullPath().isPrefixOf(rootPath) /*ensure root is a root of its project (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=185310) */) { // case of proj=src=bin and resource is a jar file on the classpath return IJavaElement.PACKAGE_FRAGMENT_ROOT; } else { return NON_JAVA_RESOURCE; } } default: return NON_JAVA_RESOURCE; } }
From source file:org.eclipse.che.jdt.internal.core.JavaModelManager.java
License:Open Source License
public synchronized Object removeInfoAndChildren(JavaElement element) throws JavaModelException { Object info = this.cache.peekAtInfo(element); if (info != null) { boolean wasVerbose = false; try {//from w ww .java2 s . c om if (JavaModelCache.VERBOSE) { String elementType; switch (element.getElementType()) { case IJavaElement.JAVA_PROJECT: elementType = "project"; //$NON-NLS-1$ break; case IJavaElement.PACKAGE_FRAGMENT_ROOT: elementType = "root"; //$NON-NLS-1$ break; case IJavaElement.PACKAGE_FRAGMENT: elementType = "package"; //$NON-NLS-1$ break; case IJavaElement.CLASS_FILE: elementType = "class file"; //$NON-NLS-1$ break; case IJavaElement.COMPILATION_UNIT: elementType = "compilation unit"; //$NON-NLS-1$ break; default: elementType = "element"; //$NON-NLS-1$ } System.out.println(Thread.currentThread() + " CLOSING " + elementType + " " + element.toStringWithAncestors()); //$NON-NLS-1$//$NON-NLS-2$ wasVerbose = true; JavaModelCache.VERBOSE = false; } element.closing(info); if (element instanceof IParent) { closeChildren(info); } this.cache.removeInfo(element); if (wasVerbose) { System.out.println(this.cache.toStringFillingRation("-> ")); //$NON-NLS-1$ } } finally { JavaModelCache.VERBOSE = wasVerbose; } return info; } return null; }
From source file:org.eclipse.che.jdt.internal.core.Openable.java
License:Open Source License
/** * @see IJavaElement//from w w w .j av a 2 s .c om */ public boolean exists() { if (manager.getInfo(this) != null) return true; switch (getElementType()) { case IJavaElement.PACKAGE_FRAGMENT: PackageFragmentRoot root = getPackageFragmentRoot(); if (root.isArchive()) { // pkg in a jar -> need to open root to know if this pkg exists JarPackageFragmentRootInfo rootInfo; try { rootInfo = (JarPackageFragmentRootInfo) root.getElementInfo(); } catch (JavaModelException e) { return false; } return rootInfo.rawPackageInfo.containsKey(((PackageFragment) this).names); } break; case IJavaElement.CLASS_FILE: if (getPackageFragmentRoot().isArchive()) { // class file in a jar -> need to open this class file to know if it exists return super.exists(); } break; } return validateExistence(resource()).isOK(); }
From source file:org.eclipse.che.jdt.internal.core.search.JavaSearchScope.java
License:Open Source License
/** * Add an element to the java search scope. * * @param element//from w w w.jav a2 s . c o m * The element we want to add to current java search scope * @throws org.eclipse.jdt.core.JavaModelException * May happen if some Java Model info are not available */ public void add(IJavaElement element) throws JavaModelException { IPath containerPath = null; String containerPathToString = null; PackageFragmentRoot root = null; int includeMask = SOURCES | APPLICATION_LIBRARIES | SYSTEM_LIBRARIES; switch (element.getElementType()) { case IJavaElement.JAVA_MODEL: // a workspace sope should be used break; case IJavaElement.JAVA_PROJECT: add((JavaProject) element, null, includeMask, new HashSet(2), new HashSet(2), null); break; case IJavaElement.PACKAGE_FRAGMENT_ROOT: root = (PackageFragmentRoot) element; IPath rootPath = root.internalPath(); containerPath = root.getKind() == IPackageFragmentRoot.K_SOURCE ? root.getParent().getPath() : rootPath; containerPathToString = containerPath.getDevice() == null ? containerPath.toString() : containerPath.toOSString(); File rootResource = root.resource(); String projectPath = root.getJavaProject().getPath().toString(); if (rootResource != null /*&& rootResource.isAccessible()*/) { String relativePath = Util.relativePath(new Path(rootResource.getAbsolutePath()), containerPath.segmentCount()); add(projectPath, relativePath, containerPathToString, false/*not a package*/, null); } else { add(projectPath, "", containerPathToString, false/*not a package*/, null); //$NON-NLS-1$ } break; case IJavaElement.PACKAGE_FRAGMENT: root = (PackageFragmentRoot) element.getParent(); projectPath = root.getJavaProject().getPath().toString(); if (root.isArchive()) { String relativePath = org.eclipse.jdt.internal.core.util.Util .concatWith(((PackageFragment) element).names, '/'); containerPath = root.getPath(); containerPathToString = containerPath.getDevice() == null ? containerPath.toString() : containerPath.toOSString(); add(projectPath, relativePath, containerPathToString, true/*package*/, null); } else { File resource = ((JavaElement) element).resource(); if (resource != null) { // if (resource.isAccessible()) { containerPath = root.getKind() == IPackageFragmentRoot.K_SOURCE ? root.getParent().getPath() : root.internalPath(); // } else { // // for working copies, get resource container full path // containerPath = resource.getParent().getFullPath(); // } containerPathToString = containerPath.getDevice() == null ? containerPath.toString() : containerPath.toOSString(); String relativePath = Util.relativePath(new Path(resource.getAbsolutePath()), containerPath.segmentCount()); add(projectPath, relativePath, containerPathToString, true/*package*/, null); } } break; default: // remember sub-cu (or sub-class file) java elements if (element instanceof IMember) { if (this.elements == null) { this.elements = new ArrayList(); } this.elements.add(element); } root = (PackageFragmentRoot) element.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT); projectPath = root.getJavaProject().getPath().toString(); String relativePath; if (root.getKind() == IPackageFragmentRoot.K_SOURCE) { containerPath = root.getParent().getPath(); relativePath = Util.relativePath(getPath(element, false/*full path*/), 1/*remove project segment*/); } else { containerPath = root.internalPath(); relativePath = getPath(element, true/*relative path*/).toString(); } containerPathToString = containerPath.getDevice() == null ? containerPath.toString() : containerPath.toOSString(); add(projectPath, relativePath, containerPathToString, false/*not a package*/, null); } if (root != null) addEnclosingProjectOrJar( root.getKind() == IPackageFragmentRoot.K_SOURCE ? root.getParent().getPath() : root.getPath()); }
From source file:org.eclipse.che.jdt.internal.core.search.JavaSearchScope.java
License:Open Source License
private IPath getPath(IJavaElement element, boolean relativeToRoot) { switch (element.getElementType()) { case IJavaElement.JAVA_MODEL: return Path.EMPTY; case IJavaElement.JAVA_PROJECT: return element.getPath(); case IJavaElement.PACKAGE_FRAGMENT_ROOT: if (relativeToRoot) return Path.EMPTY; return element.getPath(); case IJavaElement.PACKAGE_FRAGMENT: String relativePath = org.eclipse.jdt.internal.core.util.Util .concatWith(((PackageFragment) element).names, '/'); return getPath(element.getParent(), relativeToRoot).append(new Path(relativePath)); case IJavaElement.COMPILATION_UNIT: case IJavaElement.CLASS_FILE: return getPath(element.getParent(), relativeToRoot).append(new Path(element.getElementName())); default://from w w w .j av a 2 s.c om return getPath(element.getParent(), relativeToRoot); } }
From source file:org.eclipse.che.jdt.javadoc.JavadocContentAccess2.java
License:Open Source License
/** * Returns the Javadoc for a PackageDeclaration. * * @param packageDeclaration the Java element whose Javadoc has to be retrieved * @param urlPrefix//from w w w . ja v a2 s . c om * @return the package documentation in HTML format or <code>null</code> if there is no * associated Javadoc * @throws CoreException if the Java element does not exists or an exception occurs while * accessing the file containing the package Javadoc * @since 3.9 */ public static String getHTMLContent(IPackageDeclaration packageDeclaration, String urlPrefix) throws CoreException { IJavaElement element = packageDeclaration.getAncestor(IJavaElement.PACKAGE_FRAGMENT); if (element instanceof IPackageFragment) { return getHTMLContent((IPackageFragment) element, urlPrefix); } return null; }
From source file:org.eclipse.che.jdt.javadoc.JavaElementLinks.java
License:Open Source License
private static ITypeParameter resolveTypeVariable(IJavaElement baseElement, String typeVariableName) throws JavaModelException { while (baseElement != null) { switch (baseElement.getElementType()) { case IJavaElement.METHOD: IMethod method = (IMethod) baseElement; ITypeParameter[] typeParameters = method.getTypeParameters(); for (int i = 0; i < typeParameters.length; i++) { ITypeParameter typeParameter = typeParameters[i]; if (typeParameter.getElementName().equals(typeVariableName)) { return typeParameter; }//from w w w.jav a 2 s.com } break; case IJavaElement.TYPE: IType type = (IType) baseElement; typeParameters = type.getTypeParameters(); for (int i = 0; i < typeParameters.length; i++) { ITypeParameter typeParameter = typeParameters[i]; if (typeParameter.getElementName().equals(typeVariableName)) { return typeParameter; } } break; case IJavaElement.JAVA_MODEL: case IJavaElement.JAVA_PROJECT: case IJavaElement.PACKAGE_FRAGMENT: case IJavaElement.PACKAGE_FRAGMENT_ROOT: case IJavaElement.CLASS_FILE: case IJavaElement.COMPILATION_UNIT: case IJavaElement.PACKAGE_DECLARATION: case IJavaElement.IMPORT_CONTAINER: case IJavaElement.IMPORT_DECLARATION: return null; default: break; } // look for type parameters in enclosing members: baseElement = baseElement.getParent(); } return null; }