Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [Dltk-dev] profiling stuff..

Ok

i made a little bit more improvements to that area.
any objections with the patch that is attached?

I also changed the internal variable of ModelElementInfo from an [] to a List (null if nothing)
Because at my place that grows to almost 400 and every add does an array copy
And this also happens constantly even with typing because then also the source is parsed.

johan

### Eclipse Workspace Patch 1.0
#P org.eclipse.dltk.core
Index: model/org/eclipse/dltk/internal/core/ModelElementInfo.java
===================================================================
RCS file: /cvsroot/technology/org.eclipse.dltk/core/plugins/org.eclipse.dltk.core/model/org/eclipse/dltk/internal/core/ModelElementInfo.java,v
retrieving revision 1.3
diff -u -r1.3 ModelElementInfo.java
--- model/org/eclipse/dltk/internal/core/ModelElementInfo.java	2 May 2007 15:05:00 -0000	1.3
+++ model/org/eclipse/dltk/internal/core/ModelElementInfo.java	30 May 2008 15:48:17 -0000
@@ -9,98 +9,82 @@
  *******************************************************************************/
 package org.eclipse.dltk.internal.core;
 
+import java.util.ArrayList;
+import java.util.List;
+
 import org.eclipse.dltk.core.IModelElement;
 
 /**
- * Holds cached structure and properties for a model element.
- * Subclassed to carry properties for specific kinds of elements.
+ * Holds cached structure and properties for a model element. Subclassed to
+ * carry properties for specific kinds of elements.
  */
-/* package */ class ModelElementInfo {
+/* package */class ModelElementInfo {
 
 	/**
-	 * Collection of handles of immediate children of this
-	 * object. This is an empty array if this element has
-	 * no children.
+	 * Collection of handles of immediate children of this object. This is an
+	 * empty array if this element has no children.
 	 */
-	protected IModelElement[] children;
+	private List children;
 
 	/**
 	 * Shared empty collection used for efficiency.
 	 */
-	static Object[] NO_NON_SCRIPT_RESOURCES = new Object[] {};	
-	
+	static Object[] NO_NON_SCRIPT_RESOURCES = new Object[] {};
+
 	protected ModelElementInfo() {
-		this.children = ModelElement.NO_ELEMENTS;
 	}
+
 	public void addChild(IModelElement child) {
-		if (this.children == ModelElement.NO_ELEMENTS) {
-			setChildren(new IModelElement[] {child});
-		} else {
-			if (!includesChild(child)) {
-				setChildren(growAndAddToArray(this.children, child));
-			}
+		if (this.children == null) {
+			this.children = new ArrayList(5);
+		}
+		if (!this.children.contains(child)) {
+			this.children.add(child);
 		}
 	}
+
+	public int size() {
+		if (this.children == null)
+			return 0;
+		return this.children.size();
+	}
+
+	protected IModelElement get(int i) {
+		if (this.children == null)
+			return null;
+		return (IModelElement) children.get(i);
+	}
+
 	public Object clone() {
 		try {
 			return super.clone();
-		}
-		catch (CloneNotSupportedException e) {
+		} catch (CloneNotSupportedException e) {
 			throw new Error();
 		}
 	}
+
 	public IModelElement[] getChildren() {
-		return this.children;
-	}
-	/**
-	 * Adds the new element to a new array that contains all of the elements of the old array.
-	 * Returns the new array.
-	 */
-	protected IModelElement[] growAndAddToArray(IModelElement[] array, IModelElement addition) {
-		IModelElement[] old = array;
-		array = new IModelElement[old.length + 1];
-		System.arraycopy(old, 0, array, 0, old.length);
-		array[old.length] = addition;
-		return array;
-	}
-	/**
-	 * Returns <code>true</code> if this child is in my children collection
-	 */
-	protected boolean includesChild(IModelElement child) {
-		
-		for (int i= 0; i < this.children.length; i++) {
-			if (child.equals(this.children[i])) {
-				return true;
-			}
-		}
-		return false;
-	}
-	/**
-	 * Returns an array with all the same elements as the specified array except for
-	 * the element to remove. Assumes that the deletion is contained in the array.
-	 */
-	protected IModelElement[] removeAndShrinkArray(IModelElement[] array, IModelElement deletion) {
-		IModelElement[] old = array;
-		array = new IModelElement[old.length - 1];
-		int j = 0;
-		for (int i = 0; i < old.length; i++) {
-			if (!old[i].equals(deletion)) {
-				array[j] = old[i];
-			} else {
-				System.arraycopy(old, i + 1, array, j, old.length - (i + 1));
-				return array;
-			}
-			j++;
-		}
-		return array;
+		if (children == null)
+			return ModelElement.NO_ELEMENTS;
+		return (IModelElement[]) this.children
+				.toArray(new IModelElement[this.children.size()]);
 	}
+
 	public void removeChild(IModelElement child) {
-		if (includesChild(child)) {
-			setChildren(removeAndShrinkArray(this.children, child));
+		if (this.children != null) {
+			this.children.remove(child);
 		}
 	}
+
 	public void setChildren(IModelElement[] children) {
-		this.children = children;
+		if (children == null) {
+			this.children = null;
+		} else {
+			this.children = new ArrayList(children.length);
+			for (int i = 0; i < children.length; i++) {
+				this.children.add(children[i]);
+			}
+		}
 	}
-	
+
 }
Index: model/org/eclipse/dltk/internal/core/SourceTypeElementInfo.java
===================================================================
RCS file: /cvsroot/technology/org.eclipse.dltk/core/plugins/org.eclipse.dltk.core/model/org/eclipse/dltk/internal/core/SourceTypeElementInfo.java,v
retrieving revision 1.3
diff -u -r1.3 SourceTypeElementInfo.java
--- model/org/eclipse/dltk/internal/core/SourceTypeElementInfo.java	2 May 2007 15:05:00 -0000	1.3
+++ model/org/eclipse/dltk/internal/core/SourceTypeElementInfo.java	30 May 2008 15:48:17 -0000
@@ -9,7 +9,6 @@
  *******************************************************************************/
 package org.eclipse.dltk.internal.core;
 
-
 import org.eclipse.dltk.compiler.env.ISourceField;
 import org.eclipse.dltk.compiler.env.ISourceMethod;
 import org.eclipse.dltk.compiler.env.ISourceType;
@@ -17,7 +16,8 @@
 import org.eclipse.dltk.core.IType;
 import org.eclipse.dltk.core.ModelException;
 
-public class SourceTypeElementInfo extends MemberElementInfo implements ISourceType {
+public class SourceTypeElementInfo extends MemberElementInfo implements
+		ISourceType {
 
 	protected static final SourceField[] NO_FIELDS = new SourceField[0];
 
@@ -121,13 +121,13 @@
 	}
 
 	public SourceField[] getFieldHandles() {
-		int length = this.children.length;
+		int length = size();
 		if (length == 0)
 			return NO_FIELDS;
 		SourceField[] fields = new SourceField[length];
 		int fieldIndex = 0;
 		for (int i = 0; i < length; i++) {
-			IModelElement child = this.children[i];
+			IModelElement child = get(i);
 			if (child instanceof SourceField)
 				fields[fieldIndex++] = (SourceField) child;
 		}
@@ -138,6 +138,7 @@
 					0, fieldIndex);
 		return fields;
 	}
+
 	public IType getHandle() {
 		return this.handle;
 	}
Index: model/org/eclipse/dltk/internal/core/ModelElement.java
===================================================================
RCS file: /cvsroot/technology/org.eclipse.dltk/core/plugins/org.eclipse.dltk.core/model/org/eclipse/dltk/internal/core/ModelElement.java,v
retrieving revision 1.9
diff -u -r1.9 ModelElement.java
--- model/org/eclipse/dltk/internal/core/ModelElement.java	6 May 2008 06:25:43 -0000	1.9
+++ model/org/eclipse/dltk/internal/core/ModelElement.java	30 May 2008 15:48:17 -0000
@@ -12,6 +12,7 @@
 import java.util.ArrayList;
 import java.util.HashMap;
 
+import org.eclipse.core.resources.IProject;
 import org.eclipse.core.runtime.Assert;
 import org.eclipse.core.runtime.IAdaptable;
 import org.eclipse.core.runtime.IProgressMonitor;
@@ -262,14 +263,8 @@
 
 		if (this == o)
 			return true;
-
-		IEnvironment environment = EnvironmentManager.getEnvironment(this);
-		if (o instanceof IModelElement && environment != null) {
-			IEnvironment environmento = EnvironmentManager
-					.getEnvironment((IModelElement) o);
-			if (!environment.equals(environmento)) {
-				return false;
-			}
+		if (!compareEnvironment(this, (IModelElement)o)) {
+			return false;
 		}
 
 		// model parent is null
@@ -281,6 +276,40 @@
 		return getElementName().equals(other.getElementName())
 				&& this.parent.equals(other.parent);
 	}
+	
+	private static boolean compareEnvironment(IModelElement a, IModelElement b) {
+		final IScriptProject spA = a.getScriptProject();
+		if (spA == null) {
+			return false;
+		}
+		final IScriptProject spB = b.getScriptProject();
+		if (spB == null) {
+			return false;
+		}
+		if (spA == spB) {
+			return true;
+		}
+		final IProject pA = spA.getProject();
+		if (pA == null) {
+			return false;
+		}
+		final IProject pB = spB.getProject();
+		if (pB == null) {
+			return false;
+		}
+		if (pA == pB) {
+			return true;
+		}
+		final IEnvironment eA = EnvironmentManager.getEnvironment(pA);
+		if (eA == null) {
+			return false;
+		}
+		final IEnvironment eB = EnvironmentManager.getEnvironment(pB);
+		if (eB == null) {
+			return false;
+		}
+		return eA.equals(eB);
+	}
 
 	/**
 	 * Returns the hash code for this model element. By default, the hash code
Index: model/org/eclipse/dltk/internal/core/ModelCache.java
===================================================================
RCS file: /cvsroot/technology/org.eclipse.dltk/core/plugins/org.eclipse.dltk.core/model/org/eclipse/dltk/internal/core/ModelCache.java,v
retrieving revision 1.3
diff -u -r1.3 ModelCache.java
--- model/org/eclipse/dltk/internal/core/ModelCache.java	12 Mar 2008 11:06:00 -0000	1.3
+++ model/org/eclipse/dltk/internal/core/ModelCache.java	30 May 2008 15:48:17 -0000
@@ -16,7 +16,6 @@
 import org.eclipse.dltk.core.DLTKCore;
 import org.eclipse.dltk.core.IModelElement;
 
-
 /**
  * The cache ofscriptelements to their respective info.
  */
@@ -91,7 +90,8 @@
 		// processing)
 		this.rootCache = new ElementCache((int) (DEFAULT_ROOT_SIZE * ratio));
 		this.pkgCache = new ElementCache((int) (DEFAULT_PKG_SIZE * ratio));
-		this.openableCache = new ElementCache((int) (DEFAULT_OPENABLE_SIZE * ratio));
+		this.openableCache = new ElementCache(
+				(int) (DEFAULT_OPENABLE_SIZE * ratio));
 		this.childrenCache = new HashMap((int) (DEFAULT_CHILDREN_SIZE * ratio));
 	}
 
@@ -100,19 +100,19 @@
 	 */
 	public Object getInfo(IModelElement element) {
 		switch (element.getElementType()) {
-			case IModelElement.SCRIPT_MODEL:
-				return this.modelInfo;
-			case IModelElement.SCRIPT_PROJECT:
-				return this.projectCache.get(element);
-			case IModelElement.PROJECT_FRAGMENT:
-				return this.rootCache.get(element);
-			case IModelElement.SCRIPT_FOLDER:
-				return this.pkgCache.get(element);
-			case IModelElement.SOURCE_MODULE:
-			case IModelElement.BINARY_MODULE:
-				return this.openableCache.get(element);
-			default:
-				return this.childrenCache.get(element);
+		case IModelElement.SCRIPT_MODEL:
+			return this.modelInfo;
+		case IModelElement.SCRIPT_PROJECT:
+			return this.projectCache.get(element);
+		case IModelElement.PROJECT_FRAGMENT:
+			return this.rootCache.get(element);
+		case IModelElement.SCRIPT_FOLDER:
+			return this.pkgCache.get(element);
+		case IModelElement.SOURCE_MODULE:
+		case IModelElement.BINARY_MODULE:
+			return this.openableCache.get(element);
+		default:
+			return this.childrenCache.get(element);
 		}
 	}
 
@@ -121,19 +121,19 @@
 	 */
 	protected Object peekAtInfo(IModelElement element) {
 		switch (element.getElementType()) {
-			case IModelElement.SCRIPT_MODEL:
-				return this.modelInfo;
-			case IModelElement.SCRIPT_PROJECT:
-				return this.projectCache.get(element);
-			case IModelElement.PROJECT_FRAGMENT:
-				return this.rootCache.peek(element);
-			case IModelElement.SCRIPT_FOLDER:
-				return this.pkgCache.peek(element);
-			case IModelElement.SOURCE_MODULE:
-			case IModelElement.BINARY_MODULE:
-				return this.openableCache.peek(element);
-			default:
-				return this.childrenCache.get(element);
+		case IModelElement.SCRIPT_MODEL:
+			return this.modelInfo;
+		case IModelElement.SCRIPT_PROJECT:
+			return this.projectCache.get(element);
+		case IModelElement.PROJECT_FRAGMENT:
+			return this.rootCache.peek(element);
+		case IModelElement.SCRIPT_FOLDER:
+			return this.pkgCache.peek(element);
+		case IModelElement.SOURCE_MODULE:
+		case IModelElement.BINARY_MODULE:
+			return this.openableCache.peek(element);
+		default:
+			return this.childrenCache.get(element);
 		}
 	}
 
@@ -142,27 +142,30 @@
 	 */
 	protected void putInfo(IModelElement element, Object info) {
 		switch (element.getElementType()) {
-			case IModelElement.SCRIPT_MODEL:
-				this.modelInfo = (ModelInfo) info;
-				break;
-			case IModelElement.SCRIPT_PROJECT:
-				this.projectCache.put(element, info);
-				this.rootCache.ensureSpaceLimit(((ModelElementInfo) info).children.length, element);
-				break;
-			case IModelElement.PROJECT_FRAGMENT:
-				this.rootCache.put(element, info);
-				this.pkgCache.ensureSpaceLimit(((ModelElementInfo) info).children.length, element);
-				break;
-			case IModelElement.SCRIPT_FOLDER:
-				this.pkgCache.put(element, info);
-				this.openableCache.ensureSpaceLimit(((ModelElementInfo) info).children.length, element);
-				break;
-			case IModelElement.SOURCE_MODULE:
-			case IModelElement.BINARY_MODULE:
-				this.openableCache.put(element, info);
-				break;
-			default:
-				this.childrenCache.put(element, info);
+		case IModelElement.SCRIPT_MODEL:
+			this.modelInfo = (ModelInfo) info;
+			break;
+		case IModelElement.SCRIPT_PROJECT:
+			this.projectCache.put(element, info);
+			this.rootCache.ensureSpaceLimit(((ModelElementInfo) info).size(),
+					element);
+			break;
+		case IModelElement.PROJECT_FRAGMENT:
+			this.rootCache.put(element, info);
+			this.pkgCache.ensureSpaceLimit(((ModelElementInfo) info).size(),
+					element);
+			break;
+		case IModelElement.SCRIPT_FOLDER:
+			this.pkgCache.put(element, info);
+			this.openableCache.ensureSpaceLimit(((ModelElementInfo) info)
+					.size(), element);
+			break;
+		case IModelElement.SOURCE_MODULE:
+		case IModelElement.BINARY_MODULE:
+			this.openableCache.put(element, info);
+			break;
+		default:
+			this.childrenCache.put(element, info);
 		}
 	}
 
@@ -171,27 +174,27 @@
 	 */
 	protected void removeInfo(IModelElement element) {
 		switch (element.getElementType()) {
-			case IModelElement.SCRIPT_MODEL:
-				this.modelInfo = null;
-				break;
-			case IModelElement.SCRIPT_PROJECT:
-				this.projectCache.remove(element);
-				this.rootCache.resetSpaceLimit(DEFAULT_ROOT_SIZE, element);
-				break;
-			case IModelElement.PROJECT_FRAGMENT:
-				this.rootCache.remove(element);
-				this.pkgCache.resetSpaceLimit(DEFAULT_PKG_SIZE, element);
-				break;
-			case IModelElement.SCRIPT_FOLDER:
-				this.pkgCache.remove(element);
-				this.openableCache.resetSpaceLimit(DEFAULT_OPENABLE_SIZE, element);
-				break;
-			case IModelElement.SOURCE_MODULE:
-			case IModelElement.BINARY_MODULE:
-				this.openableCache.remove(element);
-				break;
-			default:
-				this.childrenCache.remove(element);
+		case IModelElement.SCRIPT_MODEL:
+			this.modelInfo = null;
+			break;
+		case IModelElement.SCRIPT_PROJECT:
+			this.projectCache.remove(element);
+			this.rootCache.resetSpaceLimit(DEFAULT_ROOT_SIZE, element);
+			break;
+		case IModelElement.PROJECT_FRAGMENT:
+			this.rootCache.remove(element);
+			this.pkgCache.resetSpaceLimit(DEFAULT_PKG_SIZE, element);
+			break;
+		case IModelElement.SCRIPT_FOLDER:
+			this.pkgCache.remove(element);
+			this.openableCache.resetSpaceLimit(DEFAULT_OPENABLE_SIZE, element);
+			break;
+		case IModelElement.SOURCE_MODULE:
+		case IModelElement.BINARY_MODULE:
+			this.openableCache.remove(element);
+			break;
+		default:
+			this.childrenCache.remove(element);
 		}
 	}
 
@@ -205,19 +208,22 @@
 		buffer.append("Root cache["); //$NON-NLS-1$
 		buffer.append(this.rootCache.getSpaceLimit());
 		buffer.append("]: "); //$NON-NLS-1$
-		buffer.append(NumberFormat.getInstance().format(this.rootCache.fillingRatio()));
+		buffer.append(NumberFormat.getInstance().format(
+				this.rootCache.fillingRatio()));
 		buffer.append("%\n"); //$NON-NLS-1$
 		buffer.append(prefix);
 		buffer.append("Folder cache["); //$NON-NLS-1$
 		buffer.append(this.pkgCache.getSpaceLimit());
 		buffer.append("]: "); //$NON-NLS-1$
-		buffer.append(NumberFormat.getInstance().format(this.pkgCache.fillingRatio()));
+		buffer.append(NumberFormat.getInstance().format(
+				this.pkgCache.fillingRatio()));
 		buffer.append("%\n"); //$NON-NLS-1$
 		buffer.append(prefix);
 		buffer.append("Openable cache["); //$NON-NLS-1$
 		buffer.append(this.openableCache.getSpaceLimit());
 		buffer.append("]: "); //$NON-NLS-1$
-		buffer.append(NumberFormat.getInstance().format(this.openableCache.fillingRatio()));
+		buffer.append(NumberFormat.getInstance().format(
+				this.openableCache.fillingRatio()));
 		buffer.append("%\n"); //$NON-NLS-1$
 		return buffer.toString();
 	}
Index: model/org/eclipse/dltk/internal/core/ProjectElementInfo.java
===================================================================
RCS file: /cvsroot/technology/org.eclipse.dltk/core/plugins/org.eclipse.dltk.core/model/org/eclipse/dltk/internal/core/ProjectElementInfo.java,v
retrieving revision 1.4
diff -u -r1.4 ProjectElementInfo.java
--- model/org/eclipse/dltk/internal/core/ProjectElementInfo.java	12 Mar 2008 11:06:00 -0000	1.4
+++ model/org/eclipse/dltk/internal/core/ProjectElementInfo.java	30 May 2008 15:48:17 -0000
@@ -25,84 +25,87 @@
 import org.eclipse.dltk.internal.core.util.HashtableOfArrayToObject;
 import org.eclipse.dltk.internal.core.util.Util;
 
-
-
 class ProjectElementInfo extends OpenableElementInfo {
 
 	static class ProjectCache {
-		ProjectCache(IProjectFragment[] allProjectFragmentCache, HashtableOfArrayToObject allPkgFragmentsCache, HashtableOfArrayToObject isPackageCache, Map rootToResolvedEntries) {
+		ProjectCache(IProjectFragment[] allProjectFragmentCache,
+				HashtableOfArrayToObject allPkgFragmentsCache,
+				HashtableOfArrayToObject isPackageCache,
+				Map rootToResolvedEntries) {
 			this.allProjectFragmentCache = allProjectFragmentCache;
 			this.allPkgFragmentsCache = allPkgFragmentsCache;
 			this.rootToResolvedEntries = rootToResolvedEntries;
 			this.isPackageCache = isPackageCache;
 		}
-		
+
 		/*
 		 * A cache of all project fragments of this project.
 		 */
 		public IProjectFragment[] allProjectFragmentCache;
-		
+
 		/*
 		 * A cache of all package fragments in this project. (a map from
 		 * String[] (the package name) to IProjectFragment[] (the package
 		 * fragment roots that contain a package fragment with this name)
 		 */
 		public HashtableOfArrayToObject allPkgFragmentsCache;
-		
+
 		/*
 		 * A set of package names (String[]) that are known to be packages.
 		 */
 		public HashtableOfArrayToObject isPackageCache;
-	
-		public Map rootToResolvedEntries;		
+
+		public Map rootToResolvedEntries;
 	}
-	
+
 	ProjectCache projectCache;
-	
+
 	/**
 	 * A array with all the non-script resources contained by this Project
 	 * fragment
 	 */
-	private Object[] foreignResources;	
-	
+	private Object[] foreignResources;
+
 	/*
 	 * Reset the package fragment roots and package fragment caches
 	 */
 	void resetCaches() {
 		this.projectCache = null;
 	}
-	
+
 	void setForeignResources(Object[] resources) {
 
 		this.foreignResources = resources;
 	}
 
-	public Object[] getForeignResources(ScriptProject project) {		
-			if (this.foreignResources == null) {
-				this.foreignResources = computeForeignResources(project);
-			}
-			return this.foreignResources;
+	public Object[] getForeignResources(ScriptProject project) {
+		if (this.foreignResources == null) {
+			this.foreignResources = computeForeignResources(project);
 		}
+		return this.foreignResources;
+	}
 
 	private Object[] computeForeignResources(ScriptProject project) {
-		
+
 		// determine if src == project and/or if bin == project
 		IPath projectPath = project.getProject().getFullPath();
 		boolean srcIsProject = false;
 		char[][] inclusionPatterns = null;
 		char[][] exclusionPatterns = null;
-		IBuildpathEntry[] buildpath = null;		
+		IBuildpathEntry[] buildpath = null;
 		try {
 			buildpath = project.getResolvedBuildpath();
 			for (int i = 0; i < buildpath.length; i++) {
 				IBuildpathEntry entry = buildpath[i];
 				if (projectPath.equals(entry.getPath())) {
 					srcIsProject = true;
-					inclusionPatterns = ((BuildpathEntry)entry).fullInclusionPatternChars();
-					exclusionPatterns = ((BuildpathEntry)entry).fullExclusionPatternChars();
+					inclusionPatterns = ((BuildpathEntry) entry)
+							.fullInclusionPatternChars();
+					exclusionPatterns = ((BuildpathEntry) entry)
+							.fullExclusionPatternChars();
 					break;
 				}
-			}			
+			}
 		} catch (ModelException e) {
 			// ignore
 		}
@@ -110,65 +113,70 @@
 		Object[] resources = new IResource[5];
 		int resourcesCounter = 0;
 		try {
-			IResource[] members = ((IContainer) project.getResource()).members();
+			IResource[] members = ((IContainer) project.getResource())
+					.members();
 			for (int i = 0, max = members.length; i < max; i++) {
 				IResource res = members[i];
 				switch (res.getType()) {
-					case IResource.FILE :
-						IPath resFullPath = res.getFullPath();
-						String resName = res.getName();
-						
-						// ignore a archive file on the buildpath
-						if (org.eclipse.dltk.compiler.util.Util.isArchiveFileName(resName) && this.isBuildpathEntry(resFullPath, buildpath)) {
-							break;
-						}
-						// ignore source file if src == project
-						if (srcIsProject 
+				case IResource.FILE:
+					IPath resFullPath = res.getFullPath();
+					String resName = res.getName();
+
+					// ignore a archive file on the buildpath
+					if (org.eclipse.dltk.compiler.util.Util
+							.isArchiveFileName(resName)
+							&& this.isBuildpathEntry(resFullPath, buildpath)) {
+						break;
+					}
+					// ignore source file if src == project
+					if (srcIsProject
 							&& Util.isValidSourceModule(project, res)
-							&& !Util.isExcluded(res, inclusionPatterns, exclusionPatterns)) {
-							break;
-						}
-						//TODO: Add language dependent filters here.
-						// else add nonscriptresource
-						if (resources.length == resourcesCounter) {
-							// resize
-							System.arraycopy(
-								resources,
-								0,
-								(resources = new IResource[resourcesCounter * 2]),
-								0,
-								resourcesCounter);
-						}
-						resources[resourcesCounter++] = res;
+							&& !Util.isExcluded(res, inclusionPatterns,
+									exclusionPatterns)) {
 						break;
-					case IResource.FOLDER :
-						resFullPath = res.getFullPath();
-						
-						// ignore non-excluded folders on the buildpath or that correspond to an output location
-						if ((srcIsProject && !Util.isExcluded(res, inclusionPatterns, exclusionPatterns) && Util.isValidFolderNameForPackage(res.getName()))
-								|| this.isBuildpathEntry(resFullPath, buildpath)) {
-							break;
-						}
-						// else add nonscriptresource
-						if (resources.length == resourcesCounter) {
-							// resize
-							System.arraycopy(
-								resources,
-								0,
-								(resources = new IResource[resourcesCounter * 2]),
-								0,
-								resourcesCounter);
-						}
-						resources[resourcesCounter++] = res;
+					}
+					// TODO: Add language dependent filters here.
+					// else add nonscriptresource
+					if (resources.length == resourcesCounter) {
+						// resize
+						System
+								.arraycopy(
+										resources,
+										0,
+										(resources = new IResource[resourcesCounter * 2]),
+										0, resourcesCounter);
+					}
+					resources[resourcesCounter++] = res;
+					break;
+				case IResource.FOLDER:
+					resFullPath = res.getFullPath();
+
+					// ignore non-excluded folders on the buildpath or that
+					// correspond to an output location
+					if ((srcIsProject
+							&& !Util.isExcluded(res, inclusionPatterns,
+									exclusionPatterns) && Util
+							.isValidFolderNameForPackage(res.getName()))
+							|| this.isBuildpathEntry(resFullPath, buildpath)) {
+						break;
+					}
+					// else add nonscriptresource
+					if (resources.length == resourcesCounter) {
+						// resize
+						System
+								.arraycopy(
+										resources,
+										0,
+										(resources = new IResource[resourcesCounter * 2]),
+										0, resourcesCounter);
+					}
+					resources[resourcesCounter++] = res;
 				}
 			}
 			if (resources.length != resourcesCounter) {
-				System.arraycopy(
-					resources,
-					0,
-					(resources = new IResource[resourcesCounter]),
-					0,
-					resourcesCounter);
+				System.arraycopy(resources, 0,
+						(resources = new IResource[resourcesCounter]), 0,
+						resourcesCounter);
 			}
 		} catch (CoreException e) {
 			resources = NO_NON_SCRIPT_RESOURCES;
@@ -176,10 +184,13 @@
 		}
 		return resources;
 	}
+
 	/*
-	 * Returns whether the given path is a buildpath entry or an output location.
+	 * Returns whether the given path is a buildpath entry or an output
+	 * location.
 	 */
-	private boolean isBuildpathEntry(IPath path, IBuildpathEntry[] resolvedBuildpath) {		
+	private boolean isBuildpathEntry(IPath path,
+			IBuildpathEntry[] resolvedBuildpath) {
 		for (int i = 0, length = resolvedBuildpath.length; i < length; i++) {
 			IBuildpathEntry entry = resolvedBuildpath[i];
 			if (entry.getPath().equals(path)) {
@@ -188,29 +199,34 @@
 		}
 		return false;
 	}
-	
+
 	/*
-	 * Adds the given name and its super names to the given set
-	 * (e.g. for {"a", "b", "c"}, adds {"a", "b", "c"}, {"a", "b"}, and {"a"})
+	 * Adds the given name and its super names to the given set (e.g. for {"a",
+	 * "b", "c"}, adds {"a", "b", "c"}, {"a", "b"}, and {"a"})
 	 */
 	public static void addNames(String[] name, HashtableOfArrayToObject set) {
 		set.put(name, name);
 		int length = name.length;
-		for (int i = length-1; i > 0; i--) {
+		for (int i = length - 1; i > 0; i--) {
 			String[] superName = new String[i];
 			System.arraycopy(name, 0, superName, 0, i);
 			set.put(superName, superName);
 		}
 	}
+
 	/*
-	 * Creates a new name lookup for this project info. 
-	 * The given project is assumed to be the handle of this info.
-	 * This name lookup first looks in the given working copies.
+	 * Creates a new name lookup for this project info. The given project is
+	 * assumed to be the handle of this info. This name lookup first looks in
+	 * the given working copies.
 	 */
-	NameLookup newNameLookup(ScriptProject project, ISourceModule[] workingCopies) {
+	NameLookup newNameLookup(ScriptProject project,
+			ISourceModule[] workingCopies) {
 		ProjectCache cache = getProjectCache(project);
-		return new NameLookup(cache.allProjectFragmentCache, cache.allPkgFragmentsCache, cache.isPackageCache, workingCopies, cache.rootToResolvedEntries);
+		return new NameLookup(cache.allProjectFragmentCache,
+				cache.allPkgFragmentsCache, cache.isPackageCache,
+				workingCopies, cache.rootToResolvedEntries);
 	}
+
 	ProjectCache getProjectCache(ScriptProject project) {
 		ProjectCache cache = this.projectCache;
 		if (cache == null) {
@@ -219,7 +235,8 @@
 			try {
 				roots = project.getAllProjectFragments(reverseMap);
 			} catch (ModelException e) {
-				// project does not exist: cannot happen since this is the info of the project
+				// project does not exist: cannot happen since this is the info
+				// of the project
 				roots = new IProjectFragment[0];
 				reverseMap.clear();
 			}
@@ -229,42 +246,48 @@
 				IProjectFragment root = roots[i];
 				IModelElement[] frags = null;
 				try {
-					if(DLTKCore.DEBUG) {
-						System.err.println("TODO: Require to check for ExternalProjectFragment compatibility."); //$NON-NLS-1$
+					if (DLTKCore.DEBUG) {
+						System.err
+								.println("TODO: Require to check for ExternalProjectFragment compatibility."); //$NON-NLS-1$
 					}
 					if (root.isArchive() && !root.isOpen()) {
 						ArchiveProjectFragmentInfo info = new ArchiveProjectFragmentInfo();
-						((ArchiveProjectFragment) root).computeChildren(info, new HashMap());
-						frags = info.children;
-					} else 
+						((ArchiveProjectFragment) root).computeChildren(info,
+								new HashMap());
+						frags = info.getChildren();
+					} else
 						frags = root.getChildren();
 				} catch (ModelException e) {
 					// root doesn't exist: ignore
 					continue;
 				}
 				for (int j = 0, length2 = frags.length; j < length2; j++) {
-					ScriptFolder fragment= (ScriptFolder) frags[j];
+					ScriptFolder fragment = (ScriptFolder) frags[j];
 					String[] pkgName = fragment.path.segments();
 					Object existing = fragmentsCache.get(pkgName);
 					if (existing == null) {
 						fragmentsCache.put(pkgName, root);
-						// cache whether each package and its including packages (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=119161)
+						// cache whether each package and its including packages
+						// (see
+						// https://bugs.eclipse.org/bugs/show_bug.cgi?id=119161)
 						// are actual packages
 						addNames(pkgName, isPackageCache);
 					} else {
 						if (existing instanceof ProjectFragment) {
-							fragmentsCache.put(pkgName, new IProjectFragment[] {(ProjectFragment) existing, root});
+							fragmentsCache.put(pkgName, new IProjectFragment[] {
+									(ProjectFragment) existing, root });
 						} else {
-							IProjectFragment[] entry= (IProjectFragment[]) existing;
-							IProjectFragment[] copy= new IProjectFragment[entry.length + 1];
+							IProjectFragment[] entry = (IProjectFragment[]) existing;
+							IProjectFragment[] copy = new IProjectFragment[entry.length + 1];
 							System.arraycopy(entry, 0, copy, 0, entry.length);
-							copy[entry.length]= root;
+							copy[entry.length] = root;
 							fragmentsCache.put(pkgName, copy);
 						}
 					}
 				}
 			}
-			cache = new ProjectCache(roots, fragmentsCache, isPackageCache, reverseMap);
+			cache = new ProjectCache(roots, fragmentsCache, isPackageCache,
+					reverseMap);
 			this.projectCache = cache;
 		}
 		return cache;
Index: model/org/eclipse/dltk/internal/core/ScriptFolderInfo.java
===================================================================
RCS file: /cvsroot/technology/org.eclipse.dltk/core/plugins/org.eclipse.dltk.core/model/org/eclipse/dltk/internal/core/ScriptFolderInfo.java,v
retrieving revision 1.3
diff -u -r1.3 ScriptFolderInfo.java
--- model/org/eclipse/dltk/internal/core/ScriptFolderInfo.java	15 Jun 2007 08:34:55 -0000	1.3
+++ model/org/eclipse/dltk/internal/core/ScriptFolderInfo.java	30 May 2008 15:48:17 -0000
@@ -13,7 +13,6 @@
 import org.eclipse.core.resources.IResource;
 import org.eclipse.dltk.core.ModelException;
 
-
 public class ScriptFolderInfo extends OpenableElementInfo {
 	private Object[] foreignResources;
 
@@ -21,13 +20,20 @@
 		foreignResources = resources;
 	}
 
-	public Object[] getForeignResources(IResource resource, ProjectFragment projectFragment) {
+	public Object[] getForeignResources(IResource resource,
+			ProjectFragment projectFragment) {
 		if (this.foreignResources == null) {
 			try {
-				this.foreignResources = ProjectFragmentInfo.computeFolderForeignResources((ScriptProject) projectFragment.getScriptProject(),
-						(IContainer) resource, projectFragment.fullInclusionPatternChars(), projectFragment.fullExclusionPatternChars());
+				this.foreignResources = ProjectFragmentInfo
+						.computeFolderForeignResources(
+								(ScriptProject) projectFragment
+										.getScriptProject(),
+								(IContainer) resource, projectFragment
+										.fullInclusionPatternChars(),
+								projectFragment.fullExclusionPatternChars());
 			} catch (ModelException e) {
-				// root doesn't exist: consider package has no nonScriptResources
+				// root doesn't exist: consider package has no
+				// nonScriptResources
 				this.foreignResources = NO_NON_SCRIPT_RESOURCES;
 			}
 		}
@@ -35,6 +41,6 @@
 	}
 
 	boolean containsScriptResources() {
-		return this.children.length != 0;
+		return size() != 0;
 	}
 }

Back to the top