Talk About Network



Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Java Machine > Re: Obtaining m...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 3 of 4 Topic 795 of 803
Post > Topic >>

Re: Obtaining methods signature

by A Pietu Pohjalainen <pohjalai@[EMAIL PROTECTED] > Nov 23, 2007 at 12:35 PM

Dmitry Marienko <dima@[EMAIL PROTECTED]
> wrote:

>    I'm dumb on simple question. How can I get  method's signature in my 

> java program in "JVM notation" ?
>   For example for class
>    class A {
>       void foo(int a,int b) { ... }
>    }
>   I would like to get  string .../A/foo(II)V  for method 'foo' . I
haven't  
> found any appropriate methods to do it.


I believe that this information is not available in the standard Java
API. Haven't followed late changes though..

To get this info, I'm using the Apache BCEL library
(http://jakarta.apache.org/bcel/):


$ cat SignatureLister.java
import java.io.*;

import org.apache.bcel.*;
import org.apache.bcel.classfile.*;
import org.apache.bcel.generic.*;
import org.apache.bcel.util.*;

public class SignatureLister {
    public static void main(String args[]) throws IOException {
        ClassParser parser  = new ClassParser(args[0]);
        JavaClass   clazz   = parser.parse();
        Method[]    methods = clazz.getMethods();

        for(int i=0; i<methods.length; i++) {
            System.out.print(clazz.getClassName());
            System.out.print(".");
            System.out.print(methods[i].getName());
            System.out.println(methods[i].getSignature());
        }    
    }
}

$ javac -classpath bcel-5.2.jar SignatureLister.java 

$ $ java -cp bcel-5.2.jar:. SignatureLister A.class
A.<init>()V
A.foo(II)V




br,
Pietu




 4 Posts in Topic:
Obtaining methods signature
"Dmitry Marienko&quo  2007-11-21 18:19:01 
Re: Obtaining methods signature
Joshua Cranmer <Pidgeo  2007-11-21 17:44:12 
Re: Obtaining methods signature
A Pietu Pohjalainen <p  2007-11-23 12:35:18 
Re: Obtaining methods signature
"Dmitry Marienko&quo  2007-11-23 15:07:08 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat May 17 3:09:36 CDT 2008.