问题
Is there any way by which i can compare a MethodDeclaration object and IMethod object and check whether they are similar? Or is there any way by whcih a MethodDeclaration object can be converted to an IMethod object (IMethod provides a isSimilar function)?
Update : Similarily i would like to know if a FieldDeclaration can be converted to a IField.
回答1:
MethodDeclaration is an ASTNode, and IMethod is a JavaElement. The definitive way to check if these two objects correspond to the same method is to compare their Binding.
See http://wiki.eclipse.org/JDT/FAQ#From_an_ASTNode_to_an_IBinding and http://wiki.eclipse.org/JDT/FAQ#From_an_IJavaElement_to_an_IBinding on how to get the Binding for an ASTNode and for a JavaElement. Once you have the Binding or the Binding key you can just compare that.
来源:https://stackoverflow.com/questions/10309824/check-if-methoddeclaration-similar-to-an-imethod