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 44628 Details for
Bug 122444
[hierarchy] Type hierarchy of inner member type misses anonymous subtypes
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
Proposed patch and regression test
122444.txt (text/plain), 13.11 KB, created by
Jerome Lanneluc
on 2006-06-16 07:10:35 EDT
(
hide
)
Description:
Proposed patch and regression test
Filename:
MIME Type:
Creator:
Jerome Lanneluc
Created:
2006-06-16 07:10:35 EDT
Size:
13.11 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.jdt.core >Index: model/org/eclipse/jdt/internal/compiler/ISourceElementRequestor.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/compiler/ISourceElementRequestor.java,v >retrieving revision 1.16 >diff -u -r1.16 ISourceElementRequestor.java >--- model/org/eclipse/jdt/internal/compiler/ISourceElementRequestor.java 29 Mar 2006 03:08:49 -0000 1.16 >+++ model/org/eclipse/jdt/internal/compiler/ISourceElementRequestor.java 16 Jun 2006 11:10:28 -0000 >@@ -50,6 +50,7 @@ > public long[] annotationPositions; > public char[][] categories; > public boolean secondary; >+ public boolean anonymousMember; > } > > public static class TypeParameterInfo { >Index: model/org/eclipse/jdt/internal/compiler/SourceElementParser.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/compiler/SourceElementParser.java,v >retrieving revision 1.69 >diff -u -r1.69 SourceElementParser.java >--- model/org/eclipse/jdt/internal/compiler/SourceElementParser.java 24 Apr 2006 10:06:17 -0000 1.69 >+++ model/org/eclipse/jdt/internal/compiler/SourceElementParser.java 16 Jun 2006 11:10:29 -0000 >@@ -1400,6 +1400,7 @@ > typeInfo.annotationPositions = collectAnnotationPositions(typeDeclaration.annotations); > typeInfo.categories = (char[][]) this.nodesToCategories.get(typeDeclaration); > typeInfo.secondary = typeDeclaration.isSecondary(); >+ typeInfo.anonymousMember = typeDeclaration.allocation != null && typeDeclaration.allocation.enclosingInstance != null; > requestor.enterType(typeInfo); > switch (kind) { > case TypeDeclaration.CLASS_DECL : >Index: model/org/eclipse/jdt/internal/compiler/parser/SourceTypeConverter.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/compiler/parser/SourceTypeConverter.java,v >retrieving revision 1.48 >diff -u -r1.48 SourceTypeConverter.java >--- model/org/eclipse/jdt/internal/compiler/parser/SourceTypeConverter.java 14 Jun 2006 16:44:26 -0000 1.48 >+++ model/org/eclipse/jdt/internal/compiler/parser/SourceTypeConverter.java 16 Jun 2006 11:10:29 -0000 >@@ -44,6 +44,15 @@ > import org.eclipse.jdt.internal.core.*; > > public class SourceTypeConverter { >+ >+ /* >+ * Exception thrown while converting an anonymous type of a member type >+ * in this case, we must parse the source as the enclosing instance cannot be recreated >+ * from the model >+ */ >+ static class AnonymousMemberFound extends RuntimeException { >+ private static final long serialVersionUID = 1L; >+ } > > public static final int FIELD = 0x01; > public static final int CONSTRUCTOR = 0x02; >@@ -138,19 +147,23 @@ > sourceImport.getModifiers()); > } > /* convert type(s) */ >- int typeCount = sourceTypes.length; >- final TypeDeclaration[] types = new TypeDeclaration[typeCount]; >- /* >- * We used a temporary types collection to prevent this.unit.types from being null during a call to >- * convert(...) when the source is syntactically incorrect and the parser is flushing the unit's types. >- * See https://bugs.eclipse.org/bugs/show_bug.cgi?id=97466 >- */ >- for (int i = 0; i < typeCount; i++) { >- SourceTypeElementInfo typeInfo = (SourceTypeElementInfo) sourceTypes[i]; >- types[i] = convert((SourceType) typeInfo.getHandle(), compilationResult); >+ try { >+ int typeCount = sourceTypes.length; >+ final TypeDeclaration[] types = new TypeDeclaration[typeCount]; >+ /* >+ * We used a temporary types collection to prevent this.unit.types from being null during a call to >+ * convert(...) when the source is syntactically incorrect and the parser is flushing the unit's types. >+ * See https://bugs.eclipse.org/bugs/show_bug.cgi?id=97466 >+ */ >+ for (int i = 0; i < typeCount; i++) { >+ SourceTypeElementInfo typeInfo = (SourceTypeElementInfo) sourceTypes[i]; >+ types[i] = convert((SourceType) typeInfo.getHandle(), compilationResult); >+ } >+ this.unit.types = types; >+ return this.unit; >+ } catch (AnonymousMemberFound e) { >+ return new Parser(this.problemReporter, true).parse(this.cu, compilationResult); > } >- this.unit.types = types; >- return this.unit; > } > > private void addIdentifiers(String typeSignature, int start, int endExclusive, int identCount, ArrayList fragments) { >@@ -422,6 +435,8 @@ > */ > private TypeDeclaration convert(SourceType typeHandle, CompilationResult compilationResult) throws JavaModelException { > SourceTypeElementInfo typeInfo = (SourceTypeElementInfo) typeHandle.getElementInfo(); >+ if (typeInfo.isAnonymousMember()) >+ throw new AnonymousMemberFound(); > /* create type declaration - can be member type */ > TypeDeclaration type = new TypeDeclaration(compilationResult); > if (typeInfo.getEnclosingType() == null) { >Index: model/org/eclipse/jdt/internal/core/SourceTypeElementInfo.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/SourceTypeElementInfo.java,v >retrieving revision 1.36 >diff -u -r1.36 SourceTypeElementInfo.java >--- model/org/eclipse/jdt/internal/core/SourceTypeElementInfo.java 10 May 2006 18:03:47 -0000 1.36 >+++ model/org/eclipse/jdt/internal/core/SourceTypeElementInfo.java 16 Jun 2006 11:10:29 -0000 >@@ -279,6 +279,12 @@ > public boolean isBinaryType() { > return false; > } >+/* >+ * Returns whether the source type is an anonymous type of a member type. >+ */ >+public boolean isAnonymousMember() { >+ return false; >+} > /** > * Sets the handle for this type info > */ >Index: model/org/eclipse/jdt/internal/core/CompilationUnitStructureRequestor.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/CompilationUnitStructureRequestor.java,v >retrieving revision 1.70 >diff -u -r1.70 CompilationUnitStructureRequestor.java >--- model/org/eclipse/jdt/internal/core/CompilationUnitStructureRequestor.java 6 Apr 2006 01:47:51 -0000 1.70 >+++ model/org/eclipse/jdt/internal/core/CompilationUnitStructureRequestor.java 16 Jun 2006 11:10:29 -0000 >@@ -357,7 +357,14 @@ > SourceType handle = new SourceType(parentHandle, nameString); //NB: occurenceCount is computed in resolveDuplicates > resolveDuplicates(handle); > >- SourceTypeElementInfo info = new SourceTypeElementInfo(); >+ SourceTypeElementInfo info = >+ typeInfo.anonymousMember ? >+ new SourceTypeElementInfo() { >+ public boolean isAnonymousMember() { >+ return true; >+ } >+ } : >+ new SourceTypeElementInfo(); > info.setHandle(handle); > info.setSourceRangeStart(typeInfo.declarationStart); > info.setFlags(typeInfo.modifiers); >#P org.eclipse.jdt.core.tests.model >Index: src/org/eclipse/jdt/core/tests/model/TypeHierarchyTests.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/TypeHierarchyTests.java,v >retrieving revision 1.60 >diff -u -r1.60 TypeHierarchyTests.java >--- src/org/eclipse/jdt/core/tests/model/TypeHierarchyTests.java 14 Jun 2006 16:44:12 -0000 1.60 >+++ src/org/eclipse/jdt/core/tests/model/TypeHierarchyTests.java 16 Jun 2006 11:10:32 -0000 >@@ -173,7 +173,7 @@ > /* > * Ensures that a hierarchy on an anonymous type in an initializer is correct. > */ >-public void testAnonymousType1() throws JavaModelException { >+public void testAnonymousType01() throws JavaModelException { > IType typeA = getCompilationUnit("TypeHierarchy", "src", "p7", "A.java").getType("A"); > IType type = typeA.getInitializer(1).getType("", 1); > ITypeHierarchy hierarchy = type.newTypeHierarchy(null); >@@ -188,7 +188,7 @@ > /* > * Ensures that a hierarchy on an anonymous type in a second initializer is correct. > */ >-public void testAnonymousType2() throws JavaModelException { >+public void testAnonymousType02() throws JavaModelException { > IType typeA = getCompilationUnit("TypeHierarchy", "src", "p7", "A.java").getType("A"); > IType type = typeA.getInitializer(2).getType("", 1); > ITypeHierarchy hierarchy = type.newTypeHierarchy(null); >@@ -203,7 +203,7 @@ > /* > * Ensures that a hierarchy on an anonymous type in a field declaration is correct. > */ >-public void testAnonymousType3() throws JavaModelException { >+public void testAnonymousType03() throws JavaModelException { > IType typeA = getCompilationUnit("TypeHierarchy", "src", "p7", "A.java").getType("A"); > IType type = typeA.getField("field1").getType("", 1); > ITypeHierarchy hierarchy = type.newTypeHierarchy(null); >@@ -218,7 +218,7 @@ > /* > * Ensures that a hierarchy on an anonymous type in a field declaration is correct. > */ >-public void testAnonymousType4() throws JavaModelException { >+public void testAnonymousType04() throws JavaModelException { > IType typeA = getCompilationUnit("TypeHierarchy", "src", "p7", "A.java").getType("A"); > IType type = typeA.getField("field2").getType("", 1); > ITypeHierarchy hierarchy = type.newTypeHierarchy(null); >@@ -242,7 +242,7 @@ > /* > * Ensures that a hierarchy on an anonymous type in a method declaration is correct. > */ >-public void testAnonymousType5() throws JavaModelException { >+public void testAnonymousType05() throws JavaModelException { > IType typeA = getCompilationUnit("TypeHierarchy", "src", "p7", "A.java").getType("A"); > IType type = typeA.getMethod("foo", new String[] {}).getType("", 1); > ITypeHierarchy hierarchy = type.newTypeHierarchy(null); >@@ -258,7 +258,7 @@ > * Ensures that a hierarchy on an anonymous type that uses a non-default constructor is correct. > * (regression test for bug 44506 Type hierarchy is missing anonymous type) > */ >-public void testAnonymousType6() throws JavaModelException { >+public void testAnonymousType06() throws JavaModelException { > IType typeA = getCompilationUnit("TypeHierarchy", "src", "p8", "X.java").getType("X"); > IType type = typeA.getMethod("foo", new String[] {}).getType("", 1); > ITypeHierarchy hierarchy = type.newTypeHierarchy(null); >@@ -274,7 +274,7 @@ > * Ensure that the key of an anonymous binary type in a hierarchy is correct. > * (regression test for bug 93826 ArrayIndexOutOfBoundsException when opening type hierarchy) > */ >-public void testAnonymousType7() throws CoreException { >+public void testAnonymousType07() throws CoreException { > IType type = getClassFile("TypeHierarchy","myLib.jar", "my.pkg", "X.class").getType(); > ITypeHierarchy hierarchy = type.newTypeHierarchy(null); > IType[] subtypes = hierarchy.getSubtypes(type); >@@ -284,7 +284,7 @@ > * Ensure that hierarchy on an enum also include the anonymous of its enum contants > * (regression test for bug 120667 [hierarchy] Type hierarchy for enum type does not include anonymous subtypes) > */ >-public void testAnonymousType8() throws CoreException { >+public void testAnonymousType08() throws CoreException { > IType type = getCompilationUnit("TypeHierarchy15/src/Try.java").getType("Try"); > ITypeHierarchy hierarchy = type.newTypeHierarchy(null); > assertHierarchyEquals( >@@ -302,7 +302,7 @@ > * Ensure that hierarchy on the anonymous type of an enum constant is correct > * (regression test for bug 120667 [hierarchy] Type hierarchy for enum type does not include anonymous subtypes) > */ >-public void testAnonymousType9() throws CoreException { >+public void testAnonymousType09() throws CoreException { > IType type = getCompilationUnit("TypeHierarchy15/src/Try.java").getType("Try").getField("ANONYMOUS").getType("", 1); > ITypeHierarchy hierarchy = type.newTypeHierarchy(null); > assertHierarchyEquals( >@@ -316,6 +316,23 @@ > "Sub types:\n", > hierarchy); > } >+/* >+ * Ensure that hierarchy on the anonymous type of a member type that is opened is correct >+ * (regression test for bug 122444 [hierarchy] Type hierarchy of inner member type misses anonymous subtypes) >+ */ >+public void testAnonymousType10() throws CoreException { >+ ICompilationUnit cu = getCompilationUnit("TypeHierarchy/src/q7/X.java"); >+ cu.open(null); >+ IType type = cu.getType("X").getType("Member"); >+ ITypeHierarchy hierarchy = type.newTypeHierarchy(null); >+ assertHierarchyEquals( >+ "Focus: Member [in X [in X.java [in q7 [in src [in TypeHierarchy]]]]]\n" + >+ "Super types:\n" + >+ " Object [in Object.class [in java.lang [in "+ getExternalJCLPathString() + "]]]\n" + >+ "Sub types:\n" + >+ " <anonymous #1> [in foo(X) [in Y [in X.java [in q7 [in src [in TypeHierarchy]]]]]]\n", >+ hierarchy); >+} > /** > * Ensures that the superclass can be retrieved for a binary inner type. > */ >Index: workspace/TypeHierarchy/src/q7/X.java >=================================================================== >RCS file: workspace/TypeHierarchy/src/q7/X.java >diff -N workspace/TypeHierarchy/src/q7/X.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ workspace/TypeHierarchy/src/q7/X.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,11 @@ >+package q7; >+public class X { >+ public class Member { >+ } >+} >+class Y { >+ void foo(X arg) { >+ arg.new Member() { >+ }; >+ } >+}
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 122444
: 44628