protected Type getType(Class<?> cl, Class<?> mappedType, String propertyName) throws NoSuchMethodException { Field field = ReflectionUtils.getFieldOrNull(cl, propertyName); if (field != null) { if (mappedType.isAssignableFrom(field.getType())) { return typeFactory.get(field.getType(), field.getGenericType()); } else { return typeFactory.get(mappedType); } } else { Method method = ReflectionUtils.getGetterOrNull(cl, propertyName); if (method != null) { if (mappedType.isAssignableFrom(method.getReturnType())) { return typeFactory.get(method.getReturnType(), method.getGenericReturnType()); } else { return typeFactory.get(mappedType); } } else { throw new IllegalArgumentException("No property found for " + cl.getName() + "." + propertyName); } } }
@Test public void UnknownAsEntity() { assertEquals(TypeCategory.SIMPLE, factory.get(TypeFactoryTest.class).getCategory()); factory = new TypeFactory(); factory.setUnknownAsEntity(true); assertEquals(TypeCategory.CUSTOM, factory.get(TypeFactoryTest.class).getCategory()); }
private EntityType createEntityType(Class<?> cl, Map<Class<?>, EntityType> types) { if (allTypes.containsKey(cl)) { return allTypes.get(cl); } else { EntityType type = typeFactory.getEntityType(cl); typeMappings.register(type, queryTypeFactory.create(type)); if (!cl.getSuperclass().equals(Object.class)) { type.addSupertype(new Supertype(typeFactory.get(cl.getSuperclass(), cl.getGenericSuperclass()))); } types.put(cl, type); allTypes.put(cl, type); return type; } }
@Test public void Base_base() throws SecurityException, NoSuchFieldException { TypeFactory typeFactory = new TypeFactory(); Field field = Base.class.getDeclaredField("base"); Type type = typeFactory.get(field.getType(), field.getGenericType()); assertEquals(0, type.getParameters().size()); }
@Test public void HidaBezGruppe() { Type type = typeFactory.getEntityType(HidaBezGruppe.class); //System.out.println(type.getGenericName(true)); }
public void setUnknownAsEntity(boolean unknownAsEntity) { typeFactory.setUnknownAsEntity(unknownAsEntity); }
@Test public void Resolve2() { TypeFactory factory = new TypeFactory(Collections.<Class<? extends Annotation>>emptyList()); Type type = factory.getEntityType(AbstractCollectionAttribute.class); assertEquals("com.mysema.query.codegen.Generic2Test.AbstractCollectionAttribute<? extends java.util.Collection<?>>", type.getGenericName(false)); assertEquals("com.mysema.query.codegen.Generic2Test.AbstractCollectionAttribute<? extends java.util.Collection<?>>", type.getGenericName(true)); }
@Test public void Resolve() { TypeFactory factory = new TypeFactory(Collections.<Class<? extends Annotation>>emptyList()); Type type = factory.get(AbstractCollectionAttribute.class); assertEquals("com.mysema.query.codegen.Generic2Test.AbstractCollectionAttribute", type.getGenericName(false)); assertEquals("com.mysema.query.codegen.Generic2Test.AbstractCollectionAttribute", type.getGenericName(true)); }
@Test public void HidaBez() { Type type = typeFactory.getEntityType(HidaBez.class); //System.out.println(type.getGenericName(true)); }
public DomainExporter(String namePrefix, String nameSuffix, File targetFolder, SerializerConfig serializerConfig, Configuration configuration) { this.targetFolder = targetFolder; this.serializerConfig = serializerConfig; this.configuration = configuration; CodegenModule module = new CodegenModule(); module.bind(CodegenModule.PREFIX, namePrefix); module.bind(CodegenModule.SUFFIX, nameSuffix); module.bind(CodegenModule.KEYWORDS, Collections.<String> emptySet()); this.queryTypeFactory = module.get(QueryTypeFactory.class); this.typeMappings = module.get(TypeMappings.class); this.entitySerializer = module.get(EntitySerializer.class); typeFactory.setUnknownAsEntity(true); }
private Type createType(Class<?> clazz) { Type type = classToType.get(clazz); if (type == null) { if (configuration.isMapped(clazz) && !clazz.isEnum()) { type = createEntityType(clazz); } else { type = typeFactory.get(clazz); } classToType.put(clazz, type); } return type; }
@Test public void Base_base2() throws SecurityException, NoSuchFieldException { TypeFactory typeFactory = new TypeFactory(); Field field = Base.class.getDeclaredField("base2"); Type type = typeFactory.get(field.getType(), field.getGenericType()); assertEquals(2, type.getParameters().size()); assertNull(((TypeExtends)type.getParameters().get(0)).getVarName()); assertNull(((TypeExtends)type.getParameters().get(1)).getVarName()); }
@Test public void Parameters() { EntityType type = factory.getEntityType(Examples.Complex.class); assertEquals(1, type.getParameters().size()); assertEquals(TypeExtends.class, type.getParameters().get(0).getClass()); }
protected EntityType createEntityType(Type type, Map<Class<?>, EntityType> types) { Class<?> key = type.getJavaClass(); if (allTypes.containsKey(key)) { return allTypes.get(key); } else { EntityType entityType = new EntityType(type, variableNameFunction); typeMappings.register(entityType, queryTypeFactory.create(entityType)); Class<?> superClass = key.getSuperclass(); if (entityType.getSuperType() == null && superClass != null && !superClass.equals(Object.class)) { entityType.addSupertype(new Supertype(typeFactory.get(superClass, key.getGenericSuperclass()))); } types.put(key, entityType); allTypes.put(key, entityType); return entityType; } }
@Test public void Generics_TypeVariable() { Type type = factory.getEntityType(Generic2Test.AbstractCollectionAttribute.class); assertEquals(TypeExtends.class, type.getParameters().get(0).getClass()); TypeExtends t = (TypeExtends) type.getParameters().get(0); assertEquals("T", t.getVarName()); }
@Test public void Extends() throws SecurityException, NoSuchFieldException{ Field field = getClass().getDeclaredField("field4"); Type type = factory.get(field.getType(), field.getGenericType()); assertEquals(1, type.getParameters().size()); // assertEquals(Types.OBJECT, type.getParameters().get(0)); }
@Test public void ComparableEntity() { Type type = factory.getEntityType(ComparableEntity.class); //ComparableEntity<T extends Comparable<? super T>> implements Serializable assertEquals(1, type.getParameters().size()); TypeExtends t = (TypeExtends)type.getParameters().get(0); assertEquals("T", t.getVarName()); assertEquals(1, t.getParameters().size()); }
@Test public void RawField() throws SecurityException, NoSuchFieldException{ Field field = getClass().getDeclaredField("field3"); Type type = factory.get(field.getType(), field.getGenericType()); assertEquals(1, type.getParameters().size()); // assertEquals(Types.OBJECT, type.getParameters().get(0)); }
@Test public void OrderBys() throws SecurityException, NoSuchFieldException { Field field = Examples.OrderBys.class.getDeclaredField("orderBy"); Type type = factory.get(field.getType(), field.getGenericType()); assertEquals(1, type.getParameters().size()); }
@Test public void Generics_Object() throws SecurityException, NoSuchFieldException{ Field field = getClass().getDeclaredField("field2"); Type type = factory.get(field.getType(), field.getGenericType()); assertEquals(1, type.getParameters().size()); assertEquals(Types.OBJECT, type.getParameters().get(0)); }