gil cattaneo created AUTOTAG-22:
-----------------------------------

             Summary: Port to Qdox 2.x
                 Key: AUTOTAG-22
                 URL: https://issues.apache.org/jira/browse/AUTOTAG-22
             Project: Tiles Autotag
          Issue Type: Improvement
            Reporter: gil cattaneo
            Priority: Minor


Hi
I wrote a small patch tile-autotag-core to use Qdox 2.x
any suggestion is appreciated
thanks in advance
regards

diff -Nru 
tiles-autotag-1.2/tiles-autotag-core/src/main/java/org/apache/tiles/autotag/core/QDoxTemplateSuiteFactory.java
 
tiles-autotag-1.2.qdox/tiles-autotag-core/src/main/java/org/apache/tiles/autotag/core/QDoxTemplateSuiteFactory.java
--- 
tiles-autotag-1.2/tiles-autotag-core/src/main/java/org/apache/tiles/autotag/core/QDoxTemplateSuiteFactory.java
      2016-07-16 10:35:22.000000000 +0200
+++ 
tiles-autotag-1.2.qdox/tiles-autotag-core/src/main/java/org/apache/tiles/autotag/core/QDoxTemplateSuiteFactory.java
 2016-11-23 17:35:48.472871076 +0100
@@ -23,6 +23,7 @@
 import java.io.File;
 import java.io.IOException;
 import java.net.URL;
+import java.nio.charset.Charset;
 import java.util.ArrayList;
 import java.util.List;
 
@@ -34,13 +35,12 @@
 import org.apache.tiles.autotag.model.TemplateSuite;
 import org.apache.tiles.autotag.model.TemplateSuiteFactory;
 
-import com.thoughtworks.qdox.JavaDocBuilder;
-import com.thoughtworks.qdox.model.Annotation;
+import com.thoughtworks.qdox.JavaProjectBuilder;
 import com.thoughtworks.qdox.model.DocletTag;
+import com.thoughtworks.qdox.model.JavaAnnotation;
 import com.thoughtworks.qdox.model.JavaClass;
 import com.thoughtworks.qdox.model.JavaMethod;
 import com.thoughtworks.qdox.model.JavaParameter;
-import com.thoughtworks.qdox.model.Type;
 
 /**
  * Creates a template suite using QDox.
@@ -57,7 +57,7 @@
     /**
      * The Javadoc builder.
      */
-    private JavaDocBuilder builder;
+    private JavaProjectBuilder builder;
 
     /**
      * The name of the suite.
@@ -80,7 +80,9 @@
      * @param sourceFiles All the source files to parse.
      */
     public QDoxTemplateSuiteFactory(File... sourceFiles) {
-        builder = new JavaDocBuilder();
+        builder = new JavaProjectBuilder();
+        // Avoid NullPointerException: charsetName
+        builder.setEncoding( Charset.defaultCharset().name() ); 
         try {
             for (File file : sourceFiles) {
                 builder.addSource(file);
@@ -97,7 +99,9 @@
      * @param urls All the URLs of source files to parse.
      */
     public QDoxTemplateSuiteFactory(URL... urls) {
-        builder = new JavaDocBuilder();
+        builder = new JavaProjectBuilder();
+        // Avoid NullPointerException: charsetName
+        builder.setEncoding( Charset.defaultCharset().name() ); 
         try {
             for (URL url : urls) {
                 builder.addSource(url);
@@ -193,18 +197,18 @@
             String exportedName = parameter.getName();
             boolean required = false;
             String defaultValue = null;
-            Annotation[] annotations = parameter.getAnnotations();
-            if (annotations != null && annotations.length > 0) {
+            List<JavaAnnotation> annotations = parameter.getAnnotations();
+            if (annotations != null) {
                 boolean found = false;
-                for (int i = 0; i < annotations.length && !found; i++) {
-                    if 
(Parameter.class.getName().equals(annotations[i].getType().getFullyQualifiedName()))
 {
+                for (JavaAnnotation annotation : annotations) {
+                    if 
(Parameter.class.getName().equals(annotation.getType().getFullyQualifiedName()))
 {
                         found = true;
-                        String candidateName = (String) 
annotations[i].getNamedParameter("name");
+                        String candidateName = 
annotation.getNamedParameter("name").toString();
                         if (candidateName != null && candidateName.length() > 
2) {
                             exportedName = candidateName.substring(1, 
candidateName.length() - 1);
                         }
-                        required = 
"true".equals(annotations[i].getNamedParameter("required"));
-                        candidateName = (String) 
annotations[i].getNamedParameter("defaultValue");
+                        required = 
"true".equals(annotation.getNamedParameter("required").toString());
+                        candidateName = 
annotation.getNamedParameter("defaultValue").toString();
                         if (candidateName != null && candidateName.length() > 
2) {
                             defaultValue = candidateName.substring(1, 
candidateName.length() - 1);
                         }
@@ -221,12 +225,12 @@
         TemplateMethod templateMethod = new TemplateMethod(method.getName(),
                 params);
         templateMethod.setDocumentation(method.getComment());
-        DocletTag[] tags = method.getTagsByName("param");
+        List<DocletTag> tags = method.getTagsByName("param");
         for (DocletTag tag : tags) {
-            String[] tagParams = tag.getParameters();
-            if (tagParams.length > 0) {
+            List<String> tagParams = tag.getParameters();
+            if (tagParams.size() > 0) {
                 TemplateParameter templateParameter = templateMethod
-                        .getParameterByName(tagParams[0]);
+                        .getParameterByName(tagParams.get(0));
                 if (templateParameter != null) {
                     String tagValue = tag.getValue();
                     int pos = tagValue.indexOf(" ");
@@ -245,22 +249,22 @@
      * @return <code>true</code> if it is an execute method.
      */
     private boolean isFeasible(JavaMethod method) {
-        Type returns = method.getReturns();
+        JavaClass returns = method.getReturns();
         if ("execute".equals(method.getName()) && returns != null
                 && "void".equals(returns.getFullyQualifiedName())
                 && method.isPublic() && !method.isStatic()
-                && !method.isAbstract() && !method.isConstructor()) {
-            JavaParameter[] params = method.getParameters();
-            if (params.length > 0) {
-                JavaParameter param = params[params.length - 1];
+                && !method.isAbstract()) {
+            List<JavaParameter> params = method.getParameters();
+            if (params.size() > 0) {
+                JavaParameter param = params.get(params.size() - 1);
                 if (requestClass.equals(
                         param.getType().getFullyQualifiedName())) {
                     return true;
                 }
             }
-            if (params.length >= 2) {
-                JavaParameter param1 = params[params.length - 2];
-                JavaParameter param2 = params[params.length - 1];
+            if (params.size() >= 2) {
+                JavaParameter param1 = params.get(params.size() - 2);
+                JavaParameter param2 = params.get(params.size() - 1);
                 if (requestClass.equals(
                         param1.getType().getFullyQualifiedName())
                         && ModelBody.class.getName().equals(
@@ -272,3 +276,4 @@
         return false;
     }
 }
+




--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to