0

假设我有 Hello 类,它有 hello 方法。

public class Hello {
public int hello(int x, int y)

我需要获取“hello”方法的 IMethod 引用。这是我可以获得 IType (Hello) 的代码。

IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
// 1. The name of the project in the workspace
IProject project = root.getProject("Hello");
project.open(null /* IProgressMonitor */);

IJavaProject javaProject = JavaCore.create(project);
// 2. The name of the Type (including the namespace)
IType itype = javaProject.findType("smcho.HelloRenameMethod");

IMethod method = itype.findMethod() // ???

我搜索了 IType#findMethod(),但该方法的输入参数是 IMethod 实例,而不是字符串

如何使用方法名称从 IType 获取 IMethod?或者,我如何使用IType#findMethod()来获取 IMethod?

4

1 回答 1

0

我需要使用getMethod方法名称来获取 IMethod。

IMethod method = itype.getMethod("hello", new String[] {"I", "I"});
于 2012-12-03T23:22:57.417 回答