Java Code Examples for org.eclipse.jdt.core.IJavaElementDelta#getKind()

The following examples show how to use org.eclipse.jdt.core.IJavaElementDelta#getKind() . 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 vote down vote up
/**
 * Collects all the deltas of the changes.
 * @param delta the root delta of the change
 * @param deltas the collection of the deltas to be collected
 */
private void collectDeltas(IJavaElementDelta delta) {
    if (delta.getKind() == IJavaElementDelta.ADDED ||
        delta.getKind() == IJavaElementDelta.REMOVED) {
        if (!contain(delta)) {
            deltas.add(delta);
        }
    } else if (delta.getKind() == IJavaElementDelta.CHANGED &&
            ((delta.getFlags() & IJavaElementDelta.F_CONTENT) != 0)) {
        if (!contain(delta)) {
            deltas.add(delta);
        }
    }
    
    for (IJavaElementDelta d : delta.getAffectedChildren()) {
        collectDeltas(d);
    }
}
 
Example 2
Source File: SearchResultUpdater.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private void collectRemoved(Set<IAdaptable> potentiallyRemovedSet, Set<IAdaptable> removedElements, IJavaElementDelta delta) {
	if (delta.getKind() == IJavaElementDelta.REMOVED)
		removedElements.add(delta.getElement());
	else if (delta.getKind() == IJavaElementDelta.CHANGED) {
		int flags= delta.getFlags();
		if ((flags & REMOVED_FLAGS) != 0) {
			potentiallyRemovedSet.add(delta.getElement());
		} else {
			IJavaElementDelta[] childDeltas= delta.getAffectedChildren();
			for (int i= 0; i < childDeltas.length; i++) {
				collectRemoved(potentiallyRemovedSet, removedElements, childDeltas[i]);
			}
		}
	}
	IResourceDelta[] resourceDeltas= delta.getResourceDeltas();
	if (resourceDeltas != null) {
		for (int i= 0; i < resourceDeltas.length; i++) {
			collectRemovals(removedElements, resourceDeltas[i]);
		}
	}
}
 
Example 3
Source File: ResourceChangedManager.java    From ContentAssist with MIT License 5 votes vote down vote up
/**
 * Tests if a given change delta was already contained in the change collection.
 * @param delta the change delta
 * @return <code>true</code> if the change delta was contained in the change collection, otherwise <code> false</code>
 */
private boolean contain(IJavaElementDelta delta) {
    String path = delta.getElement().getPath().toString();
    for (IJavaElementDelta d : deltas) {
        String p = d.getElement().getPath().toString();
        if (p.compareTo(path) == 0 && d.getKind() == delta.getKind()) {
            return true;
        }
    }
    return false;
}
 
Example 4
Source File: OthersWorkingSetUpdater.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private void processJavaDelta(List<IAdaptable> elements, IJavaElementDelta delta) {
	IJavaElement jElement= delta.getElement();
	int type= jElement.getElementType();
	if (type == IJavaElement.JAVA_PROJECT) {
		int index= elements.indexOf(jElement);
		int kind= delta.getKind();
		int flags= delta.getFlags();
		if (kind == IJavaElementDelta.CHANGED) {
			if (index != -1 && (flags & IJavaElementDelta.F_CLOSED) != 0) {
				elements.set(index, ((IJavaProject)jElement).getProject());
				fWorkingSet.setElements(elements.toArray(new IAdaptable[elements.size()]));
			} else if ((flags & IJavaElementDelta.F_OPENED) != 0) {
				index= elements.indexOf(((IJavaProject)jElement).getProject());
				if (index != -1) {
					elements.set(index, jElement);
					fWorkingSet.setElements(elements.toArray(new IAdaptable[elements.size()]));
				}
			}
		}
		// don't visit below projects
		return;
	}
	IJavaElementDelta[] children= delta.getAffectedChildren();
	for (int i= 0; i < children.length; i++) {
		processJavaDelta(elements, children[i]);
	}
}
 
Example 5
Source File: JavaWorkingSetUpdater.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private void processJavaDelta(WorkingSetDelta result, IJavaElementDelta delta) {
	IJavaElement jElement= delta.getElement();
	int index= result.indexOf(jElement);
	int type= jElement.getElementType();
	int kind= delta.getKind();
	int flags= delta.getFlags();
	if (type == IJavaElement.JAVA_PROJECT && kind == IJavaElementDelta.CHANGED) {
		if (index != -1 && (flags & IJavaElementDelta.F_CLOSED) != 0) {
			result.set(index, ((IJavaProject)jElement).getProject());
		} else if ((flags & IJavaElementDelta.F_OPENED) != 0) {
			index= result.indexOf(((IJavaProject)jElement).getProject());
			if (index != -1)
				result.set(index, jElement);
		}
	}
	if (index != -1) {
		if (kind == IJavaElementDelta.REMOVED) {
			if ((flags & IJavaElementDelta.F_MOVED_TO) != 0) {
				result.set(index, delta.getMovedToElement());
			} else {
				result.remove(index);
			}
		}
	}
	IResourceDelta[] resourceDeltas= delta.getResourceDeltas();
	if (resourceDeltas != null) {
		for (int i= 0; i < resourceDeltas.length; i++) {
			processResourceDelta(result, resourceDeltas[i]);
		}
	}
	IJavaElementDelta[] children= delta.getAffectedChildren();
	for (int i= 0; i < children.length; i++) {
		processJavaDelta(result, children[i]);
	}
}
 
Example 6
Source File: LogicalPackagesProvider.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
protected boolean isClassPathChange(IJavaElementDelta delta) {

		// need to test the flags only for package fragment roots
		if (delta.getElement().getElementType() != IJavaElement.PACKAGE_FRAGMENT_ROOT)
			return false;

		int flags= delta.getFlags();
		return (delta.getKind() == IJavaElementDelta.CHANGED &&
			((flags & IJavaElementDelta.F_ADDED_TO_CLASSPATH) != 0) ||
			 ((flags & IJavaElementDelta.F_REMOVED_FROM_CLASSPATH) != 0) ||
			 ((flags & IJavaElementDelta.F_REORDER) != 0));
	}
 
Example 7
Source File: JavaOutlinePage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private boolean isPossibleStructuralChange(IJavaElementDelta cuDelta) {
	if (cuDelta.getKind() != IJavaElementDelta.CHANGED) {
		return true; // add or remove
	}
	int flags= cuDelta.getFlags();
	if ((flags & IJavaElementDelta.F_CHILDREN) != 0) {
		return true;
	}
	return (flags & (IJavaElementDelta.F_CONTENT | IJavaElementDelta.F_FINE_GRAINED)) == IJavaElementDelta.F_CONTENT;
}
 
Example 8
Source File: BuildpathIndicatorLabelDecorator.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@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 9
Source File: StandardJavaElementContentProvider.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Tests if the a Java element delta contains a class path change
 *
 * @param delta the Java element delta
 * @return returns <code>true</code> if the delta contains a class path change
 */
protected boolean isClassPathChange(IJavaElementDelta delta) {

	// need to test the flags only for package fragment roots
	if (delta.getElement().getElementType() != IJavaElement.PACKAGE_FRAGMENT_ROOT)
		return false;

	int flags= delta.getFlags();
	return (delta.getKind() == IJavaElementDelta.CHANGED &&
		((flags & IJavaElementDelta.F_ADDED_TO_CLASSPATH) != 0) ||
		 ((flags & IJavaElementDelta.F_REMOVED_FROM_CLASSPATH) != 0) ||
		 ((flags & IJavaElementDelta.F_REORDER) != 0));
}
 
Example 10
Source File: DeltaConverter.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @since 2.5
 */
protected void convertPackageFragment(IJavaElementDelta delta, List<IResourceDescription.Delta> result) {
	if (delta.getKind() == IJavaElementDelta.ADDED) {
		convertAddedPackageFragment(delta, result);
	} else if (delta.getKind() == IJavaElementDelta.REMOVED) {
		convertRemovedTypes(delta, result);
	}
}
 
Example 11
Source File: ChangeCollector.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private void addChange(IImportDeclaration importDecl, IJavaElementDelta newDelta) {
	SimpleDelta existingDelta = (SimpleDelta)this.changes.get(importDecl);
	int newKind = newDelta.getKind();
	if (existingDelta != null) {
		switch (newKind) {
			case IJavaElementDelta.ADDED:
				if (existingDelta.getKind() == IJavaElementDelta.REMOVED) {
					// REMOVED then ADDED
					this.changes.remove(importDecl);
				}
				break;
			case IJavaElementDelta.REMOVED:
				if (existingDelta.getKind() == IJavaElementDelta.ADDED) {
					// ADDED then REMOVED
					this.changes.remove(importDecl);
				}
				break;
			// CHANGED cannot happen for import declaration
		}
	} else {
		SimpleDelta delta = new SimpleDelta();
		switch (newKind) {
			case IJavaElementDelta.ADDED:
				delta.added();
				break;
			case IJavaElementDelta.REMOVED:
				delta.removed();
				break;
		}
		this.changes.put(importDecl, delta);
	}
}
 
Example 12
Source File: ElementChangedListener.java    From JDeodorant with MIT License 5 votes vote down vote up
private void processDelta(IJavaElementDelta delta) {
	IJavaElement javaElement = delta.getElement();
	switch(javaElement.getElementType()) {
	case IJavaElement.JAVA_MODEL:
	case IJavaElement.JAVA_PROJECT:
	case IJavaElement.PACKAGE_FRAGMENT_ROOT:
	case IJavaElement.PACKAGE_FRAGMENT:
		IJavaElementDelta[] affectedChildren = delta.getAffectedChildren();
		for(IJavaElementDelta affectedChild : affectedChildren) {
			processDelta(affectedChild);
		}
		break;
	case IJavaElement.COMPILATION_UNIT:
		ICompilationUnit compilationUnit = (ICompilationUnit)javaElement;
		if(delta.getKind() == IJavaElementDelta.ADDED) {
			CompilationUnitCache.getInstance().compilationUnitAdded(compilationUnit);
		}
		else if(delta.getKind() == IJavaElementDelta.REMOVED) {
			CompilationUnitCache.getInstance().compilationUnitRemoved(compilationUnit);
		}
		else if(delta.getKind() == IJavaElementDelta.CHANGED) {
			if((delta.getFlags() & IJavaElementDelta.F_FINE_GRAINED) != 0) {
				CompilationUnitCache.getInstance().compilationUnitChanged(compilationUnit);
			}
		}
	}
}
 
Example 13
Source File: ClasspathChangeListener.java    From scava with Eclipse Public License 2.0 5 votes vote down vote up
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 14
Source File: OpenTypeHistory.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * 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 15
Source File: ClassFileDocumentProvider.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Recursively check whether the class file has been deleted.
 * 
 * @param input the package fragment root
 * @param delta the Java element delta
 * @return <code>true</code> if delta processing can be stopped
 */
protected boolean check(IPackageFragmentRoot input, IJavaElementDelta delta) {
	IJavaElement element= delta.getElement();

	if ((delta.getKind() & IJavaElementDelta.REMOVED) != 0 || (delta.getFlags() & IJavaElementDelta.F_CLOSED) != 0) {
		// http://dev.eclipse.org/bugs/show_bug.cgi?id=19023
		if (element.equals(input.getJavaProject()) || element.equals(input)) {
			handleDeleted(fInput);
			return true;
		}
	}

	if (((delta.getFlags() & IJavaElementDelta.F_ARCHIVE_CONTENT_CHANGED) != 0) && input.equals(element)) {
		handleDeleted(fInput);
		return true;
	}

	if (((delta.getFlags() & IJavaElementDelta.F_REMOVED_FROM_CLASSPATH) != 0) && input.equals(element)) {
		handleDeleted(fInput);
		return true;
	}

	IJavaElementDelta[] subdeltas= delta.getAffectedChildren();
	for (int i= 0; i < subdeltas.length; i++) {
		if (check(input, subdeltas[i]))
			return true;
	}

	if ((delta.getFlags() & IJavaElementDelta.F_SOURCEDETACHED) != 0 ||
		(delta.getFlags() & IJavaElementDelta.F_SOURCEATTACHED) != 0)
	{
		IClassFile file= fInput != null ? fInput.getClassFile() : null;
		IJavaProject project= input != null ? input.getJavaProject() : null;

		boolean isOnClasspath= false;
		if (file != null && project != null)
			isOnClasspath= project.isOnClasspath(file);

		if (isOnClasspath) {
			fireInputChanged(fInput);
			return false;
		} else {
			handleDeleted(fInput);
			return true;
		}
	}

	return false;
}
 
Example 16
Source File: JavaEditorBreadcrumb.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private boolean isStructuralChange(IJavaElementDelta delta) {
	if (delta.getKind() != IJavaElementDelta.CHANGED)
		return true;

	return (delta.getFlags() & IJavaElementDelta.F_CONTENT | IJavaElementDelta.F_FINE_GRAINED) == IJavaElementDelta.F_CONTENT;
}
 
Example 17
Source File: JavaEditorBreadcrumb.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private boolean onlyChildrenChanged(IJavaElementDelta delta) {
	if (delta.getKind() != IJavaElementDelta.CHANGED)
		return false;

	return (delta.getFlags() & ~IJavaElementDelta.F_FINE_GRAINED) == IJavaElementDelta.F_CHILDREN;
}
 
Example 18
Source File: TypeHierarchyLifeCycle.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
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 19
Source File: InterfaceIndicatorLabelDecorator.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
@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 20
Source File: JavaStructureDiffViewer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 2 votes vote down vote up
/**
 * Test whether the given delta represents a significant change.
 * 
 * @param cuDelta the Java element delta
 * @return <code>true</code> if the delta represents a content change
 * @since 3.5
 */
private boolean isContentChange(IJavaElementDelta cuDelta) {
	int flags= cuDelta.getFlags();
	return flags != IJavaElementDelta.F_AST_AFFECTED && (cuDelta.getKind() == IJavaElementDelta.CHANGED || (flags & IJavaElementDelta.F_CONTENT) != 0);
}