Mercurial > hg > Database > Alice
changeset 634:69f9c5ff1df9
work reflection setKey, but not correct
author | Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 01 Dec 2017 21:34:22 +0900 |
parents | 746447b7c3e0 |
children | 0423eb7fd9ee |
files | src/main/java/alice/Annotation/AliceAnnotation.java src/main/java/alice/Annotation/AliceAnnotationTest.java src/main/java/alice/codesegment/CodeSegment.java |
diffstat | 3 files changed, 22 insertions(+), 52 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main/java/alice/Annotation/AliceAnnotation.java Fri Dec 01 01:10:03 2017 +0900 +++ b/src/main/java/alice/Annotation/AliceAnnotation.java Fri Dec 01 21:34:22 2017 +0900 @@ -20,10 +20,10 @@ //Receiver piyo = ids.create(CommandType.TAKE); @Take("hoge") - StringData stringData; + Receiver hoge; @Take("huga") - StringData stringData2; + Receiver huga; //@TakeRemote(dsm = "remote", key = "piyo") @@ -32,14 +32,15 @@ @Override public void run() { - System.out.println("in run!!!!"); + System.out.println("in run!"); + System.out.println(hoge.asClass(String.class)); + System.out.println(huga.asClass(String.class)); } public AliceAnnotation() { - //piyo.setKey("piyo"); - ods.put("hoge", 0); - ods.put("huga", 1); + ods.put("hoge", "hogehogehgoe"); + ods.put("huga", "hugahugahuga"); ods.put("piyo", "piyopiyo"); }
--- a/src/main/java/alice/Annotation/AliceAnnotationTest.java Fri Dec 01 01:10:03 2017 +0900 +++ b/src/main/java/alice/Annotation/AliceAnnotationTest.java Fri Dec 01 21:34:22 2017 +0900 @@ -15,9 +15,11 @@ */ public class AliceAnnotationTest { public static void main(String[] args){ - CreateCodeSegment createCodeSegment = new CreateCodeSegment(AliceAnnotation.class); - createCodeSegment.run(); - //AliceAnnotation alice = new AliceAnnotation(); + //CreateCodeSegment createCodeSegment = new CreateCodeSegment(AliceAnnotation.class); + //createCodeSegment.run(); + AliceAnnotation alice = new AliceAnnotation(); + //alice.ods.put("hoge", "hogehogehgoe"); + //alice.ods.put("huga", "hugahugahuga"); //AliceAnnotationTest aliceTest = new AliceAnnotationTest(); //aliceTest.test(alice); } @@ -25,15 +27,15 @@ public void test(AliceAnnotation alice){ Class<AliceAnnotation> aliceAnnotationClass = AliceAnnotation.class; - /*for (Field field : aliceAnnotationClass.getDeclaredFields()) { + for (Field field : aliceAnnotationClass.getDeclaredFields()) { if (field.isAnnotationPresent(Take.class)){ System.out.println(field.getName()); System.out.println(field.getType()); Take i = field.getAnnotation(Take.class); System.out.println(i.value()); - Receiver receiver = ids.create(CommandType.TAKE); + Receiver receiver = alice.ids.create(CommandType.TAKE); receiver.setKey(i.value()); } - }*/ + } } }
--- a/src/main/java/alice/codesegment/CodeSegment.java Fri Dec 01 01:10:03 2017 +0900 +++ b/src/main/java/alice/codesegment/CodeSegment.java Fri Dec 01 21:34:22 2017 +0900 @@ -19,7 +19,7 @@ private ArrayList<Receiver> list = new ArrayList<Receiver>(); private int priority = Thread.NORM_PRIORITY;//? - /*public CodeSegment(){ + public CodeSegment(){ for (Field field : this.getClass().getDeclaredFields()) { if (field.isAnnotationPresent(Take.class)){ System.out.println(field.getName()); @@ -27,52 +27,19 @@ Take ano = field.getAnnotation(Take.class); System.out.println(ano.value()); - Receiver receiver; - try { - receiver = (Receiver) field.get(this); - } catch (IllegalAccessException e) { - e.printStackTrace(); - } + field.setAccessible(true); + + Receiver receiver = ids.create(CommandType.TAKE);; + receiver.setKey(ano.value()); try { - field.set(this, ids.create(CommandType.TAKE)); + field.set(this, receiver); } catch (IllegalAccessException e) { e.printStackTrace(); } - - //Receiver receiver = new Receiver(ids, CommandType.TAKE); - //receiver.setKey(ano.value()); - - - ClassPool cp = ClassPool.getDefault(); - try { - CtClass cc = cp.get(this.getClass().getName()); - - try { - CtField cf = CtField.make("public alice.datasegment.Receiver " + ano.value() + " = ids.create(CommandType.TAKE);",cc); - cc.addField(cf); - CtConstructor[] ctConstructors = cc.getConstructors(); - ctConstructors[0].setBody(ano.value() + ".setKey(\"" +ano.value() + "\");"); - cc.setModifiers(cc.getModifiers()); - } catch (CannotCompileException e) { - e.printStackTrace(); - } - - try { - Class c = cc.toClass(ClassLoader.getSystemClassLoader(), Sample.class.getProtectionDomain()); - //c.newInstance(); - } catch (CannotCompileException e) { - e.printStackTrace(); - } - - } catch (NotFoundException e) { - e.printStackTrace(); - } - - } } - }*/ + } public void execute() { ids.receive();