1212
1313import java .util .HashSet ;
1414import java .util .Set ;
15+ import java .util .stream .Stream ;
1516
1617import org .eclipse .core .runtime .IProgressMonitor ;
18+ import org .eclipse .jdt .core .compiler .CharOperation ;
1719import org .eclipse .jdt .core .dom .IModuleBinding ;
1820import org .eclipse .jdt .core .search .IJavaSearchScope ;
1921import org .eclipse .jdt .core .search .SearchPattern ;
2022import org .eclipse .jdt .core .search .SearchRequestor ;
23+ import org .eclipse .jdt .internal .compiler .lookup .MethodBinding ;
24+ import org .eclipse .jdt .internal .compiler .lookup .ReferenceBinding ;
25+ import org .eclipse .jdt .internal .compiler .lookup .TypeBinding ;
2126
2227public class DOMMatchLocator extends MatchLocator {
2328
@@ -34,4 +39,34 @@ public void registerModuleBinding(IModuleBinding binding) {
3439 }
3540 }
3641
42+ @ Override
43+ public MethodBinding getMethodBinding (MethodPattern methodPattern ) {
44+ char [][] compositeTypeName = Stream .of (methodPattern .declaringType .getFullyQualifiedName ().split ("\\ ." )).map (String ::toCharArray ).toArray (char [][]::new );
45+ ReferenceBinding typeRefBinding = lookupEnvironment .askForType (compositeTypeName , lookupEnvironment .module );
46+ for (MethodBinding method : typeRefBinding .methods ()) {
47+ int numParams = method .parameters .length ;
48+ if (numParams != methodPattern .parameterCount ) {
49+ continue ;
50+ }
51+ for (int i = 0 ; i < numParams ; i ++) {
52+ StringBuilder patternParam = new StringBuilder ();
53+ if (methodPattern .parameterQualifications [i ] != null && methodPattern .parameterQualifications [i ].length > 0 ) {
54+ patternParam .append (methodPattern .parameterQualifications [i ]);
55+ patternParam .append ('.' );
56+ }
57+ patternParam .append (methodPattern .parameterSimpleNames [i ]);
58+ char [] patternParamChar = patternParam .toString ().replaceAll ("\\ ." , "/" ).toCharArray ();
59+ TypeBinding typeBinding = method .parameters [i ];
60+ char [] potentialMatchParamType = typeBinding .constantPoolName ();
61+ if (!CharOperation .equals (patternParamChar , potentialMatchParamType )) {
62+ continue ;
63+ }
64+ }
65+ if (CharOperation .equals (method .selector , methodPattern .selector )) {
66+ return method ;
67+ }
68+ }
69+ return null ;
70+ }
71+
3772}
0 commit comments