0

I would like to get the generic information (Counter class) of my CounterPersistence class using BCEL 6.0-SNAPSHOT. The signature is like this:

public interface CounterPersistence extends BasePersistence<Counter> {
....
}

I'm using the following code to read the bytecode

JavaClass javaClass = ...;
Attribute[] attributes = javaClass.getAttributes();
for (Attribute attribute : attributes) {
    if (attribute instanceof Signature) {
        Signature signature = (Signature) attribute;
        //put the code here that get the Counter class from the signature
    }
}

But I'm failing to write a code that parse the signature and allow me to get the type Counter. Thoughts?

2 Answers2

1

You can use BCEL utilities from FindBugs, e.g. GenericUtilities.getTypeParameters(...) method or better switch to ASM framework.

Eugene Kuleshov
  • 31,461
  • 5
  • 66
  • 67
0

I found a solution:

Class.forName(org.apache.bcel.classfile.Utility.methodSignatureArgumentTypes("(" + signature + ")V")[0]);
bummi
  • 27,123
  • 14
  • 62
  • 101
Cyril Sochor
  • 692
  • 6
  • 9