commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Showalter, Jim" <Jim_Showal...@intuit.com>
Subject How can I recover .class references separate from other references to classes using BCEL?
Date Sun, 10 Sep 2017 19:50:14 GMT
The use case is, suppose you want to recover the source from a .class file.

In the original source, it said:

public class SomeExperiment {
     public static void main(String[] args) {
     System.out.println(SomeOtherClass.class); <<< WANT TO RECOVER THE ".class" FROM
HERE
     }
}

In the visitor I wrote, there's an override:

     public void visitConstantClass(final ConstantClass obj) {
           String className = JavaUtils.dotsToSlashes(javaClass().getConstantPool().getConstant(obj.getNameIndex()).toString());
          System.out.println(class file name + ": " + className);
     }

Dumping out the data on a .class from a .java file that contains no occurrences of the string
".class", I get:

com/intuit/qbo/Misc.class: com/intuit/qbo/Misc$Reader
com/intuit/qbo/Misc.class: com/intuit/qbo/util/SomeException
com/intuit/qbo/Misc.class: com/intuit/qbo/Misc
com/intuit/qbo/Misc.class: com/intuit/qbo/api/MiscIf

This means ClassConstant isn't just for .class references. It's for all references to classes.

How can I use BCEL to recover the original ".class" reference in SomeExperiment?

Jim Showalter
Programmer
Intuit, 2003H-265Z
Garcia Avenue
Mountain View, CA 94043
(408) 353-4954
(408) 204-1661


Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message