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

The following examples show how to use org.eclipse.jdt.core.IJavaElementDelta#REMOVED . 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: JavaProjectClasspathChangeAnalyzer.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * determines if the delta is a relevant change on a IPackageFragmentRoot
 * 
 * @param delta
 *            the IJavaElementDelta to analyze. the deltas element must be an instance of IPackageFragmentRoot
 */
public boolean isRelevantPackageFragmentRootChange(IJavaElementDelta delta) {
	IJavaElement element = delta.getElement();
	assert (element instanceof IPackageFragmentRoot);
	return delta.getKind() == IJavaElementDelta.REMOVED 
			|| delta.getKind() == IJavaElementDelta.ADDED
			|| (delta.getFlags() & IJavaElementDelta.F_REORDER) != 0
			|| (delta.getFlags() & IJavaElementDelta.F_REMOVED_FROM_CLASSPATH) != 0
			|| (delta.getFlags() & IJavaElementDelta.F_ADDED_TO_CLASSPATH) != 0
			|| (
					(
						((IPackageFragmentRoot) element).isExternal() 
						|| ((IPackageFragmentRoot) element).isArchive()
					) && 
					(
						delta.getFlags() & // external folders change
						(IJavaElementDelta.F_CONTENT | IJavaElementDelta.F_ARCHIVE_CONTENT_CHANGED)
					) == delta.getFlags()
			);
}
 
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: 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 4
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 5
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 6
Source File: ChangeCollector.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private void addTypeAddition(IType type, SimpleDelta existingDelta) throws JavaModelException {
	if (existingDelta != null) {
		switch (existingDelta.getKind()) {
			case IJavaElementDelta.REMOVED:
				// REMOVED then ADDED
				boolean hasChange = false;
				if (hasSuperTypeChange(type)) {
					existingDelta.superTypes();
					hasChange = true;
				}
				if (hasVisibilityChange(type)) {
					existingDelta.modifiers();
					hasChange = true;
				}
				if (!hasChange) {
					this.changes.remove(type);
				}
				break;
				// CHANGED then ADDED
				// or ADDED then ADDED: should not happen
		}
	} else {
		// check whether the type addition affects the hierarchy
		String typeName = type.getElementName();
		if (this.hierarchy.hasSupertype(typeName)
				|| this.hierarchy.subtypesIncludeSupertypeOf(type)
				|| this.hierarchy.missingTypes.contains(typeName)) {
			SimpleDelta delta = new SimpleDelta();
			delta.added();
			this.changes.put(type, delta);
		}
	}
}
 
Example 7
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 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: 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 11
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 12
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 13
Source File: DeltaConverter.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected void convertCompilationUnit(IJavaElementDelta delta, List<IResourceDescription.Delta> result) {
	if (delta.getKind() == IJavaElementDelta.ADDED) {
		convertAddedCompilationUnit(delta, result);
	} else if (delta.getKind() == IJavaElementDelta.REMOVED) {
		convertRemovedTypes(delta, result);
	} else {
		convertChangedCompilationUnit(delta, result);
	}
}
 
Example 14
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 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: 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 17
Source File: SimpleDelta.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public void removed() {
	this.kind = IJavaElementDelta.REMOVED;
	this.changeFlags = 0;
}