You are viewing a plain text version of this content. The canonical link for it is here.
Posted to bcel-dev@jakarta.apache.org by Shrinivas Joshi <sj...@cc.gatech.edu> on 2005/06/07 20:28:04 UTC
Field modifiers
Hi All,
I need to change access modifiers of all fields of a particular class
to public access.
When I use setModifiers(Constants.ACC_PUBLIC) the other attributes such as
static, final etc are not retained. The field modifier is then set to just
public. I tried using bitwise OR of Constants.ACC_PUBLIC with existing
modifiers and noticed that it retains the other access attributes and also
changes the field modifier to public. But doesnt works for protected
fields as bitwise OR results in 0x5 value which is not valid value.
Please let me know if I am doing it right or missing something over here.
Thanks and Regards
Shrinivas Joshi
---------------------------------------------------------------------
To unsubscribe, e-mail: bcel-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: bcel-dev-help@jakarta.apache.org
Re: Field modifiers
Posted by Shrinivas Joshi <sj...@cc.gatech.edu>.
Hi Ray,
Thanks for the information. Actually one of the list member also
suggested the first option. As you said second option seems much simpler
and good for maintainability of the code.
Thanks again
Shrinivas Joshi
On Tue, 7 Jun 2005, Ray Blaak wrote:
> >When I use setModifiers(Constants.ACC_PUBLIC) the other attributes such as
> >static, final etc are not retained. The field modifier is then set to just
> >public. I tried using bitwise OR of Constants.ACC_PUBLIC with existing
> >modifiers and noticed that it retains the other access attributes and also
> >changes the field modifier to public. But doesnt works for protected
> >fields as bitwise OR results in 0x5 value which is not valid value.
>
> You need to clear out the other access bits first. E.g.
>
> int modifiers = member.getModifiers();
> modifiers &= ~(Constants.ACC_PRIVATE|Constants.ACC_PROTECTED);
> modifiers |= Constants.ACC_PUBLIC;
> member.setModifiers(modifiers);
>
> But really is much much simpler to just do:
>
> member.isPrivate(false);
> member.isProtected(false);
> member.isPublic(true);
>
> Cheers,
> Ray Blaak
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: bcel-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: bcel-dev-help@jakarta.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: bcel-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: bcel-dev-help@jakarta.apache.org
Re: Field modifiers
Posted by Ray Blaak <bl...@ensemble-systems.com>.
>When I use setModifiers(Constants.ACC_PUBLIC) the other attributes such as
>static, final etc are not retained. The field modifier is then set to just
>public. I tried using bitwise OR of Constants.ACC_PUBLIC with existing
>modifiers and noticed that it retains the other access attributes and also
>changes the field modifier to public. But doesnt works for protected
>fields as bitwise OR results in 0x5 value which is not valid value.
You need to clear out the other access bits first. E.g.
int modifiers = member.getModifiers();
modifiers &= ~(Constants.ACC_PRIVATE|Constants.ACC_PROTECTED);
modifiers |= Constants.ACC_PUBLIC;
member.setModifiers(modifiers);
But really is much much simpler to just do:
member.isPrivate(false);
member.isProtected(false);
member.isPublic(true);
Cheers,
Ray Blaak
---------------------------------------------------------------------
To unsubscribe, e-mail: bcel-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: bcel-dev-help@jakarta.apache.org
Re: Field modifiers
Posted by Shrinivas Joshi <sj...@cc.gatech.edu>.
Hi,
It works elegantly. Thanks a lot for your help
Regards
Shrinivas Joshi
On Tue, 7 Jun 2005 dbrosius@qis.net wrote:
> you need to and them out
>
> something like
>
> setModifiers((getModifiers() | Constants.ACC_PUBLIC) &
> ~(Constants.ACC_PRIVATE|Constants.ACC_PROTECTED));
>
> Quoting Shrinivas Joshi <sj...@cc.gatech.edu>:
>
> > Hi All,
> > I need to change access modifiers of all fields of a particular class
> > to public access.
> > When I use setModifiers(Constants.ACC_PUBLIC) the other attributes such as
> > static, final etc are not retained. The field modifier is then set to just
> > public. I tried using bitwise OR of Constants.ACC_PUBLIC with existing
> > modifiers and noticed that it retains the other access attributes and also
> > changes the field modifier to public. But doesnt works for protected
> > fields as bitwise OR results in 0x5 value which is not valid value.
> > Please let me know if I am doing it right or missing something over here.
> >
> > Thanks and Regards
> > Shrinivas Joshi
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: bcel-dev-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: bcel-dev-help@jakarta.apache.org
> >
>
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: bcel-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: bcel-dev-help@jakarta.apache.org
Re: Field modifiers
Posted by db...@qis.net.
you need to and them out
something like
setModifiers((getModifiers() | Constants.ACC_PUBLIC) &
~(Constants.ACC_PRIVATE|Constants.ACC_PROTECTED));
Quoting Shrinivas Joshi <sj...@cc.gatech.edu>:
> Hi All,
> I need to change access modifiers of all fields of a particular class
> to public access.
> When I use setModifiers(Constants.ACC_PUBLIC) the other attributes such as
> static, final etc are not retained. The field modifier is then set to just
> public. I tried using bitwise OR of Constants.ACC_PUBLIC with existing
> modifiers and noticed that it retains the other access attributes and also
> changes the field modifier to public. But doesnt works for protected
> fields as bitwise OR results in 0x5 value which is not valid value.
> Please let me know if I am doing it right or missing something over here.
>
> Thanks and Regards
> Shrinivas Joshi
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: bcel-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: bcel-dev-help@jakarta.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: bcel-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: bcel-dev-help@jakarta.apache.org