javassist.expr

Class ExprEditor

public class ExprEditor extends Object

A translator of method bodies.

The users can define a subclass of this class to customize how to modify a method body. The overall architecture is similar to the strategy pattern.

If instrument() is called in CtMethod, the method body is scanned from the beginning to the end. Whenever an expression, such as a method call and a new expression (object creation), is found, edit() is called in ExprEdit. edit() can inspect and modify the given expression. The modification is reflected on the original method body. If edit() does nothing, the original method body is not changed.

The following code is an example:

This code inspects all method calls appearing in the method represented by cm and it prints the names and the line numbers of the methods declared in class Point. This code does not modify the body of the method represented by cm. If the method body must be modified, call replace() in MethodCall.

See Also: instrument CtMethod CtConstructor MethodCall NewExpr CodeConverter

Constructor Summary
ExprEditor()
Default constructor.
Method Summary
booleandoit(CtClass clazz, MethodInfo minfo)
Undocumented method.
voidedit(NewExpr e)
Edits a new expression (overridable).
voidedit(NewArray a)
Edits an expression for array creation (overridable).
voidedit(MethodCall m)
Edits a method call (overridable).
voidedit(ConstructorCall c)
Edits a constructor call (overridable).
voidedit(FieldAccess f)
Edits a field-access expression (overridable).
voidedit(Instanceof i)
Edits an instanceof expression (overridable).
voidedit(Cast c)
Edits an expression for explicit type casting (overridable).
voidedit(Handler h)
Edits a catch clause (overridable).

Constructor Detail

ExprEditor

public ExprEditor()
Default constructor. It does nothing.

Method Detail

doit

public boolean doit(CtClass clazz, MethodInfo minfo)
Undocumented method. Do not use; internal-use only.

edit

public void edit(NewExpr e)
Edits a new expression (overridable). The default implementation performs nothing.

Parameters: e the new expression creating an object.

edit

public void edit(NewArray a)
Edits an expression for array creation (overridable). The default implementation performs nothing.

Parameters: a the new expression for creating an array.

Throws: CannotCompileException

edit

public void edit(MethodCall m)
Edits a method call (overridable). The default implementation performs nothing.

edit

public void edit(ConstructorCall c)
Edits a constructor call (overridable). The constructor call is either super() or this() included in a constructor body. The default implementation performs nothing.

See Also: edit

edit

public void edit(FieldAccess f)
Edits a field-access expression (overridable). Field access means both read and write. The default implementation performs nothing.

edit

public void edit(Instanceof i)
Edits an instanceof expression (overridable). The default implementation performs nothing.

edit

public void edit(Cast c)
Edits an expression for explicit type casting (overridable). The default implementation performs nothing.

edit

public void edit(Handler h)
Edits a catch clause (overridable). The default implementation performs nothing.
Javassist, a Java-bytecode translator toolkit.
Copyright (C) 1999-2006 Shigeru Chiba. All Rights Reserved.