Java Code Examples for org.eclipse.jdt.core.IJavaElementDelta#getElement()
The following examples show how to use
org.eclipse.jdt.core.IJavaElementDelta#getElement() .
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: ResourceChangedManager.java From ContentAssist with MIT License | 6 votes |
/** * Creates a macro corresponding to the added delta of the change. * @param time the time when the change occurred * @param delta the added delta of the change * @return the created resource macro */ private ResourceMacro createResourceAddedMacro(long time, IJavaElementDelta delta) { IJavaElement elem = delta.getElement(); String path = elem.getPath().toString(); if (path == null) { return null; } String type = "Added"; if ((delta.getFlags() & IJavaElementDelta.F_MOVED_FROM) != 0) { if (isRenamed(delta.getElement(), delta.getMovedFromElement())) { type = "RenamedFrom"; } else { type = "MovedFrom"; } } return new ResourceMacro(time, type, path, elem); }
Example 2
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 3
Source File: DeltaConverter.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
/** * @since 2.5 */ protected void convertChangedCompilationUnit(IJavaElementDelta delta, List<IResourceDescription.Delta> result) { if ((delta.getFlags() & IJavaElementDelta.F_PRIMARY_WORKING_COPY) != 0) { return; } TypeNames typeNames = getTypeNamesFromIndex(delta); ICompilationUnit compilationUnit = (ICompilationUnit) delta.getElement(); try { boolean hasDerivedType = doForeachCompilationUnitChildType(compilationUnit, true, type -> { String typeName = type.getFullyQualifiedName(); URI topLevelURI = uriHelper.createResourceURIForFQN(typeName); convertChangedTypeAndChildren(result, typeNames, type, topLevelURI); }); if (hasDerivedType) return; convertRemovedTypes(typeNames, result); } catch (JavaModelException e) { if (LOGGER.isDebugEnabled()) { LOGGER.debug(e, e); } } }
Example 4
Source File: ChangeCollector.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private void addAffectedChildren(IJavaElementDelta delta) throws JavaModelException { IJavaElementDelta[] children = delta.getAffectedChildren(); for (int i = 0, length = children.length; i < length; i++) { IJavaElementDelta child = children[i]; IJavaElement childElement = child.getElement(); switch (childElement.getElementType()) { case IJavaElement.IMPORT_CONTAINER: addChange((IImportContainer)childElement, child); break; case IJavaElement.IMPORT_DECLARATION: addChange((IImportDeclaration)childElement, child); break; case IJavaElement.TYPE: addChange((IType)childElement, child); break; case IJavaElement.INITIALIZER: case IJavaElement.FIELD: case IJavaElement.METHOD: addChange((IMember)childElement, child); break; } } }
Example 5
Source File: JavaProjectClasspathChangeAnalyzer.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
/** * retrieves all Java Projects whose classpath was effected by the given delta * * @param delta the delta to analyze * @return a Set of the affected Java Projects */ public Set<IJavaProject> getJavaProjectsWithClasspathChange(IJavaElementDelta delta) { IJavaElement element = delta.getElement(); if (element instanceof IPackageFragmentRoot) { if (isRelevantPackageFragmentRootChange(delta)) { IPackageFragmentRoot root = (IPackageFragmentRoot) element; return Collections.singleton(root.getJavaProject()); } } else if (element instanceof IJavaModel) { return getJavaProjectsWithClasspathChange(delta.getAffectedChildren()); } else if (element instanceof IJavaProject) { if (isClasspathChangeOnProject(delta)) { // filter out IJavaElementDelta.F_SOURCEATTACHED | IJavaElementDelta.F_SOURCEDETACHED only if (isAttachmentChangeOnly(delta)) { return Collections.emptySet(); } return Collections.singleton((IJavaProject) element); } return getJavaProjectsWithClasspathChange(delta.getAffectedChildren()); } return Collections.emptySet(); }
Example 6
Source File: Storage2UriMapperJavaImpl.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
private Set<IJavaElementDelta> getProjectDeltas(IJavaElementDelta delta) { IJavaElement element = delta.getElement(); if(delta.getElement().getElementType() == IJavaElement.JAVA_PROJECT) { return Collections.singleton(delta); } Set<IJavaElementDelta> result = null; if(element instanceof IJavaModel) { for(IJavaElementDelta child: delta.getAffectedChildren()) { Set<IJavaElementDelta> projectDeltas = getProjectDeltas(child); if(!projectDeltas.isEmpty()) { if(result == null) result = newLinkedHashSet(); result.addAll(projectDeltas); } } } return result == null ? Collections.<IJavaElementDelta>emptySet() : result; }
Example 7
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 8
Source File: ResourceChangedManager.java From ContentAssist with MIT License | 6 votes |
/** * Creates a macro corresponding to the removed delta of the change. * @param time the time when the change occurred * @param delta the removed delta of the change * @return the created resource macro */ private ResourceMacro createResourceRemovedMacro(long time, IJavaElementDelta delta) { IJavaElement elem = delta.getElement(); String path = elem.getPath().toString(); if (path == null) { return null; } String type = "Removed"; if ((delta.getFlags() & IJavaElementDelta.F_MOVED_TO) != 0) { if (isRenamed(delta.getElement(), delta.getMovedToElement())) { type = "RenamedTo"; } else { type = "MovedTo"; } } return new ResourceMacro(time, type, path, elem); }
Example 9
Source File: JavaOutlinePage.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
protected IJavaElementDelta findElement(IJavaElement unit, IJavaElementDelta delta) { if (delta == null || unit == null) return null; IJavaElement element= delta.getElement(); if (unit.equals(element)) { if (isPossibleStructuralChange(delta)) { return delta; } return null; } if (element.getElementType() > IJavaElement.CLASS_FILE) return null; IJavaElementDelta[] children= delta.getAffectedChildren(); if (children == null || children.length == 0) return null; for (int i= 0; i < children.length; i++) { IJavaElementDelta d= findElement(unit, children[i]); if (d != null) return d; } return null; }
Example 10
Source File: JavaStructureDiffViewer.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
protected IJavaElementDelta findJavaElementDelta(IJavaElement unit, IJavaElementDelta delta) { if (delta == null || unit == null) return null; IJavaElement element= delta.getElement(); if (canIgnore(unit, delta.getAffectedChildren())) return null; if (unit.equals(element)) { if (isContentChange(delta)) { return delta; } return null; } if (element.getElementType() > IJavaElement.CLASS_FILE) return null; IJavaElementDelta[] children= delta.getAffectedChildren(); if (children == null || children.length == 0) return null; for (int i= 0; i < children.length; i++) { IJavaElementDelta d= findJavaElementDelta(unit, children[i]); if (d != null) return d; } return null; }
Example 11
Source File: ClasspathChangeListener.java From scava with Eclipse Public 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())) { System.out.println(); IJavaElementDelta[] affectedChildren = delta.getAffectedChildren(); for (IJavaElementDelta iJavaElementDelta : affectedChildren) { if (iJavaElementDelta.getKind() == IJavaElementDelta.CHANGED || iJavaElementDelta.getKind() == IJavaElementDelta.ADDED) { int flags = iJavaElementDelta.getFlags(); if (isRemove(flags)) { Activator.getDefault().getEventBus().post(new ClasspathChangeEvent( iJavaElementDelta.getElement().getElementName(), ClasspathChangeEventType.DELETED)); } if (isAdd(flags)) { Activator.getDefault().getEventBus().post(new ClasspathChangeEvent( iJavaElementDelta.getElement().getElementName(), ClasspathChangeEventType.ADDED)); } } } } break; default: break; } }
Example 12
Source File: ResourceChangedManager.java From ContentAssist with MIT License | 5 votes |
/** * Creates a macro corresponding to the changed delta of the change. * @param time the time when the change occurred * @param delta the changed delta of the change * @return the created resource macro */ private ResourceMacro createResourceChangedMacro(long time, IJavaElementDelta delta) { IJavaElement elem = delta.getElement(); String path = elem.getPath().toString(); if (path == null) { return null; } if ((delta.getFlags() & IJavaElementDelta.F_CONTENT) != 0) { // System.out.println("CONTENT CHANGED" + path); return null; } return new ResourceMacro(time, "Changed", path, elem); }
Example 13
Source File: DeltaConverter.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
protected void convertCompilationUnits(IJavaElementDelta delta, List<IResourceDescription.Delta> result) { IJavaElement element = delta.getElement(); if (element.getElementType() == IJavaElement.COMPILATION_UNIT) { convertCompilationUnit(delta, result); } if (element.getElementType() < IJavaElement.COMPILATION_UNIT) { for (IJavaElementDelta child : delta.getAffectedChildren()) { convertCompilationUnits(child, result); } if (element.getElementType() == IJavaElement.PACKAGE_FRAGMENT) { convertPackageFragment(delta, result); } } }
Example 14
Source File: DeltaConverter.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
/** * @since 2.5 */ protected void convertAddedPackageFragment(IJavaElementDelta delta, List<IResourceDescription.Delta> result) { IPackageFragment fragment = (IPackageFragment) delta.getElement(); try { for (ICompilationUnit cu : fragment.getCompilationUnits()) { convertNewTypes(cu, result); } } catch (JavaModelException e) { if (LOGGER.isDebugEnabled()) LOGGER.debug(e, e); } }
Example 15
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 16
Source File: ClasspathChangedListener.java From gwt-eclipse-plugin with Eclipse Public License 1.0 | 5 votes |
public void elementChanged(ElementChangedEvent event) { for (IJavaElementDelta delta : event.getDelta().getChangedChildren()) { int flags = delta.getFlags(); if ((flags & IJavaElementDelta.F_CLASSPATH_CHANGED) != 0) { IJavaElement element = delta.getElement(); if (element.getElementType() != IJavaElement.JAVA_PROJECT) { continue; } classpathChanged((IJavaProject) element); } } }
Example 17
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 18
Source File: JavaEditorBreadcrumb.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * Returns the most generic ancestor of the given input which has a change, or <b>null</b> * if no such ancestor exists. * * @param input the input of which the result must be an ancestor * @param delta the delta describing the model change * @return the changed element or <code>null</code> */ private IJavaElement getChangedParentElement(IJavaElement input, IJavaElementDelta delta) { IJavaElement element= delta.getElement(); if (!isAncestor(element, input)) return null; if (element instanceof ICompilationUnit) { ICompilationUnit cu= (ICompilationUnit) element; if (!cu.getPrimary().equals(cu)) return null; if (isStructuralChange(delta)) return element; } else { if (!onlyChildrenChanged(delta)) return element; } IJavaElementDelta[] affectedChildren= delta.getAffectedChildren(); for (int i= 0; i < affectedChildren.length; i++) { IJavaElement res= getChangedParentElement(input, affectedChildren[i]); if (res != null) return res; } return null; }
Example 19
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; } }
Example 20
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; } }