Using the attribute type to in the attribute method name reflection
authorJaroslav Tulach <jaroslav.tulach@apidesign.org>
Sun, 02 Dec 2012 12:39:51 +0100
branchreflection
changeset 236d97770281580
parent 235 bf0a77f029c4
child 237 84ffc347412d
Using the attribute type to in the attribute method name
emul/src/main/java/java/lang/AnnotationImpl.java
javap/src/main/java/org/apidesign/javap/AnnotationParser.java
vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeToJavaScript.java
     1.1 --- a/emul/src/main/java/java/lang/AnnotationImpl.java	Sun Dec 02 12:26:14 2012 +0100
     1.2 +++ b/emul/src/main/java/java/lang/AnnotationImpl.java	Sun Dec 02 12:39:51 2012 +0100
     1.3 @@ -19,7 +19,7 @@
     1.4      @JavaScriptBody(args = { "a", "n", "values" }, body =
     1.5            "var v = values;"
     1.6          + "for (p in values) {"
     1.7 -        + "  a[p + 'I'] = function() { return v[p]; }"
     1.8 +        + "  a[p] = function() { return v[p]; }"
     1.9          + "}"
    1.10          + "a['$instOf_' + n] = true;"
    1.11          + "return a;"
     2.1 --- a/javap/src/main/java/org/apidesign/javap/AnnotationParser.java	Sun Dec 02 12:26:14 2012 +0100
     2.2 +++ b/javap/src/main/java/org/apidesign/javap/AnnotationParser.java	Sun Dec 02 12:39:51 2012 +0100
     2.3 @@ -44,7 +44,7 @@
     2.4      }
     2.5      
     2.6      protected void visitAttr(
     2.7 -        String type, String attr, String value
     2.8 +        String annoType, String attr, String attrType, String value
     2.9      ) throws IOException {
    2.10      }
    2.11      
    2.12 @@ -90,7 +90,13 @@
    2.13              readAnno(dis, cd);
    2.14          } else if ("CFJZsSIDB".indexOf(type) >= 0) { // NOI18N
    2.15              int primitive = dis.readUnsignedShort();
    2.16 -            visitAttr(typeName, attrName, cd.StringValue(primitive));
    2.17 +            String attrType;
    2.18 +            if (type == 's') {
    2.19 +                attrType = "Ljava_lang_String";
    2.20 +            } else {
    2.21 +                attrType = "" + type;
    2.22 +            }
    2.23 +            visitAttr(typeName, attrName, attrType, cd.StringValue(primitive));
    2.24          } else if (type == 'c') {
    2.25              int cls = dis.readUnsignedShort();
    2.26          } else if (type == '[') {
     3.1 --- a/vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeToJavaScript.java	Sun Dec 02 12:26:14 2012 +0100
     3.2 +++ b/vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeToJavaScript.java	Sun Dec 02 12:39:51 2012 +0100
     3.3 @@ -999,7 +999,7 @@
     3.4              String body;
     3.5              
     3.6              @Override
     3.7 -            protected void visitAttr(String type, String attr, String value) {
     3.8 +            protected void visitAttr(String type, String attr, String at, String value) {
     3.9                  if (type.equals(jvmType)) {
    3.10                      if ("body".equals(attr)) {
    3.11                          body = value;
    3.12 @@ -1057,7 +1057,7 @@
    3.13          final String jvmType = "L" + className.replace('.', '/') + ";";
    3.14          AnnotationParser ap = new AnnotationParser() {
    3.15              @Override
    3.16 -            protected void visitAttr(String type, String attr, String value) {
    3.17 +            protected void visitAttr(String type, String attr, String at, String value) {
    3.18                  if (type.equals(jvmType)) {
    3.19                      found[0] = true;
    3.20                      for (int i = 0; i < attrNames.length; i++) {
    3.21 @@ -1108,12 +1108,12 @@
    3.22              }
    3.23              
    3.24              @Override
    3.25 -            protected void visitAttr(String type, String attr, String value) 
    3.26 +            protected void visitAttr(String type, String attr, String attrType, String value) 
    3.27              throws IOException {
    3.28                  if (cnt++ > 0) {
    3.29                      out.append(",\n");
    3.30                  }
    3.31 -                out.append(attr).append(" : ").append(value);
    3.32 +                out.append(attr).append(attrType).append(" : ").append(value);
    3.33              }
    3.34          };
    3.35          ap.parse(data, cd);