Re: get the class object in the byte-code and more....
"Dave Brosius" <[email protected]> Wed, 5 Jul 2006 23:21:32 -0400
| Newsgroups | gmane.comp.jakarta.bcel.user |
|---|---|
| Message-ID | <005401c6a0ab$47d63430$6401a8c0@MeBigFatGuy> |
Often times questions like, "How i do this?" can be most easily answered by BCELifier, a tool bundled with the distribution that given a java class, writes a BCEL program to generate that class. ----- Original Message ----- From: "Andrea" <[email protected]> To: <[email protected]> Sent: Wednesday, July 05, 2006 5:30 PM Subject: get the class object in the byte-code and more.... > Hi to everyone. > I'm using BCEL from some days for my thesis so I've still a lot of things > to > learn about bytecode instrumentation. I want to ask you two things: > 1) How can I create in the bytecode I'm producing, an instruction > corresponding > to the statement Classname.class? I imagine that if I use > Class.forName(classname) would be ok but it doesn't work for primitive > type. > > 2) There some way to bring an object instance I have in the method wich > does the > instrumentation into the instrumented method? > I try to explain it better: > I have a method with this signature > > public static void instrument(ClassGen cgen, Method mth, BAnnotation an > > In it I want to modify the bytecode of Method mth to insert a call to an > external method and I want to pass to this second method the BAnnotation > object > (that is more or less a java annotation but don't think to much about it). > Since now I've thought to the following solutions: > - instead of passing the annotation to the external method, I could > extract the > meta-data from the annotation, insert them in the instrumented method as > local > variables (I wouldn't have any problem cuase the metadata will be String > or > primitive) and call a new external method who takes the data in that form. > I > think it could work but with complex annotations will be an hard work to > create > all the needed bytecode and specially it will be hard in future to modify > it > - I could insert in the created bytecode the needed calls to retrieve via > reflection the annotation and then I could pass the object obtained to the > external method. Not so complicated as the first solution but everytime I > have > to search for the right annotation. > - I'm not sure it could be done with annotation (well I'm not even sure it > can > be done with other object) but I could serialize my BAnnotation object > pass to > the external method the info to the deserialize it > > I would be glad if someone have some suggestions or opinions on what I've > written above. Unfortunately my english is not so good, and I'm not sure > that > what I've written is clear... > Thanks for reading > bye! > > Andrea^^ > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [email protected] > For additional commands, e-mail: [email protected] > >