diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ResolveTests12To15.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ResolveTests12To15.java index b0100136fee..ce1c061b02a 100644 --- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ResolveTests12To15.java +++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ResolveTests12To15.java @@ -1490,4 +1490,39 @@ void getTarget() { elements ); } +// https://github.com/eclipse-jdt/eclipse.jdt.core/issues/860 +// Field assignment to anonymous type breaks selection +public void testGH860() throws JavaModelException { + this.wc = getWorkingCopy("/Resolve15/src/eclipse_bug/CurrentTextSelectionCannotBeOpened.java", + """ + package eclipse_bug; + + public class CurrentTextSelectionCannotBeOpened { + public static class Super { + public boolean boolMethod(){return true;} + } + + Object obj; + public boolean somecode(){ + obj=new Object(){ + public boolean somecode(){ + Super sup=new Super(); + return sup.boolMethod(); + } + }; + return false; + } + } + """); + String str = this.wc.getSource(); + String selection = "boolMethod"; + int start = str.lastIndexOf(selection); + int length = selection.length(); + IJavaElement[] elements = this.wc.codeSelect(start, length); + assertElementsEqual( + "Unexpected elements", + "boolMethod() [in Super [in CurrentTextSelectionCannotBeOpened [in [Working copy] CurrentTextSelectionCannotBeOpened.java [in eclipse_bug [in src [in Resolve15]]]]]]", + elements + ); +} }