3131import org .eclipse .jdt .core .dom .ASTNode ;
3232import org .eclipse .jdt .core .dom .Annotation ;
3333import org .eclipse .jdt .core .dom .AnnotationTypeMemberDeclaration ;
34+ import org .eclipse .jdt .core .dom .ConstructorInvocation ;
3435import org .eclipse .jdt .core .dom .Expression ;
3536import org .eclipse .jdt .core .dom .ExpressionMethodReference ;
3637import org .eclipse .jdt .core .dom .IBinding ;
@@ -639,10 +640,11 @@ private int computeResolveLevel(org.eclipse.jdt.core.dom.ASTNode node, IBinding
639640 return IMPOSSIBLE_MATCH ;
640641 }
641642
642- protected int resolveLevel (MethodInvocation messageSend ) {
643- IMethodBinding invocationBinding = messageSend .resolveMethodBinding ();
644- ITypeBinding initialReceiverType = messageSend .getExpression () != null ? messageSend .getExpression ().resolveTypeBinding () : null ;
645- return resolveLevelForNodeWithMethodBinding (messageSend , invocationBinding , initialReceiverType , false , false );
643+ private List <Expression > arguments (ASTNode node ) {
644+ return (List <Expression >)
645+ (node instanceof MethodInvocation method ? method .arguments () :
646+ node instanceof ConstructorInvocation constr ? constr .arguments () :
647+ List .of ());
646648 }
647649
648650 protected int resolveLevelForNodeWithMethodBinding (ASTNode messageSend ,
@@ -669,6 +671,16 @@ protected int resolveLevelForNodeWithMethodBinding(ASTNode messageSend,
669671 invocationOrDeclarationBinding = declarationBinding ;
670672 }
671673
674+ if (invocationBinding .getParameterTypes ().length == arguments (messageSend ).size ()) {
675+ for (int i = 0 ; i < invocationBinding .getParameterTypes ().length ; i ++) {
676+ var source = arguments (messageSend ).get (i ).resolveTypeBinding ();
677+ var resolved = invocationBinding .getParameterTypes ()[i ];
678+ if (source != null && !source .isAssignmentCompatible (resolved )) {
679+ return INACCURATE_MATCH ;
680+ }
681+ }
682+ }
683+
672684 int invocOrDeclLevel = invocationLevel == IMPOSSIBLE_MATCH ? declarationLevel : invocationLevel ;
673685 // receiver type
674686 if (this .pattern .declaringSimpleName == null && this .pattern .declaringQualification == null ) {
@@ -709,6 +721,8 @@ protected int resolveLevelForNodeWithMethodBinding(ASTNode messageSend,
709721 // this is an overridden method => add flavor to returned level
710722 declaringLevel = invocOrDeclLevel | SUPER_INVOCATION_FLAVOR ;
711723 }
724+ // Consider whether the next lines should be part of DOMJavaSearchDelegate as they
725+ // don't seem so specific to Method locator (same code could serve TypeRefLocator too)
712726 if ((declaringLevel & FLAVORS_MASK ) != 0 ) {
713727 // level got some flavors => return it
714728 retval = declaringLevel ;
@@ -783,7 +797,9 @@ protected boolean isVirtualInvoke(IMethodBinding method) {
783797 @ Override
784798 public LocatorResponse resolveLevel (org .eclipse .jdt .core .dom .ASTNode node , IBinding binding , MatchLocator locator ) {
785799 if (node instanceof MethodInvocation invocation ) {
786- return toResponse (resolveLevel (invocation ));
800+ IMethodBinding invocationBinding = invocation .resolveMethodBinding ();
801+ ITypeBinding initialReceiverType = invocation .getExpression () != null ? invocation .getExpression ().resolveTypeBinding () : null ;
802+ return toResponse (resolveLevelForNodeWithMethodBinding (invocation , invocationBinding , initialReceiverType , false , false ));
787803 }
788804 int level = computeResolveLevel (node , binding , locator );
789805 if (node instanceof MethodDeclaration declaration && binding != null ) {
0 commit comments