commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Geoff Longman" <glong...@intelligentworks.com>
Subject [Hivemind] [PATCH] ClassFab/MethodFab patch for
Date Fri, 26 Mar 2004 16:44:56 GMT
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.

Mime
View raw message