Java method resolving

How should I find a specific Java method with regarding to subtyping?:
I have PsiType A,B and String methodName, and I want to find a method A#methodName(C) where B is castable to C (eg: C=long, B=int).
If I use A.findMethodBySignature(..) then I got only exact A#methodName(B) methods but not A#methodName(C)
Is there API for that?
Thanks.

3 comments

Hi,
there is no such api as far as I know. You need to findMethodsByName and check them yourself. 'Castable' doesn't mean anything for overload resolution so it seems to be a specific need.

0

Sorry my question was inaccurate.
I want standard Java method invocation resolving. To find the most specific acessible and applicable method.

Seems the method resolving should be somewhere in PsiMethodCallExpression.getMethodExpression().multiResolve(false)
But how I can  create PsiMethodCallExpression or PsiMethodReferenceExpression using receiver, arguments and methodName?
Thanks

0

I would create expression from text (JavaPsiFacade.getElementFactory().createExpressionFromText()), cast it to the PsiMethodCallExpression and then call resolve. Please note, that you need to specify call context in order to be able to correctly resolve.

0

Please sign in to leave a comment.