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