Java Code Examples for org.eclipse.jdt.core.IJavaElementDelta#CHANGED

The following examples show how to use org.eclipse.jdt.core.IJavaElementDelta#CHANGED . 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: SimpleDelta.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
protected void toDebugString(StringBuffer buffer) {
	buffer.append("["); //$NON-NLS-1$
	switch (getKind()) {
		case IJavaElementDelta.ADDED :
			buffer.append('+');
			break;
		case IJavaElementDelta.REMOVED :
			buffer.append('-');
			break;
		case IJavaElementDelta.CHANGED :
			buffer.append('*');
			break;
		default :
			buffer.append('?');
			break;
	}
	buffer.append("]: {"); //$NON-NLS-1$
	toDebugString(buffer, getFlags());
	buffer.append("}"); //$NON-NLS-1$
}
 
Example 2
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 3
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 4
Source File: ChangeCollector.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private void addTypeRemoval(IType type, SimpleDelta existingDelta) {
	if (existingDelta != null) {
		switch (existingDelta.getKind()) {
			case IJavaElementDelta.ADDED:
				// ADDED then REMOVED
				this.changes.remove(type);
				break;
			case IJavaElementDelta.CHANGED:
				// CHANGED then REMOVED
				existingDelta.removed();
				break;
				// REMOVED then REMOVED: should not happen
		}
	} else {
		// check whether the type removal affects the hierarchy
		if (this.hierarchy.contains(type)) {
			SimpleDelta typeDelta = new SimpleDelta();
			typeDelta.removed();
			this.changes.put(type, typeDelta);
		}
	}
}
 
Example 5
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 6
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 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: ChangeCollector.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private void addChange(IImportContainer importContainer, IJavaElementDelta newDelta) throws JavaModelException {
	int newKind = newDelta.getKind();
	if (newKind == IJavaElementDelta.CHANGED) {
		addAffectedChildren(newDelta);
		return;
	}
	SimpleDelta existingDelta = (SimpleDelta)this.changes.get(importContainer);
	if (existingDelta != null) {
		switch (newKind) {
			case IJavaElementDelta.ADDED:
				if (existingDelta.getKind() == IJavaElementDelta.REMOVED) {
					// REMOVED then ADDED
					this.changes.remove(importContainer);
				}
				break;
			case IJavaElementDelta.REMOVED:
				if (existingDelta.getKind() == IJavaElementDelta.ADDED) {
					// ADDED then REMOVED
					this.changes.remove(importContainer);
				}
				break;
				// CHANGED handled above
		}
	} else {
		SimpleDelta delta = new SimpleDelta();
		switch (newKind) {
			case IJavaElementDelta.ADDED:
				delta.added();
				break;
			case IJavaElementDelta.REMOVED:
				delta.removed();
				break;
		}
		this.changes.put(importContainer, delta);
	}
}
 
Example 9
Source File: JavaSearchScope.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public void processDelta(IJavaElementDelta delta, int eventType) {
	switch (delta.getKind()) {
		case IJavaElementDelta.CHANGED:
			IJavaElementDelta[] children = delta.getAffectedChildren();
			for (int i = 0, length = children.length; i < length; i++) {
				IJavaElementDelta child = children[i];
				processDelta(child, eventType);
			}
			break;
		case IJavaElementDelta.REMOVED:
			IJavaElement element = delta.getElement();
			if (this.encloses(element)) {
				if (this.elements != null) {
					this.elements.remove(element);
				}
				String path = null;
				switch (element.getElementType()) {
					case IJavaElement.JAVA_PROJECT:
						path = ((IJavaProject)element).getProject().getFullPath().toString();
						break;
					case IJavaElement.PACKAGE_FRAGMENT_ROOT:
						path = ((IPackageFragmentRoot)element).getPath().toString();
						break;
					default:
						return;
				}
				for (int i = 0; i < this.pathsCount; i++) {
					if (this.relativePaths[i].equals(path)) {
						this.relativePaths[i] = null;
						rehash();
						break;
					}
				}
			}
			break;
	}
}
 
Example 10
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 11
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 12
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 13
Source File: SimpleDelta.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public void changed(int flags) {
	this.kind = IJavaElementDelta.CHANGED;
	this.changeFlags |= flags;
}
 
Example 14
Source File: ChangeCollector.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private void addTypeChange(IType type, int newFlags, SimpleDelta existingDelta) throws JavaModelException {
	if (existingDelta != null) {
		switch (existingDelta.getKind()) {
			case IJavaElementDelta.CHANGED:
				// CHANGED then CHANGED
				int existingFlags = existingDelta.getFlags();
				boolean hasChange = false;
				if ((existingFlags & IJavaElementDelta.F_SUPER_TYPES) != 0
						&& hasSuperTypeChange(type)) {
					existingDelta.superTypes();
					hasChange = true;
				}
				if ((existingFlags & IJavaElementDelta.F_MODIFIERS) != 0
						&& hasVisibilityChange(type)) {
					existingDelta.modifiers();
					hasChange = true;
				}
				if (!hasChange) {
					// super types and visibility are back to the ones in the existing hierarchy
					this.changes.remove(type);
				}
				break;
				// ADDED then CHANGED: leave it as ADDED
				// REMOVED then CHANGED: should not happen
		}
	} else {
		// check whether the type change affects the hierarchy
		SimpleDelta typeDelta = null;
		if ((newFlags & IJavaElementDelta.F_SUPER_TYPES) != 0
				&& this.hierarchy.includesTypeOrSupertype(type)) {
			typeDelta = new SimpleDelta();
			typeDelta.superTypes();
		}
		if ((newFlags & IJavaElementDelta.F_MODIFIERS) != 0
				&& (this.hierarchy.hasSupertype(type.getElementName())
					|| type.equals(this.hierarchy.focusType))) {
			if (typeDelta == null) {
				typeDelta = new SimpleDelta();
			}
			typeDelta.modifiers();
		}
		if (typeDelta != null) {
			this.changes.put(type, typeDelta);
		}
	}
}
 
Example 15
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 16
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 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: 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 19
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 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);
}