diff -r d0013f44e9b1 -r 2e2e6f946208 emul/src/main/java/org/apidesign/bck2brwsr/emul/AnnotationImpl.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/emul/src/main/java/org/apidesign/bck2brwsr/emul/AnnotationImpl.java Wed Dec 05 10:03:58 2012 +0100 @@ -0,0 +1,68 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package org.apidesign.bck2brwsr.emul; + +import java.lang.annotation.Annotation; +import org.apidesign.bck2brwsr.core.JavaScriptBody; + +/** + * + * @author Jaroslav Tulach + */ +public final class AnnotationImpl implements Annotation { + public Class annotationType() { + return getClass(); + } + + @JavaScriptBody(args = { "a", "n", "values" }, body = "" + + "function f(v, p) {\n" + + " var val = v;\n" + + " var prop = p;\n" + + " return function() {\n" + + " return val[prop];\n" + + " };\n" + + "}\n" + + "var props = Object.getOwnPropertyNames(values);\n" + + "for (var i = 0; i < props.length; i++) {\n" + + " var p = props[i];\n" + + " a[p] = new f(values, p);\n" + + "}\n" + + "a['$instOf_' + n] = true;\n" + + "return a;" + ) + private static T create(AnnotationImpl a, String n, Object values) { + return null; + } + public static T create(Class annoClass, Object values) { + return create(new AnnotationImpl(), annoClass.getName().replace('.', '_'), values); + } + + public static Annotation[] create(Object anno) { + String[] names = findNames(anno); + Annotation[] ret = new Annotation[names.length]; + for (int i = 0; i < names.length; i++) { + String n = names[i].substring(1, names[i].length() - 1).replace('/', '_'); + ret[i] = create(new AnnotationImpl(), n, findData(anno, names[i])); + } + return ret; + } + @JavaScriptBody(args = "anno", body = + "var arr = new Array();" + + "var props = Object.getOwnPropertyNames(anno);\n" + + "for (var i = 0; i < props.length; i++) {\n" + + " var p = props[i];\n" + + " arr.push(p);" + + "}" + + "return arr;" + ) + private static String[] findNames(Object anno) { + throw new UnsupportedOperationException(); + } + + @JavaScriptBody(args={ "anno", "p"}, body="return anno[p];") + private static Object findData(Object anno, String p) { + throw new UnsupportedOperationException(); + } +}