### 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 20 Sep 2007 10:50:36 -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 20 Sep 2007 10:50:36 -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.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 20 Sep 2007 10:50:37 -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 20 Sep 2007 10:50:37 -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; #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 20 Sep 2007 10:50:39 -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 20 Sep 2007 10:50:39 -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 20 Sep 2007 10:50:38 -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 20 Sep 2007 10:50:40 -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 20 Sep 2007 10:50:40 -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,30 @@ * @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: + PackageFragmentRoot root = getPackageFragmentRoot(); + if (root.isArchive()) { + // pkg in a jar -> need to open root to know if this pkg exists + JarPackageFragmentRootInfo rootInfo; + try { + rootInfo = (JarPackageFragmentRootInfo) root.getElementInfo(); + } catch (JavaModelException e) { + return false; + } + return rootInfo.rawPackageInfo.containsKey(((PackageFragment) this).names); + } + break; + case IJavaElement.CLASS_FILE: + if (getPackageFragmentRoot().isArchive()) { + // class file in a jar -> need to open this class file 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 +230,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 +249,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 +437,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 +464,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 20 Sep 2007 10:50:39 -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 - 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 + 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 20 Sep 2007 10:50:39 -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 20 Sep 2007 10:50:40 -0000 @@ -152,14 +152,8 @@ * @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); + return computeChildren(info); } SourceMapper createSourceMapper(IPath sourcePath, IPath rootPath) { @@ -187,7 +181,7 @@ * * @exception JavaModelException The resource associated with this package fragment root does not exist */ -protected boolean computeChildren(OpenableElementInfo info, Map newElements) throws JavaModelException { +protected boolean computeChildren(OpenableElementInfo info) throws JavaModelException { // Note the children are not opened (so not added to newElements) for a regular package fragment root // Howver they are opened for a Jar package fragment root (see JarPackageFragmentRoot#computeChildren) try { @@ -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: