1 11 package org.eclipse.jdt.internal.corext.refactoring.rename; 12 13 import org.eclipse.core.runtime.CoreException; 14 15 import org.eclipse.jdt.core.ICompilationUnit; 16 import org.eclipse.jdt.core.compiler.IScanner; 17 import org.eclipse.jdt.core.compiler.ITerminalSymbols; 18 import org.eclipse.jdt.core.compiler.InvalidInputException; 19 import org.eclipse.jdt.core.search.MethodReferenceMatch; 20 import org.eclipse.jdt.core.search.SearchMatch; 21 22 import org.eclipse.jdt.internal.corext.refactoring.CuCollectingSearchRequestor; 23 24 class MethodOccurenceCollector extends CuCollectingSearchRequestor { 25 26 private final String fName; 27 28 public MethodOccurenceCollector(String methodName) { 29 fName= methodName; 30 } 31 32 public void acceptSearchMatch(ICompilationUnit unit, SearchMatch match) throws CoreException { 33 if (match instanceof MethodReferenceMatch 34 && ((MethodReferenceMatch) match).isSuperInvocation() 35 && match.getAccuracy() == SearchMatch.A_INACCURATE) { 36 return; } 38 39 if (match.isImplicit()) { collectMatch(match); 41 return; 42 } 43 44 int start= match.getOffset(); 45 int length= match.getLength(); 46 String matchText= unit.getBuffer().getText(start, length); 47 48 if (fName.equals(matchText)) { 50 collectMatch(match); 51 return; 52 } 53 54 IScanner scanner= getScanner(unit); 56 scanner.setSource(matchText.toCharArray()); 57 int simpleNameStart= -1; 58 int simpleNameEnd= -1; 59 try { 60 int token = scanner.getNextToken(); 61 while (token != ITerminalSymbols.TokenNameEOF && token != ITerminalSymbols.TokenNameLPAREN) { if (token == ITerminalSymbols.TokenNameIdentifier) { 63 simpleNameStart= scanner.getCurrentTokenStartPosition(); 64 simpleNameEnd= scanner.getCurrentTokenEndPosition(); 65 } 66 token = scanner.getNextToken(); 67 } 68 } catch (InvalidInputException e){ 69 } 71 if (simpleNameStart != -1) { 72 match.setOffset(start + simpleNameStart); 73 match.setLength(simpleNameEnd + 1 - simpleNameStart); 74 } 75 collectMatch(match); 76 } 77 } 78 | Popular Tags |