### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core.tests.model Index: src/org/eclipse/jdt/core/tests/model/ResolveTests.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ResolveTests.java,v retrieving revision 1.73 diff -u -r1.73 ResolveTests.java --- src/org/eclipse/jdt/core/tests/model/ResolveTests.java 16 Mar 2007 18:35:32 -0000 1.73 +++ src/org/eclipse/jdt/core/tests/model/ResolveTests.java 6 Apr 2007 11:00:58 -0000 @@ -1124,6 +1124,50 @@ elements ); } +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=180683 +public void testUnicode2() throws JavaModelException { + this.workingCopies = new ICompilationUnit[1]; + this.workingCopies[0] = getWorkingCopy( + "/Resolve/src/test/B.java", + "package test;\n"+ + "public class \\u0042 {\n" + + " void foo() {\n" + + " \\u0042 var = null;\n" + + " }\n" + + "}"); + + String str = this.workingCopies[0].getSource(); + int start = str.lastIndexOf("42"); + int length = "".length(); + IJavaElement[] elements = this.workingCopies[0].codeSelect(start, length, this.wcOwner); + + assertElementsEqual( + "Unexpected elements", + "B [in [Working copy] B.java [in test [in src [in Resolve]]]]", + elements + ); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=180683 +public void testUnicode3() throws JavaModelException { + this.workingCopies = new ICompilationUnit[1]; + this.workingCopies[0] = getWorkingCopy( + "/Resolve/src/test/B.java", + "package test;\n"+ + "public class \\u0042 {\n" + + " void foo() {\n" + + " \\u004"); + + String str = this.workingCopies[0].getSource(); + int start = str.lastIndexOf("4"); + int length = "".length(); + IJavaElement[] elements = this.workingCopies[0].codeSelect(start, length, this.wcOwner); + + assertElementsEqual( + "Unexpected elements", + "", + elements + ); +} /** * https://bugs.eclipse.org/bugs/show_bug.cgi?id=47177 */ #P org.eclipse.jdt.core Index: codeassist/org/eclipse/jdt/internal/codeassist/SelectionEngine.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/SelectionEngine.java,v retrieving revision 1.134 diff -u -r1.134 SelectionEngine.java --- codeassist/org/eclipse/jdt/internal/codeassist/SelectionEngine.java 7 Dec 2006 14:50:05 -0000 1.134 +++ codeassist/org/eclipse/jdt/internal/codeassist/SelectionEngine.java 6 Apr 2007 11:01:00 -0000 @@ -341,6 +341,8 @@ int token; if(selectionStart > selectionEnd){ + // compute end position of the selection + int end = selectionEnd + 1 == source.length ? selectionEnd : selectionEnd + 1; // compute start position of current line int currentPosition = selectionStart - 1; @@ -355,6 +357,16 @@ while (source[pos] == 'u') { pos++; } + + int endOfUnicode = pos + 3; + if (end < endOfUnicode) { + if (endOfUnicode < source.length) { + end = endOfUnicode; + } else { + return false; // not enough characters to decode an unicode + } + } + if ((c1 = ScannerHelper.getNumericValue(source[pos++])) > 15 || c1 < 0 || (c2 = ScannerHelper.getNumericValue(source[pos++])) > 15 @@ -388,7 +400,7 @@ } // compute start and end of the last token - scanner.resetTo(nextCharacterPosition, selectionEnd + 1 == source.length ? selectionEnd : selectionEnd + 1); + scanner.resetTo(nextCharacterPosition, end); do { try { token = scanner.getNextToken();