Getting ready for check for method annotations reflection
authorJaroslav Tulach <jaroslav.tulach@apidesign.org>
Wed, 05 Dec 2012 09:31:36 +0100
branchreflection
changeset 26520c55abd6748
parent 264 ed0c92c81ea4
child 266 2e2e6f946208
Getting ready for check for method annotations
vm/src/test/java/org/apidesign/vm4brwsr/ClassTest.java
vm/src/test/java/org/apidesign/vm4brwsr/Classes.java
     1.1 --- a/vm/src/test/java/org/apidesign/vm4brwsr/ClassTest.java	Wed Dec 05 09:28:31 2012 +0100
     1.2 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/ClassTest.java	Wed Dec 05 09:31:36 2012 +0100
     1.3 @@ -84,21 +84,21 @@
     1.4          assertExec("Check class annotation", Classes.class, "getNamer__Ljava_lang_String_2Z", "my text", false);
     1.5      }
     1.6      @Test public void javaInvokeMethod() throws Exception {
     1.7 -        assertEquals(Classes.reflectiveMethodCall(true), "java.io.IOException", "Calls the name() method via reflection");
     1.8 +        assertEquals(Classes.reflectiveMethodCall(true, "name"), "java.io.IOException", "Calls the name() method via reflection");
     1.9      }
    1.10      @Test public void jsInvokeMethod() throws Exception {
    1.11          assertExec("Calls the name() method via reflection", Classes.class, 
    1.12 -            "reflectiveMethodCall__Ljava_lang_Object_2Z", 
    1.13 -            "java.io.IOException", true
    1.14 +            "reflectiveMethodCall__Ljava_lang_Object_2ZLjava_lang_String_2", 
    1.15 +            "java.io.IOException", true, "name"
    1.16          );
    1.17      }
    1.18      @Test public void javaFindMethod() throws Exception {
    1.19 -        assertEquals(Classes.reflectiveMethodCall(false), "java.io.IOException", "Calls the name() method via reflection");
    1.20 +        assertEquals(Classes.reflectiveMethodCall(false, "name"), "java.io.IOException", "Calls the name() method via reflection");
    1.21      }
    1.22      @Test public void jsFindMethod() throws Exception {
    1.23          assertExec("Calls the name() method via reflection", Classes.class, 
    1.24 -            "reflectiveMethodCall__Ljava_lang_Object_2Z", 
    1.25 -            "java.io.IOException", false
    1.26 +            "reflectiveMethodCall__Ljava_lang_Object_2ZLjava_lang_String_2", 
    1.27 +            "java.io.IOException", false, "name"
    1.28          );
    1.29      }
    1.30      
     2.1 --- a/vm/src/test/java/org/apidesign/vm4brwsr/Classes.java	Wed Dec 05 09:28:31 2012 +0100
     2.2 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/Classes.java	Wed Dec 05 09:31:36 2012 +0100
     2.3 @@ -83,24 +83,27 @@
     2.4      @JavaScriptBody(args = "msg", body = "throw msg;")
     2.5      private static native void thrw(String msg);
     2.6      
     2.7 -    public static Object reflectiveMethodCall(boolean direct) throws Exception {
     2.8 +    public static Object reflectiveMethodCall(boolean direct, String mn) throws Exception {
     2.9          Method find = null;
    2.10          StringBuilder sb = new StringBuilder();
    2.11          if (!direct) {
    2.12              final Class<? extends Annotation> v = ClassesMarker.class;
    2.13              for (Method m : Classes.class.getMethods()) {
    2.14                  sb.append("\n").append(m.getName());
    2.15 -                if (m.getName().equals("name")) {
    2.16 -                    find = m;
    2.17 -                    break;
    2.18 +                if (mn != null) {
    2.19 +                    if (m.getName().equals(mn)) {
    2.20 +                        find = m;
    2.21 +                        break;
    2.22 +                    }
    2.23 +                } else {
    2.24 +                    if (m.getAnnotation(v) != null) {
    2.25 +                        find = m;
    2.26 +                        break;
    2.27 +                    }
    2.28                  }
    2.29 -//                if (single.getAnnotation(v) != null) {
    2.30 -//                    m = single;
    2.31 -//                    break;
    2.32 -//                }
    2.33              }
    2.34          } else {
    2.35 -            find = Classes.class.getMethod("name");
    2.36 +            find = Classes.class.getMethod(mn);
    2.37          }
    2.38          if (find == null) {
    2.39              thrw(sb.toString());