This is an automated email from the ASF dual-hosted git repository.

jtulach pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-netbeans-html4j.git

commit a91992961d7c5751c40b7359b49ff1dc4b4bd569
Author: Jaroslav Tulach <jaroslav.tul...@apidesign.org>
AuthorDate: Tue Aug 14 11:13:57 2018 +0200

    #621: Cast arrays to (Object) to be treated as a single argument
---
 .../netbeans/html/json/impl/ModelProcessor.java    |  7 +++-
 .../test/java/net/java/html/json/VarArgTest.java   | 42 ++++++++++++++++++++++
 src/main/javadoc/overview.html                     |  2 ++
 3 files changed, 50 insertions(+), 1 deletion(-)

diff --git a/json/src/main/java/org/netbeans/html/json/impl/ModelProcessor.java 
b/json/src/main/java/org/netbeans/html/json/impl/ModelProcessor.java
index 9886955..d43eded 100644
--- a/json/src/main/java/org/netbeans/html/json/impl/ModelProcessor.java
+++ b/json/src/main/java/org/netbeans/html/json/impl/ModelProcessor.java
@@ -1115,6 +1115,7 @@ public final class ModelProcessor extends 
AbstractProcessor {
         List<? extends Element> enclosedElements,
         List<Object> functions
     ) {
+        final Types tu = processingEnv.getTypeUtils();
         boolean instance = clazz.getAnnotation(Model.class).instance();
         for (Element m : enclosedElements) {
             if (m.getKind() != ElementKind.METHOD) {
@@ -1158,7 +1159,11 @@ public final class ModelProcessor extends 
AbstractProcessor {
                             error("First parameter of @ModelOperation method 
must be " + className, m);
                             return false;
                         }
-                        args.add(ve.getSimpleName().toString());
+                        if (ve.asType().getKind() == TypeKind.ARRAY) {
+                            args.add("(Object) " + 
ve.getSimpleName().toString());
+                        } else {
+                            args.add(ve.getSimpleName().toString());
+                        }
                         body.append(sep).append("final ");
                         body.append(ve.asType().toString()).append(" ");
                         body.append(ve.toString());
diff --git a/json/src/test/java/net/java/html/json/VarArgTest.java 
b/json/src/test/java/net/java/html/json/VarArgTest.java
new file mode 100644
index 0000000..dcedb5b
--- /dev/null
+++ b/json/src/test/java/net/java/html/json/VarArgTest.java
@@ -0,0 +1,42 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package net.java.html.json;
+
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+@Model(className = "VarArg", instance = true, properties = {
+})
+public class VarArgTest {
+    @ModelOperation
+    void read(VarArg square, VarArgTest[] arr) {
+        Assert.assertNotNull(arr, "Array passed in");
+        Assert.assertEquals(arr.length, 1, "One slot ready");
+        arr[0] = this;
+    }
+
+    @Test
+    public void canReadThis() {
+        VarArgTest[] arr = { null };
+        VarArg model = new VarArg();
+        model.read(arr);
+        Assert.assertNotNull(arr[0]);
+    }
+}
diff --git a/src/main/javadoc/overview.html b/src/main/javadoc/overview.html
index fc858d0..8a94392 100644
--- a/src/main/javadoc/overview.html
+++ b/src/main/javadoc/overview.html
@@ -171,6 +171,8 @@ $ mvn -f client/pom.xml process-classes exec:exec
             {@link net.java.html.js.JavaScriptResource} annotation has been
             made repeatable -
             <a target="_blank" 
href="https://github.com/apache/incubator-netbeans-html4j/pull/4";>PR #4</a>.
+            <code>@Model</code> annotation processor bugfix 
+            <a target="_blank" 
href="https://issues.apache.org/jira/browse/NETBEANS-621";>#621</a>.
         </p>
 
         <h3>New in version 1.5.1</h3>


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@netbeans.apache.org
For additional commands, e-mail: commits-h...@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists

Reply via email to