Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to format internal Java names?

Tags:

java

I'm parsing a report that returns Java method signatures as something like:

method(Ljava/lang/String;[Ljava/lang/String;ZI)V

What's the best way to convert this back into something that's more human-readable? For example, the above should be something like:

void method(String, String, boolean, int)
like image 696
Noel Yap Avatar asked Jul 13 '26 23:07

Noel Yap


1 Answers

Here are a couple of examples of code that does this:

  • http://findbugs.sourceforge.net/api/edu/umd/cs/findbugs/ba/SignatureConverter.html
  • http://attrib4j.sourceforge.net/apidocs/attrib4j/bcel/DescriptorUtil.html

If all else fails, you copy the code from one or other of these places.

A couple of things to note:

  • You cannot recover meaningful variable names for a signature (obviously ...)
  • If the methods are generic, this is not indicated in the signature. The signature information is for the raw (erased) method type.
like image 171
Stephen C Avatar answered Jul 17 '26 19:07

Stephen C



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!