Java Code Examples for org.eclipse.jdt.core.IJavaElement#JAVA_MODEL
The following examples show how to use
org.eclipse.jdt.core.IJavaElement#JAVA_MODEL .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Activator.java From google-cloud-eclipse with Apache License 2.0 | 6 votes |
private void visit(IJavaElementDelta delta) { switch (delta.getElement().getElementType()) { case IJavaElement.JAVA_PROJECT: if ((delta.getFlags() & IJavaElementDelta.F_CLASSPATH_CHANGED) != 0) { final IJavaProject javaProject = (IJavaProject) delta.getElement(); Job updateContainerStateJob = new WorkspaceJob("Updating Google Cloud libraries") { @Override public IStatus runInWorkspace(IProgressMonitor monitor) { BuildPath.checkLibraryList(javaProject, null); return Status.OK_STATUS; } }; IWorkspace workspace = javaProject.getProject().getWorkspace(); ISchedulingRule buildRule = workspace.getRuleFactory().buildRule(); updateContainerStateJob.setRule(buildRule); updateContainerStateJob.setSystem(true); updateContainerStateJob.schedule(); } break; case IJavaElement.JAVA_MODEL: visitChildren(delta); break; default: break; } }
Example 2
Source File: JavaModelCache.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
/** * Remember the info for the element. */ protected void putInfo(IJavaElement element, Object info) { switch (element.getElementType()) { case IJavaElement.JAVA_MODEL: this.modelInfo = info; break; case IJavaElement.JAVA_PROJECT: this.projectCache.put(element, info); this.rootCache.ensureSpaceLimit(info, element); break; case IJavaElement.PACKAGE_FRAGMENT_ROOT: this.rootCache.put(element, info); this.pkgCache.ensureSpaceLimit(info, element); break; case IJavaElement.PACKAGE_FRAGMENT: this.pkgCache.put(element, info); this.openableCache.ensureSpaceLimit(info, element); break; case IJavaElement.COMPILATION_UNIT: case IJavaElement.CLASS_FILE: this.openableCache.put(element, info); break; default: this.childrenCache.put(element, info); } }
Example 3
Source File: OpenAction.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
/** * Selects the openable elements out of the given ones. * * @param elements the elements to filter * @return the openable elements * @since 3.4 */ private IJavaElement[] selectOpenableElements(IJavaElement[] elements) { List<IJavaElement> result= new ArrayList<IJavaElement>(elements.length); for (int i= 0; i < elements.length; i++) { IJavaElement element= elements[i]; switch (element.getElementType()) { case IJavaElement.PACKAGE_DECLARATION: case IJavaElement.PACKAGE_FRAGMENT_ROOT: case IJavaElement.JAVA_PROJECT: case IJavaElement.JAVA_MODEL: break; default: result.add(element); break; } } return result.toArray(new IJavaElement[result.size()]); }
Example 4
Source File: ClasspathUpdateHandler.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
private Set<String> processDelta(IJavaElementDelta delta, Set<String> uris) { IJavaElement element = delta.getElement(); switch (element.getElementType()) { case IJavaElement.JAVA_MODEL: uris = processDeltaChildren(delta, uris); break; case IJavaElement.JAVA_PROJECT: if (isClasspathChanged(delta.getFlags())) { if (uris == null) { uris = new HashSet<String>(); } IJavaProject javaProject = (IJavaProject) element; uris.add(ProjectUtils.getProjectRealFolder(javaProject.getProject()).toFile().toURI().toString()); } break; default: break; } return uris; }
Example 5
Source File: JavaSearchScope.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
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 = 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: return getPath(element.getParent(), relativeToRoot); } }
Example 6
Source File: JavaElementResourceMapping.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
public static ResourceMapping create(IJavaElement element) { switch (element.getElementType()) { case IJavaElement.TYPE: return create((IType)element); case IJavaElement.COMPILATION_UNIT: return create((ICompilationUnit)element); case IJavaElement.CLASS_FILE: return create((IClassFile)element); case IJavaElement.PACKAGE_FRAGMENT: return create((IPackageFragment)element); case IJavaElement.PACKAGE_FRAGMENT_ROOT: return create((IPackageFragmentRoot)element); case IJavaElement.JAVA_PROJECT: return create((IJavaProject)element); case IJavaElement.JAVA_MODEL: return create((IJavaModel)element); default: return null; } }
Example 7
Source File: JavaModelCache.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
/** * Returns the info for this element without * disturbing the cache ordering. */ protected Object peekAtInfo(IJavaElement element) { switch (element.getElementType()) { case IJavaElement.JAVA_MODEL: return this.modelInfo; case IJavaElement.JAVA_PROJECT: return this.projectCache.get(element); case IJavaElement.PACKAGE_FRAGMENT_ROOT: return this.rootCache.peek(element); case IJavaElement.PACKAGE_FRAGMENT: return this.pkgCache.peek(element); case IJavaElement.COMPILATION_UNIT: case IJavaElement.CLASS_FILE: return this.openableCache.peek(element); case IJavaElement.TYPE: Object result = this.jarTypeCache.peek(element); if (result != null) return result; else return this.childrenCache.get(element); default: return this.childrenCache.get(element); } }
Example 8
Source File: ReorgPolicyFactory.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
@Override public boolean canChildrenBeDestinations(IJavaElement javaElement) { switch (javaElement.getElementType()) { case IJavaElement.JAVA_MODEL: case IJavaElement.JAVA_PROJECT: return true; case IJavaElement.PACKAGE_FRAGMENT_ROOT: IPackageFragmentRoot root= (IPackageFragmentRoot) javaElement; return !root.isArchive() && !root.isExternal(); default: return false; } }
Example 9
Source File: DeleteChangeCreator.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
private static Change createDeleteChange(IJavaElement javaElement) throws JavaModelException { Assert.isTrue(! ReorgUtils.isInsideCompilationUnit(javaElement)); switch(javaElement.getElementType()){ case IJavaElement.PACKAGE_FRAGMENT_ROOT: return createPackageFragmentRootDeleteChange((IPackageFragmentRoot)javaElement); case IJavaElement.PACKAGE_FRAGMENT: return createSourceManipulationDeleteChange((IPackageFragment)javaElement); case IJavaElement.COMPILATION_UNIT: return createSourceManipulationDeleteChange((ICompilationUnit)javaElement); case IJavaElement.CLASS_FILE: //if this assert fails, it means that a precondition is missing Assert.isTrue(((IClassFile)javaElement).getResource() instanceof IFile); return createDeleteChange(((IClassFile)javaElement).getResource()); case IJavaElement.JAVA_MODEL: //cannot be done Assert.isTrue(false); return null; case IJavaElement.JAVA_PROJECT: //handled differently Assert.isTrue(false); return null; case IJavaElement.TYPE: case IJavaElement.FIELD: case IJavaElement.METHOD: case IJavaElement.INITIALIZER: case IJavaElement.PACKAGE_DECLARATION: case IJavaElement.IMPORT_CONTAINER: case IJavaElement.IMPORT_DECLARATION: Assert.isTrue(false);//not done here return new NullChange(); default: Assert.isTrue(false);//there's no more kinds return new NullChange(); } }
Example 10
Source File: BuildpathIndicatorLabelDecorator.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
@Override protected void processDelta(IJavaElementDelta delta, List<IJavaElement> result) { IJavaElement elem= delta.getElement(); boolean isChanged= delta.getKind() == IJavaElementDelta.CHANGED; boolean isRemoved= delta.getKind() == IJavaElementDelta.REMOVED; int flags= delta.getFlags(); switch (elem.getElementType()) { case IJavaElement.JAVA_MODEL: processChildrenDelta(delta, result); return; case IJavaElement.JAVA_PROJECT: if (isRemoved || (isChanged && (flags & IJavaElementDelta.F_CLOSED) != 0)) { return; } processChildrenDelta(delta, result); return; case IJavaElement.PACKAGE_FRAGMENT_ROOT: if (isRemoved) { return; } try { if ((((flags & IJavaElementDelta.F_REMOVED_FROM_CLASSPATH) != 0) || ((flags & IJavaElementDelta.F_ADDED_TO_CLASSPATH) != 0)) && ((IPackageFragmentRoot)elem).getKind() != IPackageFragmentRoot.K_SOURCE) { result.add(elem); } } catch (JavaModelException e) { // don't update } return; default: return; } }
Example 11
Source File: DeleteModifications.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public void delete(IJavaElement element) throws CoreException { switch(element.getElementType()) { case IJavaElement.JAVA_MODEL: return; case IJavaElement.JAVA_PROJECT: fDelete.add(element); if (element.getResource() != null) getResourceModifications().addDelete(element.getResource()); return; case IJavaElement.PACKAGE_FRAGMENT_ROOT: fDelete.add(element); IResource resource= element.getResource(); // Flag an resource change even if we have an archive. If it is // internal (we have a underlying resource then we have a resource // change. if (resource != null) getResourceModifications().addDelete(resource); IJavaProject[] referencingProjects= JavaElementUtil.getReferencingProjects((IPackageFragmentRoot) element); for (int i= 0; i < referencingProjects.length; i++) { IFile classpath= referencingProjects[i].getProject().getFile(".classpath"); //$NON-NLS-1$ getResourceModifications().addChanged(classpath); } return; case IJavaElement.PACKAGE_FRAGMENT: fDelete.add(element); fPackagesToDelete.add((IPackageFragment) element); return; case IJavaElement.COMPILATION_UNIT: fDelete.add(element); IType[] types= ((ICompilationUnit)element).getTypes(); fDelete.addAll(Arrays.asList(types)); if (element.getResource() != null) getResourceModifications().addDelete(element.getResource()); return; default: fDelete.add(element); } }
Example 12
Source File: ClasspathChagedListener.java From hybris-commerce-eclipse-plugin with Apache License 2.0 | 5 votes |
private void visit(IJavaElementDelta delta) { IJavaElement el = delta.getElement(); switch (el.getElementType()) { case IJavaElement.JAVA_MODEL: visitChildren(delta); break; case IJavaElement.JAVA_PROJECT: if (isClasspathChanged(delta.getFlags()) && platformHolder.isCurrentPlatformProject(delta.getElement().getJavaProject())) { notifyClasspathChanged((IJavaProject) el); } break; default: break; } }
Example 13
Source File: ReorgPolicyFactory.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
@Override public boolean canChildrenBeDestinations(IJavaElement javaElement) { switch (javaElement.getElementType()) { case IJavaElement.JAVA_MODEL: case IJavaElement.JAVA_PROJECT: return true; default: return false; } }
Example 14
Source File: JavaElementTypeComparator.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
int getIdForJavaElementType(int elementType) { switch (elementType) { case IJavaElement.JAVA_MODEL: return 130; case IJavaElement.JAVA_PROJECT: return 120; case IJavaElement.PACKAGE_FRAGMENT_ROOT: return 110; case IJavaElement.PACKAGE_FRAGMENT: return 100; case IJavaElement.COMPILATION_UNIT: return 90; case IJavaElement.CLASS_FILE: return 80; case IJavaElement.TYPE: return 70; case IJavaElement.FIELD: return 60; case IJavaElement.METHOD: return 50; case IJavaElement.INITIALIZER: return 40; case IJavaElement.PACKAGE_DECLARATION: return 30; case IJavaElement.IMPORT_CONTAINER: return 20; case IJavaElement.IMPORT_DECLARATION: return 10; default : return 1; } }
Example 15
Source File: ProblemsLabelDecorator.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
/** * Computes the adornment flags for the given element. * * @param obj the element to compute the flags for * * @return the adornment flags */ protected int computeAdornmentFlags(Object obj) { try { if (obj instanceof IJavaElement) { IJavaElement element= (IJavaElement) obj; int type= element.getElementType(); switch (type) { case IJavaElement.JAVA_MODEL: case IJavaElement.JAVA_PROJECT: case IJavaElement.PACKAGE_FRAGMENT_ROOT: int flags= getErrorTicksFromMarkers(element.getResource(), IResource.DEPTH_INFINITE, null); switch (type) { case IJavaElement.PACKAGE_FRAGMENT_ROOT: IPackageFragmentRoot root= (IPackageFragmentRoot) element; if (flags != ERRORTICK_ERROR && root.getKind() == IPackageFragmentRoot.K_SOURCE && isIgnoringOptionalProblems(root.getRawClasspathEntry())) { flags= ERRORTICK_IGNORE_OPTIONAL_PROBLEMS; } break; case IJavaElement.JAVA_PROJECT: IJavaProject project= (IJavaProject) element; if (flags != ERRORTICK_ERROR && flags != ERRORTICK_BUILDPATH_ERROR && isIgnoringOptionalProblems(project)) { flags= ERRORTICK_IGNORE_OPTIONAL_PROBLEMS; } break; } return flags; case IJavaElement.PACKAGE_FRAGMENT: return getPackageErrorTicksFromMarkers((IPackageFragment) element); case IJavaElement.COMPILATION_UNIT: case IJavaElement.CLASS_FILE: return getErrorTicksFromMarkers(element.getResource(), IResource.DEPTH_ONE, null); case IJavaElement.PACKAGE_DECLARATION: case IJavaElement.IMPORT_DECLARATION: case IJavaElement.IMPORT_CONTAINER: case IJavaElement.TYPE: case IJavaElement.INITIALIZER: case IJavaElement.METHOD: case IJavaElement.FIELD: case IJavaElement.LOCAL_VARIABLE: ICompilationUnit cu= (ICompilationUnit) element.getAncestor(IJavaElement.COMPILATION_UNIT); if (cu != null) { ISourceReference ref= (type == IJavaElement.COMPILATION_UNIT) ? null : (ISourceReference) element; // The assumption is that only source elements in compilation unit can have markers IAnnotationModel model= isInJavaAnnotationModel(cu); int result= 0; if (model != null) { // open in Java editor: look at annotation model result= getErrorTicksFromAnnotationModel(model, ref); } else { result= getErrorTicksFromMarkers(cu.getResource(), IResource.DEPTH_ONE, ref); } fCachedRange= null; return result; } break; default: } } else if (obj instanceof IResource) { return getErrorTicksFromMarkers((IResource) obj, IResource.DEPTH_INFINITE, null); } } catch (CoreException e) { if (e instanceof JavaModelException) { if (((JavaModelException) e).isDoesNotExist()) { return 0; } } if (e.getStatus().getCode() == IResourceStatus.MARKER_NOT_FOUND) { return 0; } JavaPlugin.log(e); } return 0; }
Example 16
Source File: InterfaceIndicatorLabelDecorator.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
@Override protected void processDelta(IJavaElementDelta delta, List<IJavaElement> result) { IJavaElement elem= delta.getElement(); boolean isChanged= delta.getKind() == IJavaElementDelta.CHANGED; boolean isRemoved= delta.getKind() == IJavaElementDelta.REMOVED; int flags= delta.getFlags(); switch (elem.getElementType()) { case IJavaElement.JAVA_PROJECT: if (isRemoved || (isChanged && (flags & IJavaElementDelta.F_CLOSED) != 0)) { return; } processChildrenDelta(delta, result); return; case IJavaElement.PACKAGE_FRAGMENT_ROOT: if (isRemoved || (isChanged && ( (flags & IJavaElementDelta.F_ARCHIVE_CONTENT_CHANGED) != 0 || (flags & IJavaElementDelta.F_REMOVED_FROM_CLASSPATH) != 0))) { return; } processChildrenDelta(delta, result); return; case IJavaElement.PACKAGE_FRAGMENT: if (isRemoved) return; processChildrenDelta(delta, result); return; case IJavaElement.TYPE: case IJavaElement.CLASS_FILE: return; case IJavaElement.JAVA_MODEL: processChildrenDelta(delta, result); return; case IJavaElement.COMPILATION_UNIT: // Not the primary compilation unit. Ignore it if (!JavaModelUtil.isPrimary((ICompilationUnit) elem)) { return; } if (isChanged && ((flags & IJavaElementDelta.F_CONTENT) != 0 || (flags & IJavaElementDelta.F_FINE_GRAINED) != 0)) { if (delta.getAffectedChildren().length == 0) return; result.add(elem); } return; default: // fields, methods, imports ect return; } }
Example 17
Source File: JavaBrowsingPerspectiveFactory.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
private boolean shouldShowPackagesView() { if (fgJavaElementFromAction == null) return true; int type= fgJavaElementFromAction.getElementType(); return type == IJavaElement.JAVA_MODEL || type == IJavaElement.JAVA_PROJECT || type == IJavaElement.PACKAGE_FRAGMENT_ROOT; }
Example 18
Source File: GenericRefactoringHandleTransplanter.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
public final IJavaElement transplantHandle(IJavaElement element) { IJavaElement parent= element.getParent(); if (parent != null) parent= transplantHandle(parent); // recursive switch (element.getElementType()) { case IJavaElement.JAVA_MODEL: return transplantHandle((IJavaModel) element); case IJavaElement.JAVA_PROJECT: return transplantHandle((IJavaProject) element); case IJavaElement.PACKAGE_FRAGMENT_ROOT: return transplantHandle((IJavaProject) parent, (IPackageFragmentRoot) element); case IJavaElement.PACKAGE_FRAGMENT: return transplantHandle((IPackageFragmentRoot) parent, (IPackageFragment) element); case IJavaElement.COMPILATION_UNIT: return transplantHandle((IPackageFragment) parent, (ICompilationUnit) element); case IJavaElement.CLASS_FILE: return transplantHandle((IPackageFragment) parent, (IClassFile) element); case IJavaElement.TYPE: return transplantHandle(parent, (IType) element); case IJavaElement.FIELD: return transplantHandle((IType) parent, (IField) element); case IJavaElement.METHOD: return transplantHandle((IType) parent, (IMethod) element); case IJavaElement.INITIALIZER: return transplantHandle((IType) parent, (IInitializer) element); case IJavaElement.PACKAGE_DECLARATION: return transplantHandle((ICompilationUnit) parent, (IPackageDeclaration) element); case IJavaElement.IMPORT_CONTAINER: return transplantHandle((ICompilationUnit) parent, (IImportContainer) element); case IJavaElement.IMPORT_DECLARATION: return transplantHandle((IImportContainer) parent, (IImportDeclaration) element); case IJavaElement.LOCAL_VARIABLE: return transplantHandle((ILocalVariable) element); case IJavaElement.TYPE_PARAMETER: return transplantHandle((IMember) parent, (ITypeParameter) element); case IJavaElement.ANNOTATION: return transplantHandle((IAnnotatable) parent, (IAnnotation) element); default: throw new IllegalArgumentException(element.toString()); } }
Example 19
Source File: TypeHierarchyLifeCycle.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
private void processDelta(IJavaElementDelta delta, ArrayList<IType> changedTypes) { IJavaElement element= delta.getElement(); switch (element.getElementType()) { case IJavaElement.TYPE: processTypeDelta((IType) element, changedTypes); processChildrenDelta(delta, changedTypes); // (inner types) break; case IJavaElement.JAVA_MODEL: case IJavaElement.JAVA_PROJECT: case IJavaElement.PACKAGE_FRAGMENT_ROOT: case IJavaElement.PACKAGE_FRAGMENT: processChildrenDelta(delta, changedTypes); break; case IJavaElement.COMPILATION_UNIT: ICompilationUnit cu= (ICompilationUnit)element; if (!JavaModelUtil.isPrimary(cu)) { return; } if (delta.getKind() == IJavaElementDelta.CHANGED && isPossibleStructuralChange(delta.getFlags())) { try { if (cu.exists()) { IType[] types= cu.getAllTypes(); for (int i= 0; i < types.length; i++) { processTypeDelta(types[i], changedTypes); } } } catch (JavaModelException e) { JavaPlugin.log(e); } } else { processChildrenDelta(delta, changedTypes); } break; case IJavaElement.CLASS_FILE: if (delta.getKind() == IJavaElementDelta.CHANGED) { IType type= ((IClassFile) element).getType(); processTypeDelta(type, changedTypes); } else { processChildrenDelta(delta, changedTypes); } break; } }
Example 20
Source File: OpenTypeHistory.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
/** * Computes whether the history needs a consistency check or not. * * @param delta the Java element delta * * @return <code>true</code> if consistency must be checked * <code>false</code> otherwise. */ private boolean processDelta(IJavaElementDelta delta) { IJavaElement elem= delta.getElement(); boolean isChanged= delta.getKind() == IJavaElementDelta.CHANGED; boolean isRemoved= delta.getKind() == IJavaElementDelta.REMOVED; switch (elem.getElementType()) { case IJavaElement.JAVA_PROJECT: if (isRemoved || (isChanged && (delta.getFlags() & IJavaElementDelta.F_CLOSED) != 0)) { return true; } return processChildrenDelta(delta); case IJavaElement.PACKAGE_FRAGMENT_ROOT: if (isRemoved || (isChanged && ( (delta.getFlags() & IJavaElementDelta.F_ARCHIVE_CONTENT_CHANGED) != 0 || (delta.getFlags() & IJavaElementDelta.F_REMOVED_FROM_CLASSPATH) != 0))) { return true; } return processChildrenDelta(delta); case IJavaElement.TYPE: if (isChanged && (delta.getFlags() & IJavaElementDelta.F_MODIFIERS) != 0) { return true; } if (isRemoved) { return true; } return processChildrenDelta(delta); case IJavaElement.JAVA_MODEL: case IJavaElement.PACKAGE_FRAGMENT: case IJavaElement.CLASS_FILE: if (isRemoved) { return true; } return processChildrenDelta(delta); case IJavaElement.COMPILATION_UNIT: // Not the primary compilation unit. Ignore it if (!JavaModelUtil.isPrimary((ICompilationUnit) elem)) { return false; } if (isRemoved || (isChanged && isUnknownStructuralChange(delta.getFlags()))) { return true; } return processChildrenDelta(delta); default: // fields, methods, imports ect return false; } }