Package org.jboss.reflect.spi

Examples of org.jboss.reflect.spi.TypeInfoFactory


      return new MethodInfoImpl(null, "someMethod", voidType, MethodInfo.NO_PARAMS, MethodInfo.NO_EXCEPTIONS, ModifierInfo.PUBLIC, anotherBean);
   }
  
   protected Set<ConstructorInfo> getSimpleBeanConstructors()
   {
      TypeInfoFactory factory = getTypeInfoFactory();

      ClassInfo simpleBean = (ClassInfo) factory.getTypeInfo(SimpleBean.class);

      TypeInfo stringType = factory.getTypeInfo(String.class);
      ParameterInfo stringParam = new ParameterInfoImpl(null, "arg0", stringType);
      ParameterInfo[] stringParameters = new ParameterInfo[] { stringParam };
     
      TypeInfo boolType = PrimitiveInfo.BOOLEAN;
      ParameterInfo boolParam = new ParameterInfoImpl(null, "arg0", boolType);
      ParameterInfo[] boolParameters = new ParameterInfo[] { boolParam };

      TypeInfo intType = PrimitiveInfo.INT;
      ParameterInfo intParam = new ParameterInfoImpl(null, "arg0", intType);
      ParameterInfo[] intParameters = new ParameterInfo[] { intParam };

      TypeInfo objectType = factory.getTypeInfo(Object.class);
      ParameterInfo objectParam = new ParameterInfoImpl(null, "arg0", objectType);
      ParameterInfo[] objectParameters = new ParameterInfo[] { objectParam };

      HashSet<ConstructorInfo> result = new HashSet<ConstructorInfo>();
      result.add(new ConstructorInfoImpl(null, MethodInfo.NO_PARAMS, MethodInfo.NO_EXCEPTIONS, ModifierInfo.PUBLIC, simpleBean));
View Full Code Here


  
   protected void assertBeanConstructors(BeanInfo beanInfo, Class<?> clazz)
   {
      ClassInfo classInfo = beanInfo.getClassInfo();
     
      TypeInfoFactory factory = getTypeInfoFactory();
      Set<ConstructorInfo> expected = new HashSet<ConstructorInfo>();
      for (Constructor<?> constructor : clazz.getConstructors())
      {
         Class<?>[] paramClasses = constructor.getParameterTypes();
         TypeInfo[] paramTypes = new TypeInfo[paramClasses.length];
         AnnotationValue[][] paramAnnotations = new AnnotationValue[paramClasses.length][0];
         int i = 0;
         for (Class<?> c : paramClasses)
            paramTypes[i++] = factory.getTypeInfo(c);
         ConstructorInfo c = new ConstructorInfoImpl(null, paramTypes, paramAnnotations, null, constructor.getModifiers(), classInfo);
         expected.add(c);
      }
     
      Set<ConstructorInfo> actual = beanInfo.getConstructors();
View Full Code Here

      assertEquals(expected, actual);
   }
  
   protected void assertBeanMethods(BeanInfo beanInfo, Class<?> clazz) throws Throwable
   {
      TypeInfoFactory factory = getTypeInfoFactory();
      Set<MethodInfo> expected = new HashSet<MethodInfo>();

      Method[] methods;
      if (clazz.isAnnotation())
         methods = clazz.getDeclaredMethods();
      else
         methods = clazz.getMethods();
      for (Method method : methods)
      {
         TypeInfo returnType = factory.getTypeInfo(method.getReturnType());
         Class<?>[] paramClasses = method.getParameterTypes();
         TypeInfo[] paramTypes = new TypeInfo[paramClasses.length];
         AnnotationValue[][] paramAnnotations = new AnnotationValue[paramClasses.length][0];
         int i = 0;
         for (Class<?> c : paramClasses)
            paramTypes[i++] = factory.getTypeInfo(c);
         ClassInfo classInfo = (ClassInfo) factory.getTypeInfo(method.getDeclaringClass());
         MethodInfo m = new MethodInfoImpl(null, method.getName(), returnType, paramTypes, paramAnnotations, null, method.getModifiers(), classInfo);
         expected.add(m);
      }
     
      Set<MethodInfo> actual = beanInfo.getMethods();
View Full Code Here

      }
   }

   protected Set<PropertyInfo> getExpectedProperties(Class<?> clazz, BeanAccessMode mode)
   {
      TypeInfoFactory factory = getTypeInfoFactory();
      Method[] methods = clazz.getMethods();
      HashMap<String, Method> getters = new HashMap<String, Method>();
      HashMap<String, List<Method>> setters = new HashMap<String, List<Method>>();
      if (methods.length > 0)
      {
         for (Method method : methods)
         {
            String name = method.getName();
            if (isGetter(method))
            {
               String upperName = getUpperPropertyName(name);
               getters.put(upperName, method);
            }
            else if (isSetter(method))
            {
               String upperName = getUpperPropertyName(name);
               List<Method> list = setters.get(upperName);
               if (list == null)
               {
                  list = new ArrayList<Method>();
                  setters.put(upperName, list);
               }
               list.add(method);
            }
         }
      }

      Map<String, PropertyInfo> properties = new HashMap<String, PropertyInfo>();
      if (getters.isEmpty() == false)
      {
         for (Iterator<Map.Entry<String, Method>> i = getters.entrySet().iterator(); i.hasNext();)
         {
            Map.Entry<String, Method> entry = i.next();
            String name = entry.getKey();
            Method getter = entry.getValue();
            Method setter = null;
            List<Method> setterList = setters.remove(name);
            if (setterList != null && setterList.size() != 0)
            {
               for (int j = 0; j < setterList.size(); ++j)
               {
                  Method thisSetter = setterList.get(j);
                  Type pinfo = thisSetter.getGenericParameterTypes()[0];
                  if (getter.getGenericReturnType().equals(pinfo) == true)
                  {
                     setter = thisSetter;
                     break;
                  }
               }
            }
            String lowerName = getLowerPropertyName(name);
           
            // Merge the annotations between the getters and setters
            Set<AnnotationValue> getterAnnotations = getExpectedAnnotations(getter.getAnnotations());
            Set<AnnotationValue> setterAnnotations = null;
            if (setter != null)
               setterAnnotations = getExpectedAnnotations(setter.getAnnotations());
            AnnotationValue[] annotations = getterAnnotations.toArray(new AnnotationValue[getterAnnotations.size()]);
            if (annotations == null || annotations.length == 0)
            {
               if (setterAnnotations != null)
                  annotations = setterAnnotations.toArray(new AnnotationValue[setterAnnotations.size()]);
            }
            else if (setterAnnotations != null && setterAnnotations.size() > 0)
            {
               HashSet<AnnotationValue> merged = new HashSet<AnnotationValue>();
               merged.addAll(getterAnnotations);
               merged.addAll(setterAnnotations);
               annotations = merged.toArray(new AnnotationValue[merged.size()]);
            }
           
            TypeInfo type = factory.getTypeInfo(getter.getGenericReturnType());
            ClassInfo declaringType = (ClassInfo) factory.getTypeInfo(getter.getDeclaringClass());
            MethodInfo getterInfo = new MethodInfoImpl(null, getter.getName(), type, new TypeInfo[0], null, null, getter.getModifiers(), declaringType);
            MethodInfo setterInfo = null;
            if (setter != null)
            {
               declaringType = (ClassInfo) factory.getTypeInfo(setter.getDeclaringClass());
               AnnotationValue[][] paramAnnotations = new AnnotationValue[1][];
               setterAnnotations = getExpectedAnnotations(setter.getParameterAnnotations()[0]);
               paramAnnotations[0] = setterAnnotations.toArray(new AnnotationValue[setterAnnotations.size()]);
               setterInfo = new MethodInfoImpl(null, setter.getName(), PrimitiveInfo.VOID, new TypeInfo[] { type }, paramAnnotations, null, setter.getModifiers(), declaringType);
            }
            properties.put(lowerName, new DefaultPropertyInfo(lowerName, name, type, getterInfo, setterInfo, annotations));
         }
      }
      if (setters.isEmpty() == false)
      {
         for (Iterator<Map.Entry<String, List<Method>>> i = setters.entrySet().iterator(); i.hasNext();)
         {
            Map.Entry<String, List<Method>> entry = i.next();
            String name = entry.getKey();
            List<Method> setterList = entry.getValue();
            // TODO JBMICROCONT-125 Maybe should just create duplicate propertyInfo and let the configurator guess?
            if (setterList.size() == 1)
            {
               Method setter = setterList.get(0);
               Type pinfo = setter.getGenericParameterTypes()[0];
               TypeInfo type = factory.getTypeInfo(pinfo);
               String lowerName = getLowerPropertyName(name);
               Set<AnnotationValue> setterAnnotations = getExpectedAnnotations(setter.getAnnotations());
               AnnotationValue[] annotations = setterAnnotations.toArray(new AnnotationValue[setterAnnotations.size()]);
               ClassInfo declaringType = (ClassInfo) factory.getTypeInfo(setter.getDeclaringClass());
               AnnotationValue[][] paramAnnotations = new AnnotationValue[1][];
               setterAnnotations = getExpectedAnnotations(setter.getParameterAnnotations()[0]);
               paramAnnotations[0] = setterAnnotations.toArray(new AnnotationValue[setterAnnotations.size()]);
               MethodInfo setterInfo = new MethodInfoImpl(null, setter.getName(), PrimitiveInfo.VOID, new TypeInfo[] { type }, paramAnnotations, null, setter.getModifiers(), declaringType);
               properties.put(lowerName, new DefaultPropertyInfo(lowerName, name, type, null, setterInfo, annotations));
            }
         }
      }
      if (mode != BeanAccessMode.STANDARD)
      {
         ClassInfo classInfo = (ClassInfo)factory.getTypeInfo(clazz);
         Set<FieldInfo> fields = getFields(classInfo, mode);
         for(FieldInfo field : fields)
         {
            String name = field.getName();
            PropertyInfo pi = properties.get(name);
View Full Code Here

      return new HashSet<PropertyInfo>(properties.values());
   }
  
   protected Set<PropertyInfo> getExpectedAnnotationProperties(Class<?> clazz)
   {
      TypeInfoFactory factory = getTypeInfoFactory();
      HashSet<PropertyInfo> properties = new HashSet<PropertyInfo>();

      Method[] methods  = clazz.getDeclaredMethods();
      for (Method method : methods)
      {
         TypeInfo returnType = factory.getTypeInfo(method.getGenericReturnType());
         Class<?>[] parameters = method.getParameterTypes();
         if (parameters.length == 0 && PrimitiveInfo.VOID.equals(returnType) == false)
         {
            String name = method.getName();
            ClassInfo declaringType = (ClassInfo) factory.getTypeInfo(method.getDeclaringClass());
            Set<AnnotationValue> getterAnnotations = getExpectedAnnotations(method.getAnnotations());
            AnnotationValue[] annotations = getterAnnotations.toArray(new AnnotationValue[getterAnnotations.size()]);
            MethodInfo getter = new MethodInfoImpl(null, name, returnType, new TypeInfo[0], new AnnotationValue[0][], null, method.getModifiers(), declaringType);
            properties.add(new DefaultPropertyInfo(name, name, returnType, getter, null, annotations));
         }
View Full Code Here

      }
   }
  
   protected ClassInfo getClassInfo(Class<?> clazz)
   {
      TypeInfoFactory factory = getTypeInfoFactory();
      TypeInfo info = factory.getTypeInfo(clazz);
      assertNotNull(info);
      assertTrue(info instanceof ClassInfo);
      ClassInfo cinfo = (ClassInfo) info;
      getLog().debug(cinfo);
      return cinfo;
View Full Code Here

      testGenericSuperInterface(ClassInfoGenericSuperInterfaceEmptyClass.class, ClassInfoGenericInterface.class, new Class[] { ClassInfoEmptyClass.class });
   }
  
   public void testGenericSuperClass(Class<?> clazz, Class<?> genericClass, Class<?>[] genericTypes)
   {
      TypeInfoFactory factory = getTypeInfoFactory();
      ClassInfo typeInfo = (ClassInfo) factory.getTypeInfo(clazz);
      ClassInfo superClassInfo = typeInfo.getGenericSuperclass();
      ClassInfo genericClassInfo = (ClassInfo) factory.getTypeInfo(genericClass);
      getLog().debug("Checking superClass: " + genericClass + " against " + superClassInfo);
      assertEquals(genericClassInfo, superClassInfo);

      TypeInfo[] types = new TypeInfo[genericTypes.length];
      for (int i = 0; i < types.length; ++i)
         types[i] = factory.getTypeInfo(genericTypes[i]);
      TypeInfo[] actualTypes = superClassInfo.getActualTypeArguments();
      getLog().debug("Checking superClass types: " + Arrays.asList(genericTypes) + " against " + Arrays.asList(actualTypes));
      assertEquals(types.length, actualTypes.length);
      for (int i = 0; i < types.length; ++i)
         assertEquals(types[i], actualTypes[i]);
View Full Code Here

         assertEquals(types[i], actualTypes[i]);
   }
  
   public void testGenericSuperInterface(Class<?> clazz, Class<?> genericClass, Class<?>[] genericTypes)
   {
      TypeInfoFactory factory = getTypeInfoFactory();
      ClassInfo typeInfo = (ClassInfo) factory.getTypeInfo(clazz);
      InterfaceInfo[] superInterfaces = typeInfo.getGenericInterfaces();
      assertNotNull(superInterfaces);
      assertEquals(1, superInterfaces.length);
      InterfaceInfo superInterface = superInterfaces[0];
      getLog().debug("Checking superInterface: " + genericClass + " against " + superInterface);
      ClassInfo genericClassInfo = (ClassInfo) factory.getTypeInfo(genericClass);
      assertEquals(genericClassInfo, superInterface);

      TypeInfo[] types = new TypeInfo[genericTypes.length];
      for (int i = 0; i < types.length; ++i)
         types[i] = factory.getTypeInfo(genericTypes[i]);
      TypeInfo[] actualTypes = superInterface.getActualTypeArguments();
      getLog().debug("Checking superInterface types: " + Arrays.asList(genericTypes) + " against " + Arrays.asList(actualTypes));
      assertEquals(types.length, actualTypes.length);
      for (int i = 0; i < types.length; ++i)
         assertEquals(types[i], actualTypes[i]);
View Full Code Here

      assertComponentType(type, expected);
   }
  
   private void assertComponentType(Type type, Class<?> expected) throws Exception
   {
      TypeInfoFactory factory = getTypeInfoFactory();
      TypeInfo typeInfo = factory.getTypeInfo(type);
      ClassInfo classInfo = assertInstanceOf(typeInfo, ClassInfo.class);
      assertTrue(classInfo.isCollection());

      TypeInfo expectedInfo = factory.getTypeInfo(expected);
      assertEquals(expectedInfo, classInfo.getComponentType());
   }
View Full Code Here

      assertKeyValueType(type, keyExpected, valueExpected);
   }
  
   private void assertKeyValueType(Type type, Class<?> keyExpected, Class<?> valueExpected) throws Exception
   {
      TypeInfoFactory factory = getTypeInfoFactory();
      TypeInfo typeInfo = factory.getTypeInfo(type);
      ClassInfo classInfo = assertInstanceOf(typeInfo, ClassInfo.class);
      assertTrue(classInfo.isMap());

      TypeInfo expectedInfo = factory.getTypeInfo(keyExpected);
      assertEquals(expectedInfo, classInfo.getKeyType());

      expectedInfo = factory.getTypeInfo(valueExpected);
      assertEquals(expectedInfo, classInfo.getValueType());
   }
View Full Code Here

TOP

Related Classes of org.jboss.reflect.spi.TypeInfoFactory

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.