From 2817e9c078a34a8b2e581fff13801bf92aa93c0f Mon Sep 17 00:00:00 2001 From: chiba Date: Wed, 31 Dec 2003 13:22:19 +0000 Subject: added the description of insertAt() in CtBehavior. git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@65 30ef5769-5b8d-40dd-aea6-55b5d6557bb3 --- tutorial/tutorial2.html | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) (limited to 'tutorial') diff --git a/tutorial/tutorial2.html b/tutorial/tutorial2.html index 0615edea..0e7530bf 100644 --- a/tutorial/tutorial2.html +++ b/tutorial/tutorial2.html @@ -11,6 +11,17 @@
Previous page
+

+5. Introspection and customization +

+ +


+

5. Introspection and customization

@@ -101,6 +112,7 @@ of the javassist.runtime package.


+

5.1 Inserting source text at the beginning/end of a method body

CtMethod and CtConstructor provide @@ -113,8 +125,18 @@ text. It receives source text written in Java and compiles it into Java bytecode, which will be inlined into a method body. -

The methods insertBefore(), insertAfter(), and -addCatch() receives a String object representing +

+Inserting a code fragment at the position specified by a line number +is also possible +(if the line number table is contained in the class file). +insertAt() in CtMethod and +CtConstructor takes source text and a line number in the source +file of the original class definition. +It compiles the source text and inserts the compiled code at the line number. + +

The methods insertBefore(), insertAfter(), +addCatch(), and insertAt() +receive a String object representing a statement or a block. A statement is a single control structure like if and while or an expression ending with a semi colon (;). A block is a set of @@ -520,7 +542,8 @@ catch (java.io.IOException e) {


-

5.2 Modifying a method body

+
+

5.2 Altering a method body

CtMethod and CtConstructor provide setBody() for substituting a whole @@ -590,6 +613,7 @@ the class currently edited. Note that $_ is not available. +

Substituting source text for an existing expression

Javassist allows modifying only an expression included in a method body. javassist.expr.ExprEditor is a class @@ -1107,6 +1131,7 @@ exception.


+

5.3 Adding a new method or field

Adding a method

@@ -1230,6 +1255,7 @@ does not end with a semi colon (;).


+

5.4 Limitations

In the current implementation, the Java compiler included in Javassist -- cgit v1.2.3