Check if MethodDeclaration similar to an IMethod

徘徊边缘 提交于 2019-12-10 20:26:34

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!