Cannot use JavaScriptResource with JavaScriptBody
authorJaroslav Tulach <jaroslav.tulach@netbeans.org>
Thu, 06 Feb 2014 09:44:06 +0100
changeset 531ff48a4a875ff
parent 530 ce0da3e90343
child 532 a9c8a1223895
Cannot use JavaScriptResource with JavaScriptBody
boot/src/main/java/org/netbeans/html/boot/impl/JavaScriptProcesor.java
boot/src/test/java/org/netbeans/html/boot/impl/Compile.java
boot/src/test/java/org/netbeans/html/boot/impl/JavaScriptProcesorTest.java
     1.1 --- a/boot/src/main/java/org/netbeans/html/boot/impl/JavaScriptProcesor.java	Thu Feb 06 09:28:25 2014 +0100
     1.2 +++ b/boot/src/main/java/org/netbeans/html/boot/impl/JavaScriptProcesor.java	Thu Feb 06 09:44:06 2014 +0100
     1.3 @@ -164,6 +164,22 @@
     1.4                      msg.printMessage(Diagnostic.Kind.ERROR, "Cannot find " + res + " in " + res + " package", e);
     1.5                  }
     1.6              }
     1.7 +            
     1.8 +            boolean found = false;
     1.9 +            for (Element mthod : e.getEnclosedElements()) {
    1.10 +                if (mthod.getKind() != ElementKind.METHOD) {
    1.11 +                    continue;
    1.12 +                }
    1.13 +                if (mthod.getAnnotation(JavaScriptBody.class) != null) {
    1.14 +                    found = true;
    1.15 +                    break;
    1.16 +                }
    1.17 +            }
    1.18 +            if (!found) {
    1.19 +                msg.printMessage(Diagnostic.Kind.ERROR, "At least one method needs @JavaScriptBody annotation. "
    1.20 +                    + "Otherwise it is not guaranteed the resource will ever be loaded,", e
    1.21 +                );
    1.22 +            }
    1.23          }
    1.24  
    1.25          if (roundEnv.processingOver()) {
     2.1 --- a/boot/src/test/java/org/netbeans/html/boot/impl/Compile.java	Thu Feb 06 09:28:25 2014 +0100
     2.2 +++ b/boot/src/test/java/org/netbeans/html/boot/impl/Compile.java	Thu Feb 06 09:44:06 2014 +0100
     2.3 @@ -198,6 +198,9 @@
     2.4                      if (packageName.equals(pkg)) {
     2.5                          return htmlFile;
     2.6                      }
     2.7 +                    if (packageName.isEmpty() && relativeName.startsWith(pkg.replace('.', '/'))) {
     2.8 +                        return htmlFile;
     2.9 +                    }
    2.10                  }
    2.11                  
    2.12                  return null;
     3.1 --- a/boot/src/test/java/org/netbeans/html/boot/impl/JavaScriptProcesorTest.java	Thu Feb 06 09:28:25 2014 +0100
     3.2 +++ b/boot/src/test/java/org/netbeans/html/boot/impl/JavaScriptProcesorTest.java	Thu Feb 06 09:44:06 2014 +0100
     3.3 @@ -113,6 +113,19 @@
     3.4          Compile c = Compile.create("", code);
     3.5          c.assertNoErrors();
     3.6      }
     3.7 +
     3.8 +    @Test public void needJavaScriptBodyToUseResource() throws IOException {
     3.9 +        String code = "package x.y.z;\n"
    3.10 +            + "import net.java.html.js.JavaScriptResource;\n"
    3.11 +            + "@JavaScriptResource(\"x.html\")\n"
    3.12 +            + "class X {\n"
    3.13 +            + "  private static native void callback(Runnable r);\n"
    3.14 +            + "}\n";
    3.15 +        
    3.16 +        Compile c = Compile.create("", code);
    3.17 +        c.assertErrors();
    3.18 +        c.assertError("needs @JavaScriptBody");
    3.19 +    }
    3.20      
    3.21      @Test public void generatesCallbacksThatReturnObject() throws Exception {
    3.22          Class<?> callbacksForTestPkg = Class.forName("org.netbeans.html.boot.impl.$JsCallbacks$");