jakarta-bcel-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dweim...@students.cs.uu.nl
Subject changing types
Date Wed, 07 Apr 2004 12:04:35 GMT
At the momemnt I am working on some rewritings that contain the
modifcation of the types of a fields and methods of an existing class. The
thing is I am rewriting classes in such a way that they use don't use a
class directly but an interface that I extracted from them.


class ClassX{

  private Foo f; // transformation Foo -> IFoo which is the interface

  public bar() {
    f = null; //just a use of f to make sure there is a FieldRef in the pool

I could do this by creating a new field that has type IFoo and use
replaceField() method and creating the new field that has the new/correct
type. However taking this approach BCEL does not change the FieldRef entry
of f, that is used by field instructions (putfield, getfield etc.).

In my case, all uses of Foo should be changed to IFoo, so what i _could_
do, I think is change the Utf8 entry describing the signature, using
something like :

cp.setConstant(field_foo.getSignatureIndex(), new ConstantUtf8("LIFoo;"));
which only changes the signature and now it is not necessary to change the
FieldRef entries, because they are 'pointing' to this utf8 entry and thus
the change works on the FieldRef too. This to me feels like a 'safe'
modification, but I haven't found docs that describe the constantpool well
enough to defend this.

I hope that others have done similar things and are able to give some
feedback. Are there situations where this directly changing the Utf8 entry
causes troubles? If not, does the same approach apply to method

To unsubscribe, e-mail: bcel-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: bcel-user-help@jakarta.apache.org

View raw message