# HG changeset patch # User Nozomi Teruya # Date 1511970202 -32400 # Node ID 77adeb85c4d028e69bc278c55d8327b678a45c93 # Parent d0d1cd3dfc11f83f071f85fefe2700253d4f919b add Annotation diff -r d0d1cd3dfc11 -r 77adeb85c4d0 src/main/java/alice/Annotation/AliceAnnotation.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/Annotation/AliceAnnotation.java Thu Nov 30 00:43:22 2017 +0900 @@ -0,0 +1,56 @@ +package alice.Annotation; + +import alice.codesegment.CodeSegment; +import alice.datasegment.CommandType; +import alice.datasegment.Receiver; +import com.sun.org.apache.bcel.internal.classfile.Code; + +import java.awt.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; + +import static javafx.scene.input.KeyCode.T; + +/** + * Created by e125769 on 10/15/17. + */ +public class AliceAnnotation extends CodeSegment{ + + //Receiver piyo = ids.create(CommandType.TAKE); + + @Take("hoge") + StringData stringData; + + @Take("huga") + StringData stringData2; + + //@TakeRemote(dsm = "remote", key = "piyo") + + public class StringData{public String[] data = {"hoge", "huga", "piyo"};} + + + @Override + public void run() { + System.out.println("in run!!!!"); + } + + + public AliceAnnotation() { + //piyo.setKey("piyo"); + ods.put("hoge", 0); + ods.put("huga", 1); + ods.put("piyo", "piyopiyo"); + } + + public static void main(String[] args){ + AliceAnnotation alice = new AliceAnnotation(); + alice.test(); + } + + public void test(){ + + } + +} + diff -r d0d1cd3dfc11 -r 77adeb85c4d0 src/main/java/alice/Annotation/AliceAnnotationTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/Annotation/AliceAnnotationTest.java Thu Nov 30 00:43:22 2017 +0900 @@ -0,0 +1,36 @@ +package alice.Annotation; + +import alice.codesegment.InputDataSegment; +import alice.datasegment.CommandType; +import alice.datasegment.Receiver; + +import java.lang.annotation.Annotation; +import java.lang.reflect.Field; +import java.lang.reflect.Array; +import java.lang.reflect.Method; + +/** + * Created by e125769 on 11/14/17. + */ +public class AliceAnnotationTest { + public static void main(String[] args){ + AliceAnnotation alice = new AliceAnnotation(); + AliceAnnotationTest aliceTest = new AliceAnnotationTest(); + aliceTest.test(alice); + } + + public void test(AliceAnnotation alice){ + Class aliceAnnotationClass = AliceAnnotation.class; + + /*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.setKey(i.value()); + } + }*/ + } +} diff -r d0d1cd3dfc11 -r 77adeb85c4d0 src/main/java/alice/Annotation/CS.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/Annotation/CS.java Thu Nov 30 00:43:22 2017 +0900 @@ -0,0 +1,30 @@ +package alice.Annotation; + +import alice.codesegment.InputDataSegment; +import alice.datasegment.CommandType; +import alice.datasegment.Receiver; + +import java.util.ArrayList; + +/** + * Created by e125769 on 11/19/17. + */ +public abstract class CS { + + public ArrayList input = new ArrayList(); + public Receiver[] receivers; + public InputDataSegment ids; + + public void setInput(String[] datas){ + System.out.println("in CS!!"); + receivers = new Receiver[datas.length]; + for(int i = 0; i < datas.length; i++){ + receivers[i] = ids.create(CommandType.TAKE); + receivers[i].setKey(datas[i]); + } + } + + public void setInput(ArrayList input) { + this.input = input; + } +} diff -r d0d1cd3dfc11 -r 77adeb85c4d0 src/main/java/alice/Annotation/InputData.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/Annotation/InputData.java Thu Nov 30 00:43:22 2017 +0900 @@ -0,0 +1,19 @@ +package alice.Annotation; + +/** + * Created by e125769 on 11/15/17. + */ +public class InputData { + + private T value; + private String key; + + public InputData(T value){ + this.value = value; + } + + public T getValue() { + return value; + } + +} diff -r d0d1cd3dfc11 -r 77adeb85c4d0 src/main/java/alice/Annotation/InputProcesser.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/Annotation/InputProcesser.java Thu Nov 30 00:43:22 2017 +0900 @@ -0,0 +1,30 @@ +package alice.Annotation; + + +import javax.annotation.processing.*; +import javax.lang.model.SourceVersion; +import javax.lang.model.element.Element; +import javax.lang.model.element.TypeElement; +import javax.tools.Diagnostic.Kind; +import java.util.Set; + +/** + * Created by e125769 on 10/16/17. + */ +@SupportedAnnotationTypes("alice.Annotation.Input") +public class InputProcesser extends AbstractProcessor { + + @Override + public boolean process(Set typeElements, RoundEnvironment roundEnv) { + + /*for (TypeElement typeElement : typeElements) { + Set elements = roundEnv.getElementsAnnotatedWith(typeElement); + for (Element element : elements) { + Input in = element.getAnnotation(Input.class); + System.out. println("@input" + in.input()); + } + }*/ + + return true; + } +} \ No newline at end of file diff -r d0d1cd3dfc11 -r 77adeb85c4d0 src/main/java/alice/Annotation/Take.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/Annotation/Take.java Thu Nov 30 00:43:22 2017 +0900 @@ -0,0 +1,15 @@ +package alice.Annotation; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import static java.lang.annotation.ElementType.*; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +@Target(ElementType.FIELD) +@Retention(RetentionPolicy.RUNTIME) +public @interface Take { + String value(); +} \ No newline at end of file diff -r d0d1cd3dfc11 -r 77adeb85c4d0 src/main/java/alice/Annotation/TakeRemote.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/Annotation/TakeRemote.java Thu Nov 30 00:43:22 2017 +0900 @@ -0,0 +1,17 @@ +package alice.Annotation; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; +import java.lang.reflect.Type; + +/** + * Created by e125769 on 11/15/17. + */ +@Target(ElementType.FIELD) +@Retention(RetentionPolicy.RUNTIME) +public @interface TakeRemote { + String dsm(); + String key(); +} diff -r d0d1cd3dfc11 -r 77adeb85c4d0 src/main/java/alice/codesegment/CodeSegment.java --- a/src/main/java/alice/codesegment/CodeSegment.java Thu Sep 14 20:04:48 2017 +0900 +++ b/src/main/java/alice/codesegment/CodeSegment.java Thu Nov 30 00:43:22 2017 +0900 @@ -1,9 +1,16 @@ package alice.codesegment; +import java.io.IOException; +import java.lang.reflect.*; import java.util.ArrayList; +import alice.Annotation.Take; import alice.codesegment.InputDataSegment; +import alice.datasegment.CommandType; import alice.datasegment.Receiver; +import javassist.*; +import javassist.tools.reflect.Sample; +import sun.jvm.hotspot.oops.Instance; public abstract class CodeSegment implements Runnable { @@ -12,6 +19,47 @@ private ArrayList list = new ArrayList(); private int priority = Thread.NORM_PRIORITY;//? + public CodeSegment(){ + for (Field field : this.getClass().getDeclaredFields()) { + if (field.isAnnotationPresent(Take.class)){ + System.out.println(field.getName()); + System.out.println(field.getType()); + Take ano = field.getAnnotation(Take.class); + System.out.println(ano.value()); + + //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("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(); } @@ -36,4 +84,5 @@ public void setPriority(int priority) { this.priority = priority; } -} + +} \ No newline at end of file