diff options
author | chiba <chiba@30ef5769-5b8d-40dd-aea6-55b5d6557bb3> | 2005-05-15 18:00:02 +0000 |
---|---|---|
committer | chiba <chiba@30ef5769-5b8d-40dd-aea6-55b5d6557bb3> | 2005-05-15 18:00:02 +0000 |
commit | fcf881dc698b1a1d07077439c632c6c013927045 (patch) | |
tree | d9ca3f2d3bc1c4b031d58533ebb516ae58a13974 /sample/reflect | |
parent | a3705668278d2faaeb297f9da81c20354a0599d6 (diff) | |
download | javassist-fcf881dc698b1a1d07077439c632c6c013927045.tar.gz javassist-fcf881dc698b1a1d07077439c632c6c013927045.zip |
cleaned up import declarations
git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@168 30ef5769-5b8d-40dd-aea6-55b5d6557bb3
Diffstat (limited to 'sample/reflect')
-rw-r--r-- | sample/reflect/Main.java | 11 | ||||
-rw-r--r-- | sample/reflect/Person.java | 54 | ||||
-rw-r--r-- | sample/reflect/VerboseMetaobj.java | 22 |
3 files changed, 43 insertions, 44 deletions
diff --git a/sample/reflect/Main.java b/sample/reflect/Main.java index 6086d9f8..d9733abc 100644 --- a/sample/reflect/Main.java +++ b/sample/reflect/Main.java @@ -1,6 +1,5 @@ package sample.reflect;
-import javassist.reflect.ClassMetaobject;
import javassist.reflect.Loader;
/*
@@ -23,11 +22,11 @@ import javassist.reflect.Loader; */
public class Main {
public static void main(String[] args) throws Throwable {
- Loader cl = (Loader)Main.class.getClassLoader();
- cl.makeReflective("sample.reflect.Person",
- "sample.reflect.VerboseMetaobj",
- "javassist.reflect.ClassMetaobject");
+ Loader cl = (Loader)Main.class.getClassLoader();
+ cl.makeReflective("sample.reflect.Person",
+ "sample.reflect.VerboseMetaobj",
+ "javassist.reflect.ClassMetaobject");
- cl.run("sample.reflect.Person", args);
+ cl.run("sample.reflect.Person", args);
}
}
diff --git a/sample/reflect/Person.java b/sample/reflect/Person.java index 5e0e2ad8..445d3807 100644 --- a/sample/reflect/Person.java +++ b/sample/reflect/Person.java @@ -1,6 +1,6 @@ /*
- A base-level class controlled by VerboseMetaobj.
-*/
+ * A base-level class controlled by VerboseMetaobj.
+ */
package sample.reflect;
@@ -9,43 +9,45 @@ import javassist.reflect.Metaobject; public class Person {
public String name;
+
public static int birth = 3;
+
public static final String defaultName = "John";
public Person(String name, int birthYear) {
- if (name == null)
- this.name = defaultName;
- else
- this.name = name;
+ if (name == null)
+ this.name = defaultName;
+ else
+ this.name = name;
- this.birth = birthYear;
+ birth = birthYear;
}
public String getName() {
- return name;
+ return name;
}
public int getAge(int year) {
- return year - birth;
+ return year - birth;
}
public static void main(String[] args) {
- String name;
- if (args.length > 0)
- name = args[0];
- else
- name = "Bill";
-
- Person p = new Person(name, 1960);
- System.out.println("name: " + p.getName());
- System.out.println("object: " + p.toString());
-
- // change the metaobject of p.
- if (p instanceof Metalevel) {
- ((Metalevel)p)._setMetaobject(new Metaobject(p, null));
- System.out.println("<< the metaobject was changed.>>");
- }
-
- System.out.println("age: " + p.getAge(1999));
+ String name;
+ if (args.length > 0)
+ name = args[0];
+ else
+ name = "Bill";
+
+ Person p = new Person(name, 1960);
+ System.out.println("name: " + p.getName());
+ System.out.println("object: " + p.toString());
+
+ // change the metaobject of p.
+ if (p instanceof Metalevel) {
+ ((Metalevel)p)._setMetaobject(new Metaobject(p, null));
+ System.out.println("<< the metaobject was changed.>>");
+ }
+
+ System.out.println("age: " + p.getAge(1999));
}
}
diff --git a/sample/reflect/VerboseMetaobj.java b/sample/reflect/VerboseMetaobj.java index a9f75dd1..91dba579 100644 --- a/sample/reflect/VerboseMetaobj.java +++ b/sample/reflect/VerboseMetaobj.java @@ -1,29 +1,27 @@ package sample.reflect;
-import javassist.*;
import javassist.reflect.*;
public class VerboseMetaobj extends Metaobject {
public VerboseMetaobj(Object self, Object[] args) {
- super(self, args);
- System.out.println("** constructed: " + self.getClass().getName());
+ super(self, args);
+ System.out.println("** constructed: " + self.getClass().getName());
}
public Object trapFieldRead(String name) {
- System.out.println("** field read: " + name);
- return super.trapFieldRead(name);
+ System.out.println("** field read: " + name);
+ return super.trapFieldRead(name);
}
public void trapFieldWrite(String name, Object value) {
- System.out.println("** field write: " + name);
- super.trapFieldWrite(name, value);
+ System.out.println("** field write: " + name);
+ super.trapFieldWrite(name, value);
}
public Object trapMethodcall(int identifier, Object[] args)
- throws Throwable
- {
- System.out.println("** trap: " + getMethodName(identifier)
- + "() in " + getClassMetaobject().getName());
- return super.trapMethodcall(identifier, args);
+ throws Throwable {
+ System.out.println("** trap: " + getMethodName(identifier) + "() in "
+ + getClassMetaobject().getName());
+ return super.trapMethodcall(identifier, args);
}
}
|