[jboss-cvs] JBossAS SVN: r105097 - in projects/jboss-reflect/trunk/src: main/java/org/jboss/reflect/plugins/javassist and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri May 21 10:24:33 EDT 2010


Author: kabir.khan at jboss.com
Date: 2010-05-21 10:24:32 -0400 (Fri, 21 May 2010)
New Revision: 105097

Added:
   projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/LazyJavassistClassInfo.java
Modified:
   projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/AnnotationValueFactory.java
   projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistMethodInfo.java
   projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistTypeInfoFactoryImpl.java
   projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/SignatureKey.java
   projects/jboss-reflect/trunk/src/test/java/org/jboss/test/beaninfo/test/AbstractBeanInfoTest.java
Log:
Committing with failing tests to branch, so I can sort out the equals

Modified: projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/AnnotationValueFactory.java
===================================================================
--- projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/AnnotationValueFactory.java	2010-05-21 14:23:32 UTC (rev 105096)
+++ projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/AnnotationValueFactory.java	2010-05-21 14:24:32 UTC (rev 105097)
@@ -56,7 +56,7 @@
    public static Value createValue(AnnotationHelper annotationHelper, TypeInfo type, Object value)
    {
       Value rtnValue = null;
-      if (type instanceof ArrayInfo)
+      if (type.isArray())
       {
          Object[] objects = getArray((ArrayInfo)type, value);
          Value[] values = new Value[objects.length];
@@ -66,7 +66,7 @@
          }
          rtnValue = new ArrayValueImpl(type, values);
       }
-      else if (type instanceof PrimitiveInfo)
+      else if (type.isPrimitive())
       {
          rtnValue = new PrimitiveValue(value.toString(), (PrimitiveInfo)type); 
       }
@@ -74,11 +74,11 @@
       {
          rtnValue = new StringValueImpl((String)value, type);
       }
-      else if (type instanceof AnnotationInfo)
+      else if (type.isAnnotation())
       {
          rtnValue = annotationHelper.createAnnotationValue((AnnotationInfo)type, value);
       }
-      else if (type instanceof EnumInfo)
+      else if (type.isEnum())
       {
          rtnValue = new EnumValueImpl(type, value.toString());
       }

Modified: projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistMethodInfo.java
===================================================================
--- projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistMethodInfo.java	2010-05-21 14:23:32 UTC (rev 105096)
+++ projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistMethodInfo.java	2010-05-21 14:24:32 UTC (rev 105097)
@@ -34,6 +34,8 @@
 import org.jboss.reflect.spi.MethodInfo;
 import org.jboss.reflect.spi.MutableMethodInfo;
 import org.jboss.reflect.spi.MutableMethodInfoCommand;
+import org.jboss.reflect.spi.NumberInfo;
+import org.jboss.reflect.spi.PrimitiveInfo;
 import org.jboss.reflect.spi.TypeInfo;
 import org.jboss.util.JBossStringBuilder;
 
@@ -84,7 +86,7 @@
       return name;
    }
 
-   public TypeInfo getReturnType()
+   public TypeInfo getReturnTypeOld()
    {
       if (returnType != null)
          return returnType;
@@ -95,19 +97,76 @@
          if (sig != null)
          {
             if (sig.getReturnType() instanceof BaseType == false)
-               return typeInfo.getFactory().getTypeInfo(typeInfo.getClassLoaderInternal(), sig.getReturnType(), JavassistTypeVariableSpy.createForBehavior(((JavassistClassInfo)getDeclaringClass()).getClassSignature(), sig));
+               returnType = typeInfo.getFactory().getTypeInfo(typeInfo.getClassLoaderInternal(), sig.getReturnType(), JavassistTypeVariableSpy.createForBehavior(((JavassistClassInfo)getDeclaringClass()).getClassSignature(), sig));
          }
 
-         CtClass clazz = ctMethod.getReturnType();
-         returnType = typeInfo.getFactory().getTypeInfo(clazz);
+         if (returnType == null)
+         {
+            CtClass clazz = ctMethod.getReturnType();
+            returnType = typeInfo.getFactory().getTypeInfo(clazz);
+         }
       }
       catch (NotFoundException e)
       {
          throw JavassistTypeInfoFactoryImpl.raiseClassNotFound("for return type of method " + getName(), e);
       }
+      
       return returnType;
    }
+   
+   public TypeInfo getReturnType()
+   {
+      if (returnType != null)
+         return returnType;
 
+      returnType = getLazyInfo(getSignatureKey(), -1);
+      return returnType;
+   }
+   
+   ClassInfo lazyLoadReturnType()
+   {
+      if (returnType instanceof LazyJavassistClassInfo)
+      {
+         TypeInfo returnType = null;
+         try
+         {
+            CtMethod ctMethod = (CtMethod)ctBehavior;
+            MethodSignature sig = getMethodSignature();
+            if (sig != null)
+            {
+               if (sig.getReturnType() instanceof BaseType == false)
+                  returnType = typeInfo.getFactory().getTypeInfo(typeInfo.getClassLoaderInternal(), sig.getReturnType(), JavassistTypeVariableSpy.createForBehavior(((JavassistClassInfo)getDeclaringClass()).getClassSignature(), sig));
+            }
+
+            if (returnType == null)
+            {
+               CtClass clazz = ctMethod.getReturnType();
+               returnType = typeInfo.getFactory().getTypeInfo(clazz);
+            }
+         }
+         catch (NotFoundException e)
+         {
+            throw JavassistTypeInfoFactoryImpl.raiseClassNotFound("for return type of method " + getName(), e);
+         }
+         this.returnType = returnType;
+      }
+      if (returnType instanceof ClassInfo == false)
+         throw new IllegalArgumentException(returnType + " is not an instance of ClassInfo");
+
+      return (ClassInfo)returnType;         
+   }
+   
+   private TypeInfo getLazyInfo(SignatureKey key, int index)
+   {
+      String param = index > 0 ? key.getParams()[index] : SignatureKey.getReturnType(ctBehavior);
+      
+      TypeInfo info = typeInfo.getFactory().getPrimitiveOrNumberInfo(param);
+      if (info != null)
+         return info;
+
+      return LazyJavassistClassInfo.createJavassistClassInfo(this, param, index);
+   }
+
    public Object invoke(Object target, Object[] args) throws Throwable
    {
       if (method == null)

Modified: projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistTypeInfoFactoryImpl.java
===================================================================
--- projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistTypeInfoFactoryImpl.java	2010-05-21 14:23:32 UTC (rev 105096)
+++ projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistTypeInfoFactoryImpl.java	2010-05-21 14:24:32 UTC (rev 105097)
@@ -454,36 +454,10 @@
       if (cl == null)
          throw new IllegalArgumentException("Null class loader");
       
-      TypeInfo primitive = PrimitiveInfo.valueOf(name);
-      if (primitive != null)
-         return primitive;
-
-      NumberInfo number = NumberInfo.valueOf(name);
+      TypeInfo number = getPrimitiveOrNumberInfo(name, cl, clazz);
       if (number != null)
-      {
-         synchronized (number)
-         {
-            if (number.getPhase() != NumberInfo.Phase.INITIALIZING)
-            {
-               if (number.getPhase() != NumberInfo.Phase.COMPLETE)
-               {
-                  number.initializing();
-                  Class<?> useClass = clazz;
-                  try
-                  {
-                     if (useClass == null)
-                        useClass = cl.loadClass(name);
-                  }
-                  catch (ClassNotFoundException e)
-                  {
-                     throw new RuntimeException(e);
-                  }
-                  number.setDelegate(get(useClass));
-               }
-               return number;
-            }
-         }
-      }
+         return number;
+         
       
       //Handle array names
       if (name.charAt(0) == '[')
@@ -537,6 +511,48 @@
       
       return result;
    }
+
+   TypeInfo getPrimitiveOrNumberInfo(String name)
+   {
+      return getPrimitiveOrNumberInfo(name, null, null);
+   }
+
+   protected TypeInfo getPrimitiveOrNumberInfo(String name, ClassLoader cl, Class<?> clazz)
+   {
+      TypeInfo primitive = PrimitiveInfo.valueOf(name);
+      if (primitive != null)
+         return primitive;
+
+      NumberInfo number = NumberInfo.valueOf(name);
+      if (number != null)
+      {
+         synchronized (number)
+         {
+            if (number.getPhase() != NumberInfo.Phase.INITIALIZING)
+            {
+               if (number.getPhase() != NumberInfo.Phase.COMPLETE)
+               {
+                  number.initializing();
+                  Class<?> useClass = clazz;
+                  try
+                  {
+                     if (cl == null)
+                        cl = SecurityActions.getContextClassLoader();
+                     if (useClass == null)
+                        useClass = cl.loadClass(name);
+                  }
+                  catch (ClassNotFoundException e)
+                  {
+                     throw new RuntimeException(e);
+                  }
+                  number.setDelegate(get(useClass));
+               }
+               return number;
+            }
+         }
+      }
+      return null;
+   }
    
    private ClassLoader getClassLoader(final TypeInfo info)
    {
@@ -571,45 +587,6 @@
     */
    private TypeInfo delegateToIntrospectionImplementation(ClassLoader cl, String name) throws ClassNotFoundException
    {
-//      System.out.println("======> " + name + " " + cl);
-//      
-//      //Extra code just for debugging
-//      ClassPool pool = poolFactory.getPoolForLoader(cl);
-//      try
-//      {
-//         CtClass ct = pool.get(name); 
-//      }
-//      catch(Exception alreadyHandled)
-//      {
-//         System.out.println("---> Not found in " + pool);
-//      }
-//      
-//      Class<?> clazz = cl.loadClass(name);
-//      System.out.println("---> Loaded real class from " + clazz.getClassLoader());
-//      
-//      try
-//      {
-//         CtClass ct = pool.get(name); 
-//      }
-//      catch(Exception alreadyHandled)
-//      {
-//         System.out.println("---> Not found again in " + pool);
-//      }
-//      
-//      pool = poolFactory.getPoolForLoader(clazz.getClassLoader());
-//      try
-//      {
-//         CtClass ct = pool.get(name); 
-//         System.out.println("---> Found in actual pool " + pool);
-//      }
-//      catch(Exception alreadyHandled)
-//      {
-//         System.out.println("---> Not found in actual pool " + pool);
-//      }
-//      
-
-      //Extra code - END
-      
       try
       {
          IntrospectionTypeInfoFactory factory = new IntrospectionTypeInfoFactory();

Added: projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/LazyJavassistClassInfo.java
===================================================================
--- projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/LazyJavassistClassInfo.java	                        (rev 0)
+++ projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/LazyJavassistClassInfo.java	2010-05-21 14:24:32 UTC (rev 105097)
@@ -0,0 +1,554 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors. 
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/ 
+package org.jboss.reflect.plugins.javassist;
+
+import java.lang.annotation.Annotation;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.jboss.reflect.spi.AnnotationAttribute;
+import org.jboss.reflect.spi.AnnotationInfo;
+import org.jboss.reflect.spi.AnnotationValue;
+import org.jboss.reflect.spi.ArrayInfo;
+import org.jboss.reflect.spi.ClassInfo;
+import org.jboss.reflect.spi.ConstructorInfo;
+import org.jboss.reflect.spi.DelegateClassInfo;
+import org.jboss.reflect.spi.EnumConstantInfo;
+import org.jboss.reflect.spi.EnumInfo;
+import org.jboss.reflect.spi.FieldInfo;
+import org.jboss.reflect.spi.InterfaceInfo;
+import org.jboss.reflect.spi.MethodInfo;
+import org.jboss.reflect.spi.PackageInfo;
+import org.jboss.reflect.spi.TypeInfo;
+import org.jboss.reflect.spi.TypeInfoFactory;
+import org.jboss.util.JBossObject;
+import org.jboss.util.JBossStringBuilder;
+
+/**
+ * When calling getReturnType() or getParameterTypes() on JavassistConstructorInfo or JavassistMethodInfo
+ * we are often only interested in the type so return this class to avoid having to load up everything from
+ * the classpools and initializing the CtClass.ClassFile. If people call something more advanced
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public abstract class LazyJavassistClassInfo extends JBossObject implements ClassInfo, ArrayInfo, EnumInfo, InterfaceInfo, AnnotationInfo
+{
+   private static final long serialVersionUID = 1L;
+
+   private final String name;
+   
+   protected volatile ClassInfo delegate;
+   
+   protected LazyJavassistClassInfo(String name)
+   {
+      //super(null, true);
+      this.name = name;
+   }
+
+   public static LazyJavassistClassInfo createJavassistClassInfo(JavassistMethodInfo behavior, String name, int index)
+   {
+      return new LazyJavassistMethodClassInfo(behavior, name, index); 
+   }
+   
+   //Simple methods
+   
+   public String getName()
+   {
+      return name;
+   }
+
+   public String getSimpleName()
+   {
+      int index = name.lastIndexOf('.');
+      if (index < 0)
+          return name;
+      else
+          return name.substring(index + 1);
+   }
+
+   public boolean isPrimitive()
+   {
+      return false;
+   }
+
+   @Override
+   public void toShortString(JBossStringBuilder buffer)
+   {
+      buffer.append(getName());
+   }
+
+   @Override
+   protected void toString(JBossStringBuilder buffer)
+   {
+      buffer.append("name=").append(getName());
+   }
+
+   @Override
+   protected int getHashCode()
+   {
+      return getName().hashCode();
+   }
+
+   @Override
+   public boolean equals(Object obj)
+   {
+      if (obj == this)
+         return true;
+      if (obj == null || obj instanceof TypeInfo == false)
+         return false;
+
+      TypeInfo other = (TypeInfo) obj;
+      return getName().equals(other.getName());
+   }
+
+   public boolean equals(Object obj, Set<String> doneTypeVariables)
+   {
+      if (obj instanceof DelegateClassInfo && obj instanceof LazyJavassistClassInfo == false)
+         return ((DelegateClassInfo)obj).equals(this, doneTypeVariables);
+      return super.equals(obj, doneTypeVariables);
+   }
+
+   //The following methods need to load up the delegate
+   
+   public TypeInfo[] getActualTypeArguments()
+   {
+      if (delegate == null)
+         loadDelegate();
+      return delegate.getActualTypeArguments();
+   }
+
+   public TypeInfo getComponentType()
+   {
+      if (delegate == null)
+         loadDelegate();
+      return delegate.getComponentType();
+   }
+
+   public ConstructorInfo getDeclaredConstructor(TypeInfo... parameters)
+   {
+      if (delegate == null)
+         loadDelegate();
+      return delegate.getDeclaredConstructor(parameters);
+   }
+
+   public ConstructorInfo[] getDeclaredConstructors()
+   {
+      if (delegate == null)
+         loadDelegate();
+      return delegate.getDeclaredConstructors();
+   }
+   
+   public Object convertValue(Object value, boolean replaceProperties, boolean trim) throws Throwable
+   {
+      if (delegate == null)
+         loadDelegate();
+      return delegate.convertValue(value, replaceProperties, trim);
+   }
+
+   public Object convertValue(Object value, boolean replaceProperties) throws Throwable
+   {
+      if (delegate == null)
+         loadDelegate();
+      return delegate.convertValue(value, replaceProperties);
+   }
+
+   public Object convertValue(Object value) throws Throwable
+   {
+      if (delegate == null)
+         loadDelegate();
+      return delegate.convertValue(value);
+   }
+
+   public AnnotationValue getAnnotation(String name)
+   {
+      if (delegate == null)
+         loadDelegate();
+      return delegate.getAnnotation(name);
+   }
+
+   public AnnotationValue[] getAnnotations()
+   {
+      if (delegate == null)
+         loadDelegate();
+      return delegate.getAnnotations();
+   }
+
+   public TypeInfo getArrayType()
+   {
+      if (delegate == null)
+         loadDelegate();
+      return delegate.getArrayType();
+   }
+
+   public <T> T getAttachment(Class<T> expectedType)
+   {
+      if (delegate == null)
+         loadDelegate();
+      return delegate.getAttachment(expectedType);
+   }
+
+   public Object getAttachment(String name)
+   {
+      if (delegate == null)
+         loadDelegate();
+      return delegate.getAttachment(name);
+   }
+
+   public ClassLoader getClassLoader()
+   {
+      if (delegate == null)
+         loadDelegate();
+      return delegate.getClassLoader();
+   }
+
+   public FieldInfo getDeclaredField(String name)
+   {
+      if (delegate == null)
+         loadDelegate();
+      return delegate.getDeclaredField(name);
+   }
+
+   public FieldInfo[] getDeclaredFields()
+   {
+      if (delegate == null)
+         loadDelegate();
+      return delegate.getDeclaredFields();
+   }
+
+   public MethodInfo getDeclaredMethod(String name, TypeInfo... parameters)
+   {
+      if (delegate == null)
+         loadDelegate();
+      return delegate.getDeclaredMethod(name, parameters);
+   }
+
+   public MethodInfo[] getDeclaredMethods()
+   {
+      if (delegate == null)
+         loadDelegate();
+      return delegate.getDeclaredMethods();
+   }
+
+   public InterfaceInfo[] getGenericInterfaces()
+   {
+      if (delegate == null)
+         loadDelegate();
+      return delegate.getGenericInterfaces();
+   }
+
+   public ClassInfo getGenericSuperclass()
+   {
+      if (delegate == null)
+         loadDelegate();
+      return delegate.getGenericSuperclass();
+   }
+
+   public InterfaceInfo[] getInterfaces()
+   {
+      if (delegate == null)
+         loadDelegate();
+      return delegate.getInterfaces();
+   }
+
+   public TypeInfo getKeyType()
+   {
+      if (delegate == null)
+         loadDelegate();
+      return delegate.getKeyType();
+   }
+
+   public int getModifiers()
+   {
+      if (delegate == null)
+         loadDelegate();
+      return delegate.getModifiers();
+   }
+
+   public TypeInfo getOwnerType()
+   {
+      if (delegate == null)
+         loadDelegate();
+      return delegate.getOwnerType();
+   }
+
+   public PackageInfo getPackage()
+   {
+      if (delegate == null)
+         loadDelegate();
+      return delegate.getPackage();
+   }
+
+   public ClassInfo getRawType()
+   {
+      if (delegate == null)
+         loadDelegate();
+      return delegate.getRawType();
+   }
+
+   public ClassInfo getSuperclass()
+   {
+      if (delegate == null)
+         loadDelegate();
+      return delegate.getSuperclass();
+   }
+
+   public Class<?> getType()
+   {
+      if (delegate == null)
+         loadDelegate();
+      return delegate.getType();
+   }
+
+   public TypeInfoFactory getTypeInfoFactory()
+   {
+      if (delegate == null)
+         loadDelegate();
+      return delegate.getTypeInfoFactory();
+   }
+
+   public String getTypeVariable()
+   {
+      if (delegate == null)
+         loadDelegate();
+      return delegate.getTypeVariable();
+   }
+
+   public <T extends Annotation> T getUnderlyingAnnotation(Class<T> annotationType)
+   {
+      if (delegate == null)
+         loadDelegate();
+      return delegate.getUnderlyingAnnotation(annotationType);
+   }
+
+   public Annotation[] getUnderlyingAnnotations()
+   {
+      if (delegate == null)
+         loadDelegate();
+      return delegate.getUnderlyingAnnotations();
+   }
+
+   public TypeInfo getValueType()
+   {
+      if (delegate == null)
+         loadDelegate();
+      return delegate.getValueType();
+   }
+
+   public boolean isAnnotation()
+   {
+      if (delegate == null)
+         loadDelegate();
+      return delegate.isAnnotation();
+   }
+
+   public boolean isAnnotationPresent(Class<? extends Annotation> annotationType)
+   {
+      if (delegate == null)
+         loadDelegate();
+      return delegate.isAnnotationPresent(annotationType);
+   }
+
+   public boolean isAnnotationPresent(String name)
+   {
+      if (delegate == null)
+         loadDelegate();
+      return delegate.isAnnotationPresent(name);
+   }
+
+   public boolean isArray()
+   {
+      if (delegate == null)
+         loadDelegate();
+      return delegate.isArray();
+   }
+
+   public boolean isAssignableFrom(TypeInfo info)
+   {
+      if (delegate == null)
+         loadDelegate();
+      return delegate.isAssignableFrom(info);
+   }
+
+   public boolean isCollection()
+   {
+      if (delegate == null)
+         loadDelegate();
+      return delegate.isCollection();
+   }
+
+   public boolean isEnum()
+   {
+      if (delegate == null)
+         loadDelegate();
+      return delegate.isEnum();
+   }
+
+   public boolean isInstance(Object object)
+   {
+      if (delegate == null)
+         loadDelegate();
+      return delegate.isInstance(object);
+   }
+
+   public boolean isInterface()
+   {
+      if (delegate == null)
+         loadDelegate();
+      return delegate.isInterface();
+   }
+
+   public boolean isMap()
+   {
+      if (delegate == null)
+         loadDelegate();
+      return delegate.isMap();
+   }
+
+   public boolean isPublic()
+   {
+      if (delegate == null)
+         loadDelegate();
+      return delegate.isPublic();
+   }
+
+   public boolean isStatic()
+   {
+      if (delegate == null)
+         loadDelegate();
+      return delegate.isStatic();
+   }
+
+   public boolean isVolatile()
+   {
+      if (delegate == null)
+         loadDelegate();
+      return delegate.isVolatile();
+   }
+
+   public Object newArrayInstance(int size) throws Throwable
+   {
+      if (delegate == null)
+         loadDelegate();
+      return delegate.newArrayInstance(size);
+   }
+
+   public void setAttachment(String name, Object attachment)
+   {
+      if (delegate == null)
+         loadDelegate();
+      delegate.setAttachment(name, attachment);
+   }
+   
+   public EnumConstantInfo getEnumConstant(String name)
+   {
+      if (delegate == null)
+         loadDelegate();
+      if (delegate instanceof EnumInfo)
+         return ((EnumInfo)delegate).getEnumConstant(name);
+      throw new IllegalStateException(delegate + " is not an EnumInfo");
+   }
+
+   public EnumConstantInfo[] getEnumConstants()
+   {
+      if (delegate == null)
+         loadDelegate();
+      if (delegate instanceof EnumInfo)
+         return ((EnumInfo)delegate).getEnumConstants();
+      throw new IllegalStateException(delegate + " is not an EnumInfo");
+   }
+
+   public Object getEnumValue(String name)
+   {
+      if (delegate == null)
+         loadDelegate();
+      if (delegate instanceof EnumInfo)
+         return ((EnumInfo)delegate).getEnumValue(name);
+      throw new IllegalStateException(delegate + " is not an EnumInfo");
+   }
+
+
+   public AnnotationAttribute getAttribute(String name)
+   {
+      if (delegate == null)
+         loadDelegate();
+      if (delegate instanceof AnnotationInfo)
+         return ((AnnotationInfo)delegate).getAttribute(name);
+      throw new IllegalStateException(delegate + " is not an AnnotationInfo");
+   }
+
+   public AnnotationAttribute[] getAttributes()
+   {
+      if (delegate == null)
+         loadDelegate();
+      if (delegate instanceof AnnotationInfo)
+         return ((AnnotationInfo)delegate).getAttributes();
+      throw new IllegalStateException(delegate + " is not an AnnotationInfo");
+   }
+   
+   protected abstract void loadDelegate();
+
+   private static class LazyJavassistBehaviorClassInfo extends LazyJavassistClassInfo
+   {
+      private static final long serialVersionUID = 1L;
+
+      protected final JavassistAnnotatedParameterInfo owner;
+      protected final int index;
+      
+      protected LazyJavassistBehaviorClassInfo(JavassistAnnotatedParameterInfo method, String name, int index)
+      {
+         super(name);
+         owner = method;
+         this.index = index;
+      }
+
+      @Override
+      protected void loadDelegate()
+      {
+            
+      }
+   }
+   
+   private static class LazyJavassistMethodClassInfo extends LazyJavassistBehaviorClassInfo
+   {
+      private static final long serialVersionUID = 1L;
+
+      protected LazyJavassistMethodClassInfo(JavassistMethodInfo method, String name, int index)
+      {
+         super(method, name, index);
+      }
+
+      @Override
+      protected void loadDelegate()
+      {
+         if (index >= 0)
+         {
+            super.loadDelegate();
+            return;
+         }
+           
+         delegate = ((JavassistMethodInfo)owner).lazyLoadReturnType();
+      }
+      
+   }
+   
+}

Modified: projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/SignatureKey.java
===================================================================
--- projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/SignatureKey.java	2010-05-21 14:23:32 UTC (rev 105096)
+++ projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/SignatureKey.java	2010-05-21 14:24:32 UTC (rev 105097)
@@ -22,6 +22,8 @@
 package org.jboss.reflect.plugins.javassist;
 
 import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
 
 import javassist.CtBehavior;
 import javassist.bytecode.Descriptor;
@@ -38,12 +40,26 @@
  */
 public class SignatureKey
 {
+   private static final Set<String> primitives = new HashSet<String>();
+   static
+   {
+      primitives.add("boolean");
+      primitives.add("char");
+      primitives.add("byte");
+      primitives.add("short");
+      primitives.add("int");
+      primitives.add("long");
+      primitives.add("float");
+      primitives.add("double");
+      primitives.add("void");
+   }
+   
    /** The name */
-   String name;
+   final String name;
    
    /** The parameter names */
-   String[] params;
-
+   final String[] params;
+   
    /** The cached hashcode */
    private transient int cachedHashCode = Integer.MIN_VALUE;
    
@@ -172,9 +188,19 @@
          i = getParameterTypeString(desc, i, args, n++);
       }
       while (i > 0 && n < args.length);
+      
+      
       return args;
    }
 
+   public static String getReturnType(CtBehavior behavior)
+   {
+      String desc = behavior.getSignature();
+      String[] rtn = new String[1];
+      getParameterTypeString(desc, desc.indexOf(')') + 1, rtn, 0);
+      return rtn[0];
+   }
+   
    /**
     * Put the next argument into the parameter string array 
     * 
@@ -183,7 +209,7 @@
     * @param args the parameter string array
     * @param n the current index of the arguments array
     */
-   private int getParameterTypeString(String desc, int i, String[] args, int n)
+   private static int getParameterTypeString(String desc, int i, String[] args, int n)
    {
       int i2;
       String name;
@@ -244,7 +270,7 @@
     * @param the character for the primitive
     * @return the primitive real name
     */
-   private String toPrimitiveClass(char c)
+   private static String toPrimitiveClass(char c)
    {
       String type = null;
       switch (c)
@@ -297,4 +323,9 @@
    {
       return params[i].equals("long");
    }
+   
+   public static boolean isPrimitive(String param)
+   {
+      return primitives.contains(param);
+   }
 }

Modified: projects/jboss-reflect/trunk/src/test/java/org/jboss/test/beaninfo/test/AbstractBeanInfoTest.java
===================================================================
--- projects/jboss-reflect/trunk/src/test/java/org/jboss/test/beaninfo/test/AbstractBeanInfoTest.java	2010-05-21 14:23:32 UTC (rev 105096)
+++ projects/jboss-reflect/trunk/src/test/java/org/jboss/test/beaninfo/test/AbstractBeanInfoTest.java	2010-05-21 14:24:32 UTC (rev 105097)
@@ -167,22 +167,26 @@
          assertEmpty(actual);
          return;
       }
-      getLog().debug(clazz + " expected properties=" + expected + " actual=" + actual);
-      boolean equals = expected.equals(actual);
-      if (equals == false)
+      
+      //Extra debug code
+      
+      for (PropertyInfo expectedInfo : expected)
       {
-         System.out.println("expected = " + expected);
-         System.out.println("actual = " + actual);
-         
-         PropertyInfo[] expecteds = expected.toArray(new PropertyInfo[2]);
-         PropertyInfo[] actuals = actual.toArray(new PropertyInfo[2]);
-         
-         expected = getExpectedProperties(clazz, mode);
-         actual = beanInfo.getProperties();
+         for (PropertyInfo actualInfo : actual)
+         {
+            if (expectedInfo.getName().equals(actualInfo.getName()))
+            {
+               assertEquals(expectedInfo.hashCode(), actualInfo.hashCode());
+               assertEquals(expectedInfo, actualInfo);
+            }
+         }
       }
-      assertTrue(equals);
-//      assertEquals(expected, actual);
       
+      //Extra - end
+      
+      getLog().debug(clazz + " expected properties=" + expected + " actual=" + actual);
+      assertEquals(expected, actual);
+      
       HashMap<String, PropertyInfo> actualProps = new HashMap<String, PropertyInfo>();
       for (PropertyInfo prop : actual)
          actualProps.put(prop.getName(), prop);




More information about the jboss-cvs-commits mailing list