You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by db...@apache.org on 2012/06/05 23:33:50 UTC

svn commit: r1346604 - in /commons/sandbox/classscan/branches/commons-finder/src/main/java/org/apache/commons/classscan/finder: AnnotationFinder.java model/

Author: dblevins
Date: Tue Jun  5 21:33:49 2012
New Revision: 1346604

URL: http://svn.apache.org/viewvc?rev=1346604&view=rev
Log:
yanked some dead code, added finals where usable

Added:
    commons/sandbox/classscan/branches/commons-finder/src/main/java/org/apache/commons/classscan/finder/model/
Modified:
    commons/sandbox/classscan/branches/commons-finder/src/main/java/org/apache/commons/classscan/finder/AnnotationFinder.java

Modified: commons/sandbox/classscan/branches/commons-finder/src/main/java/org/apache/commons/classscan/finder/AnnotationFinder.java
URL: http://svn.apache.org/viewvc/commons/sandbox/classscan/branches/commons-finder/src/main/java/org/apache/commons/classscan/finder/AnnotationFinder.java?rev=1346604&r1=1346603&r2=1346604&view=diff
==============================================================================
--- commons/sandbox/classscan/branches/commons-finder/src/main/java/org/apache/commons/classscan/finder/AnnotationFinder.java (original)
+++ commons/sandbox/classscan/branches/commons-finder/src/main/java/org/apache/commons/classscan/finder/AnnotationFinder.java Tue Jun  5 21:33:49 2012
@@ -34,7 +34,6 @@ import org.objectweb.asm.FieldVisitor;
 import org.objectweb.asm.MethodVisitor;
 import org.objectweb.asm.Type;
 import org.objectweb.asm.commons.EmptyVisitor;
-import org.objectweb.asm.signature.SignatureVisitor;
 
 import java.io.ByteArrayInputStream;
 import java.io.IOException;
@@ -58,7 +57,7 @@ import java.util.Map;
 import java.util.Set;
 
 /**
- * ClassFinder searches the classpath of the specified classloader for
+ * AnnotationFinder searches the classpath of the specified classloader for
  * packages, classes, constructors, methods, or fields with specific annotations.
  * <p/>
  * For security reasons ASM is used to find the annotations.  Classes are not
@@ -76,7 +75,6 @@ public class AnnotationFinder implements
     protected final Map<String, ClassInfo> classInfos = new HashMap<String, ClassInfo>();
     protected final Map<String, ClassInfo> originalInfos = new HashMap<String, ClassInfo>();
     private final List<String> classesNotLoaded = new ArrayList<String>();
-    private final int ASM_FLAGS = ClassReader.SKIP_CODE + ClassReader.SKIP_DEBUG + ClassReader.SKIP_FRAMES;
     private final Archive archive;
 
     private AnnotationFinder(AnnotationFinder parent, Iterable<String> classNames) {
@@ -252,19 +250,6 @@ public class AnnotationFinder implements
         if (annotated.keySet().size() != annotations.size()) {
             resolveAnnotations(annotations);
         }
-
-
-//        for (ClassInfo classInfo : classInfos.values()) {
-//            for (AnnotationInfo annotationInfo : classInfo.getAnnotations()) {
-//                for (AnnotationInfo info : annotationInfo.getAnnotations()) {
-//                    final String annotation = info.getName();
-//
-//                    if (hasName(annotation, "Metaroot") && !scanned.contains(annotation)) {
-//                        readClassDef(annotation);
-//                    }
-//                }
-//            }
-//        }
     }
 
     private void linkMetaAnnotations() {
@@ -394,7 +379,7 @@ public class AnnotationFinder implements
     }
 
     public boolean isAnnotationPresent(Class<? extends Annotation> annotation) {
-        List<Info> infos = annotated.get(annotation.getName());
+        final List<Info> infos = annotated.get(annotation.getName());
         return infos != null && !infos.isEmpty();
     }
 
@@ -417,13 +402,13 @@ public class AnnotationFinder implements
 
     public List<Package> findAnnotatedPackages(Class<? extends Annotation> annotation) {
         classesNotLoaded.clear();
-        List<Package> packages = new ArrayList<Package>();
-        List<Info> infos = getAnnotationInfos(annotation.getName());
+        final List<Package> packages = new ArrayList<Package>();
+        final List<Info> infos = getAnnotationInfos(annotation.getName());
         for (Info info : infos) {
             if (info instanceof PackageInfo) {
-                PackageInfo packageInfo = (PackageInfo) info;
+                final PackageInfo packageInfo = (PackageInfo) info;
                 try {
-                    Package pkg = packageInfo.get();
+                    final Package pkg = packageInfo.get();
                     // double check via proper reflection
                     if (pkg.isAnnotationPresent(annotation)) {
                         packages.add(pkg);
@@ -438,13 +423,13 @@ public class AnnotationFinder implements
 
     public List<Class<?>> findAnnotatedClasses(Class<? extends Annotation> annotation) {
         classesNotLoaded.clear();
-        List<Class<?>> classes = new ArrayList<Class<?>>();
-        List<Info> infos = getAnnotationInfos(annotation.getName());
+        final List<Class<?>> classes = new ArrayList<Class<?>>();
+        final List<Info> infos = getAnnotationInfos(annotation.getName());
         for (Info info : infos) {
             if (info instanceof ClassInfo) {
-                ClassInfo classInfo = (ClassInfo) info;
+                final ClassInfo classInfo = (ClassInfo) info;
                 try {
-                    Class clazz = classInfo.get();
+                    final Class clazz = classInfo.get();
                     // double check via proper reflection
                     if (clazz.isAnnotationPresent(annotation)) {
                         classes.add(clazz);
@@ -459,9 +444,9 @@ public class AnnotationFinder implements
 
     public List<Annotated<Class<?>>> findMetaAnnotatedClasses(Class<? extends Annotation> annotation) {
         classesNotLoaded.clear();
-        Set<Class<?>> classes = findMetaAnnotatedClasses(annotation, new HashSet<Class<?>>());
+        final Set<Class<?>> classes = findMetaAnnotatedClasses(annotation, new HashSet<Class<?>>());
 
-        List<Annotated<Class<?>>> list = new ArrayList<Annotated<Class<?>>>();
+        final List<Annotated<Class<?>>> list = new ArrayList<Annotated<Class<?>>>();
 
         for (Class<?> clazz : classes) {
             if (Annotation.class.isAssignableFrom(clazz) && isMetaAnnotation((Class<? extends Annotation>) clazz)) continue;
@@ -505,12 +490,12 @@ public class AnnotationFinder implements
 
 
     private Set<Class<?>> findMetaAnnotatedClasses(Class<? extends Annotation> annotation, Set<Class<?>> classes) {
-        List<Info> infos = getAnnotationInfos(annotation.getName());
+        final List<Info> infos = getAnnotationInfos(annotation.getName());
         for (Info info : infos) {
             if (info instanceof ClassInfo) {
-                ClassInfo classInfo = (ClassInfo) info;
+                final ClassInfo classInfo = (ClassInfo) info;
                 try {
-                    Class clazz = classInfo.get();
+                    final Class clazz = classInfo.get();
 
                     if (classes.contains(clazz)) continue;
 
@@ -519,7 +504,7 @@ public class AnnotationFinder implements
                         classes.add(clazz);
                     }
 
-                    String meta = info.getMetaAnnotationName();
+                    final String meta = info.getMetaAnnotationName();
                     if (meta != null) {
                         classes.addAll(findMetaAnnotatedClasses((Class<? extends Annotation>) clazz, classes));
                     }
@@ -539,8 +524,8 @@ public class AnnotationFinder implements
      */
     public List<Class<?>> findInheritedAnnotatedClasses(Class<? extends Annotation> annotation) {
         classesNotLoaded.clear();
-        List<Class<?>> classes = new ArrayList<Class<?>>();
-        List<Info> infos = getAnnotationInfos(annotation.getName());
+        final List<Class<?>> classes = new ArrayList<Class<?>>();
+        final List<Info> infos = getAnnotationInfos(annotation.getName());
         for (Info info : infos) {
             try {
                 if (info instanceof ClassInfo) {
@@ -551,14 +536,14 @@ public class AnnotationFinder implements
             }
         }
         boolean annClassFound;
-        List<ClassInfo> tempClassInfos = new ArrayList<ClassInfo>(classInfos.values());
+        final List<ClassInfo> tempClassInfos = new ArrayList<ClassInfo>(classInfos.values());
         do {
             annClassFound = false;
             for (int pos = 0; pos < tempClassInfos.size(); pos++) {
-                ClassInfo classInfo = tempClassInfos.get(pos);
+                final ClassInfo classInfo = tempClassInfos.get(pos);
                 try {
                     // check whether any superclass is annotated
-                    String superType = classInfo.getSuperType();
+                    final String superType = classInfo.getSuperType();
                     for (Class clazz : classes) {
                         if (superType.equals(clazz.getName())) {
                             classes.add(classInfo.get());
@@ -568,7 +553,7 @@ public class AnnotationFinder implements
                         }
                     }
                     // check whether any interface is annotated
-                    List<String> interfces = classInfo.getInterfaces();
+                    final List<String> interfces = classInfo.getInterfaces();
                     for (String interfce : interfces) {
                         for (Class clazz : classes) {
                             if (interfce.replaceFirst("<.*>", "").equals(clazz.getName())) {
@@ -591,20 +576,20 @@ public class AnnotationFinder implements
 
     public List<Method> findAnnotatedMethods(Class<? extends Annotation> annotation) {
         classesNotLoaded.clear();
-        List<ClassInfo> seen = new ArrayList<ClassInfo>();
-        List<Method> methods = new ArrayList<Method>();
-        List<Info> infos = getAnnotationInfos(annotation.getName());
+        final List<ClassInfo> seen = new ArrayList<ClassInfo>();
+        final List<Method> methods = new ArrayList<Method>();
+        final List<Info> infos = getAnnotationInfos(annotation.getName());
         for (Info info : infos) {
             if (info instanceof MethodInfo && !info.getName().equals("<init>")) {
-                MethodInfo methodInfo = (MethodInfo) info;
-                ClassInfo classInfo = methodInfo.getDeclaringClass();
+                final MethodInfo methodInfo = (MethodInfo) info;
+                final ClassInfo classInfo = methodInfo.getDeclaringClass();
 
                 if (seen.contains(classInfo)) continue;
 
                 seen.add(classInfo);
 
                 try {
-                    Class clazz = classInfo.get();
+                    final Class clazz = classInfo.get();
                     for (Method method : clazz.getDeclaredMethods()) {
                         if (method.isAnnotationPresent(annotation)) {
                             methods.add(method);
@@ -621,9 +606,9 @@ public class AnnotationFinder implements
     public List<Annotated<Method>> findMetaAnnotatedMethods(Class<? extends Annotation> annotation) {
         classesNotLoaded.clear();
 
-        Set<Method> methods = findMetaAnnotatedMethods(annotation, new HashSet<Method>(), new HashSet<String>());
+        final Set<Method> methods = findMetaAnnotatedMethods(annotation, new HashSet<Method>(), new HashSet<String>());
 
-        List<Annotated<Method>> targets = new ArrayList<Annotated<Method>>();
+        final List<Annotated<Method>> targets = new ArrayList<Annotated<Method>>();
 
         for (Method method : methods) {
             targets.add(new MetaAnnotatedMethod(method));
@@ -633,19 +618,19 @@ public class AnnotationFinder implements
     }
 
     private Set<Method> findMetaAnnotatedMethods(Class<? extends Annotation> annotation, Set<Method> methods, Set<String> seen) {
-        List<Info> infos = getAnnotationInfos(annotation.getName());
+        final List<Info> infos = getAnnotationInfos(annotation.getName());
 
         for (Info info : infos) {
 
-            String meta = info.getMetaAnnotationName();
+            final String meta = info.getMetaAnnotationName();
             if (meta != null) {
                 if (meta.equals(annotation.getName())) continue;
                 if (!seen.add(meta)) continue;
 
 
-                ClassInfo metaInfo = classInfos.get(meta);
+                final ClassInfo metaInfo = classInfos.get(meta);
 
-                Class<?> clazz;
+                final Class<?> clazz;
                 try {
                     clazz = metaInfo.get();
                 } catch (ClassNotFoundException e) {
@@ -657,12 +642,12 @@ public class AnnotationFinder implements
 
             } else if (info instanceof MethodInfo && !((MethodInfo) info).isConstructor()) {
 
-                MethodInfo methodInfo = (MethodInfo) info;
+                final MethodInfo methodInfo = (MethodInfo) info;
 
-                ClassInfo classInfo = methodInfo.getDeclaringClass();
+                final ClassInfo classInfo = methodInfo.getDeclaringClass();
 
                 try {
-                    Class clazz = classInfo.get();
+                    final Class clazz = classInfo.get();
                     for (Method method : clazz.getDeclaredMethods()) {
                         if (method.isAnnotationPresent(annotation)) {
                             methods.add(method);
@@ -680,9 +665,9 @@ public class AnnotationFinder implements
     public List<Annotated<Field>> findMetaAnnotatedFields(Class<? extends Annotation> annotation) {
         classesNotLoaded.clear();
 
-        Set<Field> fields = findMetaAnnotatedFields(annotation, new HashSet<Field>(), new HashSet<String>());
+        final Set<Field> fields = findMetaAnnotatedFields(annotation, new HashSet<Field>(), new HashSet<String>());
 
-        List<Annotated<Field>> targets = new ArrayList<Annotated<Field>>();
+        final List<Annotated<Field>> targets = new ArrayList<Annotated<Field>>();
 
         for (Field field : fields) {
             targets.add(new MetaAnnotatedField(field));
@@ -692,19 +677,19 @@ public class AnnotationFinder implements
     }
 
     private Set<Field> findMetaAnnotatedFields(Class<? extends Annotation> annotation, Set<Field> fields, Set<String> seen) {
-        List<Info> infos = getAnnotationInfos(annotation.getName());
+        final List<Info> infos = getAnnotationInfos(annotation.getName());
 
         for (Info info : infos) {
 
-            String meta = info.getMetaAnnotationName();
+            final String meta = info.getMetaAnnotationName();
             if (meta != null) {
                 if (meta.equals(annotation.getName())) continue;
                 if (!seen.add(meta)) continue;
 
 
-                ClassInfo metaInfo = classInfos.get(meta);
+                final ClassInfo metaInfo = classInfos.get(meta);
 
-                Class<?> clazz;
+                final Class<?> clazz;
                 try {
                     clazz = metaInfo.get();
                 } catch (ClassNotFoundException e) {
@@ -716,9 +701,9 @@ public class AnnotationFinder implements
 
             } else if (info instanceof FieldInfo) {
 
-                FieldInfo fieldInfo = (FieldInfo) info;
+                final FieldInfo fieldInfo = (FieldInfo) info;
 
-                ClassInfo classInfo = fieldInfo.getDeclaringClass();
+                final ClassInfo classInfo = fieldInfo.getDeclaringClass();
 
                 try {
                     Class clazz = classInfo.get();
@@ -738,20 +723,20 @@ public class AnnotationFinder implements
 
     public List<Constructor> findAnnotatedConstructors(Class<? extends Annotation> annotation) {
         classesNotLoaded.clear();
-        List<ClassInfo> seen = new ArrayList<ClassInfo>();
-        List<Constructor> constructors = new ArrayList<Constructor>();
-        List<Info> infos = getAnnotationInfos(annotation.getName());
+        final List<ClassInfo> seen = new ArrayList<ClassInfo>();
+        final List<Constructor> constructors = new ArrayList<Constructor>();
+        final List<Info> infos = getAnnotationInfos(annotation.getName());
         for (Info info : infos) {
             if (info instanceof MethodInfo && info.getName().equals("<init>")) {
-                MethodInfo methodInfo = (MethodInfo) info;
-                ClassInfo classInfo = methodInfo.getDeclaringClass();
+                final MethodInfo methodInfo = (MethodInfo) info;
+                final ClassInfo classInfo = methodInfo.getDeclaringClass();
 
                 if (seen.contains(classInfo)) continue;
 
                 seen.add(classInfo);
 
                 try {
-                    Class clazz = classInfo.get();
+                    final Class clazz = classInfo.get();
                     for (Constructor constructor : clazz.getConstructors()) {
                         if (constructor.isAnnotationPresent(annotation)) {
                             constructors.add(constructor);
@@ -767,20 +752,20 @@ public class AnnotationFinder implements
 
     public List<Field> findAnnotatedFields(Class<? extends Annotation> annotation) {
         classesNotLoaded.clear();
-        List<ClassInfo> seen = new ArrayList<ClassInfo>();
-        List<Field> fields = new ArrayList<Field>();
-        List<Info> infos = getAnnotationInfos(annotation.getName());
+        final List<ClassInfo> seen = new ArrayList<ClassInfo>();
+        final List<Field> fields = new ArrayList<Field>();
+        final List<Info> infos = getAnnotationInfos(annotation.getName());
         for (Info info : infos) {
             if (info instanceof FieldInfo) {
-                FieldInfo fieldInfo = (FieldInfo) info;
-                ClassInfo classInfo = fieldInfo.getDeclaringClass();
+                final FieldInfo fieldInfo = (FieldInfo) info;
+                final ClassInfo classInfo = fieldInfo.getDeclaringClass();
 
                 if (seen.contains(classInfo)) continue;
 
                 seen.add(classInfo);
 
                 try {
-                    Class clazz = classInfo.get();
+                    final Class clazz = classInfo.get();
                     for (Field field : clazz.getDeclaredFields()) {
                         if (field.isAnnotationPresent(annotation)) {
                             fields.add(field);
@@ -796,7 +781,7 @@ public class AnnotationFinder implements
 
     public List<Class<?>> findClassesInPackage(String packageName, boolean recursive) {
         classesNotLoaded.clear();
-        List<Class<?>> classes = new ArrayList<Class<?>>();
+        final List<Class<?>> classes = new ArrayList<Class<?>>();
         for (ClassInfo classInfo : classInfos.values()) {
             try {
                 if (recursive && classInfo.getPackageName().startsWith(packageName)) {
@@ -844,7 +829,7 @@ public class AnnotationFinder implements
     private <T> List<Class<? extends T>> _findSubclasses(Class<T> clazz) {
         if (clazz == null) throw new NullPointerException("class cannot be null");
 
-        List<Class<? extends T>> classes = new ArrayList<Class<? extends T>>();
+        final List<Class<? extends T>> classes = new ArrayList<Class<? extends T>>();
 
 
         for (ClassInfo classInfo : classInfos.values()) {
@@ -880,10 +865,10 @@ public class AnnotationFinder implements
         // Collect all interfaces extending the main interface (recursively)
         // Collect all implementations of interfaces
         // i.e. all *directly* implementing classes
-        List<ClassInfo> infos = collectImplementations(interfaceName);
+        final List<ClassInfo> infos = collectImplementations(interfaceName);
 
         // Collect all subclasses of implementations
-        List<Class<? extends T>> classes = new ArrayList<Class<? extends T>>();
+        final List<Class<? extends T>> classes = new ArrayList<Class<? extends T>>();
         for (ClassInfo info : infos) {
             try {
                 final Class<? extends T> impl = (Class<? extends T>) info.get();
@@ -946,64 +931,8 @@ public class AnnotationFinder implements
         return infos;
     }
 
-    protected void readClassDef(String className) {
-        if (classInfos.containsKey(className)) return;
-        try {
-            readClassDef(archive.getBytecode(className));
-        } catch (Exception e) {
-            if (className.endsWith("$$")) return;
-            classesNotLoaded.add(className);
-        }
-    }
-
-    protected void readClassDef(InputStream in) throws IOException {
-        try {
-            ClassReader classReader = new ClassReader(in);
-            classReader.accept(new InfoBuildingVisitor(), ASM_FLAGS);
-        } finally {
-            in.close();
-        }
-    }
-
-    protected void readClassDef(Class clazz) {
-        List<Info> infos = new ArrayList<Info>();
-
-        Package aPackage = clazz.getPackage();
-        if (aPackage != null) {
-            final PackageInfo info = new PackageInfo(aPackage);
-            for (AnnotationInfo annotation : info.getAnnotations()) {
-                List<Info> annotationInfos = initAnnotationInfos(annotation.getName());
-                if (!annotationInfos.contains(info)) {
-                    annotationInfos.add(info);
-                }
-            }
-        }
-
-        ClassInfo classInfo = new ClassInfo(clazz);
-        infos.add(classInfo);
-        classInfos.put(clazz.getName(), classInfo);
-        for (Method method : clazz.getDeclaredMethods()) {
-            infos.add(new MethodInfo(classInfo, method));
-        }
-
-        for (Constructor constructor : clazz.getConstructors()) {
-            infos.add(new MethodInfo(classInfo, constructor));
-        }
-
-        for (Field field : clazz.getDeclaredFields()) {
-            infos.add(new FieldInfo(classInfo, field));
-        }
-
-        for (Info info : infos) {
-            for (AnnotationInfo annotation : info.getAnnotations()) {
-                List<Info> annotationInfos = initAnnotationInfos(annotation.getName());
-                annotationInfos.add(info);
-            }
-        }
-    }
-
     public AnnotationFinder select(Class<?>... clazz) {
-        String[] names = new String[clazz.length];
+        final String[] names = new String[clazz.length];
         int i = 0;
         for (Class<?> name : clazz) {
             names[i++] = name.getName();
@@ -1064,6 +993,19 @@ public class AnnotationFinder implements
         }
     }
 
+    /**
+     * This class has the following subclasses:
+     *
+     *  PackageInfo
+     *  ClassInfo
+     *  MethodInfo
+     *  FieldInfo
+     *  AnnotationInfo
+     *
+     * The internal Data Model objects.  These could be promoted to top-level objects
+     *
+     * A bit of tweaking would be required to make them static before promoting them
+     */
     public class Annotatable {
         private final List<AnnotationInfo> annotations = new ArrayList<AnnotationInfo>();
 
@@ -1157,7 +1099,7 @@ public class AnnotationFinder implements
             if (this == o) return true;
             if (o == null || getClass() != o.getClass()) return false;
 
-            PackageInfo that = (PackageInfo) o;
+            final PackageInfo that = (PackageInfo) o;
 
             if (name != null ? !name.equals(that.name) : that.name != null) return false;
 
@@ -1186,7 +1128,9 @@ public class AnnotationFinder implements
             super(clazz);
             this.clazz = clazz;
             this.name = clazz.getName();
-            Class superclass = clazz.getSuperclass();
+
+            final Class superclass = clazz.getSuperclass();
+
             this.superType = superclass != null ? superclass.getName() : null;
             for (Class intrface : clazz.getInterfaces()) {
                 this.interfaces.add(intrface.getName());
@@ -1207,7 +1151,7 @@ public class AnnotationFinder implements
             }
 
             if (name.endsWith("$$")) {
-                ClassInfo info = classInfos.get(name.substring(0, name.length() - 2));
+                final ClassInfo info = classInfos.get(name.substring(0, name.length() - 2));
                 if (info != null) {
                     return info.getMetaAnnotationName();
                 }
@@ -1251,7 +1195,7 @@ public class AnnotationFinder implements
         public Class<?> get() throws ClassNotFoundException {
             if (clazz != null) return clazz;
             try {
-                String fixedName = name.replaceFirst("<.*>", "");
+                final String fixedName = name.replaceFirst("<.*>", "");
                 this.clazz = archive.loadClass(fixedName);
                 return clazz;
             } catch (ClassNotFoundException notFound) {
@@ -1319,7 +1263,7 @@ public class AnnotationFinder implements
         public List<AnnotationInfo> getParameterAnnotations(int index) {
             if (index >= parameterAnnotations.size()) {
                 for (int i = parameterAnnotations.size(); i <= index; i++) {
-                    List<AnnotationInfo> annotationInfos = new ArrayList<AnnotationInfo>();
+                    final List<AnnotationInfo> annotationInfos = new ArrayList<AnnotationInfo>();
                     parameterAnnotations.add(i, annotationInfos);
                 }
             }
@@ -1350,7 +1294,7 @@ public class AnnotationFinder implements
             org.objectweb.asm.commons.Method method = new org.objectweb.asm.commons.Method(name, descriptor);
 
             Class<?> clazz = this.declaringClass.get();
-            List<Class> parameterTypes = new ArrayList<Class>();
+            final List<Class> parameterTypes = new ArrayList<Class>();
 
             for (Type type : method.getArgumentTypes()) {
                 String paramType = type.getClassName();
@@ -1361,7 +1305,7 @@ public class AnnotationFinder implements
                 }
             }
 
-            Class[] parameters = parameterTypes.toArray(new Class[parameterTypes.size()]);
+            final Class[] parameters = parameterTypes.toArray(new Class[parameterTypes.size()]);
 
             IllegalStateException noSuchMethod = null;
             while (clazz != null) {
@@ -1481,6 +1425,70 @@ public class AnnotationFinder implements
         initAnnotationInfos(annotationInfo.getName()).add(info);
     }
 
+    protected void readClassDef(String className) {
+        if (classInfos.containsKey(className)) return;
+        try {
+            readClassDef(archive.getBytecode(className));
+        } catch (Exception e) {
+            if (className.endsWith("$$")) return;
+            classesNotLoaded.add(className);
+        }
+    }
+
+    protected void readClassDef(Class clazz) {
+        final List<Info> infos = new ArrayList<Info>();
+
+        final Package aPackage = clazz.getPackage();
+        if (aPackage != null) {
+            final PackageInfo info = new PackageInfo(aPackage);
+            for (AnnotationInfo annotation : info.getAnnotations()) {
+                List<Info> annotationInfos = initAnnotationInfos(annotation.getName());
+                if (!annotationInfos.contains(info)) {
+                    annotationInfos.add(info);
+                }
+            }
+        }
+
+        final ClassInfo classInfo = new ClassInfo(clazz);
+        infos.add(classInfo);
+        classInfos.put(clazz.getName(), classInfo);
+        for (Method method : clazz.getDeclaredMethods()) {
+            infos.add(new MethodInfo(classInfo, method));
+        }
+
+        for (Constructor constructor : clazz.getConstructors()) {
+            infos.add(new MethodInfo(classInfo, constructor));
+        }
+
+        for (Field field : clazz.getDeclaredFields()) {
+            infos.add(new FieldInfo(classInfo, field));
+        }
+
+        for (Info info : infos) {
+            for (AnnotationInfo annotation : info.getAnnotations()) {
+                List<Info> annotationInfos = initAnnotationInfos(annotation.getName());
+                annotationInfos.add(info);
+            }
+        }
+    }
+
+    //----------------------------------------------------------------------------
+    //
+    //  From here below are the ASM specific parts.
+    //
+    //  With a cleaned up model, this could easily be abstracted
+    //
+    //----------------------------------------------------------------------------
+    protected void readClassDef(InputStream in) throws IOException {
+        try {
+            final ClassReader classReader = new ClassReader(in);
+            final int flags = ClassReader.SKIP_CODE + ClassReader.SKIP_DEBUG + ClassReader.SKIP_FRAMES;
+            classReader.accept(new InfoBuildingVisitor(), flags);
+        } finally {
+            in.close();
+        }
+    }
+
     public class InfoBuildingVisitor extends EmptyVisitor {
         private Info info;
 
@@ -1499,14 +1507,10 @@ public class AnnotationFinder implements
 
                 ClassInfo classInfo = new ClassInfo(javaName(name), javaName(superName));
 
-//                if (signature == null) {
-                    for (String interfce : interfaces) {
-                        classInfo.getInterfaces().add(javaName(interfce));
-                    }
-//                } else {
-//                    // the class uses generics
-//                    new SignatureReader(signature).accept(new GenericAwareInfoBuildingVisitor(GenericAwareInfoBuildingVisitor.TYPE.CLASS, classInfo));
-//                }
+                for (String interfce : interfaces) {
+                    classInfo.getInterfaces().add(javaName(interfce));
+                }
+
                 info = classInfo;
 
                 classInfos.put(classInfo.getName(), classInfo);
@@ -1562,165 +1566,4 @@ public class AnnotationFinder implements
             return new InfoBuildingVisitor(annotationInfo);
         }
     }
-
-    public static class GenericAwareInfoBuildingVisitor implements SignatureVisitor {
-
-        public enum TYPE {
-            CLASS
-        }
-
-        public enum STATE {
-            BEGIN, END, SUPERCLASS, INTERFACE, FORMAL_TYPE_PARAM
-        }
-
-        private Info info;
-        private GenericAwareInfoBuildingVisitor.TYPE type;
-        private GenericAwareInfoBuildingVisitor.STATE state;
-
-        private static boolean debug = false;
-
-        public GenericAwareInfoBuildingVisitor() {
-        }
-
-        public GenericAwareInfoBuildingVisitor(GenericAwareInfoBuildingVisitor.TYPE type, Info info) {
-            this.type = type;
-            this.info = info;
-            this.state = GenericAwareInfoBuildingVisitor.STATE.BEGIN;
-        }
-
-        public void visitFormalTypeParameter(String s) {
-            if (debug) System.out.println(" s=" + s);
-            switch (state) {
-                case BEGIN:
-                    ((ClassInfo) info).name += "<" + s;
-            }
-            state = GenericAwareInfoBuildingVisitor.STATE.FORMAL_TYPE_PARAM;
-        }
-
-        public SignatureVisitor visitClassBound() {
-            if (debug) System.out.println(" visitClassBound()");
-            return this;
-        }
-
-        public SignatureVisitor visitInterfaceBound() {
-            if (debug) System.out.println(" visitInterfaceBound()");
-            return this;
-        }
-
-        public SignatureVisitor visitSuperclass() {
-            if (debug) System.out.println(" visitSuperclass()");
-            state = GenericAwareInfoBuildingVisitor.STATE.SUPERCLASS;
-            return this;
-        }
-
-        public SignatureVisitor visitInterface() {
-            if (debug) System.out.println(" visitInterface()");
-            ((ClassInfo) info).getInterfaces().add("");
-            state = GenericAwareInfoBuildingVisitor.STATE.INTERFACE;
-            return this;
-        }
-
-        public SignatureVisitor visitParameterType() {
-            if (debug) System.out.println(" visitParameterType()");
-            return this;
-        }
-
-        public SignatureVisitor visitReturnType() {
-            if (debug) System.out.println(" visitReturnType()");
-            return this;
-        }
-
-        public SignatureVisitor visitExceptionType() {
-            if (debug) System.out.println(" visitExceptionType()");
-            return this;
-        }
-
-        public void visitBaseType(char c) {
-            if (debug) System.out.println(" visitBaseType(" + c + ")");
-        }
-
-        public void visitTypeVariable(String s) {
-            if (debug) System.out.println(" visitTypeVariable(" + s + ")");
-        }
-
-        public SignatureVisitor visitArrayType() {
-            if (debug) System.out.println(" visitArrayType()");
-            return this;
-        }
-
-        public void visitClassType(String s) {
-            if (debug) System.out.println(" visitClassType(" + s + ")");
-            switch (state) {
-                case INTERFACE:
-                    List<String> interfces = ((ClassInfo) info).getInterfaces();
-                    int idx = interfces.size() - 1;
-                    String interfce = interfces.get(idx);
-                    if (interfce.length() == 0) {
-                        interfce = javaName(s);
-                    } else {
-                        interfce += javaName(s);
-                    }
-                    interfces.set(idx, interfce);
-                    break;
-                case SUPERCLASS:
-                    if (!s.equals("java/lang/Object")) {
-                        ((ClassInfo) info).superType = javaName(s);
-                    }
-            }
-        }
-
-        public void visitInnerClassType(String s) {
-            if (debug) System.out.println(" visitInnerClassType(" + s + ")");
-        }
-
-        public void visitTypeArgument() {
-            if (debug) System.out.println(" visitTypeArgument()");
-            switch (state) {
-                case INTERFACE:
-                    List<String> interfces = ((ClassInfo) info).getInterfaces();
-                    int idx = interfces.size() - 1;
-                    String interfce = interfces.get(idx);
-                    interfce += "<";
-                    interfces.set(idx, interfce);
-            }
-        }
-
-        public SignatureVisitor visitTypeArgument(char c) {
-            if (debug) System.out.println(" visitTypeArgument(" + c + ")");
-            switch (state) {
-                case INTERFACE:
-                    List<String> interfces = ((ClassInfo) info).getInterfaces();
-                    int idx = interfces.size() - 1;
-                    String interfce = interfces.get(idx);
-                    interfce += "<";
-                    interfces.set(idx, interfce);
-            }
-            return this;
-        }
-
-        public void visitEnd() {
-            if (debug) System.out.println(" visitEnd()");
-            switch (state) {
-                case INTERFACE:
-                    List<String> interfces = ((ClassInfo) info).getInterfaces();
-                    int idx = interfces.size() - 1;
-                    String interfce = interfces.get(idx);
-                    interfce += ">";
-                    interfces.set(idx, interfce);
-                    break;
-                case FORMAL_TYPE_PARAM:
-                    String name = ((ClassInfo) info).name;
-                    if (name.contains("<")) {
-                        ((ClassInfo) info).name += ">";
-                    }
-            }
-            state = GenericAwareInfoBuildingVisitor.STATE.END;
-        }
-
-        private String javaName(String name) {
-            return (name == null) ? null : name.replace('/', '.');
-        }
-
-    }
-
 }
\ No newline at end of file