Need to commonize classfile and generic packages
King Dale <[email protected]>
| Newsgroups | gmane.comp.jakarta.bcel.devel |
|---|---|
| Message-ID | <[email protected]> |
While trying to do some simple tasks, I ran into several places where there
was a lot of problems with the difference between the classfile and generic
packages. Take the constant pool for example. In my application I was
parsing one class file and using the information from that to generate
another one. The one I was constructing was using a ClassGen with a
ConstantPoolGen. The class I parsed was of course a JavaClass with a
ConstantPool. When copying fields from the parsed class to the ClassGen I
needed to copy the Constant object that represented the field's
ConstantValue. I could certainly get the Constant from the ConstantPool, but
how do I put it into the ConstantPoolGen. There is this method in
ConstantPoolGen:
void addConstant( Constant c, ConstantPoolGen cp )
That expects a ConstantPoolGen not a ConstantPool. The first line of the
Method calls getConstantPool so there is no reason for it to be
ConstantPoolGen.
My first thought is that it could be split into:
void addConstant( Constant c, ConstantPool cp )
{
// Most of the logic
}
void addConstant( Constant c, ConstantPoolGen cp )
{
addConstant( c, cp.getConstantPool );
}
But really that is not getting to the real issue. The real issue is that
these two classes are closely related. They should actually both implement a
common interface that defines those operations that are common to both. Then
the addConstant method could simply take an object that implements that
interface rather than the concrete class. This probably applies to the rest
of the objects that have this dichotomy.
--
Dale King
PS. I am not subscribed and my employer is blocking www.mail-archive.com so
if you want me to see a reply you will need to copy me via email.