From java.lang.reflect.Method to org.eclipse.jdt.core.IMethod [message #895323] |
Thu, 12 July 2012 12:57 |
Laurent Petit Messages: 21 Registered: December 2010 |
Junior Member |
|
|
Hello,
I'm developing Counterclockwise, an Eclipse plugin for the Clojure lang.
I'm implementing code completion, especially related to displaying potential instance methods.
I'm doing this dynamically, e.g. there is a started JVM somewhere, to which my plugin is connected somehow (does not matter), and from within this JVM, I manage to get a bunch of java.lang.reflect.Method instances.
My problem is: how to serialized them so that, back inside my Eclipse plugin, I can match each of them to org.eclipse.jdt.core.IMethods.
I already have the context of the current IJavaProject.
What I'm missing to find (I hope it already exists) is a way to find an IMethod if I can extract information from an java.lang.reflect.Method.
Would you please provide some guidance to me ?
Thanks,
--
Laurent Petit
|
|
|
|
|
Re: From java.lang.reflect.Method to org.eclipse.jdt.core.IMethod [message #896007 is a reply to message #895640] |
Mon, 16 July 2012 20:57 |
Stephan Herrmann Messages: 1853 Registered: July 2009 |
Senior Member |
|
|
Laurent Petit wrote on Sat, 14 July 2012 01:18My concern is : how to determine the argument String[] of the getMethod(String, String[]) method of IMethod, from the output of Method.getParameterTypes().
Yea, the different encodings of types and signatures can be confusing.
Quote:Said otherwise, when I have a Class instance representing a formal type, as obtained from java.lang.reflect.Method.getParameterTypes(), how do I transform it into a String with the right format as expected by IMethod.getMethod() ?
Actually, the Javadoc of IType.getMethod(String,String[]) contains exactly the link that I was going to suggest:
* The type signatures may be either unresolved (for source types)
* or resolved (for binary types), and either basic (for basic types)
* or rich (for parameterized types). See {@link Signature} for details.
where Signature is org.eclipse.jdt.core.Signature.
S.t. like this should get you started:
Class<?> clazz = method.getParameterTypes()[i];
String paramType = Signature.createTypeSignature(clazz.getName(), true);
You may need to replace all '.' by '/' or vice versa, haven't tried it right now.
Also watch out for arrays, primitive types, but the documentation of Signature should have all you need.
HTH,
Stephan
|
|
|
Powered by
FUDForum. Page generated in 0.03400 seconds