From 3f73777f2cdf408d47bd85417611635235bdd7ed Mon Sep 17 00:00:00 2001 From: chiba Date: Wed, 14 Apr 2004 15:49:55 +0000 Subject: modified the ClassPool framework. git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@84 30ef5769-5b8d-40dd-aea6-55b5d6557bb3 --- sample/Test.java | 2 +- sample/evolve/DemoLoader.java | 3 +-- sample/evolve/Evolution.java | 5 ++--- sample/vector/VectorAssistant.java | 4 ++-- 4 files changed, 6 insertions(+), 8 deletions(-) (limited to 'sample') diff --git a/sample/Test.java b/sample/Test.java index 810b6b61..1e2b49c2 100644 --- a/sample/Test.java +++ b/sample/Test.java @@ -37,7 +37,7 @@ public class Test { CtMethod fMethod = cc.getDeclaredMethod("f"); CtMethod gMethod = CtNewMethod.copy(fMethod, "g", cc, null); cc.addMethod(gMethod); - pool.writeFile("sample.Test"); // update the class file + cc.writeFile(); // update the class file System.out.println("g() was added."); } } diff --git a/sample/evolve/DemoLoader.java b/sample/evolve/DemoLoader.java index 1d8c33f9..f1474a1f 100644 --- a/sample/evolve/DemoLoader.java +++ b/sample/evolve/DemoLoader.java @@ -31,9 +31,8 @@ public class DemoLoader { public static void main(String[] args) throws Throwable { Evolution translator = new Evolution(); ClassPool cp = ClassPool.getDefault(); - cp.addTranslator(translator); Loader cl = new Loader(); - cl.setClassPool(cp); + cl.addTranslator(cp, translator); translator.makeUpdatable("sample.evolve.WebPage"); cl.run("sample.evolve.DemoServer", args); diff --git a/sample/evolve/Evolution.java b/sample/evolve/Evolution.java index 810f1986..ad6d1281 100644 --- a/sample/evolve/Evolution.java +++ b/sample/evolve/Evolution.java @@ -43,16 +43,15 @@ public class Evolution implements Translator { trapMethod = _pool.getMethod("sample.evolve.Sample", "make"); } - public void onWrite(ClassPool _pool, String classname) + public void onWrite(ClassPool _pool, CtClass clazz) throws NotFoundException, CannotCompileException { - onWriteUpdatable(classname); + onWriteUpdatable(clazz.getName()); /* * Replaces all the occurrences of the new operator with a call * to _makeInstance(). */ - CtClass clazz = _pool.get(classname); CtClass absClass = updatableClass; CodeConverter converter = new CodeConverter(); converter.replaceNew(absClass, absClass, handlerMethod); diff --git a/sample/vector/VectorAssistant.java b/sample/vector/VectorAssistant.java index 44fdd41c..27d5f702 100644 --- a/sample/vector/VectorAssistant.java +++ b/sample/vector/VectorAssistant.java @@ -96,7 +96,7 @@ public class VectorAssistant implements Assistant { vec.addMethod(CtNewMethod.copy(addmethod, "add", vec, map)); vec.addMethod(CtNewMethod.copy(atmethod, "at", vec, map)); - pool.writeFile(vec.getName()); + vec.writeFile(); return vec; } @@ -125,7 +125,7 @@ public class VectorAssistant implements Assistant { m = CtNewMethod.wrapped(type, "at", args2, null, atmethod, null, vec); vec.addMethod(m); - pool.writeFile(vec.getName()); + vec.writeFile(); return vec; } -- cgit v1.2.3