diff options
author | chiba <chiba@30ef5769-5b8d-40dd-aea6-55b5d6557bb3> | 2004-04-05 09:57:57 +0000 |
---|---|---|
committer | chiba <chiba@30ef5769-5b8d-40dd-aea6-55b5d6557bb3> | 2004-04-05 09:57:57 +0000 |
commit | d2ab0807aef8e006a2362396e12a25d3a0d55eb0 (patch) | |
tree | 3ac8eb4eaad6a24f017ff1a1214ca405d1183f5d /sample | |
parent | f56bd9e72f3032f66241f864725f208e0df03839 (diff) | |
download | javassist-d2ab0807aef8e006a2362396e12a25d3a0d55eb0.tar.gz javassist-d2ab0807aef8e006a2362396e12a25d3a0d55eb0.zip |
changed line delimiters.
git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@77 30ef5769-5b8d-40dd-aea6-55b5d6557bb3
Diffstat (limited to 'sample')
-rw-r--r-- | sample/Test.java | 88 | ||||
-rw-r--r-- | sample/evolve/DemoLoader.java | 82 |
2 files changed, 85 insertions, 85 deletions
diff --git a/sample/Test.java b/sample/Test.java index 07eeda98..810b6b61 100644 --- a/sample/Test.java +++ b/sample/Test.java @@ -1,44 +1,44 @@ -package sample;
-
-import javassist.*;
-
-/*
- A very simple sample program
-
- This program overwrites sample/Test.class (the class file of this
- class itself) for adding a method g(). If the method g() is not
- defined in class Test, then this program adds a copy of
- f() to the class Test with name g(). Otherwise, this program does
- not modify sample/Test.class at all.
-
- To see the modified class definition, execute:
-
- % javap sample.Test
-
- after running this program.
-*/
-public class Test {
- public int f(int i) {
- return i + 1;
- }
-
- public static void main(String[] args) throws Exception {
- ClassPool pool = ClassPool.getDefault();
-
- CtClass cc = pool.get("sample.Test");
- try {
- cc.getDeclaredMethod("g");
- System.out.println("g() is already defined in sample.Test.");
- }
- catch (NotFoundException e) {
- /* getDeclaredMethod() throws an exception if g()
- * is not defined in sample.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
- System.out.println("g() was added.");
- }
- }
-}
+package sample; + +import javassist.*; + +/* + A very simple sample program + + This program overwrites sample/Test.class (the class file of this + class itself) for adding a method g(). If the method g() is not + defined in class Test, then this program adds a copy of + f() to the class Test with name g(). Otherwise, this program does + not modify sample/Test.class at all. + + To see the modified class definition, execute: + + % javap sample.Test + + after running this program. +*/ +public class Test { + public int f(int i) { + return i + 1; + } + + public static void main(String[] args) throws Exception { + ClassPool pool = ClassPool.getDefault(); + + CtClass cc = pool.get("sample.Test"); + try { + cc.getDeclaredMethod("g"); + System.out.println("g() is already defined in sample.Test."); + } + catch (NotFoundException e) { + /* getDeclaredMethod() throws an exception if g() + * is not defined in sample.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 + System.out.println("g() was added."); + } + } +} diff --git a/sample/evolve/DemoLoader.java b/sample/evolve/DemoLoader.java index ecf45049..6c16c6dc 100644 --- a/sample/evolve/DemoLoader.java +++ b/sample/evolve/DemoLoader.java @@ -1,41 +1,41 @@ -package sample.evolve;
-
-import javassist.*;
-import java.io.*;
-import java.util.Hashtable;
-
-/**
- * DemoLoader is a class loader for running a program including
- * an updatable class. This simple loader allows only a single
- * class to be updatable. (Extending it for supporting multiple
- * updatable classes is easy.)
- *
- * To run, type as follows:
- *
- * % java sample.evolve.DemoLoader <port number>
- *
- * Then DemoLoader launches sample.evolve.DemoServer with <port number>.
- * It also translates sample.evolve.WebPage, which sample.evolve.DemoServer
- * uses, so that it is an updable class.
- *
- * Note: JDK 1.2 or later only.
- */
-public class DemoLoader {
- private static final int initialVersion = 0;
- private String updatableClassName = null;
- private CtClass updatableClass = null;
-
- /* Creates a <code>DemoLoader</code> for making class WebPage
- * updatable. Then it runs main() in sample.evolve.DemoServer.
- */
- public static void main(String[] args) throws Throwable {
- Evolution translator = new Evolution();
- ClassPool cp = ClassPool.getDefault();
- cp.insertTranslator(translator);
- Loader cl = new Loader();
- cl.setClassPool(cp);
-
- translator.makeUpdatable("sample.evolve.WebPage");
- cl.run("sample.evolve.DemoServer", args);
- }
-}
+package sample.evolve; + +import javassist.*; +import java.io.*; +import java.util.Hashtable; + +/** + * DemoLoader is a class loader for running a program including + * an updatable class. This simple loader allows only a single + * class to be updatable. (Extending it for supporting multiple + * updatable classes is easy.) + * + * To run, type as follows: + * + * % java sample.evolve.DemoLoader <port number> + * + * Then DemoLoader launches sample.evolve.DemoServer with <port number>. + * It also translates sample.evolve.WebPage, which sample.evolve.DemoServer + * uses, so that it is an updable class. + * + * Note: JDK 1.2 or later only. + */ +public class DemoLoader { + private static final int initialVersion = 0; + private String updatableClassName = null; + private CtClass updatableClass = null; + + /* Creates a <code>DemoLoader</code> for making class WebPage + * updatable. Then it runs main() in sample.evolve.DemoServer. + */ + public static void main(String[] args) throws Throwable { + Evolution translator = new Evolution(); + ClassPool cp = ClassPool.getDefault(); + cp.insertTranslator(translator); + Loader cl = new Loader(); + cl.setClassPool(cp); + + translator.makeUpdatable("sample.evolve.WebPage"); + cl.run("sample.evolve.DemoServer", args); + } +} |