2012-12-03 21 views
0

假设我有hello方法的Hello类。通过方法名称从IType中查找IMethod

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

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

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() // ??? 

我googled IType#findMethod(),但the input parameter for this method is an IMethod instance, not a string

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

回答

0

我需要使用getMethod来获得方法名称的方法。

IMethod method = itype.getMethod("hello", new String[] {"I", "I"}); 
+0

我也试过这个'itype.getMethod(string,string [])'方法,并且它返回目标方法。但是目标方法的状态是'(not open)'。你有这个问题吗?谢谢。 – andyf