Re: Method.getMethod for varargs?
Eliot Moss <[email protected]> Thu, 30 Nov 2017 08:44:58 -0500
| Newsgroups | gmane.comp.java.objectweb.asm |
|---|---|
| Message-ID | <[email protected]> |
On 11/30/2017 4:20 AM, [email protected] wrote: > Hi, > > I'm new to using ASM and I'm trying to look up some method with varargs and I > don't understand how to format the string input to getMethod to match the > actual signature. > > I'm calling getMethod like this: > method = Method.getMethod(stringArg); > > The method I want to inspect is declared in the code as: > void log(Foo foo, Object... bar); > > When I pass in "stringArg" as > void log(mypackagage/Foo, [java/lang/Object) > I get back a Method where getDescriptor() returns this > (Lmypackage/Foo;[Ljava/lang/Object;)V > > If I make a MethodVisitor and look how the "desc" argument in the > visitMethodInsn(int opcode, String owner, String name, String desc, boolean > itf) looks like when visiting the "log" method, "desc" looks like this: > (Lmypackage/Foo;L[java/lang/Object;)V > > That is, the former has "[L" and the latter has "L[" for the varargs; I'm > obviously doing this wrong. > > I've tried calling getMethod with the bracket at the end: > void log(mypackagage/Foo, java/lang/Object[) > and then my method gets the signature > (Lmypackage/Foo;Ljava/lang/Object[;)V > Which still isn't a match with what I see in the visitor. > > So what should I pass in to get the description with "L["? The usual Java Method.getMethod takes a String name for the name of the method, e.g., "log", and zero or more Class objects for the types of the arguments. These would be written Foo.class and Object[].class. At the bytecode level, according to javap, the descriptor is: "(Lmypackage/Foo;[Ljava/lang/Object;)V" That should definitely match some method on the ASM side. Since the ... stuff turns into an array type during compilation, ASM is not going to do anything special with it. [L etc. is the correct form; L[ should not occur. So I don't really have an answer. Either something is pretty broken or you're reading that descriptor incorrectly ... Regards - Eliot Moss -- You receive this message as a subscriber of the [email protected] mailing list. To unsubscribe: mailto:[email protected] For general help: mailto:[email protected]?subject=help OW2 mailing lists service home page: http://www.ow2.org/wws