You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Stefan Reich <st...@googlemail.com.INVALID> on 2022/04/30 15:42:08 UTC

BCEL How to create a field with a parameterized type?

Hi, the title basically says it... I'm trying to create a field with a
parameterized type (e.g. List<String>), but I can't find a subclass of Type
representing a parameterized type that I could pass to the FieldGen
constructor.

Thanks,
Stefan

-- 
== Gaz.AI ==

Re: BCEL How to create a field with a parameterized type?

Posted by Stefan Reich <st...@googlemail.com.INVALID>.
Forget what I said. I confused the "signature" field in the Type class with
the attribute "Signature". No code in BCEL will need to be changed. Unless
you want to add a a generator for generic type signatures. So I got things
working like this basically:

  FieldGen fg;

  fg.addAttribute(new org.apache.bcel.classfile.Signature(
          cp.addUtf8("Signature"), 2,
          cp.addUtf8(typeToVMSignature
<http://code.botcompany.de:8081/tb/show-snippet.php?id=1035321>(type)),
          cp.getConstantPool()));

It really helps to talk about problems in a forum, lol.

My Java-based scripting language is coming along very nicely now.

Have a nice day
Stefan

On Sun, 1 May 2022 at 00:35, Stefan Reich <
stefan.reich.maker.of.eye@googlemail.com> wrote:

> OK I think I figured it out. There is setSignature in
> org.apache.bcel.generic.Type which I need to call with my generic field
> signature (since direct representations of generic types are actually not
> built into BCEL yet).
>
> Not a problem, what's unfortunate is just that setSignature is
> package-protected so I'd have to patch BCEL to call it.
>
> The field signature itself is protected so I could set it directly in a
> subclass of ObjectType.
>
> However, there is a note that say this practice will be made impossible in
> the future. So, in conclusion, I am proposing to change that note (in
> org/apache/bcel/generic/Type.java):
>
> /**
>  * @deprecated (since 6.0) will be made private; do not access directly, use getter/setter
>  */
> @Deprecated
> protected String signature; // signature for the type TODO should be private
>
>
> and/or making the setSignature method in the same class public.
>
> Greetings,
> Stefan
>
>
>
> On Sat, 30 Apr 2022 at 17:42, Stefan Reich <
> stefan.reich.maker.of.eye@googlemail.com> wrote:
>
>> Hi, the title basically says it... I'm trying to create a field with a
>> parameterized type (e.g. List<String>), but I can't find a subclass of Type
>> representing a parameterized type that I could pass to the FieldGen
>> constructor.
>>
>> Thanks,
>> Stefan
>>
>> --
>> == Gaz.AI ==
>>
>
>
> --
> == Gaz.AI ==
>


-- 
== Gaz.AI ==

Re: BCEL How to create a field with a parameterized type?

Posted by Stefan Reich <st...@googlemail.com.INVALID>.
Hi Gary,

I'm not sure what to add frankly. If anything, a full-fledged generic type
signature generator would be cool, but that's beyond my reach... :)

And my simple case (think List<String>) works perfectly fine right now.

Many greetings,
Stefan

On Sun, 1 May 2022 at 13:45, Gary Gregory <ga...@gmail.com> wrote:

> Hi Stefan,
>
> Feel free to provide a PR on GitHub ;-)
> That is the best way to nudge the component in the direction you need.
>
> Gary
>
> On Sat, Apr 30, 2022, 18:36 Stefan Reich
> <st...@googlemail.com.invalid> wrote:
>
> > OK I think I figured it out. There is setSignature in
> > org.apache.bcel.generic.Type which I need to call with my generic field
> > signature (since direct representations of generic types are actually not
> > built into BCEL yet).
> >
> > Not a problem, what's unfortunate is just that setSignature is
> > package-protected so I'd have to patch BCEL to call it.
> >
> > The field signature itself is protected so I could set it directly in a
> > subclass of ObjectType.
> >
> > However, there is a note that say this practice will be made impossible
> in
> > the future. So, in conclusion, I am proposing to change that note (in
> > org/apache/bcel/generic/Type.java):
> >
> > /**
> >  * @deprecated (since 6.0) will be made private; do not access
> > directly, use getter/setter
> >  */
> > @Deprecated
> > protected String signature; // signature for the type TODO should be
> > private
> >
> >
> > and/or making the setSignature method in the same class public.
> >
> > Greetings,
> > Stefan
> >
> >
> >
> > On Sat, 30 Apr 2022 at 17:42, Stefan Reich <
> > stefan.reich.maker.of.eye@googlemail.com> wrote:
> >
> > > Hi, the title basically says it... I'm trying to create a field with a
> > > parameterized type (e.g. List<String>), but I can't find a subclass of
> > Type
> > > representing a parameterized type that I could pass to the FieldGen
> > > constructor.
> > >
> > > Thanks,
> > > Stefan
> > >
> > > --
> > > == Gaz.AI ==
> > >
> >
> >
> > --
> > == Gaz.AI ==
> >
>


-- 
== Gaz.AI ==

Re: BCEL How to create a field with a parameterized type?

Posted by Gary Gregory <ga...@gmail.com>.
Hi Stefan,

Feel free to provide a PR on GitHub ;-)
That is the best way to nudge the component in the direction you need.

Gary

On Sat, Apr 30, 2022, 18:36 Stefan Reich
<st...@googlemail.com.invalid> wrote:

> OK I think I figured it out. There is setSignature in
> org.apache.bcel.generic.Type which I need to call with my generic field
> signature (since direct representations of generic types are actually not
> built into BCEL yet).
>
> Not a problem, what's unfortunate is just that setSignature is
> package-protected so I'd have to patch BCEL to call it.
>
> The field signature itself is protected so I could set it directly in a
> subclass of ObjectType.
>
> However, there is a note that say this practice will be made impossible in
> the future. So, in conclusion, I am proposing to change that note (in
> org/apache/bcel/generic/Type.java):
>
> /**
>  * @deprecated (since 6.0) will be made private; do not access
> directly, use getter/setter
>  */
> @Deprecated
> protected String signature; // signature for the type TODO should be
> private
>
>
> and/or making the setSignature method in the same class public.
>
> Greetings,
> Stefan
>
>
>
> On Sat, 30 Apr 2022 at 17:42, Stefan Reich <
> stefan.reich.maker.of.eye@googlemail.com> wrote:
>
> > Hi, the title basically says it... I'm trying to create a field with a
> > parameterized type (e.g. List<String>), but I can't find a subclass of
> Type
> > representing a parameterized type that I could pass to the FieldGen
> > constructor.
> >
> > Thanks,
> > Stefan
> >
> > --
> > == Gaz.AI ==
> >
>
>
> --
> == Gaz.AI ==
>

Re: BCEL How to create a field with a parameterized type?

Posted by Stefan Reich <st...@googlemail.com.INVALID>.
OK I think I figured it out. There is setSignature in
org.apache.bcel.generic.Type which I need to call with my generic field
signature (since direct representations of generic types are actually not
built into BCEL yet).

Not a problem, what's unfortunate is just that setSignature is
package-protected so I'd have to patch BCEL to call it.

The field signature itself is protected so I could set it directly in a
subclass of ObjectType.

However, there is a note that say this practice will be made impossible in
the future. So, in conclusion, I am proposing to change that note (in
org/apache/bcel/generic/Type.java):

/**
 * @deprecated (since 6.0) will be made private; do not access
directly, use getter/setter
 */
@Deprecated
protected String signature; // signature for the type TODO should be private


and/or making the setSignature method in the same class public.

Greetings,
Stefan



On Sat, 30 Apr 2022 at 17:42, Stefan Reich <
stefan.reich.maker.of.eye@googlemail.com> wrote:

> Hi, the title basically says it... I'm trying to create a field with a
> parameterized type (e.g. List<String>), but I can't find a subclass of Type
> representing a parameterized type that I could pass to the FieldGen
> constructor.
>
> Thanks,
> Stefan
>
> --
> == Gaz.AI ==
>


-- 
== Gaz.AI ==