gt: 				for (int i = 0, length = allTypes.size(); i < length; i++) {
context: /*******************************************************************************
   * 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.wst.jsdt.internal.core.hierarchy;
  
  import java.util.ArrayList;
  import java.util.HashMap;
  import java.util.Iterator;
  import java.util.Map;
  
  import org.eclipse.wst.jsdt.core.IJavaScriptUnit;
  import org.eclipse.wst.jsdt.core.IImportContainer;
  import org.eclipse.wst.jsdt.core.IImportDeclaration;
  import org.eclipse.wst.jsdt.core.IJavaScriptElement;
  import org.eclipse.wst.jsdt.core.IJavaScriptElementDelta;
  import org.eclipse.wst.jsdt.core.IMember;
  import org.eclipse.wst.jsdt.core.IType;
  import org.eclipse.wst.jsdt.core.JavaScriptModelException;
  import org.eclipse.wst.jsdt.internal.core.JavaElement;
  import org.eclipse.wst.jsdt.internal.core.SimpleDelta;
  
  /*
   * Collects changes (reported through fine-grained deltas) that can affect a type hierarchy.
   */
  public class ChangeCollector {
  
  	/*
  	 * A table from ITypes to TypeDeltas
  	 */
  	HashMap changes = new HashMap();
  
  	TypeHierarchy hierarchy;
  
  	public ChangeCollector(TypeHierarchy hierarchy) {
  		this.hierarchy = hierarchy;
  	}
  
  	/*
  	 * Adds the children of the given delta to the list of changes.
  	 */
  	private void addAffectedChildren(IJavaScriptElementDelta delta) throws JavaScriptModelException {
  		IJavaScriptElementDelta[] children = delta.getAffectedChildren();
  		for (int i = 0, length = children.length; i < length; i++) {
  			IJavaScriptElementDelta child = children[i];
  			IJavaScriptElement childElement = child.getElement();
  			switch (childElement.getElementType()) {
  				case IJavaScriptElement.IMPORT_CONTAINER:
  					addChange((IImportContainer)childElement, child);
  					break;
  				case IJavaScriptElement.IMPORT_DECLARATION:
  					addChange((IImportDeclaration)childElement, child);
  					break;
  				case IJavaScriptElement.TYPE:
  					addChange((IType)childElement, child);
  					break;
  				case IJavaScriptElement.INITIALIZER:
  				case IJavaScriptElement.FIELD:
  				case IJavaScriptElement.METHOD:
  					addChange((IMember)childElement, child);
  					break;
  			}
  		}
  	}
  
  	/*
  	 * Adds the given delta on a compilation unit to the list of changes.
  	 */
  	public void addChange(IJavaScriptUnit cu, IJavaScriptElementDelta newDelta) throws JavaScriptModelException {
  		int newKind = newDelta.getKind();
  		switch (newKind) {
  			case IJavaScriptElementDelta.ADDED:
  				ArrayList allTypes = new ArrayList();
  				getAllTypesFromElement(cu, allTypes);
  				for (int i = 0, length = allTypes.size(); i < length; i++) {
  					IType type = (IType)allTypes.get(i);
  					addTypeAddition(type, (SimpleDelta)this.changes.get(type));
  				}
  				break;
  			case IJavaScriptElementDelta.REMOVED:
  				allTypes = new ArrayList();
  				getAllTypesFromHierarchy((JavaElement)cu, allTypes);
  				for (int i = 0, length = allTypes.size(); i < length; i++) {
  					IType type = (IType)allTypes.get(i);
  					addTypeRemoval(type, (SimpleDelta)this.changes.get(type));
  				}
  				break;
  			case IJavaScriptElementDelta.CHANGED:
  				addAffectedChildren(newDelta);
  				break;
  		}
  	}
  
  	private void addChange(IImportContainer importContainer, IJavaScriptElementDelta newDelta) throws JavaScriptModelException {
  		int newKind = newDelta.getKind();
  		if (newKind == IJavaScriptElementDelta.CHANGED) {
  			addAffectedChildren(newDelta);
  			return;
  		}
  		SimpleDelta existingDelta = (SimpleDelta)this.changes.get(importContainer);
  		if (existingDelta != null) {
  			switch (newKind) {
  				case IJavaScriptElementDelta.ADDED:
  					if (existingDelta.getKind() == IJavaScriptElementDelta.REMOVED) {
  						// REMOVED then ADDED
  						this.changes.remove(importContainer);
  					}
  					break;
  				case IJavaScriptElementDelta.REMOVED:
  					if (existingDelta.getKind() == IJavaScriptElementDelta.ADDED) {
  						// ADDED then REMOVED
  						this.changes.remove(importContainer);
  					}
  					break;
  					// CHANGED handled above
  			}
  		} else {
  			SimpleDelta delta = new SimpleDelta();
  			switch (newKind) {
  				case IJavaScriptElementDelta.ADDED:
  					delta.added();
  					break;
  				case IJavaScriptElementDelta.REMOVED:
  					delta.removed();
  					break;
  			}
  			this.changes.put(importContainer, delta);
  		}
  	}
  
  	private void addChange(IImportDeclaration importDecl, IJavaScriptElementDelta newDelta) {
  		SimpleDelta existingDelta = (SimpleDelta)this.changes.get(importDecl);
  		int newKind = newDelta.getKind();
  		if (existingDelta != null) {
  			switch (newKind) {
  				case IJavaScriptElementDelta.ADDED:
  					if (existingDelta.getKind() == IJavaScriptElementDelta.REMOVED) {
  						// REMOVED then ADDED
  						this.changes.remove(importDecl);
  					}
  					break;
  				case IJavaScriptElementDelta.REMOVED:
  					if (existingDelta.getKind() == IJavaScriptElementDelta.ADDED) {
  						// ADDED then REMOVED
  						this.changes.remove(importDecl);
  					}
  					break;
  				// CHANGED cannot happen for import declaration
  			}
  		} else {
  			SimpleDelta delta = new SimpleDelta();
  			switch (newKind) {
  				case IJavaScriptElementDelta.ADDED:
  					delta.added();
  					break;
  				case IJavaScriptElementDelta.REMOVED:
  					delta.removed();
  					break;
  			}
  			this.changes.put(importDecl, delta);
  		}
  	}
  
  	/*
  	 * Adds a change for the given member (a method, a field or an initializer) and the types it defines.
  	 */
  	private void addChange(IMember member, IJavaScriptElementDelta newDelta) throws JavaScriptModelException {
  		int newKind = newDelta.getKind();
  		switch (newKind) {
  			case IJavaScriptElementDelta.ADDED:
  				ArrayList allTypes = new ArrayList();
  				getAllTypesFromElement(member, allTypes);
  				for (int i = 0, length = allTypes.size(); i < length; i++) {
  					IType innerType = (IType)allTypes.get(i);
  					addTypeAddition(innerType, (SimpleDelta)this.changes.get(innerType));
  				}
  				break;
  			case IJavaScriptElementDelta.REMOVED:
  				allTypes = new ArrayList();
  				getAllTypesFromHierarchy((JavaElement)member, allTypes);
  				for (int i = 0, length = allTypes.size(); i < length; i++) {
  					IType type = (IType)allTypes.get(i);
  					addTypeRemoval(type, (SimpleDelta)this.changes.get(type));
  				}
  				break;
  			case IJavaScriptElementDelta.CHANGED:
  				addAffectedChildren(newDelta);
  				break;
  		}
  	}
  
  	/*
  	 * Adds a change for the given type and the types it defines.
  	 */
  	private void addChange(IType type, IJavaScriptElementDelta newDelta) throws JavaScriptModelException {
  		 int newKind = newDelta.getKind();
  		SimpleDelta existingDelta = (SimpleDelta)this.changes.get(type);
  		switch (newKind) {
  			case IJavaScriptElementDelta.ADDED:
  				addTypeAddition(type, existingDelta);
  				ArrayList allTypes = new ArrayList();
  				getAllTypesFromElement(type, allTypes);
  				for (int i = 0, length = allTypes.size(); i < length; i++) {
  					IType innerType = (IType)allTypes.get(i);
  					addTypeAddition(innerType, (SimpleDelta)this.changes.get(innerType));
  				}
  				break;
  			case IJavaScriptElementDelta.REMOVED:
  				addTypeRemoval(type, existingDelta);
  				allTypes = new ArrayList();
  				getAllTypesFromHierarchy((JavaElement)type, allTypes);
  