Dear Markus
My approach currently is
private Type java2BCELType(Class aClass) {
Type returnType = null;
if (aClass == void.class) { // !?
returnType = Type.VOID;
...
} else if (!(aClass.isPrimitive())) {
returnType = Type.OBJECT;
}
}
which just is ugly. You're approach seems simplier, but what I'm not
liking is that you have to map types via Strings:
Type = Type.getType(Utility.getSignature(aClass.getName()))
is what you're proposing, right?
There are similar issues with converting
java.lang.reflect.Modiifer to int access_flags
Please get me right, I'm not complainig, I'm just interested in doing it
right :)
Andreas
And thus spoke * [EMAIL PROTECTED]*:
> Hi,
>
> Neither void, nor int are "classes" of course, but primitive types.
> Type objects for primitive types are listed in the Type class, e.g.,
> Type.INT
>
> If you want to map the String "int" to a sigature, use
> Utility.getSignature() which
> will yield "I". To convert a signature to a Type object you can then
> say Type.getType(sig).
>
> Cheers
> Markus
> > -----Ursprungliche Nachricht-----
> > Von: Andreas Schlapbach [mailto:[EMAIL PROTECTED]]
> > Gesendet: Montag, 25. Februar 2002 20:11
> > An: [EMAIL PROTECTED]
> > Betreff: Reflection && BCEL - Types
> >
> >
> > <div class="moz-text-flowed" style="font-family: -moz-fixed">Hi List
> >
> > I'm using BCEL to subclass existing classes and interfaces on the fly.
> > So I use java reflection to gain insight on the to be subclassed
> > classes. But I'm not sure how to effectly map the java types to BCEL.
> >
> > For example:
> >
> > class A {
> > void b(int a);
> > }
> >
> > returns a Class of type 'void' as return type and a Class
> > 'int' as it's
> > argument type. (This part of JAVA is, let's say, strange :))
> >
> > If I want to subclass from A and overwrite b I need to
> > generate a class
> > B and a method b with exactly this signature.
> >
> > But the MethodGen classes uses it's own Type system.
> >
> > Now, is there an easy way to map this java types on to the BCEL types?
> > From looking at the API and the source I couldn't find a smooth way.
> >
> > Something like
> > |*
> > MethodGen <cid:[EMAIL PROTECTED]>*(int
> > access_flags,
> > Class return_type,
> > Class[] arg_types,
> > java.lang.String[] arg_names,
> > java.lang.String method_name,
> > java.lang.String class_name,
> > InstructionList <cid:[EMAIL PROTECTED]> il,
> > ConstantPoolGen <cid:[EMAIL PROTECTED]> cp)|
> >
> > would be nice.
> >
> > Or is there a better approach?
> >
> > Andreas
> >
> > --
> > I think, so IAM.
> >
> > Andreas Schlapbach [EMAIL PROTECTED]
> > http://www.iam.unibe.ch/~schlpbch
> >
> >
> >
> >
> >
> >
> > </div>
> >
> >
> > --
> > To unsubscribe, e-mail:
> <mailto:[EMAIL PROTECTED]>
> For additional commands, e-mail:
> <mailto:[EMAIL PROTECTED]>
>
--
0xCAFEBABE & !0xDEADBEAF
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>