Bug 20693 - Finding references to variables does not find all occurances
Summary: Finding references to variables does not find all occurances
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 2.0   Edit
Hardware: PC Windows 2000
: P2 major (vote)
Target Milestone: 2.0 F4   Edit
Assignee: Jerome Lanneluc CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2002-06-19 18:21 EDT by Michael Erdmann CLA
Modified: 2002-06-24 04:59 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Michael Erdmann CLA 2002-06-19 18:21:07 EDT
When searching for variables by using the context menu command "refernces"
not all occurances are found. 
After some investigation as an informed user I could track it down to a simple
sample (see below).
Find all references to the var "willSearchFingMe". 
All occurances are found except the one in "getWillSearchFndMe2()". 
If you remove the brackets around "this.willSearchFindMe" it will be found. 

-----

package com;
public class EclipseSearchTest {

	String willSearchFndMe;
	
	public String getWillSearchFndMe() {
		return willSearchFndMe;
	}

	public String getWillSearchFndMe2() {
		return (this.willSearchFndMe);
	}

	public void setWillSearchFndMe(String willSearchFndMe) {
		this.willSearchFndMe = willSearchFndMe;
	}

}
Comment 1 Adam Kiezun CLA 2002-06-20 05:48:07 EDT
this breaks RenameField refactoring
Comment 2 Jerome Lanneluc CLA 2002-06-20 06:20:44 EDT
Thanks for the test case. It is indeed a problem with the match locator that 
doesn't expect a field reference that contains brackets.

Fix would consist in finding the first identifier in the field reference.

Proposed fix (in MatchLocator):
	/**
	 * Finds the accurate positions of the sequence of tokens given by 
qualifiedName
	 * in the source and reports a reference to this this qualified name
	 * to the search requestor.
	 */
	public void reportAccurateReference(
		int sourceStart,
		int sourceEnd,
		char[][] qualifiedName,
		IJavaElement element,
		int accuracy)
		throws CoreException {

		if (accuracy == -1) return;

		// compute source positions of the qualified reference 
		Scanner scanner = parser.scanner;
		scanner.setSource(
			this.currentMatchingOpenable.getSource());
		scanner.resetTo(sourceStart, sourceEnd);

		int refSourceStart = -1, refSourceEnd = -1;
		int tokenNumber = qualifiedName.length;
		int token = -1;
		int previousValid = -1;
		int i = 0;
		int currentPosition;
		do {
			// find first token that is an identifier 
(parenthesized expressions include parenthesises in source range - see bug 
20693 - Finding references to variables does not find all occurrences  )
			do {
				currentPosition = scanner.currentPosition;
				try {
					token = scanner.getNextToken();
				} catch (InvalidInputException e) {
				}
			} while (token !=  ITerminalSymbols.TokenNameIdentifier 
&& token !=  ITerminalSymbols.TokenNameEOF);

			if (token != ITerminalSymbols.TokenNameEOF) {
				char[] currentTokenSource = 
scanner.getCurrentTokenSource();
				boolean equals = false;
				while (i < tokenNumber
					&& !(equals = this.pattern.matchesName
(qualifiedName[i++], currentTokenSource))) {
				}
				if (equals && (previousValid == -1 || 
previousValid == i - 2)) {
					previousValid = i - 1;
					if (refSourceStart == -1) {
						refSourceStart = 
currentPosition;
					}
					refSourceEnd = scanner.currentPosition -
 1;
				} else {
					i = 0;
					refSourceStart = -1;
					previousValid = -1;
				}
				// read '.'
				try {
					token = scanner.getNextToken();
				} catch (InvalidInputException e) {
				}
			}
			if (i == tokenNumber) {
				// accept reference
				if (refSourceStart != -1) {
					this.report(refSourceStart, 
refSourceEnd, element, accuracy);
				} else {
					this.report(sourceStart, sourceEnd, 
element, accuracy);
				}
				return;
			}
		} while (token != ITerminalSymbols.TokenNameEOF);

	}
Comment 3 Philipe Mulet CLA 2002-06-20 07:30:59 EDT
Fix is quite simple. Would candidate since it affects search based tools like 
refactoring.
Comment 4 Philipe Mulet CLA 2002-06-21 06:52:01 EDT
From Adam, regarding to refactoring test suites:

our tests run smoothly
i activated the prevously disabled tests for 
20693 Finding references to variables does not find all occurances 
20520 Refactor - expression detection incorrect 
Comment 5 Philipe Mulet CLA 2002-06-21 07:17:32 EDT
Fix got approved, releasing into 20020621
Comment 6 David Audel CLA 2002-06-24 04:59:21 EDT
Verified.