示例#1
0
 private Object newInstance(Class clazz) {
   ReflectClass classReflector = reflector().forClass(clazz);
   Object obj = classReflector.newInstance();
   if (obj == null) {
     throw new IllegalArgumentException("No usable constructor for Class " + clazz);
   }
   return obj;
 }
示例#2
0
  public void testIsNDimensional() {
    ReflectClass arrayOfArrayOfString = reflectClass(String[][].class);
    Assert.isTrue(arrayOfArrayOfString.isArray());

    final ReflectClass arrayOfString = reflectClass(String[].class);
    Assert.areSame(arrayOfString, arrayOfArrayOfString.getComponentType());
    Assert.isTrue(arrayReflector().isNDimensional(arrayOfArrayOfString));
    Assert.isFalse(arrayReflector().isNDimensional(arrayOfString));
  }
示例#3
0
 protected void assertNullItem(Object obj) throws Exception {
   ReflectClass claxx = reflector().forObject(obj);
   ReflectField[] fields = claxx.getDeclaredFields();
   for (int i = 0; i < fields.length; ++i) {
     ReflectField field = fields[i];
     if (field.isStatic() || field.isTransient()) {
       continue;
     }
     ReflectClass type = field.getFieldType();
     if (container().classMetadataForReflectClass(type).isValueType()) {
       continue;
     }
     Object value = field.get(obj);
     Assert.isNull(value);
   }
 }
  /**
   * This is to ensure that reflector.forObject(GenericArray) returns an instance of
   * GenericArrayClass instead of GenericClass http://tracker.db4o.com/jira/browse/COR-376
   */
  public void testGenericArrayClass() {
    ExtObjectContainer oc = fixture().db();
    initGenericObjects();
    ReflectClass elementType = oc.reflector().forName(PERSON_CLASSNAME);

    Object array = reflector().array().newInstance(elementType, 5);

    ReflectClass arrayClass = oc.reflector().forObject(array);
    Assert.isTrue(arrayClass.isArray());
    Assert.isTrue(arrayClass instanceof GenericArrayClass);

    arrayClass = oc.reflector().forName(array.getClass().getName());
    Assert.isTrue(arrayClass.isArray());
    Assert.isTrue(arrayClass instanceof GenericArrayClass);

    arrayClass = oc.reflector().forClass(array.getClass());
    Assert.isTrue(arrayClass.isArray());
    Assert.isTrue(arrayClass instanceof GenericArrayClass);

    Assert.areEqual(arrayClass.getName(), ReflectPlatform.fullyQualifiedName(array.getClass()));

    Assert.areEqual("(GA) " + elementType.getName(), array.toString());
  }