From 0ed1ede707440a9a981c2e0cfd5421b0ba0e364d Mon Sep 17 00:00:00 2001 From: chiba Date: Sun, 18 May 2003 15:34:30 +0000 Subject: fixed a bug in CtBehavior#setBody(). git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@19 30ef5769-5b8d-40dd-aea6-55b5d6557bb3 --- tutorial/tutorial2.html | 91 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 88 insertions(+), 3 deletions(-) (limited to 'tutorial') diff --git a/tutorial/tutorial2.html b/tutorial/tutorial2.html index b9ca5bed..5016474a 100644 --- a/tutorial/tutorial2.html +++ b/tutorial/tutorial2.html @@ -363,11 +363,12 @@ For example, if the result type is int, then ($r) does not convert a type; it does nothing. However, if the operand is a call to a void method, then ($r) results in null. For example, +if the result type is void and +foo() is a void method, then -

is a valid statement if the result type is void. -Here, foo() is a void method. +

is a valid statement.

The cast operator ($r) is also useful in a return statement. Even if the result type is @@ -485,7 +486,74 @@ catch (java.io.IOException e) {

5.2 Modifying a method body

-

javassist.expr.ExprEditor is a class +

CtMethod and CtConstructor provide +setBody() for substituting a whole +method body. They compile the given source text into Java bytecode +and substitutes it for the original method body. + +

In the source text given to setBody(), the identifiers +starting with $ have special meaning + +

+ +Note that $_ is not available. + + +

Javassist allows modifying only an expression included in a method body. +javassist.expr.ExprEditor is a class for replacing an expression in a method body. The users can define a subclass of ExprEditor to specify how an expression is modified. @@ -1047,6 +1115,23 @@ public int ymove(int dy) { this.move(0, dy); }

Note that $proceed has been replaced with this.move. +

Javassist provides another way to add a new method. +You can first create an abstract method and later give it a method body: + +

+ +

Since Javassist makes a class abstract if an abstract method is +added to the class, you have to explicitly change the class back to a +non-abstract one after calling setBody(). + +

Mutual recursive methods

Javassist cannot compile a method if it calls another method that -- cgit v1.2.3