Mercurial > hg > Database > Alice
diff src/main/java/alice/test/reflection/ReflectionTest.java @ 419:aefbe41fcf12 dispose
change tab to space
author | sugi |
---|---|
date | Tue, 15 Jul 2014 16:00:22 +0900 |
parents | 8f71c3e6f11d |
children | 6e304a7a60e7 |
line wrap: on
line diff
--- a/src/main/java/alice/test/reflection/ReflectionTest.java Tue Jul 15 06:15:53 2014 +0900 +++ b/src/main/java/alice/test/reflection/ReflectionTest.java Tue Jul 15 16:00:22 2014 +0900 @@ -8,44 +8,44 @@ public class ReflectionTest { - public static void main(String[] args){ - try { - new ReflectionTest().createCS(); - } catch (Exception e) { - e.printStackTrace(); - } - System.out.println("TEST END"); - } + public static void main(String[] args){ + try { + new ReflectionTest().createCS(); + } catch (Exception e) { + e.printStackTrace(); + } + System.out.println("TEST END"); + } - public void createCS() throws Exception{ - - ClassPool cp = ClassPool.getDefault(); - CtClass tep = cp.get("alice.test.reflection.CSTemplate"); - CtClass rec = cp.get("alice.datasegment.Receiver"); + public void createCS() throws Exception{ + + ClassPool cp = ClassPool.getDefault(); + CtClass tep = cp.get("alice.test.reflection.CSTemplate"); + CtClass rec = cp.get("alice.datasegment.Receiver"); - // ---- define Field ----- - //CtField f1 = CtField.make("alice.datasegment.Receiver arg1 = ids.create(alice.datasegment.CommandType.PEEK);", tep); - //tep.addField(f1); - CtField f1 = new CtField(rec,"arg1",tep); - tep.addField(f1,"ids.create(alice.datasegment.CommandType.PEEK)"); + // ---- define Field ----- + //CtField f1 = CtField.make("alice.datasegment.Receiver arg1 = ids.create(alice.datasegment.CommandType.PEEK);", tep); + //tep.addField(f1); + CtField f1 = new CtField(rec,"arg1",tep); + tep.addField(f1,"ids.create(alice.datasegment.CommandType.PEEK)"); - // ---- define Constructor ----- - CtConstructor c = tep.getConstructor("()V"); - c.insertAfter("arg1.setKey(\"key1\");"); + // ---- define Constructor ----- + CtConstructor c = tep.getConstructor("()V"); + c.insertAfter("arg1.setKey(\"key1\");"); - // ---- define run ----- - CtMethod m = tep.getMethod("run", "()V"); - m.insertAfter("System.out.println(\"type = \" + arg1.type);"); - m.insertAfter("System.out.println(\"index = \" + arg1.index);"); - m.insertAfter("System.out.println(\"data = \" + arg1.getVal());"); - m.insertAfter("System.out.println(((org.msgpack.type.Value)arg1.getVal()).getType());"); - m.insertAfter("if (arg1.index==10){ System.exit(0);}"); - m.insertAfter("new alice.test.reflection.CSTemplate();"); - m.insertAfter("ods.update(\"key1\", \"String Data\");"); + // ---- define run ----- + CtMethod m = tep.getMethod("run", "()V"); + m.insertAfter("System.out.println(\"type = \" + arg1.type);"); + m.insertAfter("System.out.println(\"index = \" + arg1.index);"); + m.insertAfter("System.out.println(\"data = \" + arg1.getVal());"); + m.insertAfter("System.out.println(((org.msgpack.type.Value)arg1.getVal()).getType());"); + m.insertAfter("if (arg1.index==10){ System.exit(0);}"); + m.insertAfter("new alice.test.reflection.CSTemplate();"); + m.insertAfter("ods.update(\"key1\", \"String Data\");"); - Class<?> clazz = tep.toClass(); // load Class - @SuppressWarnings("unused") - CSTemplate cs = (CSTemplate)clazz.newInstance(); // create instance - - } + Class<?> clazz = tep.toClass(); // load Class + @SuppressWarnings("unused") + CSTemplate cs = (CSTemplate)clazz.newInstance(); // create instance + + } }