|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.ObjectclassUtils.javassist.expr.ExprEditor
public class ExprEditor
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:
CtMethod cm = ...; cm.instrument(new ExprEditor() { public void edit(MethodCall m) throws CannotCompileException { if (m.getClassName().equals("Point")) { System.out.println(m.getMethodName() + " line: " + m.getLineNumber()); } });
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
.
CompileTimeClass.instrument(ExprEditor)
,
CtMethod.instrument(ExprEditor)
,
CtConstructor.instrument(ExprEditor)
,
MethodCall
,
NewExpr
,
FieldAccess
,
CodeConverter
Constructor Summary | |
---|---|
ExprEditor()
Default constructor. |
Method Summary | |
---|---|
boolean |
doit(CompileTimeClass clazz,
MethodInfo minfo)
Undocumented method. |
void |
edit(Cast c)
Edits an expression for explicit type casting (overridable). |
void |
edit(FieldAccess f)
Edits a field-access expression (overridable). |
void |
edit(Handler h)
Edits a catch clause (overridable). |
void |
edit(Instanceof i)
Edits an instanceof expression (overridable). |
void |
edit(MethodCall m)
Edits a method call (overridable). |
void |
edit(NewExpr e)
Edits a new expression (overridable). |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public ExprEditor()
Method Detail |
---|
public boolean doit(CompileTimeClass clazz, MethodInfo minfo) throws CannotCompileException
CannotCompileException
public void edit(NewExpr e) throws CannotCompileException
e
- the new expression creating an object.
CannotCompileException
public void edit(MethodCall m) throws CannotCompileException
CannotCompileException
public void edit(FieldAccess f) throws CannotCompileException
CannotCompileException
public void edit(Instanceof i) throws CannotCompileException
CannotCompileException
public void edit(Cast c) throws CannotCompileException
CannotCompileException
public void edit(Handler h) throws CannotCompileException
CannotCompileException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |