#249690: Use getQualifiedName rather than getBinaryName to avoid obtaining $ for innerclasses
Task #249690 - No error on wrong types in @Model on innerclass
1.1 --- a/json/src/main/java/org/netbeans/html/json/impl/ModelProcessor.java Sat Jan 03 06:19:09 2015 +0100
1.2 +++ b/json/src/main/java/org/netbeans/html/json/impl/ModelProcessor.java Tue Jan 13 16:41:10 2015 +0100
1.3 @@ -131,7 +131,7 @@
1.4 models.clear();
1.5 for (Map.Entry<Element, Prprt[]> entry : verify.entrySet()) {
1.6 TypeElement te = (TypeElement)entry.getKey();
1.7 - String fqn = processingEnv.getElementUtils().getBinaryName(te).toString();
1.8 + String fqn = te.getQualifiedName().toString();
1.9 Element finalElem = processingEnv.getElementUtils().getTypeElement(fqn);
1.10 if (finalElem == null) {
1.11 continue;
2.1 --- a/json/src/test/java/net/java/html/json/ModelProcessorTest.java Sat Jan 03 06:19:09 2015 +0100
2.2 +++ b/json/src/test/java/net/java/html/json/ModelProcessorTest.java Tue Jan 13 16:41:10 2015 +0100
2.3 @@ -82,6 +82,36 @@
2.4 }
2.5 }
2.6
2.7 + @Test public void verifyWrongTypeInInnerClass() 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 + + "class X {\n"
2.14 + + " @Model(className=\"XModel\", properties={\n"
2.15 + + " @Property(name=\"prop\", type=Runnable.class)\n"
2.16 + + " })\n"
2.17 + + " static class Inner {\n"
2.18 + + " }\n"
2.19 + + "}\n";
2.20 +
2.21 + Compile c = Compile.create(html, code);
2.22 + assertFalse(c.getErrors().isEmpty(), "One error: " + c.getErrors());
2.23 + boolean ok = false;
2.24 + StringBuilder msgs = new StringBuilder();
2.25 + for (Diagnostic<? extends JavaFileObject> e : c.getErrors()) {
2.26 + String msg = e.getMessage(Locale.ENGLISH);
2.27 + if (msg.contains("Runnable")) {
2.28 + ok = true;
2.29 + }
2.30 + msgs.append("\n").append(msg);
2.31 + }
2.32 + if (!ok) {
2.33 + fail("Should contain warning about Runnable:" + msgs);
2.34 + }
2.35 + }
2.36 +
2.37 @Test public void warnOnNonStatic() throws IOException {
2.38 String html = "<html><body>"
2.39 + "</body></html>";