This is the mail archive of the kawa@sourceware.cygnus.com mailing list for the Kawa project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Replacing reflection with gnu.bytecode


I am working on a utility to test binary compatibility between Java
APIs. Currently I load classes using Class.forName and iterate over the
members using getMethods(), getFields() and getConstructors(). I use a
lot of get* methods from the Reflection API to construct a full
description of the API. I have a small homepage for the project at
http://stuart.wuffies.net/japi/ .

I seem to have hit a brick wall in what Reflection is able to give me,
though, because it has absolutely no way to detect whether a field is a
primitive constant (being static and final is not enough; it must also
be initialized to a compile-time constant value). Therefore I am
considering replacing reflection with gnu.bytecode, if it can do what I
need it to do. I need to be able to load a class definition either from
a Zip file or a .class file and have equivalents for the following
methods in java.lang.reflect:

{Class,Method,Field,Constructor}.getModifiers()
{Class,Method,Field}.getName()
Class.isInterface()
Class.getInterfaces()
Class.getSuperclass()
Class.getMethods()
Class.getFields()
Class.getConstructors()
{Method,Constructor}.getParameterTypes()
{Method,Constructor}.getExceptionTypes()
Method.getReturnType()
Field.getType()

I also need a function that doesn't exist in reflection,

Field.isPrimitiveConstant()

and a method to get the value of the constant if so. All of this needs
to happen without <clinit> ever being called on the loaded class.

I looked at the API docs of gnu.bytecode but I couldn't figure out the
equivalents of a lot of these methods, specifically, Field doesn't seem
to have a getModifiers() method (even though ClassType and Method do)
and I can't find the equivalent of Constructor at all. I also couldn't
figure out how to detect a primitive constant, or to get its value.

Any suggestions would be appreciated.

Thanks,
Stuart.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]