changeset 438:80e3f02d698a

Yak shaving: move common getFields/getMethods from GeneratorSources to utils.
author shade
date Fri, 28 Feb 2014 14:26:18 +0400
parents 85b567cf6f73
children 3387329b6564
files jmh-core/src/main/java/org/openjdk/jmh/generators/annotations/APClassInfo.java jmh-core/src/main/java/org/openjdk/jmh/generators/bytecode/ASMClassInfo.java jmh-core/src/main/java/org/openjdk/jmh/generators/core/BenchmarkGenerator.java jmh-core/src/main/java/org/openjdk/jmh/generators/core/BenchmarkGeneratorUtils.java jmh-core/src/main/java/org/openjdk/jmh/generators/core/StateObjectHandler.java jmh-core/src/main/java/org/openjdk/jmh/generators/reflective/ReflectiveClassInfo.java jmh-core/src/main/java/org/openjdk/jmh/generators/source/ClassInfo.java
diffstat 7 files changed, 23 insertions(+), 68 deletions(-) [+]
line wrap: on
line diff
--- a/jmh-core/src/main/java/org/openjdk/jmh/generators/annotations/APClassInfo.java	Fri Feb 28 14:17:53 2014 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/generators/annotations/APClassInfo.java	Fri Feb 28 14:26:18 2014 +0400
@@ -86,15 +86,6 @@
         return ls;
     }
 
-    @Override
-    public Collection<FieldInfo> getFields() {
-        List<FieldInfo> ls = new ArrayList<FieldInfo>();
-        ls.addAll(getDeclaredFields());
-        for (ClassInfo cl : getSuperclasses()) {
-            ls.addAll(cl.getDeclaredFields());
-        }
-        return ls;
-    }
 
     @Override
     public Collection<MethodInfo> getDeclaredMethods() {
@@ -106,16 +97,6 @@
     }
 
     @Override
-    public Collection<MethodInfo> getMethods() {
-        List<MethodInfo> ls = new ArrayList<MethodInfo>();
-        ls.addAll(getDeclaredMethods());
-        for (ClassInfo cl : getSuperclasses()) {
-            ls.addAll(cl.getDeclaredMethods());
-        }
-        return ls;
-    }
-
-    @Override
     public String getPackageName() {
         return AnnUtils.getPackageName(el);
     }
--- a/jmh-core/src/main/java/org/openjdk/jmh/generators/bytecode/ASMClassInfo.java	Fri Feb 28 14:17:53 2014 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/generators/bytecode/ASMClassInfo.java	Fri Feb 28 14:26:18 2014 +0400
@@ -139,16 +139,6 @@
     }
 
     @Override
-    public Collection<FieldInfo> getFields() {
-        List<FieldInfo> ls = new ArrayList<FieldInfo>();
-        ls.addAll(getDeclaredFields());
-        for (ClassInfo cl : getSuperclasses()) {
-            ls.addAll(cl.getDeclaredFields());
-        }
-        return ls;
-    }
-
-    @Override
     public Collection<MethodInfo> getConstructors() {
         return constructors;
     }
@@ -159,16 +149,6 @@
     }
 
     @Override
-    public Collection<MethodInfo> getMethods() {
-        List<MethodInfo> ls = new ArrayList<MethodInfo>();
-        ls.addAll(getDeclaredMethods());
-        for (ClassInfo cl : getSuperclasses()) {
-            ls.addAll(cl.getDeclaredMethods());
-        }
-        return ls;
-    }
-
-    @Override
     public Collection<ClassInfo> getSuperclasses() {
         // TODO: FIXME
         return Collections.emptyList();
--- a/jmh-core/src/main/java/org/openjdk/jmh/generators/core/BenchmarkGenerator.java	Fri Feb 28 14:17:53 2014 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/generators/core/BenchmarkGenerator.java	Fri Feb 28 14:26:18 2014 +0400
@@ -265,7 +265,7 @@
 
         // validate against rogue fields
         if (clazz.getAnnotation(State.class) == null || clazz.isAbstract()) {
-            for (FieldInfo fi : clazz.getFields()) {
+            for (FieldInfo fi : BenchmarkGeneratorUtils.getAllFields(clazz)) {
                 // allow static fields
                 if (fi.isStatic()) continue;
                 throw new GenerationException(
@@ -385,7 +385,7 @@
             // Discovering @Params, part 1:
             //   For each parameter, walk the type hierarchy up to discover inherited @Param fields in @State objects.
             for (ParameterInfo pi : method.getParameters()) {
-                for (FieldInfo fi : pi.getType().getFields()) {
+                for (FieldInfo fi : BenchmarkGeneratorUtils.getAllFields(pi.getType())) {
                     if (fi.getAnnotation(Param.class) != null) {
                         group.addParam(fi.getName(), fi.getAnnotation(Param.class).value());
                     }
@@ -394,7 +394,7 @@
 
             // Discovering @Params, part 2:
             //  Walk the type hierarchy up to discover inherited @Param fields for class.
-            for (FieldInfo fi : clazz.getFields()) {
+            for (FieldInfo fi : BenchmarkGeneratorUtils.getAllFields(clazz)) {
                 if (fi.getAnnotation(Param.class) != null) {
                     group.addParam(fi.getName(), fi.getAnnotation(Param.class).value());
                 }
--- a/jmh-core/src/main/java/org/openjdk/jmh/generators/core/BenchmarkGeneratorUtils.java	Fri Feb 28 14:17:53 2014 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/generators/core/BenchmarkGeneratorUtils.java	Fri Feb 28 14:26:18 2014 +0400
@@ -70,4 +70,22 @@
         return mis;
     }
 
+    public static Collection<FieldInfo> getAllFields(ClassInfo ci) {
+        List<FieldInfo> ls = new ArrayList<FieldInfo>();
+        ls.addAll(ci.getDeclaredFields());
+        for (ClassInfo cl : ci.getSuperclasses()) {
+            ls.addAll(cl.getDeclaredFields());
+        }
+        return ls;
+    }
+
+    public static Collection<MethodInfo> getMethods(ClassInfo ci) {
+        List<MethodInfo> ls = new ArrayList<MethodInfo>();
+        ls.addAll(ci.getDeclaredMethods());
+        for (ClassInfo cl : ci.getSuperclasses()) {
+            ls.addAll(cl.getDeclaredMethods());
+        }
+        return ls;
+    }
+
 }
--- a/jmh-core/src/main/java/org/openjdk/jmh/generators/core/StateObjectHandler.java	Fri Feb 28 14:17:53 2014 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/generators/core/StateObjectHandler.java	Fri Feb 28 14:26:18 2014 +0400
@@ -203,14 +203,14 @@
         stateObjects.add(so);
 
         // walk the type hierarchy up to discover inherited @Params
-        for (FieldInfo fi : ci.getFields()) {
+        for (FieldInfo fi : BenchmarkGeneratorUtils.getAllFields(ci)) {
             if (fi.getAnnotation(Param.class) != null) {
                 so.addParam(fi);
             }
         }
 
         // put the @State objects helper methods
-        for (MethodInfo mi : ci.getMethods()) {
+        for (MethodInfo mi : BenchmarkGeneratorUtils.getMethods(ci)) {
             Setup setupAnn = mi.getAnnotation(Setup.class);
             if (setupAnn != null) {
                 helpersByState.put(so, new HelperMethodInvocation(mi, so, setupAnn.value(), HelperType.SETUP));
--- a/jmh-core/src/main/java/org/openjdk/jmh/generators/reflective/ReflectiveClassInfo.java	Fri Feb 28 14:17:53 2014 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/generators/reflective/ReflectiveClassInfo.java	Fri Feb 28 14:26:18 2014 +0400
@@ -65,16 +65,6 @@
     }
 
     @Override
-    public Collection<FieldInfo> getFields() {
-        List<FieldInfo> ls = new ArrayList<FieldInfo>();
-        ls.addAll(getDeclaredFields());
-        for (ClassInfo cl : getSuperclasses()) {
-            ls.addAll(cl.getDeclaredFields());
-        }
-        return ls;
-    }
-
-    @Override
     public Collection<MethodInfo> getConstructors() {
         // FIXME
         return Collections.emptyList();
@@ -87,16 +77,6 @@
     }
 
     @Override
-    public Collection<MethodInfo> getMethods() {
-        List<MethodInfo> ls = new ArrayList<MethodInfo>();
-        ls.addAll(getDeclaredMethods());
-        for (ClassInfo cl : getSuperclasses()) {
-            ls.addAll(cl.getDeclaredMethods());
-        }
-        return ls;
-    }
-
-    @Override
     public Collection<ClassInfo> getSuperclasses() {
         // FIXME
         return Collections.emptyList();
--- a/jmh-core/src/main/java/org/openjdk/jmh/generators/source/ClassInfo.java	Fri Feb 28 14:17:53 2014 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/generators/source/ClassInfo.java	Fri Feb 28 14:26:18 2014 +0400
@@ -40,14 +40,10 @@
 
     Collection<FieldInfo> getDeclaredFields();
 
-    Collection<FieldInfo> getFields();
-
     Collection<MethodInfo> getConstructors();
 
     Collection<MethodInfo> getDeclaredMethods();
 
-    Collection<MethodInfo> getMethods();
-
     Collection<ClassInfo> getSuperclasses();
 
     <T extends Annotation> T getAnnotation(Class<T> annClass);