Michael Simacek f06e69
From e424bad757e50ffa6f819e14e9347c69a7337adc Mon Sep 17 00:00:00 2001
Michael Simacek 08a56e
From: Michael Simacek <msimacek@redhat.com>
Michael Simacek 08a56e
Date: Tue, 17 Mar 2015 10:59:41 +0100
Michael Simacek f06e69
Subject: [PATCH 4/6] Port to QDox 2.0
Michael Simacek 08a56e
Michael Simacek 08a56e
---
Michael Simacek f06e69
 .../apache/fop/tools/EventProducerCollector.java   | 61 ++++++++--------------
Michael Simacek f06e69
 1 file changed, 23 insertions(+), 38 deletions(-)
Michael Simacek 08a56e
Michael Simacek 08a56e
diff --git a/src/codegen/java/org/apache/fop/tools/EventProducerCollector.java b/src/codegen/java/org/apache/fop/tools/EventProducerCollector.java
Michael Simacek f06e69
index c6674ba..620ecc4 100644
Michael Simacek 08a56e
--- a/src/codegen/java/org/apache/fop/tools/EventProducerCollector.java
Michael Simacek 08a56e
+++ b/src/codegen/java/org/apache/fop/tools/EventProducerCollector.java
Michael Simacek 08a56e
@@ -21,6 +21,7 @@ package org.apache.fop.tools;
Michael Simacek 08a56e
 
Michael Simacek 08a56e
 import java.io.File;
Michael Simacek 08a56e
 import java.io.IOException;
Michael Simacek 08a56e
+import java.util.Collection;
Michael Simacek 08a56e
 import java.util.Collections;
Michael Simacek 08a56e
 import java.util.List;
Michael Simacek 08a56e
 import java.util.Map;
Michael Simacek 08a56e
@@ -31,14 +32,11 @@ import org.apache.fop.events.model.EventModel;
Michael Simacek 08a56e
 import org.apache.fop.events.model.EventProducerModel;
Michael Simacek 08a56e
 import org.apache.fop.events.model.EventSeverity;
Michael Simacek 08a56e
 
Michael Simacek 08a56e
-import com.thoughtworks.qdox.JavaDocBuilder;
Michael Simacek 08a56e
-import com.thoughtworks.qdox.model.DefaultDocletTagFactory;
Michael Simacek 08a56e
+import com.thoughtworks.qdox.JavaProjectBuilder;
Michael Simacek 08a56e
 import com.thoughtworks.qdox.model.DocletTag;
Michael Simacek 08a56e
-import com.thoughtworks.qdox.model.DocletTagFactory;
Michael Simacek 08a56e
 import com.thoughtworks.qdox.model.JavaClass;
Michael Simacek 08a56e
 import com.thoughtworks.qdox.model.JavaMethod;
Michael Simacek 08a56e
 import com.thoughtworks.qdox.model.JavaParameter;
Michael Simacek 08a56e
-import com.thoughtworks.qdox.model.Type;
Michael Simacek 08a56e
 
Michael Simacek 08a56e
 /**
Michael Simacek 08a56e
  * Finds EventProducer interfaces and builds the event model for them.
Michael Simacek 08a56e
@@ -61,22 +59,12 @@ class EventProducerCollector {
Michael Simacek 08a56e
         PRIMITIVE_MAP = Collections.unmodifiableMap(m);
Michael Simacek 08a56e
     }
Michael Simacek 08a56e
 
Michael Simacek 08a56e
-    private DocletTagFactory tagFactory;
Michael Simacek 08a56e
     private List<EventModel> models = new java.util.ArrayList<EventModel>();
Michael Simacek 08a56e
 
Michael Simacek 08a56e
     /**
Michael Simacek 08a56e
      * Creates a new EventProducerCollector.
Michael Simacek 08a56e
      */
Michael Simacek 08a56e
     EventProducerCollector() {
Michael Simacek 08a56e
-        this.tagFactory = createDocletTagFactory();
Michael Simacek 08a56e
-    }
Michael Simacek 08a56e
-
Michael Simacek 08a56e
-    /**
Michael Simacek 08a56e
-     * Creates the {@link DocletTagFactory} to be used by the collector.
Michael Simacek 08a56e
-     * @return the doclet tag factory
Michael Simacek 08a56e
-     */
Michael Simacek 08a56e
-    protected DocletTagFactory createDocletTagFactory() {
Michael Simacek 08a56e
-        return new DefaultDocletTagFactory();
Michael Simacek 08a56e
     }
Michael Simacek 08a56e
 
Michael Simacek 08a56e
     /**
Michael Simacek 08a56e
@@ -89,12 +77,11 @@ class EventProducerCollector {
Michael Simacek 08a56e
      */
Michael Simacek 08a56e
     public boolean scanFile(File src)
Michael Simacek 08a56e
             throws IOException, EventConventionException, ClassNotFoundException {
Michael Simacek 08a56e
-        JavaDocBuilder builder = new JavaDocBuilder(this.tagFactory);
Michael Simacek 08a56e
+        JavaProjectBuilder builder = new JavaProjectBuilder();
Michael Simacek 08a56e
         builder.addSource(src);
Michael Simacek 08a56e
-        JavaClass[] classes = builder.getClasses();
Michael Simacek 08a56e
+        Collection<JavaClass> classes = builder.getClasses();
Michael Simacek 08a56e
         boolean eventProducerFound = false;
Michael Simacek 08a56e
-        for (int i = 0, c = classes.length; i < c; i++) {
Michael Simacek 08a56e
-            JavaClass clazz = classes[i];
Michael Simacek 08a56e
+        for (JavaClass clazz: classes) {
Michael Simacek 08a56e
             if (clazz.isInterface() && implementsInterface(clazz, CLASSNAME_EVENT_PRODUCER)) {
Michael Simacek 08a56e
                 processEventProducerInterface(clazz);
Michael Simacek 08a56e
                 eventProducerFound = true;
Michael Simacek 08a56e
@@ -104,9 +91,8 @@ class EventProducerCollector {
Michael Simacek 08a56e
     }
Michael Simacek 08a56e
 
Michael Simacek 08a56e
     private boolean implementsInterface(JavaClass clazz, String intf) {
Michael Simacek 08a56e
-        JavaClass[] classes = clazz.getImplementedInterfaces();
Michael Simacek 08a56e
-        for (int i = 0, c = classes.length; i < c; i++) {
Michael Simacek 08a56e
-            JavaClass cl = classes[i];
Michael Simacek f06e69
+        List<JavaClass> classes = clazz.getInterfaces();
Michael Simacek 08a56e
+        for (JavaClass cl: classes) {
Michael Simacek 08a56e
             if (cl.getFullyQualifiedName().equals(intf)) {
Michael Simacek 08a56e
                 return true;
Michael Simacek 08a56e
             }
Michael Simacek 08a56e
@@ -123,9 +109,8 @@ class EventProducerCollector {
Michael Simacek 08a56e
     protected void processEventProducerInterface(JavaClass clazz)
Michael Simacek 08a56e
                 throws EventConventionException, ClassNotFoundException {
Michael Simacek 08a56e
         EventProducerModel prodMeta = new EventProducerModel(clazz.getFullyQualifiedName());
Michael Simacek 08a56e
-        JavaMethod[] methods = clazz.getMethods(true);
Michael Simacek 08a56e
-        for (int i = 0, c = methods.length; i < c; i++) {
Michael Simacek 08a56e
-            JavaMethod method = methods[i];
Michael Simacek 08a56e
+        List<JavaMethod> methods = clazz.getMethods(true);
Michael Simacek 08a56e
+        for (JavaMethod method: methods) {
Michael Simacek 08a56e
             EventMethodModel methodMeta = createMethodModel(method);
Michael Simacek 08a56e
             prodMeta.addMethod(methodMeta);
Michael Simacek 08a56e
         }
Michael Simacek f06e69
@@ -136,20 +121,20 @@ class EventProducerCollector {
Michael Simacek f06e69
 
Michael Simacek f06e69
     private EventMethodModel createMethodModel(JavaMethod method)
Michael Simacek 08a56e
             throws EventConventionException, ClassNotFoundException {
Michael Simacek f06e69
-        JavaClass clazz = method.getParentClass();
Michael Simacek f06e69
+        JavaClass clazz = method.getDeclaringClass();
Michael Simacek 08a56e
         //Check EventProducer conventions
Michael Simacek 08a56e
-        if (!method.getReturnType().isVoid()) {
Michael Simacek 08a56e
+        if (!method.getReturns().isVoid()) {
Michael Simacek 08a56e
             throw new EventConventionException("All methods of interface "
Michael Simacek 08a56e
                     + clazz.getFullyQualifiedName() + " must have return type 'void'!");
Michael Simacek 08a56e
         }
Michael Simacek 08a56e
         String methodSig = clazz.getFullyQualifiedName() + "." + method.getCallSignature();
Michael Simacek 08a56e
-        JavaParameter[] params = method.getParameters();
Michael Simacek 08a56e
-        if (params.length < 1) {
Michael Simacek 08a56e
+        List<JavaParameter> params = method.getParameters();
Michael Simacek 08a56e
+        if (params.size() < 1) {
Michael Simacek 08a56e
             throw new EventConventionException("The method " + methodSig
Michael Simacek 08a56e
                     + " must have at least one parameter: 'Object source'!");
Michael Simacek 08a56e
         }
Michael Simacek 08a56e
-        Type firstType = params[0].getType();
Michael Simacek 08a56e
-        if (firstType.isPrimitive() || !"source".equals(params[0].getName())) {
Michael Simacek 08a56e
+        JavaClass firstType = params.get(0).getJavaClass();
Michael Simacek 08a56e
+        if (firstType.isPrimitive() || !"source".equals(params.get(0).getName())) {
Michael Simacek 08a56e
             throw new EventConventionException("The first parameter of the method " + methodSig
Michael Simacek 08a56e
                     + " must be: 'Object source'!");
Michael Simacek 08a56e
         }
Michael Simacek 08a56e
@@ -164,12 +149,12 @@ class EventProducerCollector {
Michael Simacek 08a56e
         }
Michael Simacek 08a56e
         EventMethodModel methodMeta = new EventMethodModel(
Michael Simacek 08a56e
                 method.getName(), severity);
Michael Simacek 08a56e
-        if (params.length > 1) {
Michael Simacek 08a56e
-            for (int j = 1, cj = params.length; j < cj; j++) {
Michael Simacek 08a56e
-                JavaParameter p = params[j];
Michael Simacek 08a56e
+        if (params.size() > 1) {
Michael Simacek 08a56e
+            for (int j = 1, cj = params.size(); j < cj; j++) {
Michael Simacek 08a56e
+                JavaParameter p = params.get(j);
Michael Simacek 08a56e
                 Class type;
Michael Simacek 08a56e
-                JavaClass pClass = p.getType().getJavaClass();
Michael Simacek 08a56e
-                if (p.getType().isPrimitive()) {
Michael Simacek 08a56e
+                JavaClass pClass = p.getJavaClass();
Michael Simacek 08a56e
+                if (pClass.isPrimitive()) {
Michael Simacek 08a56e
                     type = PRIMITIVE_MAP.get(pClass.getName());
Michael Simacek 08a56e
                     if (type == null) {
Michael Simacek 08a56e
                         throw new UnsupportedOperationException(
Michael Simacek 08a56e
@@ -182,10 +167,10 @@ class EventProducerCollector {
Michael Simacek 08a56e
                 methodMeta.addParameter(type, p.getName());
Michael Simacek 08a56e
             }
Michael Simacek 08a56e
         }
Michael Simacek 08a56e
-        Type[] exceptions = method.getExceptions();
Michael Simacek 08a56e
-        if (exceptions != null && exceptions.length > 0) {
Michael Simacek 08a56e
+        List<JavaClass> exceptions = method.getExceptions();
Michael Simacek 08a56e
+        if (exceptions != null && exceptions.size() > 0) {
Michael Simacek 08a56e
             //We only use the first declared exception because that is always thrown
Michael Simacek 08a56e
-            JavaClass cl = exceptions[0].getJavaClass();
Michael Simacek 08a56e
+            JavaClass cl = exceptions.get(0);
Michael Simacek 08a56e
             methodMeta.setExceptionClass(cl.getFullyQualifiedName());
Michael Simacek 08a56e
             methodMeta.setSeverity(EventSeverity.FATAL); //In case it's not set in the comments
Michael Simacek 08a56e
         }
Michael Simacek 08a56e
-- 
Michael Simacek f06e69
2.9.3
Michael Simacek 08a56e