This is cool. I think this is a good change.

One caveat: I don't think removeAbstractClassModifier() is needed. It can just be 
assumed (ClassFab
exists to create concrete classes, not abstract classes), with the logic rolled into 
createClass().

--
Howard M. Lewis Ship
Independent J2EE / Open-Source Java Consultant
Creator, Tapestry: Java Web Components 
http://howardlewisship.com


> -----Original Message-----
> From: Geoff Longman [mailto:[EMAIL PROTECTED] 
> Sent: Friday, March 26, 2004 11:45 AM
> To: Jakarta Commons Developers List
> Subject: [Hivemind] [PATCH] ClassFab/MethodFab patch for 
> 
> 
> Ran into a problem creating an interceptor method that calls another
> interceptor method that has not been added yet.
> 
> Javassist's compiler doesn't like that. Fortunately, 
> Javassist  provides a
> workaround.
> One needs to add both the methods as abstract, then set the 
> bodies on them.
> Lastly, because adding an abstract method to a CtClass make the class
> abstract, one must be able to reset the class modifier to public (non
> abstract).
> 
> Attached is are patches for the following classes:
> 
> ClassFab:
> 
> adds a method signature removeAbstractClassModifier() for removing an
> abstract modifier from the class
> 
> MethodFab:
> 
> adds a setBody() method, so you can set the method body after 
> creating the
> method
> 
> ClassFabImpl:
> 
> calling addMethod with a null body will still add the method, 
> but with an
> abstract modifier.
> has an impementation of removeAbstractClassModifier
> 
> MethodFabImpl
> 
> has an implementation of setBody()
> 
> 
> example:
> 
> ClassFab classFab = fClassFactory.newClass(... blah .. blah ..);
> 
> MethodFab method1 = classFab.addMethod(
>         Modifier.PUBLIC,
>         "methodA",
>         Void.TYPE,
>         new Class[] { },
>         new Class[] { },
>         null);
> 
> MethodFab method2 = classFab.addMethod(
>         Modifier.PUBLIC,
>         "methodB",
>         Void.TYPE,
>         new Class[] { },
>         new Class[] { },
>         null);
> 
> method1.setBody( .. stuff that calls method2 ..);
> method2.setBody( .. stuff ..);
> 
> ClassFab.removeAbstractClassModifier() ;
> 
> Class resultClass = classFab.createClass();
> 
> 
> 
> Geoff
> 
> offrey Longman
> Intelligent Works Inc.
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to