This is the mail archive of the
kawa@sourceware.cygnus.com
mailing list for the Kawa project.
Re: Replacing reflection with gnu.bytecode
- To: Stuart Ballard <sballard at netreach dot net>
- Subject: Re: Replacing reflection with gnu.bytecode
- From: Per Bothner <per at bothner dot com>
- Date: 15 Jun 2000 08:44:21 -0700
- Cc: kawa at sourceware dot cygnus dot com
- References: <3948F7C3.8AF9013E@netreach.net>
Stuart Ballard <sballard@netreach.net> writes:
> Therefore I am considering replacing reflection with gnu.bytecode,
> if it can do what I need it to do.
It can.
> 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
The version in cvs does. It was added April 12. Alternatively, you
can use getFlags(), which is an older method that does the same.
> and I can't find the equivalent of Constructor at all.
A constructor is represented as a method whose name is "<init>".
> I also couldn't
> figure out how to detect a primitive constant, or to get its value.
There is no direct way to do it. However, the following (untested)
should work:
ConstantValueAttr attr
= (ConstantValueAttr) Attribute.get(fld, "ConstantValue");
if (attr == null)
not a constant;
else
value = attr.getValue(clas.getConstants());
ConstantValueAttr was also added April 12, so you need to use the
cvs version. Or wait for Kawa 1.6.68, which I hope to have out "soon".
The gnu.bytecode.dump application reads a .class file and prints it
out in human-readable form. It is useful as example code (as well as
in its own right).
--
--Per Bothner
per@bothner.com http://www.bothner.com/~per/