Mercurial > hg > Database > Alice
changeset 635:0423eb7fd9ee
work create Receiver from Annotation.
Please invoke setKey after create all Receiver.
author | Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp> |
---|---|
date | Sun, 03 Dec 2017 00:09:04 +0900 |
parents | 69f9c5ff1df9 |
children | 33f300d0720a |
files | src/main/java/alice/Annotation/AliceAnnotationTest.java src/main/java/alice/codesegment/CodeSegment.java |
diffstat | 2 files changed, 19 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main/java/alice/Annotation/AliceAnnotationTest.java Fri Dec 01 21:34:22 2017 +0900 +++ b/src/main/java/alice/Annotation/AliceAnnotationTest.java Sun Dec 03 00:09:04 2017 +0900 @@ -20,8 +20,6 @@ AliceAnnotation alice = new AliceAnnotation(); //alice.ods.put("hoge", "hogehogehgoe"); //alice.ods.put("huga", "hugahugahuga"); - //AliceAnnotationTest aliceTest = new AliceAnnotationTest(); - //aliceTest.test(alice); } public void test(AliceAnnotation alice){
--- a/src/main/java/alice/codesegment/CodeSegment.java Fri Dec 01 21:34:22 2017 +0900 +++ b/src/main/java/alice/codesegment/CodeSegment.java Sun Dec 03 00:09:04 2017 +0900 @@ -17,28 +17,41 @@ public InputDataSegment ids = new InputDataSegment(this); public OutputDataSegment ods = new OutputDataSegment(); private ArrayList<Receiver> list = new ArrayList<Receiver>(); + private ArrayList<Receiver> metaReceivers = new ArrayList<Receiver>(); private int priority = Thread.NORM_PRIORITY;//? public CodeSegment(){ + createReceiver(); + setKey(); + } + + public void createReceiver(){ for (Field field : this.getClass().getDeclaredFields()) { if (field.isAnnotationPresent(Take.class)){ - System.out.println(field.getName()); - System.out.println(field.getType()); + metaReceivers.add(ids.create(CommandType.TAKE)); + } + } + } + + public void setKey(){ + int i = 0; + for (Field field : this.getClass().getDeclaredFields()) { + if (field.isAnnotationPresent(Take.class)){ Take ano = field.getAnnotation(Take.class); - System.out.println(ano.value()); field.setAccessible(true); - Receiver receiver = ids.create(CommandType.TAKE);; - receiver.setKey(ano.value()); + metaReceivers.get(i).setKey(ano.value()); try { - field.set(this, receiver); + field.set(this, metaReceivers.get(i)); + i++; } catch (IllegalAccessException e) { e.printStackTrace(); } } } + } public void execute() {