changeset 268:23317fcda782

Few more @GenerateMicroBenchmark method tests: abstract, private, synchronized are restricted.
author shade
date Sat, 23 Nov 2013 19:40:42 +0400
parents fd83add52cba
children 35ea8b9247b0
files jmh-core/src/main/java/org/openjdk/jmh/processor/internal/GenerateMicroBenchmarkProcessor.java
diffstat 1 files changed, 18 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/jmh-core/src/main/java/org/openjdk/jmh/processor/internal/GenerateMicroBenchmarkProcessor.java	Fri Nov 22 18:29:11 2013 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/processor/internal/GenerateMicroBenchmarkProcessor.java	Sat Nov 23 19:40:42 2013 +0400
@@ -195,6 +195,24 @@
             }
         }
 
+        for (Element m : methods) {
+            if (m.getModifiers().contains(Modifier.ABSTRACT)) {
+                throw new GenerationException("@" + GenerateMicroBenchmark.class.getSimpleName()
+                        + " method can not be abstract.", m);
+            }
+            if (m.getModifiers().contains(Modifier.PRIVATE)) {
+                throw new GenerationException("@" + GenerateMicroBenchmark.class.getSimpleName()
+                        + " method can not be private.", m);
+            }
+            if (m.getModifiers().contains(Modifier.SYNCHRONIZED)) {
+                if (clazz.getAnnotation(State.class) == null) {
+                    throw new GenerationException("@" + GenerateMicroBenchmark.class.getSimpleName()
+                            + " method can only be synchronized if the enclosing class is annotated with "
+                            + "@" + State.class.getSimpleName() + ".", m);
+                    }
+            }
+        }
+
         Map<String, MethodGroup> result = new TreeMap<String, MethodGroup>();
 
         boolean classStrictFP = clazz.getModifiers().contains(Modifier.STRICTFP);