I want to check if two PsiMethods I have are the same (name and signature) or not.
I can do a psimethod1.getName().equals(psimethod2.getName()) for checking the name.
For getting the signature , psiMethod.getSignature(PsiSubstitutor) requires a PsiSubstitutor. I have no control over the signatures of the PsiMethods to be compared so what kind of PsiSubstitutor should I pass.
How to compare the two MethodSignatures returned?
Also is there any better way to achieve this comparison?
There's com.intellij.psi.util.MethodSignatureUtil#areSignaturesEqual()
For that I need to pass the MethodSignature and to get MethodSignature from PsiMethod I need to pass the PsiSubstitutor.
Passing the Substitutor as EMPTY or UNKNOWN works for methods with normal parameters but if we have a Generic type argument they do not work.
Does com.intellij.psi.util.MethodSignatureUtil#areSignaturesEqual(com.intellij.psi.PsiMethod, com.intellij.psi.PsiMethod) not work?
That method internally takes the PsiSubstitutor as Empty which works otherwise but not when the methods have a generic type argument.
Please provide the context, why do you need to compare 2 methods. I don't get why do you want to consider different method foo(T) from 2 different parameterisations of the containing class.
The correct way is as Yann pointed - MethodSignatureUtil.
Anna
I want to check the presence of a method in a file before adding it, hence the comparison.
How do know what method to add? Where do you get the correct signature?