### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core Index: dom/org/eclipse/jdt/core/dom/TypeBinding.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/TypeBinding.java,v retrieving revision 1.132.2.1 diff -u -r1.132.2.1 TypeBinding.java --- dom/org/eclipse/jdt/core/dom/TypeBinding.java 24 Aug 2007 02:13:58 -0000 1.132.2.1 +++ dom/org/eclipse/jdt/core/dom/TypeBinding.java 28 Nov 2007 14:20:40 -0000 @@ -554,7 +554,9 @@ // must use getElementAt(...) as there is no back pointer to the defining method (scope is null after resolution has ended) try { int sourceStart = ((LocalTypeBinding) referenceBinding).sourceStart; - return (JavaElement) cu.getElementAt(sourceStart); + IJavaElement element =cu.getElementAt(sourceStart); + // workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=208013 + return (JavaElement) element.getAncestor(IJavaElement.TYPE); } catch (JavaModelException e) { // does not exist return null; #P org.eclipse.jdt.core.tests.model Index: src/org/eclipse/jdt/core/tests/dom/ASTModelBridgeTests.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTModelBridgeTests.java,v retrieving revision 1.49.2.1 diff -u -r1.49.2.1 ASTModelBridgeTests.java --- src/org/eclipse/jdt/core/tests/dom/ASTModelBridgeTests.java 17 Oct 2007 15:53:14 -0000 1.49.2.1 +++ src/org/eclipse/jdt/core/tests/dom/ASTModelBridgeTests.java 28 Nov 2007 14:20:41 -0000 @@ -1225,6 +1225,35 @@ } /* + * Ensures that no ClassCastException is thrown if the method is in an anonymous + * which is inside the initializer of another anonymous. + * (regression test for https://bugs.eclipse.org/bugs/show_bug.cgi?id=208013) + */ + public void testMethod11() throws JavaModelException { + ASTNode node = buildAST( + "public class X {\n" + + " public void foo() {\n" + + " new Object() {\n" + + " Object o;\n" + + " {\n"+ + " new Object() {\n" + + " /*start*/void bar() {\n" + + " }/*end*/\n" + + " };\n" + + " }\n" + + " };\n"+ + " }\n" + + "}" + ); + IBinding binding = ((MethodDeclaration) node).resolveBinding(); + IJavaElement element = binding.getJavaElement(); + assertElementEquals( + "Unexpected Java element", + "bar() [in [in foo() [in X [in [Working copy] X.java [in [in src [in P]]]]]]]", + element + ); + } + /* * Ensures that the IJavaElement of an IBinding representing a package is correct. */ public void testPackage1() throws CoreException {