从 java 中的方法名称获取 IMethod
Get IMethod from the method name in java
我正在寻找找到 IMethod 的方法,将方法名称作为进一步开发我的 eclipse 插件的输入。
找不到这样做的方法。
谁能给我指引正确的道路。
可以有两种方法:
您可以使用 ASTVisitor
模式访问 MethodDeclaration
节点,检查名称和参数,并通过解析捆绑。参考以下帖子:
- Eclipse create CompilationUnit from .java file
- How to convert AST to JDT Java model
从编译单元获取 IType
s 并循环遍历 IMethods
,检查名称和参数以找到所需的。
IType [] typeDeclarationList = unit.getTypes();
for (IType typeDeclaration : typeDeclarationList) {
// Get methods under each type declaration.
IMethod [] methodList = typeDeclaration.getMethods();
for (IMethod method : methodList) {
// Logic here.
}
}
我正在寻找找到 IMethod 的方法,将方法名称作为进一步开发我的 eclipse 插件的输入。
找不到这样做的方法。
谁能给我指引正确的道路。
可以有两种方法:
您可以使用
ASTVisitor
模式访问MethodDeclaration
节点,检查名称和参数,并通过解析捆绑。参考以下帖子:- Eclipse create CompilationUnit from .java file
- How to convert AST to JDT Java model
从编译单元获取
IType
s 并循环遍历IMethods
,检查名称和参数以找到所需的。IType [] typeDeclarationList = unit.getTypes(); for (IType typeDeclaration : typeDeclarationList) { // Get methods under each type declaration. IMethod [] methodList = typeDeclaration.getMethods(); for (IMethod method : methodList) { // Logic here. } }