Community
Participate
Working Groups
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; } }
this breaks RenameField refactoring
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); }
Fix is quite simple. Would candidate since it affects search based tools like refactoring.
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
Fix got approved, releasing into 20020621
Verified.