Return type of @ComputedProperty's write method has to be void
authorJaroslav Tulach <jtulach@netbeans.org>
Sun, 02 Aug 2015 10:03:54 +0200
changeset 9558e0439c4cc72
parent 954 95755c3c836b
child 956 3e051dd888c4
Return type of @ComputedProperty's write method has to be void
json/src/main/java/org/netbeans/html/json/impl/ModelProcessor.java
json/src/test/java/net/java/html/json/ModelProcessorTest.java
     1.1 --- a/json/src/main/java/org/netbeans/html/json/impl/ModelProcessor.java	Sun Aug 02 09:59:37 2015 +0200
     1.2 +++ b/json/src/main/java/org/netbeans/html/json/impl/ModelProcessor.java	Sun Aug 02 10:03:54 2015 +0200
     1.3 @@ -2062,6 +2062,11 @@
     1.4                  continue;
     1.5              }
     1.6              ExecutableElement ee = (ExecutableElement) e;
     1.7 +            if (ee.getReturnType().getKind() != TypeKind.VOID) {
     1.8 +                computedPropElem = (ExecutableElement) e;
     1.9 +                err = "Write method has to return void";
    1.10 +                continue;
    1.11 +            }
    1.12              TypeMirror retType = computedPropElem.getReturnType();
    1.13              final List<? extends VariableElement> params = ee.getParameters();
    1.14              boolean error = false;
     2.1 --- a/json/src/test/java/net/java/html/json/ModelProcessorTest.java	Sun Aug 02 09:59:37 2015 +0200
     2.2 +++ b/json/src/test/java/net/java/html/json/ModelProcessorTest.java	Sun Aug 02 10:03:54 2015 +0200
     2.3 @@ -210,6 +210,40 @@
     2.4          }
     2.5      }
     2.6  
     2.7 +    @Test public void writeableComputedPropertyReturnsVoid() throws IOException {
     2.8 +        String html = "<html><body>"
     2.9 +            + "</body></html>";
    2.10 +        String code = "package x.y.z;\n"
    2.11 +            + "import net.java.html.json.Model;\n"
    2.12 +            + "import net.java.html.json.Property;\n"
    2.13 +            + "import net.java.html.json.ComputedProperty;\n"
    2.14 +            + "@Model(className=\"XModel\", properties={\n"
    2.15 +            + "  @Property(name=\"prop\", type=int.class)\n"
    2.16 +            + "})\n"
    2.17 +            + "class X {\n"
    2.18 +            + "    static @ComputedProperty(write=\"setY\") int y(int prop) {\n"
    2.19 +            + "        return prop;\n"
    2.20 +            + "    }\n"
    2.21 +            + "    static Number setY(XModel model, int prop) {\n"
    2.22 +            + "    }\n"
    2.23 +            + "}\n";
    2.24 +
    2.25 +        Compile c = Compile.create(html, code);
    2.26 +        assertFalse(c.getErrors().isEmpty(), "One error: " + c.getErrors());
    2.27 +        boolean ok = false;
    2.28 +        StringBuilder msgs = new StringBuilder();
    2.29 +        for (Diagnostic<? extends JavaFileObject> e : c.getErrors()) {
    2.30 +            String msg = e.getMessage(Locale.ENGLISH);
    2.31 +            if (msg.contains("Write method has to return void")) {
    2.32 +                ok = true;
    2.33 +            }
    2.34 +            msgs.append("\n").append(msg);
    2.35 +        }
    2.36 +        if (!ok) {
    2.37 +            fail("Should contain warning about non-static method:" + msgs);
    2.38 +        }
    2.39 +    }
    2.40 +
    2.41      @Test public void computedCantReturnVoid() throws IOException {
    2.42          String html = "<html><body>"
    2.43              + "</body></html>";