Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (c) 2000, 2009 IBM Corporation and others. All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html Contributors: IBM Corporation - initial API and implementation /
 
 package org.eclipse.jdt.internal.core.hierarchy;
 
 
 import  org.eclipse.core.runtime.CoreException;
 
 public class RegionBasedTypeHierarchy extends TypeHierarchy {
The region of types for which to build the hierarchy
 
 	protected IRegion region;

Creates a TypeHierarchy on the types in the specified region, considering first the given working copies, using the projects in the given region for a name lookup context. If a specific type is also specified, the type hierarchy is pruned to only contain the branch including the specified type.
 
 public RegionBasedTypeHierarchy(IRegion regionICompilationUnit[] workingCopiesIType typeboolean computeSubtypes) {
 	super(typeworkingCopies, (IJavaSearchScope)nullcomputeSubtypes);
 
 	Region newRegion = new Region() {
 		public void add(IJavaElement element) {
 			if (!contains(element)) {
 				//"new" element added to region
 				removeAllChildren(element);
 				this..add(element);
 				if (element.getElementType() == .) {
 					// add jar roots as well so that jars don't rely on their parent to know
 					// if they are contained in the region
 					// (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=146615)
 					try {
 						for (int i = 0, length = roots.lengthi < lengthi++) {
 							if (roots[i].isArchive() && !this..contains(roots[i]))
 								this..add(roots[i]);
 						}
 					} catch (JavaModelException e) {
 						// project doesn't exist
 					}
 				}
 			}
 		}
 	};
 	IJavaElement[] elements = region.getElements();
 	for (int i = 0, length = elements.lengthi < lengthi++) {
 		newRegion.add(elements[i]);
 
 	}
 	this. = newRegion;
 	if (elements.length > 0)
 		this. = elements[0].getJavaProject();
 }
 /*
  * @see TypeHierarchy#initializeRegions
  */
 protected void initializeRegions() {
 	IJavaElement[] roots = this..getElements();
 	for (int i = 0; i < roots.lengthi++) {
 		IJavaElement root = roots[i];
 		if (root instanceof IOpenable) {
 			this..put(rootnew ArrayList());
 		} else {
 			if (o != null) {
 				this..put(onew ArrayList());
 			}
 		}
 	}
 }
Compute this type hierarchy.
 
 protected void compute() throws JavaModelException, CoreException {
 	builder.build(this.);
 }
 protected boolean isAffectedByOpenable(IJavaElementDelta deltaIJavaElement elementint eventType) {
	// change to working copy
	if (element instanceof CompilationUnit && ((CompilationUnit)element).isWorkingCopy()) {
		return super.isAffectedByOpenable(deltaelementeventType);
	}
	// if no focus, hierarchy is affected if the element is part of the region
	if (this. == null) {
		return this..contains(element);
else {
		return super.isAffectedByOpenable(deltaelementeventType);
	}
Returns the java project this hierarchy was created in.
	return this.;
public void pruneDeadBranches() {
/*
 * Returns whether all subtypes of the given type have been pruned.
 */
private boolean pruneDeadBranches(IType type) {
	TypeVector subtypes = (TypeVector)this..get(type);
	if (subtypes == nullreturn true;
	subtypes = (TypeVector)this..get(type);
	return (subtypes == null || subtypes.size == 0);
private void pruneDeadBranches(IType[] types) {
	for (int i = 0, length = types.lengthi < lengthi++) {
		IType type = types[i];
		if (pruneDeadBranches(type) && !this..contains(type)) {
		}
	}
Removes all the subtypes of the given type from the type hierarchy, removes its superclass entry and removes the references from its super types.
protected void removeType(IType type) {
	IType[] subtypes = getSubtypes(type);
	if (subtypes != null) {
		for (int i= 0; i < subtypes.lengthi++) {
			removeType(subtypes[i]);
		}
	}
	IType superclass = (IType)this..remove(type);
	if (superclass != null) {
		TypeVector types = (TypeVector)this..get(superclass);
		if (types != nulltypes.remove(type);
	}
	IType[] superinterfaces = (IType[])this..remove(type);
	if (superinterfaces != null) {
		for (int i = 0, length = superinterfaces.lengthi < lengthi++) {
			IType superinterface = superinterfaces[i];
			TypeVector types = (TypeVector)this..get(superinterface);
			if (types != nulltypes.remove(type);
		}
	}
	this..remove(type);
New to GrepCode? Check out our FAQ X