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