private GenericField[] fields(ReflectClass personClass) { return new GenericField[] { new GenericField("surname", _reflector.forClass(String.class), false), new GenericField("birthdate", _reflector.forClass(Date.class), false), new GenericField("bestFriend", personClass, false) }; }
public GenericObjects() throws ClassNotFoundException { _reflector = new GenericReflector( null, new JdkReflector(Thread.currentThread().getContextClassLoader())); _reflector.configuration(new MockReflectorConfiguration()); _objectIClass = (GenericClass) _reflector.forClass(Object.class); }
private GenericField[] fields(GenericClass personClass, GenericReflector reflector) { return new GenericField[] { new GenericField("surname", reflector.forClass(String.class), false), new GenericField("birthdate", reflector.forClass(Date.class), false), new GenericField("bestFriend", personClass, false), new GenericField("nArray", reflector.forClass(int[][].class), true) }; }
/** * todo: Move the GenericClass creation into a utility/factory class. * * @return */ public GenericClass initGenericClass() { GenericReflector reflector = new GenericReflector(null, Platform4.reflectorForType(GenericObjectsTest.class)); GenericClass _objectIClass = (GenericClass) reflector.forClass(Object.class); GenericClass result = new GenericClass(reflector, null, PERSON_CLASSNAME, _objectIClass); result.initFields(fields(result, reflector)); return result; }
public void test() throws ClassNotFoundException { _reflector.register(acmeDataClass()); _iClass = (GenericClass) _reflector.forName("com.acme.Person"); _assert(_iClass.getName().equals("com.acme.Person")); _assert(_iClass.getSuperclass() == _objectIClass); _assert(_iClass.isAssignableFrom(subclass())); _assert(!_iClass.isAssignableFrom(otherDataClass())); _assert(!_iClass.isAssignableFrom(_objectIClass)); _assert(_iClass.isInstance(_iClass.newInstance())); _assert(_iClass.isInstance(subclass().newInstance())); _assert(!_iClass.isInstance(otherDataClass().newInstance())); _assert(!_iClass.isInstance("whatever")); _assert(_reflector.forObject(_iClass.newInstance()) == _iClass); tstFields(); tstReflectionDelegation(); }