changeset 440:3ccedf7d3298

Yak shaving: ClassInfo.getSuperclasses() -> ClassInfo.getSuperclass().
author shade
date Fri, 28 Feb 2014 15:00:35 +0400
parents 3387329b6564
children e285f2d94773
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/reflective/ReflectiveClassInfo.java jmh-core/src/main/java/org/openjdk/jmh/generators/source/ClassInfo.java
diffstat 6 files changed, 27 insertions(+), 35 deletions(-) [+]
line wrap: on
line diff
--- a/jmh-core/src/main/java/org/openjdk/jmh/generators/annotations/APClassInfo.java	Fri Feb 28 14:28:17 2014 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/generators/annotations/APClassInfo.java	Fri Feb 28 15:00:35 2014 +0400
@@ -33,6 +33,8 @@
 import javax.lang.model.element.Modifier;
 import javax.lang.model.element.TypeElement;
 import javax.lang.model.element.VariableElement;
+import javax.lang.model.type.TypeKind;
+import javax.lang.model.type.TypeMirror;
 import javax.lang.model.util.ElementFilter;
 import java.lang.annotation.Annotation;
 import java.util.ArrayList;
@@ -102,13 +104,14 @@
     }
 
     @Override
-    public Collection<ClassInfo> getSuperclasses() {
-        List<ClassInfo> list = new ArrayList<ClassInfo>();
-        TypeElement walk = el;
-        while ((walk = (TypeElement) processEnv.getTypeUtils().asElement(walk.getSuperclass())) != null) {
-            list.add(new APClassInfo(processEnv, walk));
+    public ClassInfo getSuperclass() {
+        TypeMirror superclass = el.getSuperclass();
+        if (superclass.getKind() == TypeKind.NONE) {
+            return null;
         }
-        return list;
+
+        TypeElement element = (TypeElement) processEnv.getTypeUtils().asElement(superclass);
+        return new APClassInfo(processEnv, element);
     }
 
     @Override
--- a/jmh-core/src/main/java/org/openjdk/jmh/generators/bytecode/ASMClassInfo.java	Fri Feb 28 14:28:17 2014 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/generators/bytecode/ASMClassInfo.java	Fri Feb 28 15:00:35 2014 +0400
@@ -149,12 +149,11 @@
     }
 
     @Override
-    public Collection<ClassInfo> getSuperclasses() {
+    public ClassInfo getSuperclass() {
         // TODO: FIXME
-        return Collections.emptyList();
+        return null;
     }
 
-
     @Override
     public <T extends Annotation> T getAnnotationRecursive(Class<T> annClass) {
         return getAnnotation(annClass); // TODO: FIXME
--- a/jmh-core/src/main/java/org/openjdk/jmh/generators/core/BenchmarkGenerator.java	Fri Feb 28 14:28:17 2014 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/generators/core/BenchmarkGenerator.java	Fri Feb 28 15:00:35 2014 +0400
@@ -185,25 +185,17 @@
 
         Multimap<ClassInfo, MethodInfo> result = new HashMultimap<ClassInfo, MethodInfo>();
         for (ClassInfo currentClass : source.getClasses()) {
-            if (currentClass.getQualifiedName().contains("generated")) continue;
-            if (currentClass.isAbstract()) continue;
-
-            for (MethodInfo mi : currentClass.getMethods()) {
-                GenerateMicroBenchmark ann = mi.getAnnotation(GenerateMicroBenchmark.class);
-                if (ann != null) {
-                    result.put(currentClass, mi);
-                }
-            }
-
-            for (ClassInfo upperClass : currentClass.getSuperclasses()) {
-                if (upperClass.getQualifiedName().contains("generated")) continue;
-                for (MethodInfo mi : upperClass.getMethods()) {
+            ClassInfo walk = currentClass;
+            do {
+                if (currentClass.getQualifiedName().contains("generated")) continue;
+                if (currentClass.isAbstract()) continue;
+                for (MethodInfo mi : walk.getMethods()) {
                     GenerateMicroBenchmark ann = mi.getAnnotation(GenerateMicroBenchmark.class);
                     if (ann != null) {
                         result.put(currentClass, mi);
                     }
                 }
-            }
+            } while ((walk = walk.getSuperclass()) != null);
         }
         return result;
     }
--- a/jmh-core/src/main/java/org/openjdk/jmh/generators/core/BenchmarkGeneratorUtils.java	Fri Feb 28 14:28:17 2014 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/generators/core/BenchmarkGeneratorUtils.java	Fri Feb 28 15:00:35 2014 +0400
@@ -72,19 +72,17 @@
 
     public static Collection<FieldInfo> getAllFields(ClassInfo ci) {
         List<FieldInfo> ls = new ArrayList<FieldInfo>();
-        ls.addAll(ci.getFields());
-        for (ClassInfo cl : ci.getSuperclasses()) {
-            ls.addAll(cl.getFields());
-        }
+        do {
+            ls.addAll(ci.getFields());
+        } while ((ci = ci.getSuperclass()) != null);
         return ls;
     }
 
     public static Collection<MethodInfo> getMethods(ClassInfo ci) {
         List<MethodInfo> ls = new ArrayList<MethodInfo>();
-        ls.addAll(ci.getMethods());
-        for (ClassInfo cl : ci.getSuperclasses()) {
-            ls.addAll(cl.getMethods());
-        }
+        do {
+            ls.addAll(ci.getMethods());
+        } while ((ci = ci.getSuperclass()) != null);
         return ls;
     }
 
--- a/jmh-core/src/main/java/org/openjdk/jmh/generators/reflective/ReflectiveClassInfo.java	Fri Feb 28 14:28:17 2014 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/generators/reflective/ReflectiveClassInfo.java	Fri Feb 28 15:00:35 2014 +0400
@@ -77,9 +77,9 @@
     }
 
     @Override
-    public Collection<ClassInfo> getSuperclasses() {
+    public ClassInfo getSuperclass() {
         // FIXME
-        return Collections.emptyList();
+        return null;
     }
 
     @Override
--- a/jmh-core/src/main/java/org/openjdk/jmh/generators/source/ClassInfo.java	Fri Feb 28 14:28:17 2014 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/generators/source/ClassInfo.java	Fri Feb 28 15:00:35 2014 +0400
@@ -38,14 +38,14 @@
 
     String getQualifiedName();
 
+    ClassInfo getSuperclass();
+
     Collection<FieldInfo> getFields();
 
     Collection<MethodInfo> getMethods();
 
     Collection<MethodInfo> getConstructors();
 
-    Collection<ClassInfo> getSuperclasses();
-
     <T extends Annotation> T getAnnotation(Class<T> annClass);
 
     <T extends Annotation> T getAnnotationRecursive(Class<T> annClass);