diff options
author | chiba <chiba@30ef5769-5b8d-40dd-aea6-55b5d6557bb3> | 2008-09-08 10:56:50 +0000 |
---|---|---|
committer | chiba <chiba@30ef5769-5b8d-40dd-aea6-55b5d6557bb3> | 2008-09-08 10:56:50 +0000 |
commit | 7f87aaa503eae6730f2b077b428d65f9bc3efc14 (patch) | |
tree | a5a9f9b1a1517992cc894501936634b38093283b /src/main/javassist/CodeConverter.java | |
parent | 4bd7105829441948f5f142da387205026b8571a7 (diff) | |
download | javassist-7f87aaa503eae6730f2b077b428d65f9bc3efc14.tar.gz javassist-7f87aaa503eae6730f2b077b428d65f9bc3efc14.zip |
implemented CodeConverter.replaceNew(CtClass,CtClass)
git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@454 30ef5769-5b8d-40dd-aea6-55b5d6557bb3
Diffstat (limited to 'src/main/javassist/CodeConverter.java')
-rw-r--r-- | src/main/javassist/CodeConverter.java | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/src/main/javassist/CodeConverter.java b/src/main/javassist/CodeConverter.java index 4ffe1eeb..91f5657a 100644 --- a/src/main/javassist/CodeConverter.java +++ b/src/main/javassist/CodeConverter.java @@ -98,6 +98,32 @@ public class CodeConverter { } /** + * Modify a method body so that instantiation of the class + * specified by <code>oldClass</code> + * is replaced with instantiation of another class <code>newClass</code>. + * For example, + * <code>replaceNew(ctPoint, ctPoint2)</code> + * (where <code>ctPoint</code> and <code>ctPoint2</code> are + * compile-time classes for class <code>Point</code> and class + * <code>Point2</code>, respectively) + * replaces all occurrences of: + * + * <ul><code>new Point(x, y)</code></ul> + * + * in the method body with: + * + * <ul><code>new Point2(x, y)</code></ul> + * + * <p>Note that <code>Point2</code> must be type-compatible with <code>Point</code>. + * It must have the same set of methods, fields, and constructors as the + * replaced class. + */ + public void replaceNew(CtClass oldClass, CtClass newClass) { + transformers = new TransformNewClass(transformers, oldClass.getName(), + newClass.getName()); + } + + /** * Modify a method body so that field read/write expressions access * a different field from the original one. * @@ -503,7 +529,7 @@ public class CodeConverter { * as array access replacements. * * @author <a href="kabir.khan@jboss.com">Kabir Khan</a> - * @version $Revision: 1.14 $ + * @version $Revision: 1.15 $ */ public interface ArrayAccessReplacementMethodNames { @@ -612,7 +638,7 @@ public class CodeConverter { * accesses to array elements. * * @author <a href="kabir.khan@jboss.com">Kabir Khan</a> - * @version $Revision: 1.14 $ + * @version $Revision: 1.15 $ */ public static class DefaultArrayAccessReplacementMethodNames implements ArrayAccessReplacementMethodNames |