Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 78664 Details for
Bug 190094
Java Outline Causes Eclipse Lock-up.
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
Proposed fix and performance test
190094_lazy_v6_with_no_private_tests.txt (text/plain), 60.84 KB, created by
Jerome Lanneluc
on 2007-09-18 12:26:54 EDT
(
hide
)
Description:
Proposed fix and performance test
Filename:
MIME Type:
Creator:
Jerome Lanneluc
Created:
2007-09-18 12:26:54 EDT
Size:
60.84 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.jdt.core.tests.model >Index: src/org/eclipse/jdt/core/tests/model/OverflowingCacheTests.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/OverflowingCacheTests.java,v >retrieving revision 1.12 >diff -u -r1.12 OverflowingCacheTests.java >--- src/org/eclipse/jdt/core/tests/model/OverflowingCacheTests.java 29 Mar 2006 04:03:08 -0000 1.12 >+++ src/org/eclipse/jdt/core/tests/model/OverflowingCacheTests.java 18 Sep 2007 16:23:15 -0000 >@@ -18,15 +18,10 @@ > import org.eclipse.core.runtime.CoreException; > import org.eclipse.core.runtime.IPath; > import org.eclipse.core.runtime.IProgressMonitor; >+import org.eclipse.core.runtime.IStatus; > import org.eclipse.core.runtime.Path; > import org.eclipse.jdt.core.*; >-import org.eclipse.jdt.core.IBuffer; >-import org.eclipse.jdt.core.IBufferChangedListener; >-import org.eclipse.jdt.core.IOpenable; > import org.eclipse.jdt.internal.core.*; >-import org.eclipse.jdt.internal.core.BufferCache; >-import org.eclipse.jdt.internal.core.Openable; >-import org.eclipse.jdt.internal.core.OverflowingLRUCache; > import org.eclipse.jdt.internal.core.util.MementoTokenizer; > > import junit.framework.Test; >@@ -265,6 +260,10 @@ > public void save(IProgressMonitor pm, boolean force) { > this.buffer.hasUnsavedChanges = false; > } >+ >+ protected IStatus validateExistence(IResource underlyingResource) { >+ return null; >+ } > } > > public static Test suite() { >Index: src/org/eclipse/jdt/core/tests/model/AttachedJavadocTests.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AttachedJavadocTests.java,v >retrieving revision 1.30 >diff -u -r1.30 AttachedJavadocTests.java >--- src/org/eclipse/jdt/core/tests/model/AttachedJavadocTests.java 20 Mar 2007 11:18:53 -0000 1.30 >+++ src/org/eclipse/jdt/core/tests/model/AttachedJavadocTests.java 18 Sep 2007 16:23:15 -0000 >@@ -116,7 +116,7 @@ > > // test javadoc for a package fragment > public void test001() throws JavaModelException { >- IPackageFragment packageFragment = this.root.getPackageFragment("p1/p2"); //$NON-NLS-1$ >+ IPackageFragment packageFragment = this.root.getPackageFragment("p1.p2"); //$NON-NLS-1$ > assertNotNull("Should not be null", packageFragment); //$NON-NLS-1$ > String javadoc = packageFragment.getAttachedJavadoc(new NullProgressMonitor()); //$NON-NLS-1$ > assertNotNull("Should have a javadoc", javadoc); //$NON-NLS-1$ >@@ -124,7 +124,7 @@ > > // for a class file > public void test002() throws JavaModelException { >- IPackageFragment packageFragment = this.root.getPackageFragment("p1/p2"); //$NON-NLS-1$ >+ IPackageFragment packageFragment = this.root.getPackageFragment("p1.p2"); //$NON-NLS-1$ > assertNotNull("Should not be null", packageFragment); //$NON-NLS-1$ > IClassFile classFile = packageFragment.getClassFile("X.class"); //$NON-NLS-1$ > assertNotNull(classFile); >@@ -134,7 +134,7 @@ > > // for a field > public void test003() throws JavaModelException { >- IPackageFragment packageFragment = this.root.getPackageFragment("p1/p2"); //$NON-NLS-1$ >+ IPackageFragment packageFragment = this.root.getPackageFragment("p1.p2"); //$NON-NLS-1$ > assertNotNull("Should not be null", packageFragment); //$NON-NLS-1$ > IClassFile classFile = packageFragment.getClassFile("X.class"); //$NON-NLS-1$ > assertNotNull(classFile); >@@ -147,7 +147,7 @@ > > // for a method > public void test004() throws JavaModelException { >- IPackageFragment packageFragment = this.root.getPackageFragment("p1/p2"); //$NON-NLS-1$ >+ IPackageFragment packageFragment = this.root.getPackageFragment("p1.p2"); //$NON-NLS-1$ > assertNotNull("Should not be null", packageFragment); //$NON-NLS-1$ > IClassFile classFile = packageFragment.getClassFile("X.class"); //$NON-NLS-1$ > assertNotNull(classFile); >@@ -166,7 +166,7 @@ > > // for a constructor > public void test005() throws JavaModelException { >- IPackageFragment packageFragment = this.root.getPackageFragment("p1/p2"); //$NON-NLS-1$ >+ IPackageFragment packageFragment = this.root.getPackageFragment("p1.p2"); //$NON-NLS-1$ > assertNotNull("Should not be null", packageFragment); //$NON-NLS-1$ > IClassFile classFile = packageFragment.getClassFile("X.class"); //$NON-NLS-1$ > assertNotNull(classFile); >@@ -183,7 +183,7 @@ > > // for a member type > public void test006() throws JavaModelException { >- IPackageFragment packageFragment = this.root.getPackageFragment("p1/p2"); //$NON-NLS-1$ >+ IPackageFragment packageFragment = this.root.getPackageFragment("p1.p2"); //$NON-NLS-1$ > assertNotNull("Should not be null", packageFragment); //$NON-NLS-1$ > IClassFile classFile = packageFragment.getClassFile("X$A.class"); //$NON-NLS-1$ > assertNotNull(classFile); >@@ -193,7 +193,7 @@ > > // for a constructor > public void test007() throws JavaModelException { >- IPackageFragment packageFragment = this.root.getPackageFragment("p1/p2"); //$NON-NLS-1$ >+ IPackageFragment packageFragment = this.root.getPackageFragment("p1.p2"); //$NON-NLS-1$ > assertNotNull("Should not be null", packageFragment); //$NON-NLS-1$ > IClassFile classFile = packageFragment.getClassFile("X$A.class"); //$NON-NLS-1$ > assertNotNull(classFile); >@@ -210,7 +210,7 @@ > > // for a method foo2 > public void test008() throws JavaModelException { >- IPackageFragment packageFragment = this.root.getPackageFragment("p1/p2"); //$NON-NLS-1$ >+ IPackageFragment packageFragment = this.root.getPackageFragment("p1.p2"); //$NON-NLS-1$ > assertNotNull("Should not be null", packageFragment); //$NON-NLS-1$ > IClassFile classFile = packageFragment.getClassFile("X.class"); //$NON-NLS-1$ > assertNotNull(classFile); >@@ -226,7 +226,7 @@ > > // for a field f2 > public void test009() throws JavaModelException { >- IPackageFragment packageFragment = this.root.getPackageFragment("p1/p2"); //$NON-NLS-1$ >+ IPackageFragment packageFragment = this.root.getPackageFragment("p1.p2"); //$NON-NLS-1$ > assertNotNull("Should not be null", packageFragment); //$NON-NLS-1$ > IClassFile classFile = packageFragment.getClassFile("X.class"); //$NON-NLS-1$ > assertNotNull(classFile); >@@ -267,7 +267,7 @@ > } > } > this.project.setRawClasspath(entries, null); >- IPackageFragment packageFragment = this.root.getPackageFragment("p1/p2"); //$NON-NLS-1$ >+ IPackageFragment packageFragment = this.root.getPackageFragment("p1.p2"); //$NON-NLS-1$ > assertNotNull("Should not be null", packageFragment); //$NON-NLS-1$ > IClassFile classFile = packageFragment.getClassFile("X.class"); //$NON-NLS-1$ > assertNotNull(classFile); >@@ -286,7 +286,7 @@ > > // https://bugs.eclipse.org/bugs/show_bug.cgi?id=120597 > public void test011() throws JavaModelException { >- IPackageFragment packageFragment = this.root.getPackageFragment("p1/p2"); //$NON-NLS-1$ >+ IPackageFragment packageFragment = this.root.getPackageFragment("p1.p2"); //$NON-NLS-1$ > assertNotNull("Should not be null", packageFragment); //$NON-NLS-1$ > IClassFile classFile = packageFragment.getClassFile("Z.class"); //$NON-NLS-1$ > assertNotNull(classFile); >@@ -299,7 +299,7 @@ > > // https://bugs.eclipse.org/bugs/show_bug.cgi?id=120637 > public void test012() throws JavaModelException { >- IPackageFragment packageFragment = this.root.getPackageFragment("p1/p2"); //$NON-NLS-1$ >+ IPackageFragment packageFragment = this.root.getPackageFragment("p1.p2"); //$NON-NLS-1$ > assertNotNull("Should not be null", packageFragment); //$NON-NLS-1$ > IClassFile classFile = packageFragment.getClassFile("Z.class"); //$NON-NLS-1$ > assertNotNull(classFile); >@@ -310,7 +310,7 @@ > > // https://bugs.eclipse.org/bugs/show_bug.cgi?id=120559 > public void test013() throws JavaModelException { >- IPackageFragment packageFragment = this.root.getPackageFragment("p1/p2"); //$NON-NLS-1$ >+ IPackageFragment packageFragment = this.root.getPackageFragment("p1.p2"); //$NON-NLS-1$ > assertNotNull("Should not be null", packageFragment); //$NON-NLS-1$ > IClassFile classFile = packageFragment.getClassFile("W.class"); //$NON-NLS-1$ > assertNotNull(classFile); >@@ -320,7 +320,7 @@ > > // https://bugs.eclipse.org/bugs/show_bug.cgi?id=120637 > public void test014() throws JavaModelException { >- IPackageFragment packageFragment = this.root.getPackageFragment("p1/p2"); //$NON-NLS-1$ >+ IPackageFragment packageFragment = this.root.getPackageFragment("p1.p2"); //$NON-NLS-1$ > assertNotNull("Should not be null", packageFragment); //$NON-NLS-1$ > IClassFile classFile = packageFragment.getClassFile("E.class"); //$NON-NLS-1$ > assertNotNull(classFile); >@@ -331,7 +331,7 @@ > > // https://bugs.eclipse.org/bugs/show_bug.cgi?id=120637 > public void test015() throws JavaModelException { >- IPackageFragment packageFragment = this.root.getPackageFragment("p1/p2"); //$NON-NLS-1$ >+ IPackageFragment packageFragment = this.root.getPackageFragment("p1.p2"); //$NON-NLS-1$ > assertNotNull("Should not be null", packageFragment); //$NON-NLS-1$ > IClassFile classFile = packageFragment.getClassFile("Annot.class"); //$NON-NLS-1$ > assertNotNull(classFile); >@@ -356,7 +356,7 @@ > } > } > this.project.setRawClasspath(entries, null); >- IPackageFragment packageFragment = this.root.getPackageFragment("p1/p2"); //$NON-NLS-1$ >+ IPackageFragment packageFragment = this.root.getPackageFragment("p1.p2"); //$NON-NLS-1$ > assertNotNull("Should not be null", packageFragment); //$NON-NLS-1$ > IClassFile classFile = packageFragment.getClassFile("X.class"); //$NON-NLS-1$ > assertNotNull(classFile); >@@ -378,7 +378,7 @@ > > // https://bugs.eclipse.org/bugs/show_bug.cgi?id=120875 > public void test017() throws JavaModelException { >- IPackageFragment packageFragment = this.root.getPackageFragment("p1/p2"); //$NON-NLS-1$ >+ IPackageFragment packageFragment = this.root.getPackageFragment("p1.p2"); //$NON-NLS-1$ > assertNotNull("Should not be null", packageFragment); //$NON-NLS-1$ > IClassFile classFile = packageFragment.getClassFile("Annot2.class"); //$NON-NLS-1$ > assertNotNull(classFile); >@@ -389,7 +389,7 @@ > > // https://bugs.eclipse.org/bugs/show_bug.cgi?id=138167 > public void test018() throws JavaModelException { >- IPackageFragment packageFragment = this.root.getPackageFragment("p1/p2/p3"); //$NON-NLS-1$ >+ IPackageFragment packageFragment = this.root.getPackageFragment("p1.p2.p3"); //$NON-NLS-1$ > assertNotNull("Should not be null", packageFragment); //$NON-NLS-1$ > IClassFile classFile = packageFragment.getClassFile("C.class"); //$NON-NLS-1$ > assertNotNull(classFile); >@@ -407,7 +407,7 @@ > > // https://bugs.eclipse.org/bugs/show_bug.cgi?id=138167 > public void test019() throws JavaModelException { >- IPackageFragment packageFragment = this.root.getPackageFragment("p1/p2/p3"); //$NON-NLS-1$ >+ IPackageFragment packageFragment = this.root.getPackageFragment("p1.p2.p3"); //$NON-NLS-1$ > assertNotNull("Should not be null", packageFragment); //$NON-NLS-1$ > IClassFile classFile = packageFragment.getClassFile("C.class"); //$NON-NLS-1$ > assertNotNull(classFile); >@@ -426,7 +426,7 @@ > > // https://bugs.eclipse.org/bugs/show_bug.cgi?id=139160 > public void test020() throws JavaModelException { >- IPackageFragment packageFragment = this.root.getPackageFragment("p1/p2"); //$NON-NLS-1$ >+ IPackageFragment packageFragment = this.root.getPackageFragment("p1.p2"); //$NON-NLS-1$ > assertNotNull("Should not be null", packageFragment); //$NON-NLS-1$ > IClassFile classFile = packageFragment.getClassFile("Z.class"); //$NON-NLS-1$ > assertNotNull(classFile); >@@ -484,7 +484,7 @@ > > // https://bugs.eclipse.org/bugs/show_bug.cgi?id=149154 > public void test022() throws JavaModelException { >- IPackageFragment packageFragment = this.root.getPackageFragment("p1/p2"); //$NON-NLS-1$ >+ IPackageFragment packageFragment = this.root.getPackageFragment("p1.p2"); //$NON-NLS-1$ > assertNotNull("Should not be null", packageFragment); //$NON-NLS-1$ > IClassFile classFile = packageFragment.getClassFile("X.class"); //$NON-NLS-1$ > assertNotNull(classFile); >#P org.eclipse.jdt.core >Index: model/org/eclipse/jdt/internal/core/ExternalJavaProject.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/ExternalJavaProject.java,v >retrieving revision 1.5 >diff -u -r1.5 ExternalJavaProject.java >--- model/org/eclipse/jdt/internal/core/ExternalJavaProject.java 27 Apr 2007 15:51:38 -0000 1.5 >+++ model/org/eclipse/jdt/internal/core/ExternalJavaProject.java 18 Sep 2007 16:23:17 -0000 >@@ -12,6 +12,7 @@ > > import org.eclipse.core.resources.IResource; > import org.eclipse.core.resources.ResourcesPlugin; >+import org.eclipse.core.runtime.IStatus; > import org.eclipse.jdt.core.IClasspathEntry; > import org.eclipse.jdt.core.IJavaElement; > import org.eclipse.jdt.core.JavaCore; >@@ -59,4 +60,8 @@ > return false; > } > >+ protected IStatus validateExistence(IResource underlyingResource) { >+ // allow opening of external project >+ return JavaModelStatus.VERIFIED_OK; >+ } > } >Index: model/org/eclipse/jdt/internal/core/JavaModel.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JavaModel.java,v >retrieving revision 1.90 >diff -u -r1.90 JavaModel.java >--- model/org/eclipse/jdt/internal/core/JavaModel.java 6 Apr 2006 01:47:51 -0000 1.90 >+++ model/org/eclipse/jdt/internal/core/JavaModel.java 18 Sep 2007 16:23:17 -0000 >@@ -25,6 +25,7 @@ > import org.eclipse.core.runtime.Assert; > import org.eclipse.core.runtime.IPath; > import org.eclipse.core.runtime.IProgressMonitor; >+import org.eclipse.core.runtime.IStatus; > import org.eclipse.core.runtime.Path; > import org.eclipse.jdt.core.*; > import org.eclipse.jdt.internal.core.util.MementoTokenizer; >@@ -377,4 +378,9 @@ > > return null; > } >+ >+protected IStatus validateExistence(IResource underlyingResource) { >+ // Java model always exists >+ return JavaModelStatus.VERIFIED_OK; >+} > } >Index: model/org/eclipse/jdt/internal/core/ClassFile.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/ClassFile.java,v >retrieving revision 1.135 >diff -u -r1.135 ClassFile.java >--- model/org/eclipse/jdt/internal/core/ClassFile.java 9 May 2007 18:53:13 -0000 1.135 >+++ model/org/eclipse/jdt/internal/core/ClassFile.java 18 Sep 2007 16:23:17 -0000 >@@ -79,11 +79,6 @@ > * @see Signature > */ > protected boolean buildStructure(OpenableElementInfo info, IProgressMonitor pm, Map newElements, IResource underlyingResource) throws JavaModelException { >- // check whether the class file can be opened >- IStatus status = validateClassFile(); >- if (!status.isOK()) throw newJavaModelException(status); >- if (underlyingResource != null && !underlyingResource.isAccessible()) throw newNotPresentException(); >- > IBinaryType typeInfo = getBinaryTypeInfo((IFile) underlyingResource); > if (typeInfo == null) { > // The structure of a class file is unknown if a class file format errors occurred >@@ -176,9 +171,6 @@ > ClassFile other = (ClassFile) o; > return this.name.equals(other.name) && this.parent.equals(other.parent); > } >-public boolean exists() { >- return super.exists() && validateClassFile().isOK(); >-} > public boolean existsUsingJarTypeCache() { > if (getPackageFragmentRoot().isArchive()) { > JavaModelManager manager = JavaModelManager.getJavaModelManager(); >@@ -793,4 +785,14 @@ > } > }); > } >+ >+protected IStatus validateExistence(IResource underlyingResource) { >+ // check whether the class file can be opened >+ IStatus status = validateClassFile(); >+ if (!status.isOK()) >+ return status; >+ if (underlyingResource != null && !underlyingResource.isAccessible()) >+ return newDoesNotExistStatus(); >+ return JavaModelStatus.VERIFIED_OK; >+} > } >Index: model/org/eclipse/jdt/internal/core/PackageFragment.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/PackageFragment.java,v >retrieving revision 1.80 >diff -u -r1.80 PackageFragment.java >--- model/org/eclipse/jdt/internal/core/PackageFragment.java 27 Aug 2007 08:50:55 -0000 1.80 >+++ model/org/eclipse/jdt/internal/core/PackageFragment.java 18 Sep 2007 16:23:19 -0000 >@@ -21,6 +21,7 @@ > import org.eclipse.core.runtime.CoreException; > import org.eclipse.core.runtime.IPath; > import org.eclipse.core.runtime.IProgressMonitor; >+import org.eclipse.core.runtime.IStatus; > import org.eclipse.core.runtime.OperationCanceledException; > import org.eclipse.core.runtime.Path; > import org.eclipse.jdt.core.IClassFile; >@@ -64,21 +65,9 @@ > * @see Openable > */ > protected boolean buildStructure(OpenableElementInfo info, IProgressMonitor pm, Map newElements, IResource underlyingResource) throws JavaModelException { >- >- // check whether this pkg can be opened >- if (!underlyingResource.isAccessible()) throw newNotPresentException(); >- >- // check that it is not excluded (https://bugs.eclipse.org/bugs/show_bug.cgi?id=138577) >- int kind = getKind(); >- if (kind == IPackageFragmentRoot.K_SOURCE && Util.isExcluded(this)) >- throw newNotPresentException(); >- >- // check that the name of the package is valid (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=108456) >- if (!isValidPackageName()) >- throw newNotPresentException(); >- > // add compilation units/class files from resources > HashSet vChildren = new HashSet(); >+ int kind = getKind(); > try { > PackageFragmentRoot root = getPackageFragmentRoot(); > char[][] inclusionPatterns = root.fullInclusionPatternChars(); >@@ -506,4 +495,26 @@ > } > return contents; > } >+ >+protected IStatus validateExistence(IResource underlyingResource) { >+ // check that the name of the package is valid (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=108456) >+ if (!isValidPackageName()) >+ return newDoesNotExistStatus(); >+ >+ // check whether this pkg can be opened >+ if (underlyingResource != null && !resourceExists(underlyingResource)) >+ return newDoesNotExistStatus(); >+ >+ // check that it is not excluded (https://bugs.eclipse.org/bugs/show_bug.cgi?id=138577) >+ int kind; >+ try { >+ kind = getKind(); >+ } catch (JavaModelException e) { >+ return e.getStatus(); >+ } >+ if (kind == IPackageFragmentRoot.K_SOURCE && Util.isExcluded(this)) >+ return newDoesNotExistStatus(); >+ >+ return JavaModelStatus.VERIFIED_OK; >+} > } >Index: model/org/eclipse/jdt/internal/core/Openable.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/Openable.java,v >retrieving revision 1.113 >diff -u -r1.113 Openable.java >--- model/org/eclipse/jdt/internal/core/Openable.java 10 May 2007 15:10:41 -0000 1.113 >+++ model/org/eclipse/jdt/internal/core/Openable.java 18 Sep 2007 16:23:19 -0000 >@@ -16,6 +16,7 @@ > > import org.eclipse.core.resources.*; > import org.eclipse.core.runtime.IProgressMonitor; >+import org.eclipse.core.runtime.IStatus; > import org.eclipse.core.runtime.OperationCanceledException; > import org.eclipse.core.runtime.PerformanceStats; > import org.eclipse.jdt.core.*; >@@ -173,15 +174,18 @@ > * @see IJavaElement > */ > public boolean exists() { >- JavaModelManager manager = JavaModelManager.getJavaModelManager(); >- if (manager.getInfo(this) != null) return true; >- if (!parentExists()) return false; >- PackageFragmentRoot root = getPackageFragmentRoot(); >- if (root != null >- && (root == this || !root.isArchive())) { >- return resourceExists(); >+ if (JavaModelManager.getJavaModelManager().getInfo(this) != null) >+ return true; >+ switch (getElementType()) { >+ case IJavaElement.PACKAGE_FRAGMENT: >+ case IJavaElement.CLASS_FILE: >+ if (getPackageFragmentRoot().isArchive()) { >+ // pkg or class file in a jar -> need to open it to know if it exists >+ return super.exists(); >+ } >+ break; > } >- return super.exists(); >+ return validateExistence(getResource()).isOK(); > } > public String findRecommendedLineSeparator() throws JavaModelException { > IBuffer buffer = getBuffer(); >@@ -214,8 +218,15 @@ > System.out.println(Thread.currentThread() +" OPENING " + element + " " + this.toStringWithAncestors()); //$NON-NLS-1$//$NON-NLS-2$ > } > >- // open the parent if necessary >- openParent(info, newElements, monitor); >+ // open its ancestors if needed >+ openAncestors(newElements, monitor); >+ >+ // validate existence >+ IResource underlResource = getResource(); >+ IStatus status = validateExistence(underlResource); >+ if (!status.isOK()) >+ throw newJavaModelException(status); >+ > if (monitor != null && monitor.isCanceled()) > throw new OperationCanceledException(); > >@@ -226,7 +237,7 @@ > // build the structure of the openable (this will open the buffer if needed) > try { > OpenableElementInfo openableElementInfo = (OpenableElementInfo)info; >- boolean isStructureKnown = buildStructure(openableElementInfo, monitor, newElements, getResource()); >+ boolean isStructureKnown = buildStructure(openableElementInfo, monitor, newElements, underlResource); > openableElementInfo.setIsStructureKnown(isStructureKnown); > } catch (JavaModelException e) { > newElements.remove(this); >@@ -414,38 +425,10 @@ > } > > /** >- * Open the parent element if necessary. >- */ >-protected void openParent(Object childInfo, HashMap newElements, IProgressMonitor pm) throws JavaModelException { >- >- Openable openableParent = (Openable)getOpenableParent(); >- if (openableParent != null && !openableParent.isOpen()){ >- openableParent.generateInfos(openableParent.createElementInfo(), newElements, pm); >- } >-} >- >-/** >- * Answers true if the parent exists (null parent is answering true) >- * >- */ >-protected boolean parentExists(){ >- >- IJavaElement parentElement = getParent(); >- if (parentElement == null) return true; >- return parentElement.exists(); >-} >- >-/** > * Returns whether the corresponding resource or associated file exists > */ >-protected boolean resourceExists() { >- IWorkspace workspace = ResourcesPlugin.getWorkspace(); >- if (workspace == null) return false; // workaround for http://bugs.eclipse.org/bugs/show_bug.cgi?id=34069 >- return >- JavaModel.getTarget( >- workspace.getRoot(), >- this.getPath().makeRelative(), // ensure path is relative (see http://dev.eclipse.org/bugs/show_bug.cgi?id=22517) >- true) != null; >+protected boolean resourceExists(IResource underlyingResource) { >+ return underlyingResource.isAccessible(); > } > > /** >@@ -469,4 +452,19 @@ > return (PackageFragmentRoot) getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT); > } > >+/* >+ * Validates the existence of this openable. Returns a non ok status if it doesn't exist. >+ */ >+abstract protected IStatus validateExistence(IResource underlyingResource); >+ >+/* >+ * Opens the ancestors of this openable that are not yet opened, validating their existence. >+ */ >+protected void openAncestors(HashMap newElements, IProgressMonitor monitor) throws JavaModelException { >+ Openable openableParent = (Openable)getOpenableParent(); >+ if (openableParent != null && !openableParent.isOpen()) { >+ openableParent.generateInfos(openableParent.createElementInfo(), newElements, monitor); >+ } >+} >+ > } >Index: model/org/eclipse/jdt/internal/core/JarPackageFragment.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JarPackageFragment.java,v >retrieving revision 1.36 >diff -u -r1.36 JarPackageFragment.java >--- model/org/eclipse/jdt/internal/core/JarPackageFragment.java 16 Mar 2007 18:28:58 -0000 1.36 >+++ model/org/eclipse/jdt/internal/core/JarPackageFragment.java 18 Sep 2007 16:23:17 -0000 >@@ -41,95 +41,103 @@ > super(root, names); > } > /** >+ * @see Openable >+ */ >+protected boolean buildStructure(OpenableElementInfo info, IProgressMonitor pm, Map newElements, IResource underlyingResource) throws JavaModelException { >+ JarPackageFragmentRoot root = (JarPackageFragmentRoot) getParent(); >+ JarPackageFragmentRootInfo parentInfo = (JarPackageFragmentRootInfo) root.getElementInfo(); >+ ArrayList[] entries = (ArrayList[]) parentInfo.rawPackageInfo.get(this.names); >+ if (entries == null) >+ throw newNotPresentException(); >+ JarPackageFragmentInfo fragInfo = (JarPackageFragmentInfo) info; >+ >+ // compute children >+ fragInfo.setChildren(computeChildren(entries[0/*class files*/])); >+ >+ // compute non-Java resources >+ fragInfo.setNonJavaResources(computeNonJavaResources(entries[1/*non Java resources*/])); >+ >+ newElements.put(this, fragInfo); >+ return true; >+} >+/** > * Compute the children of this package fragment. Children of jar package fragments > * can only be IClassFile (representing .class files). > */ >-protected boolean computeChildren(OpenableElementInfo info, ArrayList entryNames) { >- if (entryNames != null && entryNames.size() > 0) { >- ArrayList vChildren = new ArrayList(); >- for (Iterator iter = entryNames.iterator(); iter.hasNext();) { >- String child = (String) iter.next(); >- IClassFile classFile = getClassFile(child); >- vChildren.add(classFile); >- } >- IJavaElement[] children= new IJavaElement[vChildren.size()]; >- vChildren.toArray(children); >- info.setChildren(children); >- } else { >- info.setChildren(NO_ELEMENTS); >+private IJavaElement[] computeChildren(ArrayList namesWithoutExtension) { >+ int size = namesWithoutExtension.size(); >+ if (size == 0) >+ return NO_ELEMENTS; >+ IJavaElement[] children = new IJavaElement[size]; >+ for (int i = 0; i < size; i++) { >+ String nameWithoutExtension = (String) namesWithoutExtension.get(i); >+ children[i] = new ClassFile(this, nameWithoutExtension); > } >- return true; >+ return children; > } > /** >- * Compute all the non-java resources according to the entry name found in the jar file. >+ * Compute all the non-java resources according to the given entry names. > */ >-/* package */ void computeNonJavaResources(String[] resNames, JarPackageFragment pkg, JarPackageFragmentInfo info, String zipName) { >- if (resNames == null) { >- info.setNonJavaResources(null); >- return; >- } >- int max = resNames.length; >- if (max == 0) { >- info.setNonJavaResources(JavaElementInfo.NO_NON_JAVA_RESOURCES); >- } else { >- HashMap jarEntries = new HashMap(); // map from IPath to IJarEntryResource >- HashMap childrenMap = new HashMap(); // map from IPath to ArrayList<IJarEntryResource> >- ArrayList topJarEntries = new ArrayList(); >- for (int i = 0; i < max; i++) { >- String resName = resNames[i]; >- // consider that a .java file is not a non-java resource (see bug 12246 Packages view shows .class and .java files when JAR has source) >- if (!Util.isJavaLikeFileName(resName)) { >- IPath filePath = new Path(resName); >- IPath childPath = filePath.removeFirstSegments(this.names.length); >- JarEntryFile file = new JarEntryFile(filePath.lastSegment()); >- jarEntries.put(childPath, file); >- if (childPath.segmentCount() == 1) { >- file.setParent(pkg); >- topJarEntries.add(file); >- } else { >- IPath parentPath = childPath.removeLastSegments(1); >- while (parentPath.segmentCount() > 0) { >- ArrayList parentChildren = (ArrayList) childrenMap.get(parentPath); >- if (parentChildren == null) { >- Object dir = new JarEntryDirectory(parentPath.lastSegment()); >- jarEntries.put(parentPath, dir); >- childrenMap.put(parentPath, parentChildren = new ArrayList()); >- parentChildren.add(childPath); >- if (parentPath.segmentCount() == 1) { >- topJarEntries.add(dir); >- break; >- } >- childPath = parentPath; >- parentPath = childPath.removeLastSegments(1); >- } else { >- parentChildren.add(childPath); >- break; // all parents are already registered >+private Object[] computeNonJavaResources(ArrayList entryNames) { >+ int length = entryNames.size(); >+ if (length == 0) >+ return JavaElementInfo.NO_NON_JAVA_RESOURCES; >+ HashMap jarEntries = new HashMap(); // map from IPath to IJarEntryResource >+ HashMap childrenMap = new HashMap(); // map from IPath to ArrayList<IJarEntryResource> >+ ArrayList topJarEntries = new ArrayList(); >+ for (int i = 0; i < length; i++) { >+ String resName = (String) entryNames.get(i); >+ // consider that a .java file is not a non-java resource (see bug 12246 Packages view shows .class and .java files when JAR has source) >+ if (!Util.isJavaLikeFileName(resName)) { >+ IPath filePath = new Path(resName); >+ IPath childPath = filePath.removeFirstSegments(this.names.length); >+ JarEntryFile file = new JarEntryFile(filePath.lastSegment()); >+ jarEntries.put(childPath, file); >+ if (childPath.segmentCount() == 1) { >+ file.setParent(this); >+ topJarEntries.add(file); >+ } else { >+ IPath parentPath = childPath.removeLastSegments(1); >+ while (parentPath.segmentCount() > 0) { >+ ArrayList parentChildren = (ArrayList) childrenMap.get(parentPath); >+ if (parentChildren == null) { >+ Object dir = new JarEntryDirectory(parentPath.lastSegment()); >+ jarEntries.put(parentPath, dir); >+ childrenMap.put(parentPath, parentChildren = new ArrayList()); >+ parentChildren.add(childPath); >+ if (parentPath.segmentCount() == 1) { >+ topJarEntries.add(dir); >+ break; > } >+ childPath = parentPath; >+ parentPath = childPath.removeLastSegments(1); >+ } else { >+ parentChildren.add(childPath); >+ break; // all parents are already registered > } > } > } > } >- Iterator entries = childrenMap.entrySet().iterator(); >- while (entries.hasNext()) { >- Map.Entry entry = (Map.Entry) entries.next(); >- IPath entryPath = (IPath) entry.getKey(); >- ArrayList entryValue = (ArrayList) entry.getValue(); >- JarEntryDirectory jarEntryDirectory = (JarEntryDirectory) jarEntries.get(entryPath); >- int size = entryValue.size(); >- IJarEntryResource[] children = new IJarEntryResource[size]; >- for (int i = 0; i < size; i++) { >- JarEntryResource child = (JarEntryResource) jarEntries.get(entryValue.get(i)); >- child.setParent(jarEntryDirectory); >- children[i] = child; >- } >- jarEntryDirectory.setChildren(children); >- if (entryPath.segmentCount() == 1) { >- jarEntryDirectory.setParent(pkg); >- } >+ } >+ Iterator entries = childrenMap.entrySet().iterator(); >+ while (entries.hasNext()) { >+ Map.Entry entry = (Map.Entry) entries.next(); >+ IPath entryPath = (IPath) entry.getKey(); >+ ArrayList entryValue = (ArrayList) entry.getValue(); >+ JarEntryDirectory jarEntryDirectory = (JarEntryDirectory) jarEntries.get(entryPath); >+ int size = entryValue.size(); >+ IJarEntryResource[] children = new IJarEntryResource[size]; >+ for (int i = 0; i < size; i++) { >+ JarEntryResource child = (JarEntryResource) jarEntries.get(entryValue.get(i)); >+ child.setParent(jarEntryDirectory); >+ children[i] = child; >+ } >+ jarEntryDirectory.setChildren(children); >+ if (entryPath.segmentCount() == 1) { >+ jarEntryDirectory.setParent(this); > } >- Object[] res = topJarEntries.toArray(new Object[topJarEntries.size()]); >- info.setNonJavaResources(res); > } >+ return topJarEntries.toArray(new Object[topJarEntries.size()]); > } > /** > * Returns true if this fragment contains at least one java resource. >@@ -148,17 +156,7 @@ > * @see JavaElement > */ > protected Object createElementInfo() { >- return null; // not used for JarPackageFragments: info is created when jar is opened >-} >-/* >- * @see JavaElement#generateInfos >- */ >-protected void generateInfos(Object info, HashMap newElements, IProgressMonitor pm) throws JavaModelException { >- // Open my jar: this creates all the pkg infos >- Openable openableParent = (Openable)this.parent; >- if (!openableParent.isOpen()) { >- openableParent.generateInfos(openableParent.createElementInfo(), newElements, pm); >- } >+ return new JarPackageFragmentInfo(); > } > /** > * @see org.eclipse.jdt.core.IPackageFragment >Index: model/org/eclipse/jdt/internal/core/JavaElement.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JavaElement.java,v >retrieving revision 1.125 >diff -u -r1.125 JavaElement.java >--- model/org/eclipse/jdt/internal/core/JavaElement.java 27 Apr 2007 15:51:38 -0000 1.125 >+++ model/org/eclipse/jdt/internal/core/JavaElement.java 18 Sep 2007 16:23:17 -0000 >@@ -482,7 +482,10 @@ > * Creates and returns a new not present exception for this element. > */ > public JavaModelException newNotPresentException() { >- return new JavaModelException(new JavaModelStatus(IJavaModelStatusConstants.ELEMENT_DOES_NOT_EXIST, this)); >+ return new JavaModelException(newDoesNotExistStatus()); >+ } >+ protected JavaModelStatus newDoesNotExistStatus() { >+ return new JavaModelStatus(IJavaModelStatusConstants.ELEMENT_DOES_NOT_EXIST, this); > } > /** > * Creates and returns a new Java model exception for this element with the given status. >Index: model/org/eclipse/jdt/internal/core/PackageFragmentRoot.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/PackageFragmentRoot.java,v >retrieving revision 1.124 >diff -u -r1.124 PackageFragmentRoot.java >--- model/org/eclipse/jdt/internal/core/PackageFragmentRoot.java 26 Apr 2007 13:19:22 -0000 1.124 >+++ model/org/eclipse/jdt/internal/core/PackageFragmentRoot.java 18 Sep 2007 16:23:19 -0000 >@@ -152,12 +152,6 @@ > * @see Openable > */ > protected boolean buildStructure(OpenableElementInfo info, IProgressMonitor pm, Map newElements, IResource underlyingResource) throws JavaModelException { >- >- // check whether this pkg fragment root can be opened >- IStatus status = validateOnClasspath(); >- if (!status.isOK()) throw newJavaModelException(status); >- if (!resourceExists()) throw newNotPresentException(); >- > ((PackageFragmentRootInfo) info).setRootKind(determineKind(underlyingResource)); > return computeChildren(info, newElements); > } >@@ -334,13 +328,6 @@ > this.parent.equals(other.parent); > } > >-/** >- * @see IJavaElement >- */ >-public boolean exists() { >- return super.exists() && validateOnClasspath().isOK(); >-} >- > private IClasspathEntry findSourceAttachmentRecommendation() { > try { > IPath rootPath = this.getPath(); >@@ -792,6 +779,16 @@ > } > } > >+protected IStatus validateExistence(IResource underlyingResource) { >+ // check whether this pkg fragment root can be opened >+ IStatus status = validateOnClasspath(); >+ if (!status.isOK()) >+ return status; >+ if (!resourceExists(underlyingResource)) >+ return newDoesNotExistStatus(); >+ return JavaModelStatus.VERIFIED_OK; >+} >+ > /** > * Possible failures: <ul> > * <li>ELEMENT_NOT_PRESENT - the root supplied to the operation >Index: model/org/eclipse/jdt/internal/core/CompilationUnit.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/CompilationUnit.java,v >retrieving revision 1.241 >diff -u -r1.241 CompilationUnit.java >--- model/org/eclipse/jdt/internal/core/CompilationUnit.java 15 Mar 2007 16:06:40 -0000 1.241 >+++ model/org/eclipse/jdt/internal/core/CompilationUnit.java 18 Sep 2007 16:23:17 -0000 >@@ -76,18 +76,6 @@ > becomeWorkingCopy(requestor, monitor); > } > protected boolean buildStructure(OpenableElementInfo info, final IProgressMonitor pm, Map newElements, IResource underlyingResource) throws JavaModelException { >- >- // check if this compilation unit can be opened >- if (!isWorkingCopy()) { // no check is done on root kind or exclusion pattern for working copies >- IStatus status = validateCompilationUnit(underlyingResource); >- if (!status.isOK()) throw newJavaModelException(status); >- } >- >- // prevents reopening of non-primary working copies (they are closed when they are discarded and should not be reopened) >- if (!isPrimary() && getPerWorkingCopyInfo() == null) { >- throw newNotPresentException(); >- } >- > CompilationUnitElementInfo unitInfo = (CompilationUnitElementInfo) info; > > // get buffer contents >@@ -464,13 +452,6 @@ > CompilationUnit other = (CompilationUnit)obj; > return this.owner.equals(other.owner) && super.equals(obj); > } >-public boolean exists() { >- // working copy always exists in the model until it is gotten rid of (even if not on classpath) >- if (getPerWorkingCopyInfo() != null) return true; >- >- // if not a working copy, it exists only if it is a primary compilation unit >- return isPrimary() && validateCompilationUnit(getResource()).isOK(); >-} > /** > * @see ICompilationUnit#findElements(IJavaElement) > */ >@@ -1097,10 +1078,11 @@ > } > return buffer; > } >-protected void openParent(Object childInfo, HashMap newElements, IProgressMonitor pm) throws JavaModelException { >- if (!isWorkingCopy()) >- super.openParent(childInfo, newElements, pm); >- // don't open parent for a working copy to speed up the first becomeWorkingCopy >+protected void openAncestors(HashMap newElements, IProgressMonitor monitor) throws JavaModelException { >+ if (!isWorkingCopy()) { >+ super.openAncestors(newElements, monitor); >+ } >+ // else don't open ancestors for a working copy to speed up the first becomeWorkingCopy > // (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=89411) > } > /** >@@ -1249,4 +1231,20 @@ > ((CompilationUnitElementInfo) getElementInfo()).timestamp = timeStamp; > } > >+protected IStatus validateExistence(IResource underlyingResource) { >+ // check if this compilation unit can be opened >+ if (!isWorkingCopy()) { // no check is done on root kind or exclusion pattern for working copies >+ IStatus status = validateCompilationUnit(underlyingResource); >+ if (!status.isOK()) >+ return status; >+ } >+ >+ // prevents reopening of non-primary working copies (they are closed when they are discarded and should not be reopened) >+ if (!isPrimary() && getPerWorkingCopyInfo() == null) { >+ return newDoesNotExistStatus(); >+ } >+ >+ return JavaModelStatus.VERIFIED_OK; >+} >+ > } >Index: model/org/eclipse/jdt/internal/core/ElementCache.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/ElementCache.java,v >retrieving revision 1.13 >diff -u -r1.13 ElementCache.java >--- model/org/eclipse/jdt/internal/core/ElementCache.java 29 Mar 2006 03:08:47 -0000 1.13 >+++ model/org/eclipse/jdt/internal/core/ElementCache.java 18 Sep 2007 16:23:17 -0000 >@@ -46,14 +46,7 @@ > if (!element.canBeRemovedFromCache()) { > return false; > } else { >- // We must close an entire JarPackageFragmentRoot at once. >- if (element instanceof JarPackageFragment) { >- JarPackageFragment packageFragment= (JarPackageFragment) element; >- JarPackageFragmentRoot root = (JarPackageFragmentRoot) packageFragment.getParent(); >- root.close(); >- } else { >- element.close(); >- } >+ element.close(); > return true; > } > } catch (JavaModelException npe) { >@@ -62,11 +55,12 @@ > } > > /* >- * Ensures that there is enough room for adding the given number of children. >+ * Ensures that there is enough room for adding the children of the given info. > * If the space limit must be increased, record the parent that needed this space limit. > */ >-protected void ensureSpaceLimit(int childrenSize, IJavaElement parent) { >+protected void ensureSpaceLimit(Object info, IJavaElement parent) { > // ensure the children can be put without closing other elements >+ int childrenSize = ((JavaElementInfo) info).children.length; > int spaceNeeded = 1 + (int)((1 + fLoadFactor) * (childrenSize + fOverflow)); > if (fSpaceLimit < spaceNeeded) { > // parent is being opened with more children than the space limit >Index: model/org/eclipse/jdt/internal/core/JavaProject.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JavaProject.java,v >retrieving revision 1.390 >diff -u -r1.390 JavaProject.java >--- model/org/eclipse/jdt/internal/core/JavaProject.java 20 Aug 2007 14:59:54 -0000 1.390 >+++ model/org/eclipse/jdt/internal/core/JavaProject.java 18 Sep 2007 16:23:19 -0000 >@@ -385,12 +385,6 @@ > * @see Openable > */ > protected boolean buildStructure(OpenableElementInfo info, IProgressMonitor pm, Map newElements, IResource underlyingResource) throws JavaModelException { >- >- // check whether the java project can be opened >- if (!hasJavaNature((IProject) underlyingResource)) { >- throw newNotPresentException(); >- } >- > // cannot refresh cp markers on opening (emulate cp check on startup) since can create deadlocks (see bug 37274) > IClasspathEntry[] resolvedClasspath = getResolvedClasspath(); > >@@ -1008,15 +1002,6 @@ > return this.project.equals(other.getProject()); > } > >- public boolean exists() { >- try { >- return this.project.hasNature(JavaCore.NATURE_ID); >- } catch (CoreException e) { >- // project does not exist or is not open >- } >- return false; >- } >- > /** > * @see IJavaProject#findElement(IPath) > */ >@@ -2967,4 +2952,15 @@ > } > } > } >+ >+ protected IStatus validateExistence(IResource underlyingResource) { >+ // check whether the java project can be opened >+ try { >+ if (!((IProject) underlyingResource).hasNature(JavaCore.NATURE_ID)) >+ return newDoesNotExistStatus(); >+ } catch (CoreException e) { >+ return newDoesNotExistStatus(); >+ } >+ return JavaModelStatus.VERIFIED_OK; >+ } > } >Index: model/org/eclipse/jdt/internal/core/JavaModelCache.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JavaModelCache.java,v >retrieving revision 1.27 >diff -u -r1.27 JavaModelCache.java >--- model/org/eclipse/jdt/internal/core/JavaModelCache.java 29 Mar 2006 03:08:48 -0000 1.27 >+++ model/org/eclipse/jdt/internal/core/JavaModelCache.java 18 Sep 2007 16:23:17 -0000 >@@ -37,7 +37,7 @@ > /** > * Active Java Model Info > */ >- protected JavaModelInfo modelInfo; >+ protected Object modelInfo; > > /** > * Cache of open projects. >@@ -157,19 +157,19 @@ > protected void putInfo(IJavaElement element, Object info) { > switch (element.getElementType()) { > case IJavaElement.JAVA_MODEL: >- this.modelInfo = (JavaModelInfo) info; >+ this.modelInfo = info; > break; > case IJavaElement.JAVA_PROJECT: > this.projectCache.put(element, info); >- this.rootCache.ensureSpaceLimit(((JavaElementInfo) info).children.length, element); >+ this.rootCache.ensureSpaceLimit(info, element); > break; > case IJavaElement.PACKAGE_FRAGMENT_ROOT: > this.rootCache.put(element, info); >- this.pkgCache.ensureSpaceLimit(((JavaElementInfo) info).children.length, element); >+ this.pkgCache.ensureSpaceLimit(info, element); > break; > case IJavaElement.PACKAGE_FRAGMENT: > this.pkgCache.put(element, info); >- this.openableCache.ensureSpaceLimit(((JavaElementInfo) info).children.length, element); >+ this.openableCache.ensureSpaceLimit(info, element); > break; > case IJavaElement.COMPILATION_UNIT: > case IJavaElement.CLASS_FILE: >Index: model/org/eclipse/jdt/internal/core/JarPackageFragmentRootInfo.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JarPackageFragmentRootInfo.java,v >retrieving revision 1.10 >diff -u -r1.10 JarPackageFragmentRootInfo.java >--- model/org/eclipse/jdt/internal/core/JarPackageFragmentRootInfo.java 10 May 2006 18:03:48 -0000 1.10 >+++ model/org/eclipse/jdt/internal/core/JarPackageFragmentRootInfo.java 18 Sep 2007 16:23:17 -0000 >@@ -10,10 +10,14 @@ > *******************************************************************************/ > package org.eclipse.jdt.internal.core; > >+import org.eclipse.jdt.internal.core.util.HashtableOfArrayToObject; >+ > /** > * The element info for <code>JarPackageFragmentRoot</code>s. > */ > class JarPackageFragmentRootInfo extends PackageFragmentRootInfo { >+ // a map from package name (String[]) to a size-2 array of Array<String>, the first element being the .class file names, and the second element being the non-Java resource names >+ HashtableOfArrayToObject rawPackageInfo; > /** > * Returns an array of non-java resources contained in the receiver. > */ >Index: model/org/eclipse/jdt/internal/core/JavaModelManager.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JavaModelManager.java,v >retrieving revision 1.377 >diff -u -r1.377 JavaModelManager.java >--- model/org/eclipse/jdt/internal/core/JavaModelManager.java 28 Aug 2007 11:04:36 -0000 1.377 >+++ model/org/eclipse/jdt/internal/core/JavaModelManager.java 18 Sep 2007 16:23:18 -0000 >@@ -2942,39 +2942,28 @@ > /* > * Puts the infos in the given map (keys are IJavaElements and values are JavaElementInfos) > * in the Java model cache in an atomic way. >- * First checks that the info for the opened element (or one of its ancestors) has not been >- * added to the cache. If it is the case, another thread has opened the element (or one of >- * its ancestors). So returns without updating the cache. > */ > protected synchronized void putInfos(IJavaElement openedElement, Map newElements) { >- // remove children >+ // remove existing children as the are replaced with the new children contained in newElements > Object existingInfo = this.cache.peekAtInfo(openedElement); >- if (openedElement instanceof IParent && existingInfo instanceof JavaElementInfo) { >- IJavaElement[] children = ((JavaElementInfo)existingInfo).getChildren(); >- for (int i = 0, size = children.length; i < size; ++i) { >- JavaElement child = (JavaElement) children[i]; >- try { >- child.close(); >- } catch (JavaModelException e) { >- // ignore >- } >- } >+ if (openedElement instanceof IParent) { >+ closeChildren(existingInfo); > } > > // Need to put any JarPackageFragmentRoot in first. > // This is due to the way the LRU cache flushes entries. >- // When a JarPackageFragment is flused from the LRU cache, the entire >+ // When a JarPackageFragment is flushed from the LRU cache, the entire > // jar is flushed by removing the JarPackageFragmentRoot and all of its > // children (see ElementCache.close()). If we flush the JarPackageFragment > // when its JarPackageFragmentRoot is not in the cache and the root is about to be >- // added (during the 'while' loop), we will end up in an inconsist state. >+ // added (during the 'while' loop), we will end up in an inconsistent state. > // Subsequent resolution against package in the jar would fail as a result. > // https://bugs.eclipse.org/bugs/show_bug.cgi?id=102422 > // (theodora) > for(Iterator it = newElements.entrySet().iterator(); it.hasNext(); ) { > Map.Entry entry = (Map.Entry)it.next(); > IJavaElement element = (IJavaElement)entry.getKey(); >- if( element instanceof JarPackageFragmentRoot ){ >+ if (element instanceof JarPackageFragmentRoot) { > Object info = entry.getValue(); > it.remove(); > this.cache.putInfo(element, info); >@@ -2987,6 +2976,20 @@ > this.cache.putInfo((IJavaElement) entry.getKey(), entry.getValue()); > } > } >+ >+ private void closeChildren(Object info) { >+ if (info instanceof JavaElementInfo) { >+ IJavaElement[] children = ((JavaElementInfo)info).getChildren(); >+ for (int i = 0, size = children.length; i < size; ++i) { >+ JavaElement child = (JavaElement) children[i]; >+ try { >+ child.close(); >+ } catch (JavaModelException e) { >+ // ignore >+ } >+ } >+ } >+ } > > /* > * Remember the info for the jar binary type >@@ -3132,12 +3135,8 @@ > JavaModelCache.VERBOSE = false; > } > element.closing(info); >- if (element instanceof IParent && info instanceof JavaElementInfo) { >- IJavaElement[] children = ((JavaElementInfo)info).getChildren(); >- for (int i = 0, size = children.length; i < size; ++i) { >- JavaElement child = (JavaElement) children[i]; >- child.close(); >- } >+ if (element instanceof IParent) { >+ closeChildren(info); > } > this.cache.removeInfo(element); > if (wasVerbose) { >Index: model/org/eclipse/jdt/internal/core/JarPackageFragmentRoot.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JarPackageFragmentRoot.java,v >retrieving revision 1.66 >diff -u -r1.66 JarPackageFragmentRoot.java >--- model/org/eclipse/jdt/internal/core/JarPackageFragmentRoot.java 16 Mar 2007 18:28:58 -0000 1.66 >+++ model/org/eclipse/jdt/internal/core/JarPackageFragmentRoot.java 18 Sep 2007 16:23:17 -0000 >@@ -35,7 +35,7 @@ > */ > public class JarPackageFragmentRoot extends PackageFragmentRoot { > >- public final static ArrayList EMPTY_LIST = new ArrayList(); >+ private final static ArrayList EMPTY_LIST = new ArrayList(); > > /** > * The path to the jar file >@@ -69,44 +69,29 @@ > * Has the side effect of opening the package fragment children. > */ > protected boolean computeChildren(OpenableElementInfo info, Map newElements) throws JavaModelException { >- >- ArrayList vChildren= new ArrayList(); >- final int JAVA = 0; >- final int NON_JAVA = 1; >- ZipFile jar= null; >+ ArrayList children = new ArrayList(); >+ HashtableOfArrayToObject rawPackageInfo = new HashtableOfArrayToObject(); >+ ZipFile jar = null; > try { >- jar= getJar(); >- >- HashtableOfArrayToObject packageFragToTypes= new HashtableOfArrayToObject(); >- > // always create the default package >- packageFragToTypes.put(CharOperation.NO_STRINGS, new ArrayList[] { EMPTY_LIST, EMPTY_LIST }); >+ rawPackageInfo.put(CharOperation.NO_STRINGS, new ArrayList[] { EMPTY_LIST, EMPTY_LIST }); > >+ IJavaProject project = getJavaProject(); >+ String sourceLevel = project.getOption(JavaCore.COMPILER_SOURCE, true); >+ String compliance = project.getOption(JavaCore.COMPILER_COMPLIANCE, true); >+ jar = getJar(); > for (Enumeration e= jar.entries(); e.hasMoreElements();) { > ZipEntry member= (ZipEntry) e.nextElement(); >- initPackageFragToTypes(packageFragToTypes, member.getName(), member.isDirectory()); >+ initRawPackageInfo(rawPackageInfo, member.getName(), member.isDirectory(), sourceLevel, compliance); > } > > //loop through all of referenced packages, creating package fragments if necessary >- // and cache the entry names in the infos created for those package fragments >- for (int i = 0, length = packageFragToTypes.keyTable.length; i < length; i++) { >- String[] pkgName = (String[]) packageFragToTypes.keyTable[i]; >+ // and cache the entry names in the rawPackageInfo table >+ for (int i = 0, length = rawPackageInfo.keyTable.length; i < length; i++) { >+ String[] pkgName = (String[]) rawPackageInfo.keyTable[i]; > if (pkgName == null) continue; >- >- ArrayList[] entries= (ArrayList[]) packageFragToTypes.get(pkgName); > JarPackageFragment packFrag= (JarPackageFragment) getPackageFragment(pkgName); >- JarPackageFragmentInfo fragInfo= new JarPackageFragmentInfo(); >- int resLength= entries[NON_JAVA].size(); >- if (resLength == 0) { >- packFrag.computeNonJavaResources(CharOperation.NO_STRINGS, packFrag, fragInfo, jar.getName()); >- } else { >- String[] resNames= new String[resLength]; >- entries[NON_JAVA].toArray(resNames); >- packFrag.computeNonJavaResources(resNames, packFrag, fragInfo, jar.getName()); >- } >- packFrag.computeChildren(fragInfo, entries[JAVA]); >- newElements.put(packFrag, fragInfo); >- vChildren.add(packFrag); >+ children.add(packFrag); > } > } catch (CoreException e) { > if (e instanceof JavaModelException) throw (JavaModelException)e; >@@ -114,11 +99,10 @@ > } finally { > JavaModelManager.getJavaModelManager().closeZipFile(jar); > } >- >- >- IJavaElement[] children= new IJavaElement[vChildren.size()]; >- vChildren.toArray(children); >- info.setChildren(children); >+ >+ IJavaElement[] pkgs = (IJavaElement[]) children.toArray(new IJavaElement[children.size()]); >+ info.setChildren(pkgs); >+ ((JarPackageFragmentRootInfo) info).rawPackageInfo = rawPackageInfo; > return true; > } > /** >@@ -222,28 +206,27 @@ > public int hashCode() { > return this.jarPath.hashCode(); > } >- private void initPackageFragToTypes(HashtableOfArrayToObject packageFragToTypes, String entryName, boolean isDirectory) { >+ private void initRawPackageInfo(HashtableOfArrayToObject rawPackageInfo, String entryName, boolean isDirectory, String sourceLevel, String compliance) { > int lastSeparator = isDirectory ? entryName.length()-1 : entryName.lastIndexOf('/'); > String[] pkgName = Util.splitOn('/', entryName, 0, lastSeparator); > String[] existing = null; > int length = pkgName.length; > int existingLength = length; > while (existingLength >= 0) { >- existing = (String[]) packageFragToTypes.getKey(pkgName, existingLength); >+ existing = (String[]) rawPackageInfo.getKey(pkgName, existingLength); > if (existing != null) break; > existingLength--; > } > JavaModelManager manager = JavaModelManager.getJavaModelManager(); >- IJavaProject project = getJavaProject(); > for (int i = existingLength; i < length; i++) { >- if (Util.isValidFolderNameForPackage(pkgName[i], project.getOption(JavaCore.COMPILER_SOURCE, true), project.getOption(JavaCore.COMPILER_COMPLIANCE, true))) { >+ if (Util.isValidFolderNameForPackage(pkgName[i], sourceLevel, compliance)) { > System.arraycopy(existing, 0, existing = new String[i+1], 0, i); > existing[i] = manager.intern(pkgName[i]); >- packageFragToTypes.put(existing, new ArrayList[] { EMPTY_LIST, EMPTY_LIST }); >+ rawPackageInfo.put(existing, new ArrayList[] { EMPTY_LIST, EMPTY_LIST }); > } else { > // non-Java resource folder > if (!isDirectory) { >- ArrayList[] children = (ArrayList[]) packageFragToTypes.get(existing); >+ ArrayList[] children = (ArrayList[]) rawPackageInfo.get(existing); > if (children[1/*NON_JAVA*/] == EMPTY_LIST) children[1/*NON_JAVA*/] = new ArrayList(); > children[1/*NON_JAVA*/].add(entryName); > } >@@ -254,11 +237,11 @@ > return; > > // add classfile info amongst children >- ArrayList[] children = (ArrayList[]) packageFragToTypes.get(pkgName); >+ ArrayList[] children = (ArrayList[]) rawPackageInfo.get(pkgName); > if (org.eclipse.jdt.internal.compiler.util.Util.isClassFileName(entryName)) { > if (children[0/*JAVA*/] == EMPTY_LIST) children[0/*JAVA*/] = new ArrayList(); >- String fileName = entryName.substring(lastSeparator + 1); >- children[0/*JAVA*/].add(fileName); >+ String nameWithoutExtension = entryName.substring(lastSeparator + 1, entryName.length() - 6); >+ children[0/*JAVA*/].add(nameWithoutExtension); > } else { > if (children[1/*NON_JAVA*/] == EMPTY_LIST) children[1/*NON_JAVA*/] = new ArrayList(); > children[1/*NON_JAVA*/].add(entryName); >@@ -287,15 +270,15 @@ > /** > * Returns whether the corresponding resource or associated file exists > */ >-protected boolean resourceExists() { >- if (this.isExternal()) { >+protected boolean resourceExists(IResource underlyingResource) { >+ if (underlyingResource == null) { > return > JavaModel.getTarget( > ResourcesPlugin.getWorkspace().getRoot(), >- this.getPath(), // don't make the path relative as this is an external archive >+ getPath(), // don't make the path relative as this is an external archive > true) != null; > } else { >- return super.resourceExists(); >+ return super.resourceExists(underlyingResource); > } > } > protected void toStringAncestors(StringBuffer buffer) { >#P org.eclipse.jdt.core.tests.performance >Index: src/org/eclipse/jdt/core/tests/performance/FullSourceWorkspaceModelTests.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.performance/src/org/eclipse/jdt/core/tests/performance/FullSourceWorkspaceModelTests.java,v >retrieving revision 1.36 >diff -u -r1.36 FullSourceWorkspaceModelTests.java >--- src/org/eclipse/jdt/core/tests/performance/FullSourceWorkspaceModelTests.java 30 May 2007 14:59:46 -0000 1.36 >+++ src/org/eclipse/jdt/core/tests/performance/FullSourceWorkspaceModelTests.java 18 Sep 2007 16:23:21 -0000 >@@ -21,6 +21,7 @@ > import org.eclipse.core.resources.IFile; > import org.eclipse.core.resources.IProject; > import org.eclipse.core.resources.IProjectDescription; >+import org.eclipse.core.resources.IResource; > import org.eclipse.core.resources.IWorkspace; > import org.eclipse.core.resources.IWorkspaceRoot; > import org.eclipse.core.resources.ResourcesPlugin; >@@ -83,6 +84,7 @@ > protected void setUp() throws Exception { > super.setUp(); > setUpBigProject(); >+ setUpBigJars(); > } > private void setUpBigProject() throws CoreException, IOException { > try { >@@ -171,6 +173,36 @@ > } > > } >+private void setUpBigJars() throws Exception { >+ String bigProjectLocation = BIG_PROJECT.getResource().getLocation().toOSString(); >+ int size = PACKAGES_COUNT * 10; >+ File bigJar1 = new File(bigProjectLocation, BIG_JAR1_NAME); >+ if (!bigJar1.exists()) { >+ String[] pathAndContents = new String[size * 2]; >+ for (int i = 0; i < size; i++) { >+ pathAndContents[i*2] = "/p" + i + "/X" + i + ".java"; >+ pathAndContents[i*2 + 1] = >+ "package p" + i + ";\n" + >+ "public class X" + i + "{\n" + >+ "}"; >+ } >+ org.eclipse.jdt.core.tests.util.Util.createJar(pathAndContents, bigJar1.getPath(), "1.3"); >+ BIG_PROJECT.getProject().refreshLocal(IResource.DEPTH_INFINITE, null); >+ } >+ File bigJar2 = new File(bigProjectLocation, BIG_JAR2_NAME); >+ if (!bigJar2.exists()) { >+ String[] pathAndContents = new String[size * 2]; >+ for (int i = 0; i < size; i++) { >+ pathAndContents[i*2] = "/q" + i + "/Y" + i + ".java"; >+ pathAndContents[i*2 + 1] = >+ "package q" + i + ";\n" + >+ "public class Y" + i + "{\n" + >+ "}"; >+ } >+ org.eclipse.jdt.core.tests.util.Util.createJar(pathAndContents, bigJar2.getPath(), "1.3"); >+ BIG_PROJECT.getProject().refreshLocal(IResource.DEPTH_INFINITE, null); >+ } >+} > /* (non-Javadoc) > * @see junit.framework.TestCase#tearDown() > */ >@@ -742,6 +774,58 @@ > } > > /* >+ * Performance test for the opening of class files in 2 big jars (that each would fill the Java model cache if all pkgs were opened). >+ * (see bug 190094 Java Outline Causes Eclipse Lock-up.) >+ */ >+public void testPopulateTwoBigJars() throws CoreException { >+ >+ IJavaProject project = null; >+ try { >+ project = createJavaProject("HugeJarProject"); >+ IFile bigJar1 = BIG_PROJECT.getProject().getFile(BIG_JAR1_NAME); >+ IFile bigJar2 = BIG_PROJECT.getProject().getFile(BIG_JAR2_NAME); >+ project.setRawClasspath( >+ new IClasspathEntry[] { >+ JavaCore.newLibraryEntry(bigJar1.getFullPath(), null, null), >+ JavaCore.newLibraryEntry(bigJar2.getFullPath(), null, null), >+ }, null); >+ AbstractJavaModelTests.waitUntilIndexesReady(); >+ AbstractJavaModelTests.waitForAutoBuild(); >+ IPackageFragmentRoot root1 = project.getPackageFragmentRoot(bigJar1); >+ IPackageFragmentRoot root2 = project.getPackageFragmentRoot(bigJar2); >+ >+ // warm up >+ int max = 20; >+ int warmup = WARMUP_COUNT / 10; >+ for (int i = 0; i < warmup; i++) { >+ project.close(); >+ for (int j = 0; j < max; j++) { >+ root1.getPackageFragment("p" + j).open(null); >+ root2.getPackageFragment("q" + j).open(null); >+ } >+ } >+ >+ // measure performance >+ for (int i = 0; i < MEASURES_COUNT; i++) { >+ project.close(); >+ runGc(); >+ startMeasuring(); >+ for (int j = 0; j < max; j++) { >+ root1.getPackageFragment("p" + j).open(null); >+ root2.getPackageFragment("q" + j).open(null); >+ } >+ stopMeasuring(); >+ } >+ >+ commitMeasurements(); >+ assertPerformance(); >+ } finally { >+ if (project != null) >+ project.getProject().delete(false, null); >+ } >+} >+ >+/* > * Performance test for looking up package fragments > * (see bug 72683 Slow code assist in Display view) > */ >Index: src/org/eclipse/jdt/core/tests/performance/FullSourceWorkspaceTests.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.performance/src/org/eclipse/jdt/core/tests/performance/FullSourceWorkspaceTests.java,v >retrieving revision 1.46 >diff -u -r1.46 FullSourceWorkspaceTests.java >--- src/org/eclipse/jdt/core/tests/performance/FullSourceWorkspaceTests.java 28 Aug 2007 10:03:41 -0000 1.46 >+++ src/org/eclipse/jdt/core/tests/performance/FullSourceWorkspaceTests.java 18 Sep 2007 16:23:21 -0000 >@@ -99,6 +99,8 @@ > protected static ICompilationUnit PARSER_WORKING_COPY; > protected final static String BIG_PROJECT_NAME = "BigProject"; > protected static JavaProject BIG_PROJECT; >+ protected static final String BIG_JAR1_NAME = "big1.jar"; >+ protected static final String BIG_JAR2_NAME = "big2.jar"; > // protected final static String JUNIT_PROJECT_NAME = "junit"; > // protected static IJavaProject JUNIT_PROJECT; >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 190094
:
69660
|
69906
|
78664
|
78870