[jboss-cvs] JBossAS SVN: r92281 - in projects/annotations/trunk/core/src/main/java/org/jboss/annotations: javassistclasspool and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Aug 12 14:45:45 EDT 2009


Author: jesper.pedersen
Date: 2009-08-12 14:45:45 -0400 (Wed, 12 Aug 2009)
New Revision: 92281

Modified:
   projects/annotations/trunk/core/src/main/java/org/jboss/annotations/impl/AbstractJavassistAnnotationScanner.java
   projects/annotations/trunk/core/src/main/java/org/jboss/annotations/javassistclasspool/JavassistClassPool.java
   projects/annotations/trunk/core/src/main/java/org/jboss/annotations/javassistinputstream/JavassistInputStream.java
Log:
[JBANN-10] Create the JBoss Annotations XSD (Part 2)

Modified: projects/annotations/trunk/core/src/main/java/org/jboss/annotations/impl/AbstractJavassistAnnotationScanner.java
===================================================================
--- projects/annotations/trunk/core/src/main/java/org/jboss/annotations/impl/AbstractJavassistAnnotationScanner.java	2009-08-12 18:30:46 UTC (rev 92280)
+++ projects/annotations/trunk/core/src/main/java/org/jboss/annotations/impl/AbstractJavassistAnnotationScanner.java	2009-08-12 18:45:45 UTC (rev 92281)
@@ -31,6 +31,12 @@
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
+import javassist.CtClass;
+import javassist.CtConstructor;
+import javassist.CtField;
+import javassist.CtMethod;
+import javassist.NotFoundException;
+
 /**
  * An abstract annotation scanner - base class
  * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
@@ -52,7 +58,194 @@
       trace = log.isLoggable(Level.FINEST);
    }
 
+   /**
+    * Process class
+    * @param ctClass The class
+    * @param result The resulting map
+    * @exception NotFoundException Thrown if the class types cant be resolved
+    */
+   protected void processClass(CtClass ctClass, Map<String, Collection<Annotation>> result) throws NotFoundException
+   {
+      if (trace)
+         log.finest("Class=" + ctClass.getName());
 
+      // Class level annotations
+      Object[] classAnnotations = ctClass.getAvailableAnnotations();
+                        
+      if (classAnnotations != null)
+      {
+         for (Object annotation : classAnnotations)
+         {
+            processAnnotation(annotation, 
+                              AnnotationType.CLASS, 
+                              ctClass.getName(), null, null,
+                              result);
+         }
+      }
+
+      if (!ctClass.isInterface())
+      {
+         // Constructor level annotations
+         CtConstructor[] constructors = ctClass.getDeclaredConstructors();
+         if (constructors != null)
+         {
+            for (CtConstructor constructor : constructors)
+            {
+               if (trace)
+                  log.finest("Constructor=" + constructor.getName());
+
+               Object[] constructorAnnotations = constructor.getAvailableAnnotations();
+               if (constructorAnnotations != null)
+               {
+                  String[] parameterTypes = null;
+                  CtClass[] parameters = constructor.getParameterTypes();
+                  if (parameters != null && parameters.length > 0)
+                  {
+                     parameterTypes = new String[parameters.length];
+                     for (int i = 0; i < parameters.length; i++)
+                     {
+                        parameterTypes[i] = parameters[i].getName();
+                        
+                        if (trace)
+                           log.finest("Parameter=" + parameters[i].getName());
+                     }
+                  }
+                  
+                  for (Object annotation : constructorAnnotations)
+                  {
+                     processAnnotation(annotation,
+                                       AnnotationType.CONSTRUCTOR, 
+                                       ctClass.getName(), null, parameterTypes,
+                                       result);
+                  }
+               }
+            }
+         }
+      }
+
+      // Method level annotations
+      CtMethod[] methods = ctClass.getDeclaredMethods();
+      if (methods != null)
+      {
+         for (CtMethod method : methods)
+         {
+            if (trace)
+               log.finest("Method=" + method.getName());
+            
+            Object[] methodAnnotations = method.getAvailableAnnotations();
+            if (methodAnnotations != null)
+            {
+               String[] parameterTypes = null;
+               CtClass[] parameters = method.getParameterTypes();
+               if (parameters != null && parameters.length > 0)
+               {
+                  parameterTypes = new String[parameters.length];
+                  for (int i = 0; i < parameters.length; i++)
+                  {
+                     parameterTypes[i] = parameters[i].getName();
+                     
+                     if (trace)
+                        log.finest("Parameter=" + parameters[i].getName());
+                  }
+               }
+               
+               for (Object annotation : methodAnnotations)
+               {
+                  processAnnotation(annotation, 
+                                    AnnotationType.METHOD,
+                                    ctClass.getName(), method.getName(), parameterTypes,
+                                    result);
+               }
+            }
+         }
+      }
+                        
+      if (!ctClass.isInterface())
+      {
+         // Field level annotations
+         CtField[] fields = ctClass.getDeclaredFields();
+         if (fields != null)
+         {
+            for (CtField field : fields)
+            {
+               if (trace)
+                  log.finest("Field=" + field.getName());
+            
+               Object[] fieldAnnotations = field.getAvailableAnnotations();
+               if (fieldAnnotations != null)
+               {
+                  for (Object annotation : fieldAnnotations)
+                  {
+                     processAnnotation(annotation, 
+                                       AnnotationType.FIELD,
+                                       ctClass.getName(), field.getName(), null,
+                                       result);
+                  }
+               }
+            }
+         }
+      }
+
+      // Interface annotations
+      CtClass[] interfaces = ctClass.getInterfaces();
+      if (interfaces != null)
+      {
+         for (CtClass interfaceClass : interfaces)
+         {
+            // Interface level annotations
+            Object[] interfaceAnnotations = interfaceClass.getAvailableAnnotations();
+            
+            if (interfaceAnnotations != null)
+            {
+               for (Object annotation : interfaceAnnotations)
+               {
+                  processAnnotation(annotation, 
+                                    AnnotationType.CLASS, 
+                                    ctClass.getName(), null, null,
+                                    result);
+               }
+            }
+
+            // Interface method level annotations
+            CtMethod[] interfaceMethods = interfaceClass.getDeclaredMethods();
+            if (interfaceMethods != null)
+            {
+               for (CtMethod method : interfaceMethods)
+               {
+                  if (trace)
+                     log.finest("Interface Method=" + method.getName());
+                  
+                  Object[] methodAnnotations = method.getAvailableAnnotations();
+                  if (methodAnnotations != null)
+                  {
+                     String[] parameterTypes = null;
+                     CtClass[] parameters = method.getParameterTypes();
+                     if (parameters != null && parameters.length > 0)
+                     {
+                        parameterTypes = new String[parameters.length];
+                        for (int i = 0; i < parameters.length; i++)
+                        {
+                           parameterTypes[i] = parameters[i].getName();
+                           
+                           if (trace)
+                              log.finest("Interface Parameter=" + parameters[i].getName());
+                        }
+                     }
+                     
+                     for (Object annotation : methodAnnotations)
+                     {
+                        processAnnotation(annotation, 
+                                          AnnotationType.METHOD,
+                                          ctClass.getName(), method.getName(), parameterTypes,
+                                          result);
+                     }
+                  }
+               }
+            }
+         }
+      }
+   }
+
    /**
     * Add an annotation to the result map
     * @param annotation The annotation

Modified: projects/annotations/trunk/core/src/main/java/org/jboss/annotations/javassistclasspool/JavassistClassPool.java
===================================================================
--- projects/annotations/trunk/core/src/main/java/org/jboss/annotations/javassistclasspool/JavassistClassPool.java	2009-08-12 18:30:46 UTC (rev 92280)
+++ projects/annotations/trunk/core/src/main/java/org/jboss/annotations/javassistclasspool/JavassistClassPool.java	2009-08-12 18:45:45 UTC (rev 92281)
@@ -24,7 +24,6 @@
 
 import org.jboss.annotations.Annotation;
 import org.jboss.annotations.AnnotationRepository;
-import org.jboss.annotations.AnnotationType;
 import org.jboss.annotations.impl.AbstractJavassistAnnotationScanner;
 import org.jboss.annotations.impl.AnnotationRepositoryImpl;
 
@@ -42,9 +41,6 @@
 
 import javassist.ClassPool;
 import javassist.CtClass;
-import javassist.CtConstructor;
-import javassist.CtField;
-import javassist.CtMethod;
 import javassist.LoaderClassPath;
 import javassist.Modifier;
 import javassist.NotFoundException;
@@ -107,178 +103,7 @@
                   if (ctClass.getClassFile2().getMajorVersion() >= ClassFile.JAVA_5 && !ctClass.isAnnotation() &&
                      (!Modifier.isAbstract(ctClass.getModifiers()) || ctClass.isInterface()))
                   {
-                     if (trace)
-                        log.finest("Class=" + ctClass.getName());
-
-                     // Class level annotations
-                     Object[] classAnnotations = ctClass.getAvailableAnnotations();
-
-                     if (classAnnotations != null)
-                     {
-                        for (Object annotation : classAnnotations)
-                        {
-                           processAnnotation(annotation, 
-                                             AnnotationType.CLASS, 
-                                             ctClass.getName(), null, null,
-                                             result);
-                        }
-                     }
-
-                     // Constructor level annotations
-                     CtConstructor[] constructors = ctClass.getDeclaredConstructors();
-                     if (constructors != null)
-                     {
-                        for (CtConstructor constructor : constructors)
-                        {
-                           if (trace)
-                              log.finest("Constructor=" + constructor.getName());
-
-                           Object[] constructorAnnotations = constructor.getAvailableAnnotations();
-                           if (constructorAnnotations != null)
-                           {
-                              String[] parameterTypes = null;
-                              CtClass[] parameters = constructor.getParameterTypes();
-                              if (parameters != null && parameters.length > 0)
-                              {
-                                 parameterTypes = new String[parameters.length];
-                                 for (int i = 0; i < parameters.length; i++)
-                                 {
-                                    parameterTypes[i] = parameters[i].getName();
-
-                                    if (trace)
-                                       log.finest("Parameter=" + parameters[i].getName());
-                                 }
-                              }
-
-                              for (Object annotation : constructorAnnotations)
-                              {
-                                 processAnnotation(annotation,
-                                                   AnnotationType.CONSTRUCTOR, 
-                                                   ctClass.getName(), null, parameterTypes,
-                                                   result);
-                              }
-                           }
-                        }
-                     }
-
-                     // Method level annotations
-                     CtMethod[] methods = ctClass.getDeclaredMethods();
-                     if (methods != null)
-                     {
-                        for (CtMethod method : methods)
-                        {
-                           if (trace)
-                              log.finest("Method=" + method.getName());
-
-                           Object[] methodAnnotations = method.getAvailableAnnotations();
-                           if (methodAnnotations != null)
-                           {
-                              String[] parameterTypes = null;
-                              CtClass[] parameters = method.getParameterTypes();
-                              if (parameters != null && parameters.length > 0)
-                              {
-                                 parameterTypes = new String[parameters.length];
-                                 for (int i = 0; i < parameters.length; i++)
-                                 {
-                                    parameterTypes[i] = parameters[i].getName();
-
-                                    if (trace)
-                                       log.finest("Parameter=" + parameters[i].getName());
-                                 }
-                              }
-
-                              for (Object annotation : methodAnnotations)
-                              {
-                                 processAnnotation(annotation, 
-                                                   AnnotationType.METHOD,
-                                                   ctClass.getName(), method.getName(), parameterTypes,
-                                                   result);
-                              }
-                           }
-                        }
-                     }
-
-                     // Field level annotations
-                     CtField[] fields = ctClass.getDeclaredFields();
-                     if (fields != null)
-                     {
-                        for (CtField field : fields)
-                        {
-                           if (trace)
-                              log.finest("Field=" + field.getName());
-
-                           Object[] fieldAnnotations = field.getAvailableAnnotations();
-                           if (fieldAnnotations != null)
-                           {
-                              for (Object annotation : fieldAnnotations)
-                              {
-                                 processAnnotation(annotation, 
-                                                   AnnotationType.FIELD,
-                                                   ctClass.getName(), field.getName(), null,
-                                                   result);
-                              }
-                           }
-                        }
-                     }
-
-                     // Interface annotations
-                     CtClass[] interfaces = ctClass.getInterfaces();
-                     if (interfaces != null)
-                     {
-                        for (CtClass interfaceClass : interfaces)
-                        {
-                           // Interface level annotations
-                           Object[] interfaceAnnotations = interfaceClass.getAvailableAnnotations();
-                        
-                           if (interfaceAnnotations != null)
-                           {
-                              for (Object annotation : interfaceAnnotations)
-                              {
-                                 processAnnotation(annotation, 
-                                                   AnnotationType.CLASS, 
-                                                   ctClass.getName(), null, null,
-                                                   result);
-                              }
-                           }
-
-                           // Interface method level annotations
-                           CtMethod[] interfaceMethods = interfaceClass.getDeclaredMethods();
-                           if (interfaceMethods != null)
-                           {
-                              for (CtMethod method : interfaceMethods)
-                              {
-                                 if (trace)
-                                    log.finest("Interface Method=" + method.getName());
-
-                                 Object[] methodAnnotations = method.getAvailableAnnotations();
-                                 if (methodAnnotations != null)
-                                 {
-                                    String[] parameterTypes = null;
-                                    CtClass[] parameters = method.getParameterTypes();
-                                    if (parameters != null && parameters.length > 0)
-                                    {
-                                       parameterTypes = new String[parameters.length];
-                                       for (int i = 0; i < parameters.length; i++)
-                                       {
-                                          parameterTypes[i] = parameters[i].getName();
-                                          
-                                          if (trace)
-                                             log.finest("Interface Parameter=" + parameters[i].getName());
-                                       }
-                                    }
-
-                                    for (Object annotation : methodAnnotations)
-                                    {
-                                       processAnnotation(annotation, 
-                                                         AnnotationType.METHOD,
-                                                         ctClass.getName(), method.getName(), parameterTypes,
-                                                         result);
-                                    }
-                                 }
-                              }
-                           }
-                        }
-                     }
+                     processClass(ctClass, result);
                   }
                }
                catch (NotFoundException nfe)

Modified: projects/annotations/trunk/core/src/main/java/org/jboss/annotations/javassistinputstream/JavassistInputStream.java
===================================================================
--- projects/annotations/trunk/core/src/main/java/org/jboss/annotations/javassistinputstream/JavassistInputStream.java	2009-08-12 18:30:46 UTC (rev 92280)
+++ projects/annotations/trunk/core/src/main/java/org/jboss/annotations/javassistinputstream/JavassistInputStream.java	2009-08-12 18:45:45 UTC (rev 92281)
@@ -24,7 +24,6 @@
 
 import org.jboss.annotations.Annotation;
 import org.jboss.annotations.AnnotationRepository;
-import org.jboss.annotations.AnnotationType;
 import org.jboss.annotations.impl.AbstractJavassistAnnotationScanner;
 import org.jboss.annotations.impl.AnnotationRepositoryImpl;
 
@@ -46,9 +45,6 @@
 
 import javassist.ClassPool;
 import javassist.CtClass;
-import javassist.CtConstructor;
-import javassist.CtField;
-import javassist.CtMethod;
 import javassist.LoaderClassPath;
 import javassist.Modifier;
 import javassist.bytecode.ClassFile;
@@ -134,178 +130,7 @@
                      if (isJava5.booleanValue() && !ctClass.isAnnotation() && 
                          (!Modifier.isAbstract(ctClass.getModifiers()) || ctClass.isInterface()))
                      {
-                        if (trace)
-                           log.finest("Class=" + ctClass.getName());
-
-                        // Class level annotations
-                        Object[] classAnnotations = ctClass.getAvailableAnnotations();
-                        
-                        if (classAnnotations != null)
-                        {
-                           for (Object annotation : classAnnotations)
-                           {
-                              processAnnotation(annotation, 
-                                                AnnotationType.CLASS, 
-                                                ctClass.getName(), null, null,
-                                                result);
-                           }
-                        }
-                        
-                        // Constructor level annotations
-                        CtConstructor[] constructors = ctClass.getDeclaredConstructors();
-                        if (constructors != null)
-                        {
-                           for (CtConstructor constructor : constructors)
-                           {
-                              if (trace)
-                                 log.finest("Constructor=" + constructor.getName());
-
-                              Object[] constructorAnnotations = constructor.getAvailableAnnotations();
-                              if (constructorAnnotations != null)
-                              {
-                                 String[] parameterTypes = null;
-                                 CtClass[] parameters = constructor.getParameterTypes();
-                                 if (parameters != null && parameters.length > 0)
-                                 {
-                                    parameterTypes = new String[parameters.length];
-                                    for (int i = 0; i < parameters.length; i++)
-                                    {
-                                       parameterTypes[i] = parameters[i].getName();
-
-                                       if (trace)
-                                          log.finest("Parameter=" + parameters[i].getName());
-                                    }
-                                 }
-
-                                 for (Object annotation : constructorAnnotations)
-                                 {
-                                    processAnnotation(annotation,
-                                                      AnnotationType.CONSTRUCTOR, 
-                                                      ctClass.getName(), null, parameterTypes,
-                                                      result);
-                                 }
-                              }
-                           }
-                        }
-
-                        // Method level annotations
-                        CtMethod[] methods = ctClass.getDeclaredMethods();
-                        if (methods != null)
-                        {
-                           for (CtMethod method : methods)
-                           {
-                              if (trace)
-                                 log.finest("Method=" + method.getName());
-
-                              Object[] methodAnnotations = method.getAvailableAnnotations();
-                              if (methodAnnotations != null)
-                              {
-                                 String[] parameterTypes = null;
-                                 CtClass[] parameters = method.getParameterTypes();
-                                 if (parameters != null && parameters.length > 0)
-                                 {
-                                    parameterTypes = new String[parameters.length];
-                                    for (int i = 0; i < parameters.length; i++)
-                                    {
-                                       parameterTypes[i] = parameters[i].getName();
-
-                                       if (trace)
-                                          log.finest("Parameter=" + parameters[i].getName());
-                                    }
-                                 }
-
-                                 for (Object annotation : methodAnnotations)
-                                 {
-                                    processAnnotation(annotation, 
-                                                      AnnotationType.METHOD,
-                                                      ctClass.getName(), method.getName(), parameterTypes,
-                                                      result);
-                                 }
-                              }
-                           }
-                        }
-                        
-                        // Field level annotations
-                        CtField[] fields = ctClass.getDeclaredFields();
-                        if (fields != null)
-                        {
-                           for (CtField field : fields)
-                           {
-                              if (trace)
-                                 log.finest("Field=" + field.getName());
-
-                              Object[] fieldAnnotations = field.getAvailableAnnotations();
-                              if (fieldAnnotations != null)
-                              {
-                                 for (Object annotation : fieldAnnotations)
-                                 {
-                                    processAnnotation(annotation, 
-                                                      AnnotationType.FIELD,
-                                                      ctClass.getName(), field.getName(), null,
-                                                      result);
-                                 }
-                              }
-                           }
-                        }
-
-                        // Interface annotations
-                        CtClass[] interfaces = ctClass.getInterfaces();
-                        if (interfaces != null)
-                        {
-                           for (CtClass interfaceClass : interfaces)
-                           {
-                              // Interface level annotations
-                              Object[] interfaceAnnotations = interfaceClass.getAvailableAnnotations();
-                        
-                              if (interfaceAnnotations != null)
-                              {
-                                 for (Object annotation : interfaceAnnotations)
-                                 {
-                                    processAnnotation(annotation, 
-                                                      AnnotationType.CLASS, 
-                                                      ctClass.getName(), null, null,
-                                                      result);
-                                 }
-                              }
-
-                              // Interface method level annotations
-                              CtMethod[] interfaceMethods = interfaceClass.getDeclaredMethods();
-                              if (interfaceMethods != null)
-                              {
-                                 for (CtMethod method : interfaceMethods)
-                                 {
-                                    if (trace)
-                                       log.finest("Interface Method=" + method.getName());
-
-                                    Object[] methodAnnotations = method.getAvailableAnnotations();
-                                    if (methodAnnotations != null)
-                                    {
-                                       String[] parameterTypes = null;
-                                       CtClass[] parameters = method.getParameterTypes();
-                                       if (parameters != null && parameters.length > 0)
-                                       {
-                                          parameterTypes = new String[parameters.length];
-                                          for (int i = 0; i < parameters.length; i++)
-                                          {
-                                             parameterTypes[i] = parameters[i].getName();
-                                             
-                                             if (trace)
-                                                log.finest("Interface Parameter=" + parameters[i].getName());
-                                          }
-                                       }
-
-                                       for (Object annotation : methodAnnotations)
-                                       {
-                                          processAnnotation(annotation, 
-                                                            AnnotationType.METHOD,
-                                                            ctClass.getName(), method.getName(), parameterTypes,
-                                                            result);
-                                       }
-                                    }
-                                 }
-                              }
-                           }
-                        }
+                        processClass(ctClass, result);
                      }
                   }
                }




More information about the jboss-cvs-commits mailing list