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?

Comment actions Permalink

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.

Comment actions Permalink

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?

Comment actions Permalink

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.


Please sign in to leave a comment.