View | Details | Raw Unified | Return to bug 89686
Collapse All | Expand All

(-)search/org/eclipse/jdt/internal/core/search/matching/MatchLocator.java (-1 / +51 lines)
Lines 1817-1822 Link Here
1817
 * reports a reference to this token to the search requestor.
1817
 * reports a reference to this token to the search requestor.
1818
 * A token is valid if it has an accuracy which is not -1.
1818
 * A token is valid if it has an accuracy which is not -1.
1819
 */
1819
 */
1820
protected void reportAccurateEnumConstructorReference(SearchMatch match, FieldDeclaration field, AllocationExpression allocation) throws CoreException {
1821
	// Verify that field declaration is really an enum constant
1822
	if (allocation == null || allocation.enumConstant == null) {
1823
		report(match);
1824
		return;
1825
	}
1826
1827
	// Get scan area
1828
	int sourceStart = match.getOffset()+match.getLength();
1829
	if (allocation.arguments != null && allocation.arguments.length > 0) {
1830
		sourceStart = allocation.arguments[allocation.arguments.length-1].sourceEnd+1;
1831
	}
1832
	int sourceEnd = field.declarationSourceEnd;
1833
	if (allocation instanceof QualifiedAllocationExpression) {
1834
		QualifiedAllocationExpression qualifiedAllocation = (QualifiedAllocationExpression) allocation;
1835
		if (qualifiedAllocation.anonymousType != null) {
1836
			sourceEnd = qualifiedAllocation.anonymousType.sourceStart - 1;
1837
		}
1838
	}
1839
	
1840
	// Scan to find last closing parenthesis
1841
	Scanner scanner = this.parser.scanner;
1842
	scanner.setSource(this.currentPossibleMatch.getContents());
1843
	scanner.resetTo(sourceStart, sourceEnd);
1844
	try {
1845
		int token = scanner.getNextToken();
1846
		while (token != TerminalTokens.TokenNameEOF) {
1847
			if (token == TerminalTokens.TokenNameRPAREN) {
1848
				sourceEnd = scanner.getCurrentTokenEndPosition();
1849
			}
1850
			token = scanner.getNextToken();
1851
		}
1852
	}
1853
	catch (InvalidInputException iie) {
1854
		// give up
1855
	}
1856
1857
	// Report match
1858
	match.setLength(sourceEnd-match.getOffset()+1);
1859
	report(match);
1860
}
1861
/**
1862
 * Finds the accurate positions of each valid token in the source and
1863
 * reports a reference to this token to the search requestor.
1864
 * A token is valid if it has an accuracy which is not -1.
1865
 */
1820
protected void reportAccurateFieldReference(SearchMatch[] matches, QualifiedNameReference qNameRef) throws CoreException {
1866
protected void reportAccurateFieldReference(SearchMatch[] matches, QualifiedNameReference qNameRef) throws CoreException {
1821
	if (matches == null) return; // there's nothing to accurate in this case
1867
	if (matches == null) return; // there's nothing to accurate in this case
1822
	int matchesLength = matches.length;
1868
	int matchesLength = matches.length;
Lines 2158-2164 Link Here
2158
		if (encloses(enclosingElement)) {
2204
		if (encloses(enclosingElement)) {
2159
			int offset = field.sourceStart;
2205
			int offset = field.sourceStart;
2160
			SearchMatch match = newDeclarationMatch(enclosingElement, field.binding, accuracy, offset, field.sourceEnd-offset+1);
2206
			SearchMatch match = newDeclarationMatch(enclosingElement, field.binding, accuracy, offset, field.sourceEnd-offset+1);
2161
			report(match);
2207
			if (field.initialization instanceof AllocationExpression) {
2208
				reportAccurateEnumConstructorReference(match, field, (AllocationExpression) field.initialization);
2209
			} else {
2210
				report(match);
2211
			}
2162
		}
2212
		}
2163
	}
2213
	}
2164
2214
(-)search/org/eclipse/jdt/internal/core/search/matching/ConstructorLocator.java (+7 lines)
Lines 257-262 Link Here
257
	int offset = reference.sourceStart;
257
	int offset = reference.sourceStart;
258
	match.setOffset(offset);
258
	match.setOffset(offset);
259
	match.setLength(reference.sourceEnd - offset + 1);
259
	match.setLength(reference.sourceEnd - offset + 1);
260
	if (reference instanceof FieldDeclaration) { // enum declaration
261
		FieldDeclaration enumConstant  = (FieldDeclaration) reference;
262
		if (enumConstant.initialization instanceof QualifiedAllocationExpression) {
263
			locator.reportAccurateEnumConstructorReference(match, enumConstant, (QualifiedAllocationExpression) enumConstant.initialization);
264
			return;
265
		}
266
	}
260
	locator.report(match);
267
	locator.report(match);
261
}
268
}
262
public SearchMatch newDeclarationMatch(ASTNode reference, IJavaElement element, Binding binding, int accuracy, int length, MatchLocator locator) {
269
public SearchMatch newDeclarationMatch(ASTNode reference, IJavaElement element, Binding binding, int accuracy, int length, MatchLocator locator) {
(-)src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests.java (-1 / +36 lines)
Lines 49-55 Link Here
49
//	org.eclipse.jdt.internal.codeassist.SelectionEngine.DEBUG = true;
49
//	org.eclipse.jdt.internal.codeassist.SelectionEngine.DEBUG = true;
50
//	TESTS_PREFIX =  "testBug110060";
50
//	TESTS_PREFIX =  "testBug110060";
51
//	TESTS_NAMES = new String[] { "testBug126330" };
51
//	TESTS_NAMES = new String[] { "testBug126330" };
52
//	TESTS_NUMBERS = new int[] { 127628 };
52
//	TESTS_NUMBERS = new int[] { 89686 };
53
//	TESTS_RANGE = new int[] { 83304, -1 };
53
//	TESTS_RANGE = new int[] { 83304, -1 };
54
	}
54
	}
55
55
Lines 2666-2671 Link Here
2666
}
2666
}
2667
2667
2668
/**
2668
/**
2669
 * Bug 89686: [1.5][search] JavaModelException on ResolvedSourceMethod during refactoring
2670
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=89686"
2671
 */
2672
public void testBug89686() throws CoreException {
2673
	workingCopies = new ICompilationUnit[1];
2674
	workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/b89686/A.java",
2675
		"package b89686;\n" + 
2676
		"public enum Color {\n" + 
2677
		"    RED, GREEN(), BLUE(17), PINK((1+(1+1))) {/*anon*/};\n" + 
2678
		"    Color() {}\n" + 
2679
		"    Color(int i) {}\n" + 
2680
		"}"
2681
	);
2682
	IType type = workingCopies[0].getType("Color");
2683
	IMethod method = type.getMethod("Color", new String[0]);
2684
	search(method, REFERENCES);
2685
	this.discard = false;
2686
	assertSearchResults(
2687
		"src/b89686/A.java b89686.Color.RED [RED] EXACT_MATCH\n" + 
2688
		"src/b89686/A.java b89686.Color.GREEN [GREEN()] EXACT_MATCH"
2689
	);
2690
}
2691
public void testBug89686b() throws CoreException {
2692
	assertNotNull("There should be working copies!", workingCopies);
2693
	assertEquals("Invalid number of working copies kept between tests!", 1, workingCopies.length);
2694
	IType type = workingCopies[0].getType("Color");
2695
	IMethod method = type.getMethod("Color", new String[] { "I"} );
2696
	search(method, REFERENCES);
2697
	assertSearchResults(
2698
		"src/b89686/A.java b89686.Color.BLUE [BLUE(17)] EXACT_MATCH\n" + 
2699
		"src/b89686/A.java b89686.Color.PINK [PINK((1+(1+1)))] EXACT_MATCH"
2700
	);
2701
}
2702
2703
/**
2669
 * Bug 89848: [search] does not find method references in anonymous class of imported jarred plugin
2704
 * Bug 89848: [search] does not find method references in anonymous class of imported jarred plugin
2670
 * @see "http://bugs.eclipse.org/bugs/show_bug.cgi?id=89848"
2705
 * @see "http://bugs.eclipse.org/bugs/show_bug.cgi?id=89848"
2671
 */
2706
 */
(-)src/org/eclipse/jdt/core/tests/model/JavaSearchTests.java (-5 / +5 lines)
Lines 3090-3100 Link Here
3090
	IMethod method = type.getMethod("Team", new String[] { "I" });
3090
	IMethod method = type.getMethod("Team", new String[] { "I" });
3091
	search(method, REFERENCES, getJavaSearchScope15("e1", false), this.resultCollector);
3091
	search(method, REFERENCES, getJavaSearchScope15("e1", false), this.resultCollector);
3092
	assertSearchResults(
3092
	assertSearchResults(
3093
		"src/e1/Team.java e1.Team.PHILIPPE [PHILIPPE]\n" + 
3093
		"src/e1/Team.java e1.Team.PHILIPPE [PHILIPPE(37)]\n" + 
3094
		"src/e1/Team.java e1.Team.DAVID [DAVID]\n" + 
3094
		"src/e1/Team.java e1.Team.DAVID [DAVID(27)]\n" + 
3095
		"src/e1/Team.java e1.Team.JEROME [JEROME]\n" + 
3095
		"src/e1/Team.java e1.Team.JEROME [JEROME(33)]\n" + 
3096
		"src/e1/Team.java e1.Team.OLIVIER [OLIVIER]\n" + 
3096
		"src/e1/Team.java e1.Team.OLIVIER [OLIVIER(35)]\n" + 
3097
		"src/e1/Team.java e1.Team.KENT [KENT]",
3097
		"src/e1/Team.java e1.Team.KENT [KENT(40)]",
3098
		this.resultCollector);
3098
		this.resultCollector);
3099
}
3099
}
3100
public void testEnum04() throws CoreException {
3100
public void testEnum04() throws CoreException {

Return to bug 89686