我需要集成 Eclipse JDT 到一些基于 java.lang.reflect。我的问题是:是否有现有的接口或适配器?最好的方法是什么?谁能指点我一个教程来做到这一点?
例如,我需要从 org.eclipse.jdt.core.dom.IMethodBinding
检索 java.lang.reflect.Method
。
同样,我需要从 org.eclipse.jdt.core.dom.Type
或 org.eclipse.jdt.core 获取 java.lang.Class
。 dom.ITypeBinding
。我发现这可以通过以下方式实现:
Class<?> clazz = Class.forName(typeBinding.getBinaryName());
当然,这是一个非常简单的解决方案,假设该类已经存在于类路径中,并且没有通过 JDT API 进行更改 - 所以它远非完美。但应该指出的是,这两个假设对于我的具体情况确实成立。
I need to integrate Eclipse JDT into some existing API that is based on java.lang.reflect. My questions are: Is there an existing interface or adapter? What is the best way to do this? Can anyone point me to a tutorial to do this?
For instance I need to retrieve the java.lang.reflect.Method
from a org.eclipse.jdt.core.dom.IMethodBinding
.
Similarly I need to get the java.lang.Class
from a org.eclipse.jdt.core.dom.Type
or org.eclipse.jdt.core.dom.ITypeBinding
. I found that this can be achieved by:
Class<?> clazz = Class.forName(typeBinding.getBinaryName());
Of course this is a very simple solution that assumes that the class already exists on the classpath and is not changed via the JDT API -- so it is far from perfect. But it should be noted that these two assumptions do hold for my specific situation.
发布评论
评论(1)
鉴于该类已经存在于类路径中并且不会通过 JDT API 进行实质性更改,我自己实现了一些内容。
例如,可以使用以下代码将
IMethodBinding
转换为Method
:请注意,方法
retrieveTypeClass
还解决了第二个问题。希望这对任何人都有帮助。Given that the class already exists on the classpath and is not changes substantially via the JDT API, I implemented something myself.
For instance an
IMethodBinding
can be transformed to aMethod
with the following code:Note that the method
retrieveTypeClass
also solves the second problem. Hope this helps anyone.