public Type get(Class<?> cl) { return get(cl, cl); }
@Test public void hidaBez() { Type type = typeFactory.getEntityType(HidaBez.class); //System.out.println(type.getGenericName(true)); }
@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()); }
public Type get(Class<?> cl, java.lang.reflect.Type genericType) { return get(isEntityClass(cl), cl, null, genericType); }
ReflectionUtils.getTypeParameterCount(genericType)); cache.put(key, new ClassType(cl, tempParams)); Type[] parameters = getParameters(cl, genericType); Type componentType = get(cl.getComponentType()); if (cl.getComponentType().isPrimitive()) { componentType = Types.PRIMITIVES.get(componentType); value = new ClassType(TypeCategory.NUMERIC, cl, parameters); } else if (entity) { value = createOther(cl, entity, annotationHelper, annotation, parameters); } else if (Map.class.isAssignableFrom(cl)) { value = new SimpleType(Types.MAP, parameters[0], asGeneric(parameters[1])); } else if (List.class.isAssignableFrom(cl)) { value = new SimpleType(Types.LIST, asGeneric(parameters[0])); } else if (Set.class.isAssignableFrom(cl)) { value = new SimpleType(Types.SET, asGeneric(parameters[0])); } else if (Collection.class.isAssignableFrom(cl)) { value = new SimpleType(Types.COLLECTION, asGeneric(parameters[0])); } else { value = createOther(cl, entity, annotationHelper, annotation, parameters);
EntityType type = allTypes.get(ClassUtils.getFullName(cl)); if (type == null) { type = typeFactory.getEntityType(cl); type.addSupertype(new Supertype(typeFactory.get(cl.getSuperclass(), cl.getGenericSuperclass()))); type.addSupertype(new Supertype(typeFactory.get(iface)));
@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()); }
@Test public void resolve2() { TypeFactory factory = new TypeFactory(Collections.<Class<? extends Annotation>>emptyList()); Type type = factory.getEntityType(AbstractCollectionAttribute.class); assertEquals("com.querydsl.codegen.Generic2Test.AbstractCollectionAttribute<? extends java.util.Collection<?>>", type.getGenericName(false)); assertEquals("com.querydsl.codegen.Generic2Test.AbstractCollectionAttribute<? extends java.util.Collection<?>>", type.getGenericName(true)); }
typeFactory.addEmbeddableType(embeddableType); if (!embeddableTypes.containsKey(embeddableType) && !entityTypes.containsKey(embeddableType) propertyType = typeFactory.get(type, annotated, genericType); if (propertyType instanceof EntityType && !allTypes.containsKey(ClassUtils.getFullName(type))) { String fullName = ClassUtils.getFullName(type);
typeMappings = codegenModule.get(TypeMappings.class); queryTypeFactory = codegenModule.get(QueryTypeFactory.class); typeFactory = new TypeFactory(ImmutableList.of(entityAnnotation, supertypeAnnotation, embeddableAnnotation), codegenModule.get(Function.class, CodegenModule.VARIABLE_NAME_FUNCTION_CLASS)); typeFactory.addAnnotationHelper(helper); typeFactory.extendTypes();
public void setUnknownAsEntity(boolean unknownAsEntity) { typeFactory.setUnknownAsEntity(unknownAsEntity); }
Type value = create(entity, cl, annotationHelper, selectedAnnotation, genericType, key); cache.put(key, value); return value;
private void addSupertypeFields(EntityType model, Map<String, EntityType> superTypes, Set<EntityType> handled) { if (handled.add(model)) { for (Supertype supertype : model.getSuperTypes()) { EntityType entityType = superTypes.get(supertype.getType().getFullName()); if (entityType == null) { if (supertype.getType().getPackageName().startsWith("java.")) { // skip internal supertypes continue; } // FIXME this misses the generics Class<?> cl = supertype.getType().getJavaClass(); typeFactory.addEmbeddableType(cl); entityType = createEntityType(cl, new HashMap<Class<?>, EntityType>()); addProperties(cl, entityType); } addSupertypeFields(entityType, superTypes, handled); supertype.setEntityType(entityType); model.include(supertype); } } }
@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); registerConfig(type); 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 resolve2() { TypeFactory factory = new TypeFactory(Collections.<Class<? extends Annotation>>emptyList()); Type type = factory.getEntityType(AbstractCollectionAttribute.class); assertEquals("com.querydsl.codegen.Generic2Test.AbstractCollectionAttribute<? extends java.util.Collection<?>>", type.getGenericName(false)); assertEquals("com.querydsl.codegen.Generic2Test.AbstractCollectionAttribute<? extends java.util.Collection<?>>", type.getGenericName(true)); }
public Type get(Class<?> cl, AnnotatedElement annotated, java.lang.reflect.Type genericType) { return get(isEntityClass(cl), cl, annotated, genericType); }
public Type get(boolean entity, Class<?> cl, java.lang.reflect.Type genericType) { return get(entity, cl, null, genericType); }
@Test public void resolve() { TypeFactory factory = new TypeFactory(Collections.<Class<? extends Annotation>>emptyList()); Type type = factory.get(AbstractCollectionAttribute.class); assertEquals("com.querydsl.codegen.Generic2Test.AbstractCollectionAttribute", type.getGenericName(false)); assertEquals("com.querydsl.codegen.Generic2Test.AbstractCollectionAttribute", type.getGenericName(true)); }
@Test public void hidaBezGruppe() { Type type = typeFactory.getEntityType(HidaBezGruppe.class); //System.out.println(type.getGenericName(true)); }