> 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(). >
Sure. I forgot to add in my last that the patch represents a hackish solution I made so I could get past the problem. Geoff ----- Original Message ----- From: "Howard M. Lewis Ship" <[EMAIL PROTECTED]> To: "'Jakarta Commons Developers List'" <[EMAIL PROTECTED]> Sent: Friday, March 26, 2004 1:17 PM Subject: RE: [Hivemind] [PATCH] ClassFab/MethodFab patch for > This is cool. I think this is a good change. > > -- > 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] > --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
