### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core.tests.model Index: src/org/eclipse/jdt/core/tests/model/AttachSourceTests.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AttachSourceTests.java,v retrieving revision 1.49 diff -u -r1.49 AttachSourceTests.java --- src/org/eclipse/jdt/core/tests/model/AttachSourceTests.java 8 Aug 2007 15:28:12 -0000 1.49 +++ src/org/eclipse/jdt/core/tests/model/AttachSourceTests.java 29 Nov 2007 15:49:19 -0000 @@ -493,7 +493,7 @@ IType type = this.innerClasses.getClassFile("X$1.class").getType(); assertSourceEquals( "Unexpected source", - "X() {}", + "new X() {}", type.getSource()); } /* @@ -503,7 +503,7 @@ IType type = this.innerClasses.getClassFile("X$2.class").getType(); assertSourceEquals( "Unexpected source", - "Y() {\n" + + "new Y() {\n" + " class Z {}\n" + " }", type.getSource()); @@ -515,7 +515,7 @@ IType type = this.innerClasses.getClassFile("X$3.class").getType(); assertSourceEquals( "Unexpected source", - "W() {}", + "new W() {}", type.getSource()); } /* Index: src/org/eclipse/jdt/core/tests/model/GetSourceTests.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/GetSourceTests.java,v retrieving revision 1.20 diff -u -r1.20 GetSourceTests.java --- src/org/eclipse/jdt/core/tests/model/GetSourceTests.java 16 Nov 2007 10:06:38 -0000 1.20 +++ src/org/eclipse/jdt/core/tests/model/GetSourceTests.java 29 Nov 2007 15:49:19 -0000 @@ -196,6 +196,30 @@ } /* + * Ensures that the source range for an anonymous type is correct. + * (regression test for https://bugs.eclipse.org/bugs/show_bug.cgi?id=207775) + */ + public void testAnonymousSourceRange() throws CoreException { + try { + String cuSource = + "package p;\n" + + "public class Y {\n" + + " void foo() {\n" + + " new Object() {};\n" + + " }\n" + + "}"; + createFile("/P/p/Y.java", cuSource); + IType type = getCompilationUnit("/P/p/Y.java").getType("Y").getMethod("foo", new String[0]).getType("", 1); + assertSourceEquals( + "Unexpected source'", + "new Object() {}", + getSource(cuSource, type.getSourceRange())); + } finally { + deleteFile("/P/p/Y.java"); + } + } + + /* * Ensures that the name range for an annotation is correct. */ public void testAnnotationNameRange1() throws CoreException { #P org.eclipse.jdt.core 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.79 diff -u -r1.79 SourceElementParser.java --- model/org/eclipse/jdt/internal/compiler/SourceElementParser.java 28 Nov 2007 08:02:28 -0000 1.79 +++ model/org/eclipse/jdt/internal/compiler/SourceElementParser.java 29 Nov 2007 15:49:20 -0000 @@ -1390,7 +1390,7 @@ superclassName = superclass != null ? CharOperation.concatWith(superclass.getParameterizedTypeName(), '.') : null; } ISourceElementRequestor.TypeInfo typeInfo = new ISourceElementRequestor.TypeInfo(); - typeInfo.declarationStart = typeDeclaration.declarationSourceStart; + typeInfo.declarationStart = typeDeclaration.allocation == null ? typeDeclaration.declarationSourceStart : typeDeclaration.allocation.sourceStart; typeInfo.modifiers = deprecated ? (currentModifiers & ExtraCompilerModifiers.AccJustFlag) | ClassFileConstants.AccDeprecated : currentModifiers & ExtraCompilerModifiers.AccJustFlag; typeInfo.name = typeDeclaration.name; typeInfo.nameSourceStart = typeDeclaration.sourceStart;