6bc20a
From 6d7da5456a7458a249bed9c4c1e768cc7cc2fe40 Mon Sep 17 00:00:00 2001
6bc20a
From: Michael Simacek <msimacek@redhat.com>
6bc20a
Date: Wed, 1 Feb 2017 12:57:14 +0100
6bc20a
Subject: [PATCH] Port to qdox 2.0
6bc20a
6bc20a
---
6bc20a
 .../src/main/java/org/hamcrest/generator/QDox.java |  4 ++--
6bc20a
 .../org/hamcrest/generator/QDoxFactoryReader.java  | 26 ++++++++++++----------
6bc20a
 2 files changed, 16 insertions(+), 14 deletions(-)
6bc20a
6bc20a
diff --git a/hamcrest-generator/src/main/java/org/hamcrest/generator/QDox.java b/hamcrest-generator/src/main/java/org/hamcrest/generator/QDox.java
6bc20a
index efaf615..338178d 100644
6bc20a
--- a/hamcrest-generator/src/main/java/org/hamcrest/generator/QDox.java
6bc20a
+++ b/hamcrest-generator/src/main/java/org/hamcrest/generator/QDox.java
6bc20a
@@ -1,6 +1,6 @@
6bc20a
 package org.hamcrest.generator;
6bc20a
 
6bc20a
-import com.thoughtworks.qdox.JavaDocBuilder;
6bc20a
+import com.thoughtworks.qdox.JavaProjectBuilder;
6bc20a
 import com.thoughtworks.qdox.model.JavaClass;
6bc20a
 
6bc20a
 import java.io.File;
6bc20a
@@ -16,7 +16,7 @@ import java.io.Reader;
6bc20a
  */
6bc20a
 public class QDox {
6bc20a
 
6bc20a
-    private final JavaDocBuilder javaDocBuilder = new JavaDocBuilder();
6bc20a
+    private final JavaProjectBuilder javaDocBuilder = new JavaProjectBuilder();
6bc20a
 
6bc20a
     public void addSourceTree(File sourceDir) {
6bc20a
         javaDocBuilder.addSourceTree(sourceDir);
6bc20a
diff --git a/hamcrest-generator/src/main/java/org/hamcrest/generator/QDoxFactoryReader.java b/hamcrest-generator/src/main/java/org/hamcrest/generator/QDoxFactoryReader.java
6bc20a
index 5108140..97fce01 100644
6bc20a
--- a/hamcrest-generator/src/main/java/org/hamcrest/generator/QDoxFactoryReader.java
6bc20a
+++ b/hamcrest-generator/src/main/java/org/hamcrest/generator/QDoxFactoryReader.java
6bc20a
@@ -4,8 +4,10 @@ import com.thoughtworks.qdox.model.DocletTag;
6bc20a
 import com.thoughtworks.qdox.model.JavaClass;
6bc20a
 import com.thoughtworks.qdox.model.JavaMethod;
6bc20a
 import com.thoughtworks.qdox.model.JavaParameter;
6bc20a
-import com.thoughtworks.qdox.model.Type;
6bc20a
+import com.thoughtworks.qdox.model.JavaType;
6bc20a
+import com.thoughtworks.qdox.model.impl.DefaultJavaClass;
6bc20a
 
6bc20a
+import java.util.ArrayList;
6bc20a
 import java.util.Iterator;
6bc20a
 import java.util.List;
6bc20a
 import java.util.regex.Pattern;
6bc20a
@@ -56,15 +58,15 @@ public class QDoxFactoryReader implements Iterable<FactoryMethod> {
6bc20a
         JavaMethod methodSource = findMethodInSource(factoryMethod);
6bc20a
         if (methodSource != null) {
6bc20a
             factoryMethod.setJavaDoc(createJavaDocComment(methodSource));
6bc20a
-            JavaParameter[] parametersFromSource
6bc20a
+            List<JavaParameter> parametersFromSource
6bc20a
                     = methodSource.getParameters();
6bc20a
             List<FactoryMethod.Parameter> parametersFromReflection
6bc20a
                     = factoryMethod.getParameters();
6bc20a
 
6bc20a
-            if (parametersFromReflection.size() == parametersFromSource.length) {
6bc20a
-                for (int i = 0; i < parametersFromSource.length; i++) {
6bc20a
+            if (parametersFromReflection.size() == parametersFromSource.size()) {
6bc20a
+                for (int i = 0; i < parametersFromSource.size(); i++) {
6bc20a
                     parametersFromReflection.get(i).setName(
6bc20a
-                            parametersFromSource[i].getName());
6bc20a
+                            parametersFromSource.get(i).getName());
6bc20a
                 }
6bc20a
             }
6bc20a
         }
6bc20a
@@ -79,18 +81,18 @@ public class QDoxFactoryReader implements Iterable<FactoryMethod> {
6bc20a
         // Note, this doesn't always work - it struggles with some kinds of generics.
6bc20a
         // This seems to cover most cases though.
6bc20a
         List<FactoryMethod.Parameter> params = factoryMethod.getParameters();
6bc20a
-        Type[] types = new Type[params.size()];
6bc20a
+        List<JavaType> types = new ArrayList<JavaType>(params.size());
6bc20a
         boolean varArgs = false;
6bc20a
-        for (int i = 0; i < types.length; i++) {
6bc20a
+        for (int i = 0; i < params.size(); i++) {
6bc20a
             String type = params.get(i).getType();
6bc20a
             varArgs = VARARGS_REGEX.matcher(type).find();
6bc20a
             // QDox ignores varargs and generics, so we strip them out to help QDox.
6bc20a
             type = GENERIC_REGEX.matcher(type).replaceAll("");
6bc20a
             type = VARARGS_REGEX.matcher(type).replaceAll("");
6bc20a
-            types[i] = new Type(type);
6bc20a
+            types.add(new DefaultJavaClass(type));
6bc20a
         }
6bc20a
-        JavaMethod[] methods = classSource.getMethodsBySignature(factoryMethod.getName(), types, false, varArgs);
6bc20a
-        return methods.length == 1 ?  methods[0] : null;
6bc20a
+        List<JavaMethod> methods = classSource.getMethodsBySignature(factoryMethod.getName(), types, false, varArgs);
6bc20a
+        return methods.size() == 1 ?  methods.get(0) : null;
6bc20a
     }
6bc20a
 
6bc20a
     /**
6bc20a
@@ -98,8 +100,8 @@ public class QDoxFactoryReader implements Iterable<FactoryMethod> {
6bc20a
      */
6bc20a
     private static String createJavaDocComment(JavaMethod methodSource) {
6bc20a
         String comment = methodSource.getComment();
6bc20a
-        DocletTag[] tags = methodSource.getTags();
6bc20a
-        if ((comment == null || comment.trim().length() == 0) && tags.length == 0) {
6bc20a
+        List<DocletTag> tags = methodSource.getTags();
6bc20a
+        if ((comment == null || comment.trim().length() == 0) && tags.size() == 0) {
6bc20a
             return null;
6bc20a
         }
6bc20a
         StringBuilder result = new StringBuilder();
6bc20a
-- 
6bc20a
2.9.3
6bc20a