1616import java .util .List ;
1717import java .util .Map ;
1818import java .util .Objects ;
19+ import java .util .Optional ;
1920import java .util .Set ;
2021import java .util .stream .Collectors ;
2122import java .util .stream .Stream ;
@@ -284,7 +285,7 @@ private IMethod getJavaElementForMethodDeclaration(IType currentType, MethodDecl
284285
285286 IMethod result = currentType .getMethod (getName (), Stream .of (getParameterTypes ()).map (SignatureUtils ::getSignature ).toArray (String []::new ));
286287 if (result .exists ()) {
287- return result ;
288+ return declaredMethod ( result ). orElse ( result ) ;
288289 }
289290 List <SingleVariableDeclaration > p = methodDeclaration .parameters ();
290291 String [] params = p .stream () //
@@ -299,18 +300,19 @@ private IMethod getJavaElementForMethodDeclaration(IType currentType, MethodDecl
299300 if (result .exists ()) {
300301 return result ;
301302 }
303+ return declaredMethod (result ).orElse (null );
304+ }
302305
306+ private Optional <IMethod > declaredMethod (IMethod method ) {
303307 IMethod [] methods = null ;
304308 try {
305- methods = currentType .getMethods ();
309+ methods = method . getDeclaringType () .getMethods ();
306310 } catch (JavaModelException e ) {
307311 // declaring type doesn't exist
308- return null ;
312+ return Optional . empty () ;
309313 }
310- IMethod [] candidates = Member .findMethods (result , methods );
311- if (candidates == null || candidates .length == 0 )
312- return null ;
313- return candidates [0 ];
314+ IMethod [] candidates = Member .findMethods (method , methods );
315+ return candidates == null || candidates .length == 0 ? Optional .empty () : Optional .of (candidates [0 ]);
314316 }
315317
316318 private IMethod resolved (IMethod from ) {
0 commit comments