Ejemplo n.º 1
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());
  }
  public static ReflectConstructorSpec createConstructor(
      final ConstructorAwareReflectClass claxx,
      Class clazz,
      ReflectorConfiguration config,
      ReflectConstructor[] constructors) {

    if (claxx == null) {
      return ReflectConstructorSpec.INVALID_CONSTRUCTOR;
    }

    if (claxx.isAbstract() || claxx.isInterface()) {
      return ReflectConstructorSpec.INVALID_CONSTRUCTOR;
    }

    if (!Platform4.callConstructor()) {
      boolean skipConstructor = !config.callConstructor(claxx);
      if (!claxx.isCollection()) {
        ReflectConstructor serializableConstructor =
            skipConstructor(claxx, skipConstructor, config.testConstructors());
        if (serializableConstructor != null) {
          return new ReflectConstructorSpec(serializableConstructor, null);
        }
      }
    }

    if (!config.testConstructors()) {
      return new ReflectConstructorSpec(new PlatformReflectConstructor(clazz), null);
    }

    if (ReflectPlatform.createInstance(clazz) != null) {
      return new ReflectConstructorSpec(new PlatformReflectConstructor(clazz), null);
    }

    Tree sortedConstructors = sortConstructorsByParamsCount(constructors);
    return findConstructor(claxx, sortedConstructors);
  }