[jboss-cvs] container/src/main/org/jboss/reflect/plugins/javassist ...

Kabir Khan kkhan at jboss.com
Tue Jul 18 07:23:49 EDT 2006


  User: kkhan   
  Date: 06/07/18 07:23:49

  Modified:    src/main/org/jboss/reflect/plugins/javassist   
                        JavassistInheritableAnnotationHolder.java
                        JavassistAnnotatedParameterInfo.java
                        JavassistTypeInfoFactoryImpl.java
  Log:
  Move annotation creator into container from aop module
  
  Use jboss retro to create a JDK 1.4 dist and test under JDK 1,4.
  
  Revision  Changes    Path
  1.3       +10 -2     container/src/main/org/jboss/reflect/plugins/javassist/JavassistInheritableAnnotationHolder.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: JavassistInheritableAnnotationHolder.java
  ===================================================================
  RCS file: /cvsroot/jboss/container/src/main/org/jboss/reflect/plugins/javassist/JavassistInheritableAnnotationHolder.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -b -r1.2 -r1.3
  --- JavassistInheritableAnnotationHolder.java	23 Jun 2006 10:07:21 -0000	1.2
  +++ JavassistInheritableAnnotationHolder.java	18 Jul 2006 11:23:49 -0000	1.3
  @@ -21,6 +21,7 @@
   */
   package org.jboss.reflect.plugins.javassist;
   
  +import java.lang.annotation.Inherited;
   import java.util.HashMap;
   import java.util.Map;
   
  @@ -32,10 +33,13 @@
   /**
    *
    * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
  - * @version $Revision: 1.2 $
  + * @version $Revision: 1.3 $
    */
   public abstract class JavassistInheritableAnnotationHolder extends JavassistAnnotatedInfo
   {
  +   /** The classname of the <code>@Inherited</code> annotation, this needs retroing to work on JDK 1.4 */
  +   private static final String INHERITED_NAME = Inherited.class.getName();//This 
  +
      /** All annotations Map<String, AnnotationValue> */
      protected Map<String, AnnotationValue> allAnnotations;
   
  @@ -109,7 +113,7 @@
               for (int i = 0; i < superAllAnnotations.length; i++)
               {
                  AnnotationValue av = superAllAnnotations[i];
  -               if (av.getAnnotationType().isAnnotationPresent("java.lang.annotation.Inherited"))
  +               if (av.getAnnotationType().isAnnotationPresent(INHERITED_NAME))
                  {
                     allAnnotations.put(av.getAnnotationType().getName(), av);
                  }
  @@ -130,6 +134,10 @@
               allAnnotations = superHolder.getAllAnnotations();
               allAnnotationsArray = superAllAnnotations;
            }
  +         else
  +         {
  +            allAnnotations = new HashMap<String, AnnotationValue>();
  +         }
         }
      }
   
  
  
  
  1.2       +2 -7      container/src/main/org/jboss/reflect/plugins/javassist/JavassistAnnotatedParameterInfo.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: JavassistAnnotatedParameterInfo.java
  ===================================================================
  RCS file: /cvsroot/jboss/container/src/main/org/jboss/reflect/plugins/javassist/JavassistAnnotatedParameterInfo.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -b -r1.1 -r1.2
  --- JavassistAnnotatedParameterInfo.java	15 Jun 2006 17:39:25 -0000	1.1
  +++ JavassistAnnotatedParameterInfo.java	18 Jul 2006 11:23:49 -0000	1.2
  @@ -21,6 +21,7 @@
   */ 
   package org.jboss.reflect.plugins.javassist;
   
  +import java.lang.annotation.Annotation;
   import java.util.Arrays;
   
   import org.jboss.reflect.plugins.AnnotationHelper;
  @@ -33,7 +34,7 @@
   /**
    * 
    * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
  - * @version $Revision: 1.1 $
  + * @version $Revision: 1.2 $
    */
   public abstract class JavassistAnnotatedParameterInfo extends JavassistAnnotatedInfo
   {
  @@ -62,13 +63,7 @@
            AnnotationValue[] annotationValues = new AnnotationValue[annotations[param].length];
            for (int ann = 0 ; ann < annotations.length ; ann++)
            {
  -            Class[] interfaces = annotations[param][ann].getClass().getInterfaces();
  -            if (interfaces.length != 1)
  -            {
  -               throw new RuntimeException("Annotation proxy implements more than one interface! " + Arrays.asList(interfaces));
  -            }
  -
  -            Class clazz = interfaces[0];
  +            Class clazz = ((Annotation)annotations[param][ann]).annotationType();
   
               AnnotationInfo info = (AnnotationInfo)((JavassistTypeInfoFactoryImpl)annotationHelper).getTypeInfo(clazz);
               annotationValues[ann] = annotationHelper.createAnnotationValue(info, annotations[param][ann]);
  
  
  
  1.10      +37 -28    container/src/main/org/jboss/reflect/plugins/javassist/JavassistTypeInfoFactoryImpl.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: JavassistTypeInfoFactoryImpl.java
  ===================================================================
  RCS file: /cvsroot/jboss/container/src/main/org/jboss/reflect/plugins/javassist/JavassistTypeInfoFactoryImpl.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -b -r1.9 -r1.10
  --- JavassistTypeInfoFactoryImpl.java	14 Jul 2006 10:52:17 -0000	1.9
  +++ JavassistTypeInfoFactoryImpl.java	18 Jul 2006 11:23:49 -0000	1.10
  @@ -21,27 +21,25 @@
   */
   package org.jboss.reflect.plugins.javassist;
   
  -import java.lang.reflect.Method;
  +import java.lang.annotation.Annotation;
   import java.util.Arrays;
  -import java.util.HashMap;
   
   import javassist.ClassPool;
   import javassist.CtClass;
   import javassist.CtMember;
  +import javassist.CtMethod;
   import javassist.CtPrimitiveType;
   import javassist.NotFoundException;
  -import javassist.bytecode.AccessFlag;
   
  +import org.jboss.reflect.plugins.AnnotationAttributeImpl;
   import org.jboss.reflect.plugins.AnnotationHelper;
   import org.jboss.reflect.plugins.AnnotationValueImpl;
  -import org.jboss.reflect.plugins.ArrayInfoImpl;
   import org.jboss.reflect.plugins.AnnotationValueFactory;
   import org.jboss.reflect.spi.AnnotationInfo;
   import org.jboss.reflect.spi.AnnotationValue;
   import org.jboss.reflect.spi.PrimitiveInfo;
   import org.jboss.reflect.spi.TypeInfo;
   import org.jboss.reflect.spi.TypeInfoFactory;
  -import org.jboss.reflect.spi.Value;
   import org.jboss.util.JBossStringBuilder;
   import org.jboss.util.collection.WeakClassCache;
   
  @@ -120,6 +118,8 @@
   
      protected Object instantiate(Class clazz)
      {
  +      try
  +      {
         CtClass ctClass = getCtClass(clazz.getName());
   
         if (clazz.isArray())
  @@ -130,7 +130,17 @@
   
         if (ctClass.isAnnotation())
         {
  -         return new JavassistAnnotationInfo(this, ctClass, clazz);
  +            JavassistAnnotationInfo result = new JavassistAnnotationInfo(this, ctClass, clazz);
  +            CtMethod[] methods = ctClass.getDeclaredMethods();
  +            AnnotationAttributeImpl[] atttributes = new AnnotationAttributeImpl[methods.length];
  +            for (int i = 0 ; i < methods.length ; i++)
  +            {
  +               AnnotationAttributeImpl impl = new AnnotationAttributeImpl(methods[i].getName(), getTypeInfo(methods[i].getReturnType()), null);
  +               atttributes[i] = impl;
  +            }
  +            result.setAttributes(atttributes);
  +            return result;
  +
         }
         else if (ctClass.isEnum())
         {
  @@ -140,6 +150,11 @@
         
         return new JavassistTypeInfo(this, ctClass, clazz);
      }
  +      catch (NotFoundException e)
  +      {
  +         throw new RuntimeException(e);
  +      }
  +   }
   
      /**
       * Get the type info
  @@ -257,11 +272,11 @@
            Object[] annotations = null;
            if (obj instanceof CtMember)
            {
  -            annotations = ((CtMember)obj).getAnnotations();
  +            annotations = ((CtMember)obj).getAvailableAnnotations();
            }
            else if (obj instanceof CtClass)
            {
  -            annotations = ((CtClass)obj).getAnnotations();
  +            annotations = ((CtClass)obj).getAvailableAnnotations();
            }
            else
            {
  @@ -276,13 +291,7 @@
            AnnotationValue[] annotationValues = new AnnotationValueImpl[annotations.length];
            for (int i = 0 ; i < annotations.length ; i++)
            {
  -            Class[] interfaces = annotations[i].getClass().getInterfaces();
  -            if (interfaces.length != 1)
  -            {
  -               throw new RuntimeException("Annotation proxy implements more than one interface! " + Arrays.asList(interfaces));
  -            }
  -
  -            Class clazz = interfaces[0];
  +            Class clazz = ((Annotation)annotations[i]).annotationType();
               
               AnnotationInfo info = (AnnotationInfo)getTypeInfo(clazz);
               annotationValues[i] = AnnotationValueFactory.createAnnotationValue(this, this, info, annotations[i]);
  
  
  



More information about the jboss-cvs-commits mailing list