Пример #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
  /**
   * 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());
  }