### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core Index: search/org/eclipse/jdt/internal/core/search/matching/MatchLocator.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/MatchLocator.java,v retrieving revision 1.273 diff -u -r1.273 MatchLocator.java --- search/org/eclipse/jdt/internal/core/search/matching/MatchLocator.java 29 Mar 2006 03:14:00 -0000 1.273 +++ search/org/eclipse/jdt/internal/core/search/matching/MatchLocator.java 4 Apr 2006 09:08:08 -0000 @@ -1817,6 +1817,52 @@ * reports a reference to this token to the search requestor. * A token is valid if it has an accuracy which is not -1. */ +protected void reportAccurateEnumConstructorReference(SearchMatch match, FieldDeclaration field, AllocationExpression allocation) throws CoreException { + // Verify that field declaration is really an enum constant + if (allocation == null || allocation.enumConstant == null) { + report(match); + return; + } + + // Get scan area + int sourceStart = match.getOffset()+match.getLength(); + if (allocation.arguments != null && allocation.arguments.length > 0) { + sourceStart = allocation.arguments[allocation.arguments.length-1].sourceEnd+1; + } + int sourceEnd = field.declarationSourceEnd; + if (allocation instanceof QualifiedAllocationExpression) { + QualifiedAllocationExpression qualifiedAllocation = (QualifiedAllocationExpression) allocation; + if (qualifiedAllocation.anonymousType != null) { + sourceEnd = qualifiedAllocation.anonymousType.sourceStart - 1; + } + } + + // Scan to find last closing parenthesis + Scanner scanner = this.parser.scanner; + scanner.setSource(this.currentPossibleMatch.getContents()); + scanner.resetTo(sourceStart, sourceEnd); + try { + int token = scanner.getNextToken(); + while (token != TerminalTokens.TokenNameEOF) { + if (token == TerminalTokens.TokenNameRPAREN) { + sourceEnd = scanner.getCurrentTokenEndPosition(); + } + token = scanner.getNextToken(); + } + } + catch (InvalidInputException iie) { + // give up + } + + // Report match + match.setLength(sourceEnd-match.getOffset()+1); + report(match); +} +/** + * Finds the accurate positions of each valid token in the source and + * reports a reference to this token to the search requestor. + * A token is valid if it has an accuracy which is not -1. + */ protected void reportAccurateFieldReference(SearchMatch[] matches, QualifiedNameReference qNameRef) throws CoreException { if (matches == null) return; // there's nothing to accurate in this case int matchesLength = matches.length; @@ -2158,7 +2204,11 @@ if (encloses(enclosingElement)) { int offset = field.sourceStart; SearchMatch match = newDeclarationMatch(enclosingElement, field.binding, accuracy, offset, field.sourceEnd-offset+1); - report(match); + if (field.initialization instanceof AllocationExpression) { + reportAccurateEnumConstructorReference(match, field, (AllocationExpression) field.initialization); + } else { + report(match); + } } } Index: search/org/eclipse/jdt/internal/core/search/matching/ConstructorLocator.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/ConstructorLocator.java,v retrieving revision 1.24 diff -u -r1.24 ConstructorLocator.java --- search/org/eclipse/jdt/internal/core/search/matching/ConstructorLocator.java 28 Nov 2005 14:21:24 -0000 1.24 +++ search/org/eclipse/jdt/internal/core/search/matching/ConstructorLocator.java 4 Apr 2006 09:08:06 -0000 @@ -257,6 +257,13 @@ int offset = reference.sourceStart; match.setOffset(offset); match.setLength(reference.sourceEnd - offset + 1); + if (reference instanceof FieldDeclaration) { // enum declaration + FieldDeclaration enumConstant = (FieldDeclaration) reference; + if (enumConstant.initialization instanceof QualifiedAllocationExpression) { + locator.reportAccurateEnumConstructorReference(match, enumConstant, (QualifiedAllocationExpression) enumConstant.initialization); + return; + } + } locator.report(match); } public SearchMatch newDeclarationMatch(ASTNode reference, IJavaElement element, Binding binding, int accuracy, int length, MatchLocator locator) { #P org.eclipse.jdt.core.tests.model Index: src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests.java,v retrieving revision 1.67 diff -u -r1.67 JavaSearchBugsTests.java --- src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests.java 29 Mar 2006 04:03:07 -0000 1.67 +++ src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests.java 4 Apr 2006 09:08:30 -0000 @@ -49,7 +49,7 @@ // org.eclipse.jdt.internal.codeassist.SelectionEngine.DEBUG = true; // TESTS_PREFIX = "testBug110060"; // TESTS_NAMES = new String[] { "testBug126330" }; -// TESTS_NUMBERS = new int[] { 127628 }; +// TESTS_NUMBERS = new int[] { 89686 }; // TESTS_RANGE = new int[] { 83304, -1 }; } @@ -2666,6 +2666,41 @@ } /** + * Bug 89686: [1.5][search] JavaModelException on ResolvedSourceMethod during refactoring + * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=89686" + */ +public void testBug89686() throws CoreException { + workingCopies = new ICompilationUnit[1]; + workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/b89686/A.java", + "package b89686;\n" + + "public enum Color {\n" + + " RED, GREEN(), BLUE(17), PINK((1+(1+1))) {/*anon*/};\n" + + " Color() {}\n" + + " Color(int i) {}\n" + + "}" + ); + IType type = workingCopies[0].getType("Color"); + IMethod method = type.getMethod("Color", new String[0]); + search(method, REFERENCES); + this.discard = false; + assertSearchResults( + "src/b89686/A.java b89686.Color.RED [RED] EXACT_MATCH\n" + + "src/b89686/A.java b89686.Color.GREEN [GREEN()] EXACT_MATCH" + ); +} +public void testBug89686b() throws CoreException { + assertNotNull("There should be working copies!", workingCopies); + assertEquals("Invalid number of working copies kept between tests!", 1, workingCopies.length); + IType type = workingCopies[0].getType("Color"); + IMethod method = type.getMethod("Color", new String[] { "I"} ); + search(method, REFERENCES); + assertSearchResults( + "src/b89686/A.java b89686.Color.BLUE [BLUE(17)] EXACT_MATCH\n" + + "src/b89686/A.java b89686.Color.PINK [PINK((1+(1+1)))] EXACT_MATCH" + ); +} + +/** * Bug 89848: [search] does not find method references in anonymous class of imported jarred plugin * @see "http://bugs.eclipse.org/bugs/show_bug.cgi?id=89848" */ Index: src/org/eclipse/jdt/core/tests/model/JavaSearchTests.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchTests.java,v retrieving revision 1.148 diff -u -r1.148 JavaSearchTests.java --- src/org/eclipse/jdt/core/tests/model/JavaSearchTests.java 29 Mar 2006 04:03:06 -0000 1.148 +++ src/org/eclipse/jdt/core/tests/model/JavaSearchTests.java 4 Apr 2006 09:08:34 -0000 @@ -3090,11 +3090,11 @@ IMethod method = type.getMethod("Team", new String[] { "I" }); search(method, REFERENCES, getJavaSearchScope15("e1", false), this.resultCollector); assertSearchResults( - "src/e1/Team.java e1.Team.PHILIPPE [PHILIPPE]\n" + - "src/e1/Team.java e1.Team.DAVID [DAVID]\n" + - "src/e1/Team.java e1.Team.JEROME [JEROME]\n" + - "src/e1/Team.java e1.Team.OLIVIER [OLIVIER]\n" + - "src/e1/Team.java e1.Team.KENT [KENT]", + "src/e1/Team.java e1.Team.PHILIPPE [PHILIPPE(37)]\n" + + "src/e1/Team.java e1.Team.DAVID [DAVID(27)]\n" + + "src/e1/Team.java e1.Team.JEROME [JEROME(33)]\n" + + "src/e1/Team.java e1.Team.OLIVIER [OLIVIER(35)]\n" + + "src/e1/Team.java e1.Team.KENT [KENT(40)]", this.resultCollector); } public void testEnum04() throws CoreException {