changeset 351:d1f7de548b59

Regression: after @GMB processor started to accept all classes, other processors stopped to run. Notably, @CompilerControl processor broke. Fix that by calling other processors within the @GMB round.
author shade
date Wed, 15 Jan 2014 19:30:56 +0400
parents 15dc4634cbb8
children 2a5c68105d9a
files jmh-core/src/main/java/org/openjdk/jmh/processor/internal/CompilerControlProcessor.java jmh-core/src/main/java/org/openjdk/jmh/processor/internal/GenerateMicroBenchmarkProcessor.java jmh-core/src/main/java/org/openjdk/jmh/processor/internal/GroupValidationProcessor.java jmh-core/src/main/java/org/openjdk/jmh/processor/internal/HelperMethodValidationProcessor.java jmh-core/src/main/java/org/openjdk/jmh/processor/internal/SubProcessor.java jmh-core/src/main/resources/META-INF/services/javax.annotation.processing.Processor
diffstat 6 files changed, 107 insertions(+), 110 deletions(-) [+]
line wrap: on
line diff
--- a/jmh-core/src/main/java/org/openjdk/jmh/processor/internal/CompilerControlProcessor.java	Wed Jan 15 18:49:28 2014 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/processor/internal/CompilerControlProcessor.java	Wed Jan 15 19:30:56 2014 +0400
@@ -27,59 +27,45 @@
 import org.openjdk.jmh.annotations.CompilerControl;
 import org.openjdk.jmh.runner.CompilerHints;
 
-import javax.annotation.processing.AbstractProcessor;
+import javax.annotation.processing.ProcessingEnvironment;
 import javax.annotation.processing.RoundEnvironment;
-import javax.annotation.processing.SupportedSourceVersion;
-import javax.lang.model.SourceVersion;
 import javax.lang.model.element.Element;
-import javax.lang.model.element.TypeElement;
 import javax.tools.Diagnostic.Kind;
 import javax.tools.FileObject;
 import javax.tools.StandardLocation;
 import java.io.IOException;
 import java.io.PrintWriter;
 import java.util.ArrayList;
-import java.util.Collections;
 import java.util.List;
-import java.util.Set;
 
-@SupportedSourceVersion(SourceVersion.RELEASE_6)
-public class CompilerControlProcessor extends AbstractProcessor {
+public class CompilerControlProcessor implements SubProcessor {
 
     private final List<String> lines = new ArrayList<String>();
 
-    @Override
-    public Set<String> getSupportedAnnotationTypes() {
-        return Collections.singleton(CompilerControl.class.getName());
-    }
-
-    @Override
-    public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
+    public void process(RoundEnvironment roundEnv, ProcessingEnvironment processingEnv) {
         try {
             if (!roundEnv.processingOver()) {
-                for (TypeElement annotation : annotations) {
-                    for (Element element : roundEnv.getElementsAnnotatedWith(annotation)) {
+                for (Element element : roundEnv.getElementsAnnotatedWith(CompilerControl.class)) {
 
-                        CompilerControl ann = element.getAnnotation(CompilerControl.class);
-                        if (ann == null) {
-                            throw new IllegalStateException("No annotation");
-                        }
+                    CompilerControl ann = element.getAnnotation(CompilerControl.class);
+                    if (ann == null) {
+                        throw new IllegalStateException("No annotation");
+                    }
 
-                        switch (element.getKind()) {
-                            case CLASS:
-                                lines.add(ann.value().command() + "," + element.toString().replaceAll("\\.", "/") + ".*");
-                                break;
-                            case METHOD:
-                                lines.add(ann.value().command() + "," + element.getEnclosingElement().toString().replaceAll("\\.", "/") + "." + element.getSimpleName().toString());
-                                break;
-                            default:
-                                processingEnv.getMessager().printMessage(Kind.ERROR,
-                                        "@" + CompilerControl.class.getSimpleName() + " annotation is placed within " +
-                                                "unexpected target",
-                                        element);
-                        }
+                    switch (element.getKind()) {
+                        case CLASS:
+                            lines.add(ann.value().command() + "," + element.toString().replaceAll("\\.", "/") + ".*");
+                            break;
+                        case METHOD:
+                            lines.add(ann.value().command() + "," + element.getEnclosingElement().toString().replaceAll("\\.", "/") + "." + element.getSimpleName().toString());
+                            break;
+                        default:
+                            processingEnv.getMessager().printMessage(Kind.ERROR,
+                                    "@" + CompilerControl.class.getSimpleName() + " annotation is placed within " +
+                                            "unexpected target",
+                                    element);
+                    }
 
-                    }
                 }
             } else {
                 try {
@@ -93,13 +79,11 @@
                 } catch (IOException ex) {
                     processingEnv.getMessager().printMessage(Kind.ERROR, "Error writing compiler hint list " + ex);
                 }
-
             }
         } catch (Throwable t) {
             processingEnv.getMessager().printMessage(Kind.ERROR, "Annotation processor had thrown exception: " + t);
             t.printStackTrace(System.err);
         }
-        return true;
     }
 
 }
--- a/jmh-core/src/main/java/org/openjdk/jmh/processor/internal/GenerateMicroBenchmarkProcessor.java	Wed Jan 15 18:49:28 2014 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/processor/internal/GenerateMicroBenchmarkProcessor.java	Wed Jan 15 19:30:56 2014 +0400
@@ -33,7 +33,6 @@
 import org.openjdk.jmh.annotations.Measurement;
 import org.openjdk.jmh.annotations.Mode;
 import org.openjdk.jmh.annotations.OperationsPerInvocation;
-import org.openjdk.jmh.annotations.OutputTimeUnit;
 import org.openjdk.jmh.annotations.Scope;
 import org.openjdk.jmh.annotations.State;
 import org.openjdk.jmh.annotations.Threads;
@@ -50,14 +49,13 @@
 import org.openjdk.jmh.logic.results.ThroughputResult;
 import org.openjdk.jmh.runner.BenchmarkRecord;
 import org.openjdk.jmh.runner.MicroBenchmarkList;
-import org.openjdk.jmh.util.AnnotationUtils;
-import org.openjdk.jmh.util.internal.CollectionUtils;
 import org.openjdk.jmh.util.internal.HashMultimap;
 import org.openjdk.jmh.util.internal.Multimap;
 import org.openjdk.jmh.util.internal.SampleBuffer;
 
 import javax.annotation.Generated;
 import javax.annotation.processing.AbstractProcessor;
+import javax.annotation.processing.ProcessingEnvironment;
 import javax.annotation.processing.RoundEnvironment;
 import javax.annotation.processing.SupportedAnnotationTypes;
 import javax.annotation.processing.SupportedSourceVersion;
@@ -101,9 +99,23 @@
 
     private final Set<BenchmarkInfo> benchmarkInfos = new HashSet<BenchmarkInfo>();
 
+    private final Collection<SubProcessor> subProcessors = new ArrayList<SubProcessor>();
+
+    @Override
+    public synchronized void init(ProcessingEnvironment processingEnv) {
+        super.init(processingEnv);
+        subProcessors.add(new CompilerControlProcessor());
+        subProcessors.add(new HelperMethodValidationProcessor());
+        subProcessors.add(new GroupValidationProcessor());
+    }
+
     @Override
     public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
         try {
+            for (SubProcessor sub : subProcessors) {
+                sub.process(roundEnv, processingEnv);
+            }
+
             if (!roundEnv.processingOver()) {
                 TypeElement gmb = processingEnv.getElementUtils().getTypeElement(GenerateMicroBenchmark.class.getCanonicalName());
                 // Build a Set of classes with a list of annotated methods
--- a/jmh-core/src/main/java/org/openjdk/jmh/processor/internal/GroupValidationProcessor.java	Wed Jan 15 18:49:28 2014 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/processor/internal/GroupValidationProcessor.java	Wed Jan 15 19:30:56 2014 +0400
@@ -28,47 +28,30 @@
 import org.openjdk.jmh.annotations.GroupThreads;
 import org.openjdk.jmh.annotations.Threads;
 
-import javax.annotation.processing.AbstractProcessor;
+import javax.annotation.processing.ProcessingEnvironment;
 import javax.annotation.processing.RoundEnvironment;
-import javax.annotation.processing.SupportedSourceVersion;
-import javax.lang.model.SourceVersion;
 import javax.lang.model.element.Element;
-import javax.lang.model.element.TypeElement;
 import javax.tools.Diagnostic.Kind;
-import java.util.HashSet;
-import java.util.Set;
 
-@SupportedSourceVersion(SourceVersion.RELEASE_6)
-public class GroupValidationProcessor extends AbstractProcessor {
+public class GroupValidationProcessor implements SubProcessor {
 
     @Override
-    public Set<String> getSupportedAnnotationTypes() {
-        Set<String> supported = new HashSet<String>();
-        supported.add(Group.class.getName());
-        return supported;
-    }
-
-    @Override
-    public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
+    public void process(RoundEnvironment roundEnv, ProcessingEnvironment processingEnv) {
         try {
-            for (TypeElement annotation : annotations) {
-                for (Element element : roundEnv.getElementsAnnotatedWith(annotation)) {
-
-                    if (element.getAnnotation(Threads.class) != null) {
-                        processingEnv.getMessager().printMessage(Kind.ERROR,
-                                "@" + Threads.class.getSimpleName() + " annotation is placed within " +
-                                        "the benchmark method with @" + Group.class.getSimpleName() + " annotation. " +
-                                        "This has ambiguous behavioral effect, and prohibited. " +
-                                "Did you mean @" + GroupThreads.class.getSimpleName() + " instead?",
-                                element);
-                    }
+            for (Element element : roundEnv.getElementsAnnotatedWith(Group.class)) {
+                if (element.getAnnotation(Threads.class) != null) {
+                    processingEnv.getMessager().printMessage(Kind.ERROR,
+                            "@" + Threads.class.getSimpleName() + " annotation is placed within " +
+                                    "the benchmark method with @" + Group.class.getSimpleName() + " annotation. " +
+                                    "This has ambiguous behavioral effect, and prohibited. " +
+                                    "Did you mean @" + GroupThreads.class.getSimpleName() + " instead?",
+                            element);
                 }
             }
         } catch (Throwable t) {
             processingEnv.getMessager().printMessage(Kind.ERROR, "Annotation processor had throw exception: " + t);
             t.printStackTrace(System.err);
         }
-        return true;
     }
 
 }
--- a/jmh-core/src/main/java/org/openjdk/jmh/processor/internal/HelperMethodValidationProcessor.java	Wed Jan 15 18:49:28 2014 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/processor/internal/HelperMethodValidationProcessor.java	Wed Jan 15 19:30:56 2014 +0400
@@ -28,62 +28,49 @@
 import org.openjdk.jmh.annotations.State;
 import org.openjdk.jmh.annotations.TearDown;
 
-import javax.annotation.processing.AbstractProcessor;
+import javax.annotation.processing.ProcessingEnvironment;
 import javax.annotation.processing.RoundEnvironment;
-import javax.annotation.processing.SupportedSourceVersion;
-import javax.lang.model.SourceVersion;
 import javax.lang.model.element.Element;
 import javax.lang.model.element.Modifier;
-import javax.lang.model.element.TypeElement;
 import javax.tools.Diagnostic.Kind;
-import java.util.HashSet;
-import java.util.Set;
 
-@SupportedSourceVersion(SourceVersion.RELEASE_6)
-public class HelperMethodValidationProcessor extends AbstractProcessor {
+public class HelperMethodValidationProcessor implements SubProcessor {
 
     @Override
-    public Set<String> getSupportedAnnotationTypes() {
-        HashSet<String> supported = new HashSet<String>();
-        supported.add(Setup.class.getName());
-        supported.add(TearDown.class.getName());
-        return supported;
-    }
+    public void process(RoundEnvironment roundEnv, ProcessingEnvironment processingEnv) {
+        try {
+            for (Element element : roundEnv.getElementsAnnotatedWith(Setup.class)) {
+                // OK to have these annotation for @State objects
+                if (element.getEnclosingElement().getAnnotation(State.class) != null) continue;
 
-    @Override
-    public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
-        try {
-            for (TypeElement annotation : annotations) {
-                for (Element element : roundEnv.getElementsAnnotatedWith(annotation)) {
+                // Abstract classes are not instantiated, assume OK
+                if (element.getEnclosingElement().getModifiers().contains(Modifier.ABSTRACT)) continue;
 
-                    // OK to have these annotation for @State objects
-                    if (element.getEnclosingElement().getAnnotation(State.class) != null) continue;
+                    processingEnv.getMessager().printMessage(Kind.ERROR,
+                            "@" + Setup.class.getSimpleName() + " annotation is placed within " +
+                                    "the class not having @" + State.class.getSimpleName() + " annotation. " +
+                                    "This has no behavioral effect, and prohibited.",
+                            element);
+            }
 
-                    // Abstract classes are not instantiated, assume OK
-                    if (element.getEnclosingElement().getModifiers().contains(Modifier.ABSTRACT)) continue;
+            for (Element element : roundEnv.getElementsAnnotatedWith(TearDown.class)) {
+                // OK to have these annotation for @State objects
+                if (element.getEnclosingElement().getAnnotation(State.class) != null) continue;
 
-                    if (element.getAnnotation(Setup.class) != null) {
-                        processingEnv.getMessager().printMessage(Kind.ERROR,
-                                "@" + Setup.class.getSimpleName() + " annotation is placed within " +
-                                        "the class not having @" + State.class.getSimpleName() + " annotation. " +
-                                        "This has no behavioral effect, and prohibited.",
-                                element);
-                    }
-                    if (element.getAnnotation(TearDown.class) != null) {
-                        processingEnv.getMessager().printMessage(Kind.ERROR,
-                                "@" + TearDown.class.getSimpleName() + " annotation is placed within " +
-                                        "the class not having @" + State.class.getSimpleName() + " annotation. " +
-                                        "This can be futile if no @State-bearing subclass is used.",
-                                element);
-                    }
-                }
+                // Abstract classes are not instantiated, assume OK
+                if (element.getEnclosingElement().getModifiers().contains(Modifier.ABSTRACT)) continue;
 
+                processingEnv.getMessager().printMessage(Kind.ERROR,
+                            "@" + TearDown.class.getSimpleName() + " annotation is placed within " +
+                                    "the class not having @" + State.class.getSimpleName() + " annotation. " +
+                                    "This can be futile if no @State-bearing subclass is used.",
+                            element);
             }
+
         } catch (Throwable t) {
             processingEnv.getMessager().printMessage(Kind.ERROR, "Annotation processor had throw exception: " + t);
             t.printStackTrace(System.err);
         }
-        return true;
     }
 
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jmh-core/src/main/java/org/openjdk/jmh/processor/internal/SubProcessor.java	Wed Jan 15 19:30:56 2014 +0400
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package org.openjdk.jmh.processor.internal;
+
+import javax.annotation.processing.ProcessingEnvironment;
+import javax.annotation.processing.RoundEnvironment;
+
+public interface SubProcessor {
+
+    void process(RoundEnvironment roundEnv, ProcessingEnvironment processingEnv);
+
+}
--- a/jmh-core/src/main/resources/META-INF/services/javax.annotation.processing.Processor	Wed Jan 15 18:49:28 2014 +0400
+++ b/jmh-core/src/main/resources/META-INF/services/javax.annotation.processing.Processor	Wed Jan 15 19:30:56 2014 +0400
@@ -22,6 +22,3 @@
 #    questions.
 #
 org.openjdk.jmh.processor.internal.GenerateMicroBenchmarkProcessor
-org.openjdk.jmh.processor.internal.HelperMethodValidationProcessor
-org.openjdk.jmh.processor.internal.GroupValidationProcessor
-org.openjdk.jmh.processor.internal.CompilerControlProcessor