### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core.tests.model Index: src/org/eclipse/jdt/core/tests/model/HierarchyOnWorkingCopiesTests.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/HierarchyOnWorkingCopiesTests.java,v retrieving revision 1.18 diff -u -r1.18 HierarchyOnWorkingCopiesTests.java --- src/org/eclipse/jdt/core/tests/model/HierarchyOnWorkingCopiesTests.java 27 Jun 2008 16:02:38 -0000 1.18 +++ src/org/eclipse/jdt/core/tests/model/HierarchyOnWorkingCopiesTests.java 25 Nov 2008 10:40:53 -0000 @@ -10,12 +10,17 @@ *******************************************************************************/ package org.eclipse.jdt.core.tests.model; +import java.io.IOException; + +import junit.framework.Test; + import org.eclipse.core.resources.IFile; import org.eclipse.core.runtime.CoreException; +import org.eclipse.jdt.core.IClassFile; import org.eclipse.jdt.core.ICompilationUnit; import org.eclipse.jdt.core.IType; import org.eclipse.jdt.core.ITypeHierarchy; -import junit.framework.Test; +import org.eclipse.jdt.core.JavaCore; public class HierarchyOnWorkingCopiesTests extends WorkingCopyTests { @@ -104,5 +109,101 @@ } } } +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=228845 +//make sure uncommitted changes to primary working copy shows up in hierarchy +public void test228845() throws CoreException { + String newContents = + "package x.y;\n" + + "public class A extends B {\n" + + "}"; + + ICompilationUnit primaryCu = this.copy.getPrimary(); + primaryCu.becomeWorkingCopy(null); + + primaryCu.getBuffer().setContents(newContents); + primaryCu.reconcile(ICompilationUnit.NO_AST, false, null, null); + + IFile file = null; + try { + file = this.createFile( + "P/src/x/y/B.java", + "package x.y;\n" + + "public class B {\n" + + "}"); + + IType type = this.getCompilationUnit("P/src/x/y/B.java").getType("B"); + ITypeHierarchy h = type.newTypeHierarchy(null); // no working copies explicitly passed, should still honor primary working copies. + + assertHierarchyEquals( + "Focus: B [in B.java [in x.y [in src [in P]]]]\n" + + "Super types:\n" + + " Object [in Object.class [in java.lang [in "+ getExternalJCLPathString() + "]]]\n" + + "Sub types:\n" + + " A [in [Working copy] A.java [in x.y [in src [in P]]]]\n", + h); + } finally { + primaryCu.discardWorkingCopy(); + if (file != null) { + this.deleteResource(file); + } + } +} + +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=228845 +//make sure uncommitted changes to primary working copy shows up in hierarchy +//created out of a BinaryType. +public void test228845b() throws CoreException, IOException { + + addLibrary(getJavaProject("P"), "myLib.jar", "myLibsrc.zip", new String[] { + "my/pkg/X.java", + "package my.pkg;\n" + + "public class X {\n" + + "}", + "my/pkg/Y.java", + "package my.pkg;\n" + + "public class Y {\n" + + " }\n", + }, JavaCore.VERSION_1_4); + + + IFile file = null; + ICompilationUnit primaryCu = null; + + try { + file = this.createFile( + "P/src/Q.java", + "public class Q {} \n"); + + primaryCu = this.getCompilationUnit("P/src/Q.java").getWorkingCopy(null).getPrimary(); + primaryCu.becomeWorkingCopy(null); + + String newContents = + "public class Q extends my.pkg.X {\n" + + "}"; + + primaryCu.getBuffer().setContents(newContents); + primaryCu.reconcile(ICompilationUnit.NO_AST, false, null, null); + + IClassFile cf = getClassFile("P", "myLib.jar", "my.pkg", "X.class"); + IType typ = cf.getType(); + + ITypeHierarchy h = typ.newTypeHierarchy(null); + + assertHierarchyEquals( + "Focus: X [in X.class [in my.pkg [in myLib.jar [in P]]]]\n" + + "Super types:\n" + + " Object [in Object.class [in java.lang [in "+ getExternalJCLPathString() + "]]]\n" + + "Sub types:\n" + + " Q [in [Working copy] Q.java [in [in src [in P]]]]\n", + h); + } finally { + if (primaryCu != null) { + primaryCu.discardWorkingCopy(); + } + if (file!= null) { + this.deleteResource(file); + } + } +} } #P org.eclipse.jdt.core Index: model/org/eclipse/jdt/internal/core/SourceType.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/SourceType.java,v retrieving revision 1.146 diff -u -r1.146 SourceType.java --- model/org/eclipse/jdt/internal/core/SourceType.java 10 Oct 2008 07:28:57 -0000 1.146 +++ model/org/eclipse/jdt/internal/core/SourceType.java 25 Nov 2008 10:40:56 -0000 @@ -767,9 +767,9 @@ * @see IType */ public ITypeHierarchy newTypeHierarchy(IProgressMonitor monitor) throws JavaModelException { - CreateTypeHierarchyOperation op= new CreateTypeHierarchyOperation(this, null, SearchEngine.createWorkspaceScope(), true); - op.runOperation(monitor); - return op.getResult(); + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=228845, The new type hierarchy should consider changes in primary + // working copy. + return newTypeHierarchy(DefaultWorkingCopyOwner.PRIMARY, monitor); } /* * @see IType#newTypeHierarchy(ICompilationUnit[], IProgressMonitor) Index: model/org/eclipse/jdt/internal/core/BinaryType.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/BinaryType.java,v retrieving revision 1.161 diff -u -r1.161 BinaryType.java --- model/org/eclipse/jdt/internal/core/BinaryType.java 23 Oct 2008 13:56:41 -0000 1.161 +++ model/org/eclipse/jdt/internal/core/BinaryType.java 25 Nov 2008 10:40:56 -0000 @@ -870,7 +870,9 @@ * @deprecated */ public ITypeHierarchy newTypeHierarchy(IProgressMonitor monitor) throws JavaModelException { - return newTypeHierarchy((IWorkingCopy[])null, monitor); + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=228845, consider any + // changes that may exist on primary working copies. + return newTypeHierarchy(DefaultWorkingCopyOwner.PRIMARY, monitor); } /* * @see IType#newTypeHierarchy(ICompilationUnit[], IProgressMonitor)