changeset 319:99f21384901b

Yak shaving: move @State arg validation to appropriate place.
author shade
date Fri, 06 Dec 2013 19:03:07 +0400
parents 9497a55f865f
children 9c392e4cd432
files jmh-core/src/main/java/org/openjdk/jmh/processor/internal/GenerateMicroBenchmarkProcessor.java
diffstat 1 files changed, 14 insertions(+), 27 deletions(-) [+]
line wrap: on
line diff
--- a/jmh-core/src/main/java/org/openjdk/jmh/processor/internal/GenerateMicroBenchmarkProcessor.java	Fri Dec 06 18:50:09 2013 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/processor/internal/GenerateMicroBenchmarkProcessor.java	Fri Dec 06 19:03:07 2013 +0400
@@ -176,6 +176,20 @@
             throw new GenerationException("Microbenchmark should have package other than default.", clazz);
         }
 
+        // validate all arguments are @State-s
+        for (Element e : methods) {
+            ExecutableElement method = (ExecutableElement) e;
+            for (VariableElement var : method.getParameters()) {
+                Element argClass = processingEnv.getTypeUtils().asElement(var.asType());
+                if (argClass.getAnnotation(State.class) == null) {
+                    throw new GenerationException(
+                            "The " + GenerateMicroBenchmark.class.getSimpleName() +
+                            " annotation only supports methods with @State-bearing typed parameters.",
+                            var);
+                }
+            }
+        }
+
         // validate against rogue fields
         if (clazz.getAnnotation(State.class) == null || clazz.getModifiers().contains(Modifier.ABSTRACT)) {
             for (VariableElement field : ElementFilter.fieldsIn(clazz.getEnclosedElements())) {
@@ -266,7 +280,6 @@
         boolean classStrictFP = clazz.getModifiers().contains(Modifier.STRICTFP);
 
         for (Element method : methods) {
-            validateSignature(clazz, method);
 
             boolean methodStrictFP = method.getModifiers().contains(Modifier.STRICTFP);
 
@@ -435,16 +448,6 @@
         // nothing here
     }
 
-    private void validateSignature(TypeElement clazz, Element method) {
-        if (!(method instanceof ExecutableElement)
-                || !validMethodSignature((ExecutableElement) method)) {
-            throw new GenerationException(
-                    "The " + GenerateMicroBenchmark.class.getSimpleName()
-                            + " annotation only supports methods with @State-bearing typed parameters.",
-                    method);
-        }
-    }
-
     private void generatePadding(PrintWriter writer) {
         for (int p = 0; p < 16; p++) {
             StringBuilder sb = new StringBuilder();
@@ -475,22 +478,6 @@
         writer.println();
     }
 
-    /**
-     * Check that the method signature is correct for GenerateMicrobenchmark methods
-     *
-     * @param element The annotated method
-     * @return True iff the method has the correct signature
-     */
-    public boolean validMethodSignature(ExecutableElement element) {
-        Types typeUtils = processingEnv.getTypeUtils();
-        for (VariableElement var : element.getParameters()) {
-            if (typeUtils.asElement(var.asType()).getAnnotation(State.class) == null) {
-                return false;
-            }
-        }
-        return true;
-    }
-
     private TimeUnit findTimeUnit(MethodGroup methodGroup) {
         OutputTimeUnit ann = methodGroup.methods().iterator().next().getEnclosingElement().getAnnotation(OutputTimeUnit.class);
         for (Element method : methodGroup.methods()) {