From 2efa88bc1fd29bda07ae8a487f68101feeb453df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20Westk=C3=A4mper?= Date: Sun, 7 Mar 2010 18:54:44 +0000 Subject: [PATCH] stripped Model suffix off from codegen class names made references to external supertypes possible in APT based query type generation added Java compiler API based test --- ...eModelFactory.java => APTTypeFactory.java} | 260 +++++++++--------- .../com/mysema/query/apt/Configuration.java | 4 +- .../query/apt/DefaultConfiguration.java | 4 +- .../com/mysema/query/apt/ElementHandler.java | 93 ++++--- .../java/com/mysema/query/apt/Processor.java | 145 ++++------ .../apt/QuerydslAnnotationProcessorTest.java | 69 +++++ .../query/domain/Inheritance2Test$Base.class | Bin 0 -> 839 bytes .../query/domain/Inheritance2Test$Base2.class | Bin 0 -> 751 bytes .../domain/Inheritance2Test$Base2Sub.class | Bin 0 -> 831 bytes .../domain/Inheritance2Test$BaseSub.class | Bin 0 -> 696 bytes .../domain/Inheritance2Test$BaseSub2.class | Bin 0 -> 711 bytes .../query/domain/Inheritance2Test$IFace.class | Bin 0 -> 228 bytes .../query/domain/Inheritance2Test.class | Bin 0 -> 784 bytes .../mysema/query/domain/Inheritance2Test.java | 4 +- .../mysema/query/domain/InheritanceTest.java | 1 + .../mysema/query/domain/Superclass3Test.java | 22 ++ .../com/mysema/query/SimpleProjectable.java | 30 ++ .../java/com/mysema/query/SimpleQuery.java | 25 ++ ...stractTypeModel.java => AbstractType.java} | 8 +- .../{ClassTypeModel.java => ClassType.java} | 34 +-- ...ConstructorModel.java => Constructor.java} | 14 +- .../mysema/query/codegen/DTOSerializer.java | 18 +- .../query/codegen/EmbeddableSerializer.java | 10 +- .../query/codegen/EntityModelFactory.java | 84 ------ .../query/codegen/EntitySerializer.java | 96 +++---- .../{EntityModel.java => EntityType.java} | 111 ++++---- .../codegen/{MethodModel.java => Method.java} | 20 +- .../{ParameterModel.java => Parameter.java} | 14 +- .../{PropertyModel.java => Property.java} | 38 +-- .../com/mysema/query/codegen/Serializer.java | 8 +- .../{SimpleTypeModel.java => SimpleType.java} | 30 +- .../query/codegen/SupertypeSerializer.java | 8 +- .../codegen/{TypeModel.java => Type.java} | 20 +- .../com/mysema/query/codegen/TypeAdapter.java | 130 +++++++++ ...TypeExtendsModel.java => TypeExtends.java} | 16 +- ...TypeModelFactory.java => TypeFactory.java} | 49 ++-- .../mysema/query/codegen/TypeMappings.java | 16 +- .../query/codegen/TypeModelAdapter.java | 130 --------- .../com/mysema/query/codegen/TypeModels.java | 38 --- .../com/mysema/query/codegen/TypeSuper.java | 51 ++++ .../mysema/query/codegen/TypeSuperModel.java | 53 ---- .../java/com/mysema/query/codegen/Types.java | 38 +++ ...tityModelTest.java => EntityTypeTest.java} | 6 +- .../query/codegen/ParameterModelTest.java | 26 -- .../mysema/query/codegen/ParameterTest.java | 26 ++ .../mysema/query/codegen/SerializerTest.java | 14 +- ...lFactoryTest.java => TypeFactoryTest.java} | 8 +- .../{TypeModelTest.java => TypeTest.java} | 4 +- .../mysema/query/sql/MetaDataExporter.java | 30 +- 49 files changed, 921 insertions(+), 884 deletions(-) rename querydsl-apt/src/main/java/com/mysema/query/apt/{APTTypeModelFactory.java => APTTypeFactory.java} (66%) create mode 100644 querydsl-apt/src/test/java/com/mysema/query/apt/QuerydslAnnotationProcessorTest.java create mode 100644 querydsl-apt/src/test/java/com/mysema/query/domain/Inheritance2Test$Base.class create mode 100644 querydsl-apt/src/test/java/com/mysema/query/domain/Inheritance2Test$Base2.class create mode 100644 querydsl-apt/src/test/java/com/mysema/query/domain/Inheritance2Test$Base2Sub.class create mode 100644 querydsl-apt/src/test/java/com/mysema/query/domain/Inheritance2Test$BaseSub.class create mode 100644 querydsl-apt/src/test/java/com/mysema/query/domain/Inheritance2Test$BaseSub2.class create mode 100644 querydsl-apt/src/test/java/com/mysema/query/domain/Inheritance2Test$IFace.class create mode 100644 querydsl-apt/src/test/java/com/mysema/query/domain/Inheritance2Test.class create mode 100644 querydsl-apt/src/test/java/com/mysema/query/domain/Superclass3Test.java create mode 100644 querydsl-core/src/main/java/com/mysema/query/SimpleProjectable.java create mode 100644 querydsl-core/src/main/java/com/mysema/query/SimpleQuery.java rename querydsl-core/src/main/java/com/mysema/query/codegen/{AbstractTypeModel.java => AbstractType.java} (71%) rename querydsl-core/src/main/java/com/mysema/query/codegen/{ClassTypeModel.java => ClassType.java} (74%) rename querydsl-core/src/main/java/com/mysema/query/codegen/{ConstructorModel.java => Constructor.java} (58%) delete mode 100644 querydsl-core/src/main/java/com/mysema/query/codegen/EntityModelFactory.java rename querydsl-core/src/main/java/com/mysema/query/codegen/{EntityModel.java => EntityType.java} (56%) rename querydsl-core/src/main/java/com/mysema/query/codegen/{MethodModel.java => Method.java} (66%) rename querydsl-core/src/main/java/com/mysema/query/codegen/{ParameterModel.java => Parameter.java} (62%) rename querydsl-core/src/main/java/com/mysema/query/codegen/{PropertyModel.java => Property.java} (59%) rename querydsl-core/src/main/java/com/mysema/query/codegen/{SimpleTypeModel.java => SimpleType.java} (76%) rename querydsl-core/src/main/java/com/mysema/query/codegen/{TypeModel.java => Type.java} (68%) create mode 100644 querydsl-core/src/main/java/com/mysema/query/codegen/TypeAdapter.java rename querydsl-core/src/main/java/com/mysema/query/codegen/{TypeExtendsModel.java => TypeExtends.java} (50%) rename querydsl-core/src/main/java/com/mysema/query/codegen/{TypeModelFactory.java => TypeFactory.java} (61%) delete mode 100644 querydsl-core/src/main/java/com/mysema/query/codegen/TypeModelAdapter.java delete mode 100644 querydsl-core/src/main/java/com/mysema/query/codegen/TypeModels.java create mode 100644 querydsl-core/src/main/java/com/mysema/query/codegen/TypeSuper.java delete mode 100644 querydsl-core/src/main/java/com/mysema/query/codegen/TypeSuperModel.java create mode 100644 querydsl-core/src/main/java/com/mysema/query/codegen/Types.java rename querydsl-core/src/test/java/com/mysema/query/codegen/{EntityModelTest.java => EntityTypeTest.java} (84%) delete mode 100644 querydsl-core/src/test/java/com/mysema/query/codegen/ParameterModelTest.java create mode 100644 querydsl-core/src/test/java/com/mysema/query/codegen/ParameterTest.java rename querydsl-core/src/test/java/com/mysema/query/codegen/{TypeModelFactoryTest.java => TypeFactoryTest.java} (84%) rename querydsl-core/src/test/java/com/mysema/query/codegen/{TypeModelTest.java => TypeTest.java} (62%) diff --git a/querydsl-apt/src/main/java/com/mysema/query/apt/APTTypeModelFactory.java b/querydsl-apt/src/main/java/com/mysema/query/apt/APTTypeFactory.java similarity index 66% rename from querydsl-apt/src/main/java/com/mysema/query/apt/APTTypeModelFactory.java rename to querydsl-apt/src/main/java/com/mysema/query/apt/APTTypeFactory.java index 3c019d012..3e4007d46 100644 --- a/querydsl-apt/src/main/java/com/mysema/query/apt/APTTypeModelFactory.java +++ b/querydsl-apt/src/main/java/com/mysema/query/apt/APTTypeFactory.java @@ -10,6 +10,7 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.HashMap; +import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Map; @@ -30,14 +31,15 @@ import javax.lang.model.type.TypeMirror; import javax.lang.model.type.TypeVariable; import javax.lang.model.type.WildcardType; -import com.mysema.query.codegen.EntityModel; -import com.mysema.query.codegen.SimpleTypeModel; +import com.mysema.query.codegen.EntityType; +import com.mysema.query.codegen.SimpleType; +import com.mysema.query.codegen.Type; +import com.mysema.query.codegen.TypeAdapter; import com.mysema.query.codegen.TypeCategory; -import com.mysema.query.codegen.TypeExtendsModel; -import com.mysema.query.codegen.TypeModel; -import com.mysema.query.codegen.TypeModelFactory; -import com.mysema.query.codegen.TypeModels; -import com.mysema.query.codegen.TypeSuperModel; +import com.mysema.query.codegen.TypeExtends; +import com.mysema.query.codegen.TypeFactory; +import com.mysema.query.codegen.TypeSuper; +import com.mysema.query.codegen.Types; /** * APTTypeModelFactory is a factory for APT inspection based TypeModel creation @@ -45,26 +47,35 @@ import com.mysema.query.codegen.TypeSuperModel; * @author tiwe * */ -public final class APTTypeModelFactory { +public final class APTTypeFactory { - private final Map,TypeModel> cache = new HashMap,TypeModel>(); + @Nullable + private static Class safeForName(String name){ + try { + return Class.forName(name); + } catch (ClassNotFoundException e) { + return null; + } + } + private final Map,Type> cache = new HashMap,Type>(); + private final Configuration configuration; - private final TypeModel defaultValue; + private final Type defaultValue; private final List> entityAnnotations; - private final Map,EntityModel> entityTypeCache = new HashMap,EntityModel>(); + private final Map,EntityType> entityTypeCache = new HashMap,EntityType>(); private final ProcessingEnvironment env; - private final TypeModelFactory factory; + private final TypeFactory factory; private final TypeElement numberType, comparableType; - public APTTypeModelFactory(ProcessingEnvironment env, Configuration configuration, - TypeModelFactory factory, List> annotations){ + public APTTypeFactory(ProcessingEnvironment env, Configuration configuration, + TypeFactory factory, List> annotations){ this.env = env; this.configuration = configuration; this.factory = factory; @@ -74,67 +85,23 @@ public final class APTTypeModelFactory { this.comparableType = env.getElementUtils().getTypeElement(Comparable.class.getName()); } - private EntityModel asEntityModel(TypeMirror type, TypeModel value) { - if (type.getKind() == TypeKind.TYPEVAR){ - TypeVariable typeVar = (TypeVariable)type; - if (typeVar.getUpperBound() != null){ - type = typeVar.getUpperBound(); - } - }else if (type.getKind() == TypeKind.WILDCARD){ - WildcardType wildcard = (WildcardType)type; - if (wildcard.getExtendsBound() != null){ - type = wildcard.getExtendsBound(); - } - } - - Collection superTypes = Collections.emptySet(); - if (type.getKind() == TypeKind.DECLARED){ - DeclaredType declaredType = (DeclaredType)type; - TypeElement e = (TypeElement)declaredType.asElement(); - if (e.getKind() == ElementKind.CLASS){ - superTypes = Collections.singleton(create(e.getSuperclass()).getFullName()); - }else{ - superTypes = new ArrayList(e.getInterfaces().size()); - for (TypeMirror mirror : e.getInterfaces()){ - TypeModel iface = create(mirror); - if (!iface.getFullName().startsWith("java")){ - superTypes.add(iface.getFullName()); - } - } - } - - }else{ - throw new IllegalArgumentException("Unsupported type kind " + type.getKind()); - } - - return new EntityModel(configuration.getNamePrefix(), value, superTypes); - } - - private TypeModel create(TypeElement typeElement, TypeCategory category, - List typeArgs) { + private Type create(TypeElement typeElement, TypeCategory category, List typeArgs) { String name = typeElement.getQualifiedName().toString(); String simpleName = typeElement.getSimpleName().toString(); String packageName = env.getElementUtils().getPackageOf(typeElement).getQualifiedName().toString(); - TypeModel[] params = new TypeModel[typeArgs.size()]; + Type[] params = new Type[typeArgs.size()]; for (int i = 0; i < params.length; i++){ params[i] = create(typeArgs.get(i)); } - return new SimpleTypeModel(category, + return new SimpleType(category, name, packageName, simpleName, typeElement.getModifiers().contains(Modifier.FINAL), params); } - - /** - * Create a TypeModel for the given TypeMirror - * - * @param type - * @param el - * @return - */ + @Nullable - public TypeModel create(TypeMirror type){ - List key = getKey(type, true); + public Type create(TypeMirror type){ + List key = createKey(type, true, true); if (entityTypeCache.containsKey(key)){ return entityTypeCache.get(key); @@ -143,18 +110,19 @@ public final class APTTypeModelFactory { }else{ cache.put(key, null); - TypeModel value = handle(type); - if (value != null && value.getCategory() == TypeCategory.ENTITY){ - value = asEntityModel(type, value); - entityTypeCache.put(key, (EntityModel)value); + Type typeModel = handle(type); + if (typeModel != null && typeModel.getCategory() == TypeCategory.ENTITY){ + EntityType entityType = createEntityType(type); + cache.put(key, entityType); + return entityType; }else{ - cache.put(key, value); - } - return value; + cache.put(key, typeModel); + return typeModel; + } } } - private TypeModel createClassType(DeclaredType t, TypeElement typeElement) { + private Type createClassType(DeclaredType t, TypeElement typeElement) { // entity type for (Class entityAnn : entityAnnotations){ if (typeElement.getAnnotation(entityAnn) != null){ @@ -178,33 +146,31 @@ public final class APTTypeModelFactory { return create(typeElement, typeCategory, t.getTypeArguments()); } - /** - * Create an EntityModel for the given TypeMirror - * - * @param type - * @param el - * @return - */ @Nullable - public EntityModel createEntityModel(TypeMirror type){ - List key = getKey(type, true); + public EntityType createEntityType(TypeMirror type){ + List key = createKey(type, false, true); if (entityTypeCache.containsKey(key)){ return entityTypeCache.get(key); - }else{ + }else{ entityTypeCache.put(key, null); - TypeModel value = handle(type); + Type value = handle(type); if (value != null){ - EntityModel entityModel = asEntityModel(type, value); + EntityType entityModel = new EntityType(configuration.getNamePrefix(), value); +// entityTypeCache.put(Collections.singletonList(value.getFullName()), entityModel); entityTypeCache.put(key, entityModel); + cache.put(createKey(type, true, true), entityModel); + for (EntityType superType : getSupertypes(type, value)){ + entityModel.getSuperTypes().add(superType); + } return entityModel; }else{ return null; } } } - - private TypeModel createEnumType(DeclaredType t, TypeElement typeElement) { + + private Type createEnumType(DeclaredType t, TypeElement typeElement) { for (Class entityAnn : entityAnnotations){ if (typeElement.getAnnotation(entityAnn) != null){ return create(typeElement, TypeCategory.ENTITY, t.getTypeArguments()); @@ -215,16 +181,7 @@ public final class APTTypeModelFactory { return create(typeElement, TypeCategory.SIMPLE, t.getTypeArguments()); } - @Nullable - private static Class safeForName(String name){ - try { - return Class.forName(name); - } catch (ClassNotFoundException e) { - return null; - } - } - - private TypeModel createInterfaceType(DeclaredType t, TypeElement typeElement) { + private Type createInterfaceType(DeclaredType t, TypeElement typeElement) { // entity type for (Class entityAnn : entityAnnotations){ if (typeElement.getAnnotation(entityAnn) != null){ @@ -269,43 +226,94 @@ public final class APTTypeModelFactory { } } - /** - * Create a cache key for the given TypeMirror - * - * @param type - * @param deep inspect type arguments - * @return - */ - private List getKey(TypeMirror type, boolean deep){ + private List createKey(TypeMirror type, boolean useTypeArgs, boolean deep){ List key = new ArrayList(); - key.add(type.toString()); + String name = type.toString(); + if (name.contains("<")){ + name = name.substring(0, name.indexOf('<')); + } + key.add(name); + if (type.getKind() == TypeKind.TYPEVAR){ TypeVariable t = (TypeVariable)type; if (t.getUpperBound() != null){ - key.addAll(getKey(t.getUpperBound(), false)); + key.addAll(createKey(t.getUpperBound(), useTypeArgs, false)); } if (t.getLowerBound() != null){ - key.addAll(getKey(t.getLowerBound(), false)); + key.addAll(createKey(t.getLowerBound(), useTypeArgs, false)); } + }else if (type.getKind() == TypeKind.WILDCARD){ WildcardType t = (WildcardType)type; if (t.getExtendsBound() != null){ - key.addAll(getKey(t.getExtendsBound(), false)); + key.addAll(createKey(t.getExtendsBound(), useTypeArgs, false)); } if (t.getSuperBound() != null){ - key.addAll(getKey(t.getSuperBound(), false)); + key.addAll(createKey(t.getSuperBound(), useTypeArgs, false)); } - }else if (type.getKind() == TypeKind.DECLARED){ + + }else if (type.getKind() == TypeKind.DECLARED){ DeclaredType t = (DeclaredType)type; - for (TypeMirror arg : t.getTypeArguments()){ - key.addAll(deep ? getKey(arg, false) : Collections.singleton(arg.toString())); + if (useTypeArgs){ + for (TypeMirror arg : t.getTypeArguments()){ + if (deep){ + key.addAll(createKey(arg, useTypeArgs, false)); + }else{ + key.add(arg.toString()); + } + } + } + } + return key; + } + + private Set getSupertypes(TypeMirror type, Type value) { + type = normalize(type); + Set superTypes = Collections.emptySet(); + if (type.getKind() == TypeKind.DECLARED){ + DeclaredType declaredType = (DeclaredType)type; + TypeElement e = (TypeElement)declaredType.asElement(); + if (e.getKind() == ElementKind.CLASS){ + if (e.getSuperclass().getKind() != TypeKind.NONE){ + TypeMirror supertype = normalize(e.getSuperclass()); + Type superClass = create(supertype); + if (!superClass.getFullName().startsWith("java")){ + superTypes = Collections.singleton(createEntityType(supertype)); + } + } + }else{ + superTypes = new HashSet(e.getInterfaces().size()); + for (TypeMirror mirror : e.getInterfaces()){ + EntityType iface = createEntityType(mirror); + if (!iface.getFullName().startsWith("java")){ + superTypes.add(iface); + } + } + } + + }else{ + throw new IllegalArgumentException("Unsupported type kind " + type.getKind()); + } + return superTypes; + } + + private TypeMirror normalize(TypeMirror type) { + if (type.getKind() == TypeKind.TYPEVAR){ + TypeVariable typeVar = (TypeVariable)type; + if (typeVar.getUpperBound() != null){ + type = typeVar.getUpperBound(); + } + }else if (type.getKind() == TypeKind.WILDCARD){ + WildcardType wildcard = (WildcardType)type; + if (wildcard.getExtendsBound() != null){ + type = wildcard.getExtendsBound(); } } - return key; + return type; } @Nullable - private TypeModel handle(TypeMirror type) { + private Type handle(TypeMirror type) { if (type instanceof DeclaredType){ DeclaredType t = (DeclaredType)type; if (t.asElement() instanceof TypeElement){ @@ -324,9 +332,9 @@ public final class APTTypeModelFactory { TypeVariable t = (TypeVariable)type; String varName = t.toString(); if (t.getUpperBound() != null){ - return new TypeExtendsModel(varName, handle(t.getUpperBound())); + return new TypeExtends(varName, handle(t.getUpperBound())); }else if (t.getLowerBound() != null && !(t.getLowerBound() instanceof NullType)){ - return new TypeSuperModel(varName, handle(t.getLowerBound())); + return new TypeSuper(varName, handle(t.getLowerBound())); }else{ return null; } @@ -334,9 +342,9 @@ public final class APTTypeModelFactory { }else if (type instanceof WildcardType){ WildcardType t = (WildcardType)type; if (t.getExtendsBound() != null){ - return new TypeExtendsModel(handle(t.getExtendsBound())); + return new TypeExtends(handle(t.getExtendsBound())); }else if (t.getSuperBound() != null){ - return new TypeSuperModel(handle(t.getSuperBound())); + return new TypeSuper(handle(t.getSuperBound())); }else{ return null; } @@ -348,14 +356,14 @@ public final class APTTypeModelFactory { }else if (type instanceof PrimitiveType){ PrimitiveType t = (PrimitiveType)type; switch (t.getKind()) { - case BOOLEAN: return TypeModels.BOOLEAN; - case BYTE: return TypeModels.BYTE; - case CHAR: return TypeModels.CHAR; - case DOUBLE: return TypeModels.DOUBLE; - case FLOAT: return TypeModels.FLOAT; - case INT: return TypeModels.INT; - case LONG: return TypeModels.LONG; - case SHORT: return TypeModels.SHORT; + case BOOLEAN: return Types.BOOLEAN; + case BYTE: return Types.BYTE; + case CHAR: return Types.CHAR; + case DOUBLE: return Types.DOUBLE; + case FLOAT: return Types.FLOAT; + case INT: return Types.INT; + case LONG: return Types.LONG; + case SHORT: return Types.SHORT; } throw new IllegalArgumentException("Unsupported type " + t.getKind()); diff --git a/querydsl-apt/src/main/java/com/mysema/query/apt/Configuration.java b/querydsl-apt/src/main/java/com/mysema/query/apt/Configuration.java index 2eefcdf78..5bd7b4e0a 100644 --- a/querydsl-apt/src/main/java/com/mysema/query/apt/Configuration.java +++ b/querydsl-apt/src/main/java/com/mysema/query/apt/Configuration.java @@ -14,7 +14,7 @@ import javax.lang.model.element.ExecutableElement; import javax.lang.model.element.TypeElement; import javax.lang.model.element.VariableElement; -import com.mysema.query.codegen.EntityModel; +import com.mysema.query.codegen.EntityType; import com.mysema.query.codegen.Serializer; import com.mysema.query.codegen.SerializerConfig; import com.mysema.query.codegen.TypeMappings; @@ -74,7 +74,7 @@ public interface Configuration { * @param model * @return */ - SerializerConfig getSerializerConfig(EntityModel model); + SerializerConfig getSerializerConfig(EntityType model); /** * @return diff --git a/querydsl-apt/src/main/java/com/mysema/query/apt/DefaultConfiguration.java b/querydsl-apt/src/main/java/com/mysema/query/apt/DefaultConfiguration.java index bd38082c6..058b17c5e 100644 --- a/querydsl-apt/src/main/java/com/mysema/query/apt/DefaultConfiguration.java +++ b/querydsl-apt/src/main/java/com/mysema/query/apt/DefaultConfiguration.java @@ -25,7 +25,7 @@ import com.mysema.query.annotations.QueryType; import com.mysema.query.annotations.QuerydslConfig; import com.mysema.query.codegen.DTOSerializer; import com.mysema.query.codegen.EmbeddableSerializer; -import com.mysema.query.codegen.EntityModel; +import com.mysema.query.codegen.EntityType; import com.mysema.query.codegen.EntitySerializer; import com.mysema.query.codegen.Serializer; import com.mysema.query.codegen.SerializerConfig; @@ -134,7 +134,7 @@ public class DefaultConfiguration implements Configuration { } @Override - public SerializerConfig getSerializerConfig(EntityModel model) { + public SerializerConfig getSerializerConfig(EntityType model) { if (typeToConfig.containsKey(model.getFullName())){ return typeToConfig.get(model.getFullName()); }else if (packageToConfig.containsKey(model.getPackageName())){ diff --git a/querydsl-apt/src/main/java/com/mysema/query/apt/ElementHandler.java b/querydsl-apt/src/main/java/com/mysema/query/apt/ElementHandler.java index c970aee0e..b345017cc 100644 --- a/querydsl-apt/src/main/java/com/mysema/query/apt/ElementHandler.java +++ b/querydsl-apt/src/main/java/com/mysema/query/apt/ElementHandler.java @@ -26,13 +26,13 @@ import com.mysema.query.annotations.PropertyType; import com.mysema.query.annotations.QueryInit; import com.mysema.query.annotations.QueryMethod; import com.mysema.query.annotations.QueryType; -import com.mysema.query.codegen.ConstructorModel; -import com.mysema.query.codegen.EntityModel; -import com.mysema.query.codegen.MethodModel; -import com.mysema.query.codegen.ParameterModel; -import com.mysema.query.codegen.PropertyModel; +import com.mysema.query.codegen.Constructor; +import com.mysema.query.codegen.EntityType; +import com.mysema.query.codegen.Method; +import com.mysema.query.codegen.Parameter; +import com.mysema.query.codegen.Property; import com.mysema.query.codegen.TypeCategory; -import com.mysema.query.codegen.TypeModel; +import com.mysema.query.codegen.Type; /** * EntityElementVisitor is a an APT visitor for entity types @@ -45,15 +45,15 @@ public final class ElementHandler{ private final Configuration configuration; - private final APTTypeModelFactory typeFactory; + private final APTTypeFactory typeFactory; - public ElementHandler(Configuration configuration, APTTypeModelFactory typeFactory){ + public ElementHandler(Configuration configuration, APTTypeFactory typeFactory){ this.configuration = configuration; this.typeFactory = typeFactory; } - private TypeModel getType(VariableElement element){ - TypeModel rv = typeFactory.create(element.asType()); + private Type getType(VariableElement element){ + Type rv = typeFactory.create(element.asType()); if (element.getAnnotation(QueryType.class) != null){ QueryType qt = element.getAnnotation(QueryType.class); if (qt.value() != PropertyType.NONE){ @@ -64,22 +64,22 @@ public final class ElementHandler{ return rv; } - public void handleConstructors(EntityModel entityModel, List elements) { + public void handleConstructors(EntityType entityModel, List elements) { for (ExecutableElement constructor : ElementFilter.constructorsIn(elements)){ if (configuration.isValidConstructor(constructor)){ - List parameters = transformParams(constructor.getParameters()); - entityModel.addConstructor(new ConstructorModel(parameters)); + List parameters = transformParams(constructor.getParameters()); + entityModel.addConstructor(new Constructor(parameters)); } } } - public void handleFieldProperty(EntityModel entityModel, VariableElement field, - Map properties, + public void handleFieldProperty(EntityType entityModel, VariableElement field, + Map properties, Set blockedProperties, Map types) { String name = field.getSimpleName().toString(); try{ - TypeModel fieldType = typeFactory.create(field.asType()); + Type fieldType = typeFactory.create(field.asType()); if (field.getAnnotation(QueryType.class) != null){ TypeCategory typeCategory = TypeCategory.get(field.getAnnotation(QueryType.class).value()); if (typeCategory == null){ @@ -93,7 +93,7 @@ public final class ElementHandler{ if (field.getAnnotation(QueryInit.class) != null){ inits = field.getAnnotation(QueryInit.class).value(); } - properties.put(name, new PropertyModel(entityModel, name, fieldType, inits)); + properties.put(name, new Property(entityModel, name, fieldType, inits)); }catch(IllegalArgumentException ex){ StringBuilder builder = new StringBuilder(); builder.append("Caught exception for field "); @@ -102,12 +102,12 @@ public final class ElementHandler{ } } - public void handleMethodProperty(EntityModel entityModel, String propertyName, + public void handleMethodProperty(EntityType entityModel, String propertyName, ExecutableElement method, - Map properties, Set blockedProperties, + Map properties, Set blockedProperties, Map types) { try{ - TypeModel propertyType = typeFactory.create(method.getReturnType()); + Type propertyType = typeFactory.create(method.getReturnType()); if (method.getAnnotation(QueryType.class) != null){ TypeCategory typeCategory = TypeCategory.get(method.getAnnotation(QueryType.class).value()); if (typeCategory == null){ @@ -124,7 +124,7 @@ public final class ElementHandler{ if (method.getAnnotation(QueryInit.class) != null){ inits = method.getAnnotation(QueryInit.class).value(); } - properties.put(propertyName, new PropertyModel(entityModel, propertyName, propertyType, inits)); + properties.put(propertyName, new Property(entityModel, propertyName, propertyType, inits)); }catch(IllegalArgumentException ex){ StringBuilder builder = new StringBuilder(); @@ -134,21 +134,24 @@ public final class ElementHandler{ } } + public EntityType handleNormalType(TypeElement e) { + EntityType entityType = typeFactory.createEntityType(e.asType()); + return handleNormalType(entityType, e); + } - public EntityModel handleNormalType(TypeElement e) { - EntityModel entityModel = typeFactory.createEntityModel(e.asType()); - List elements = e.getEnclosedElements(); + public EntityType handleNormalType(EntityType entityType, TypeElement e) { + List elements = e.getEnclosedElements(); VisitorConfig config = configuration.getConfig(e, elements); Set blockedProperties = new HashSet(); - Map properties = new HashMap(); + Map properties = new HashMap(); Map types = new HashMap(); - Set queryMethods = new HashSet(); + Set queryMethods = new HashSet(); // constructors if (config.visitConstructors()){ - handleConstructors(entityModel, elements); + handleConstructors(entityType, elements); } // fields @@ -156,7 +159,7 @@ public final class ElementHandler{ for (VariableElement field : ElementFilter.fieldsIn(elements)){ String name = field.getSimpleName().toString(); if (configuration.isValidField(field)){ - handleFieldProperty(entityModel, field, properties, blockedProperties, types); + handleFieldProperty(entityType, field, properties, blockedProperties, types); }else if (configuration.isBlockedField(field)){ blockedProperties.add(name); } @@ -166,7 +169,7 @@ public final class ElementHandler{ // methods for (ExecutableElement method : ElementFilter.methodsIn(elements)){ if (method.getAnnotation(QueryMethod.class) != null){ - handleQueryMethod(entityModel, method, queryMethods); + handleQueryMethod(entityType, method, queryMethods); }else if (config.visitMethodProperties()){ String name = method.getSimpleName().toString(); @@ -179,7 +182,7 @@ public final class ElementHandler{ } if (configuration.isValidGetter(method)){ - handleMethodProperty(entityModel, name, method, properties, blockedProperties, types); + handleMethodProperty(entityType, name, method, properties, blockedProperties, types); }else if (configuration.isBlockedGetter(method)){ blockedProperties.add(name); } @@ -187,40 +190,40 @@ public final class ElementHandler{ } - for (MethodModel entry : queryMethods){ - entityModel.addMethod(entry); + for (Method entry : queryMethods){ + entityType.addMethod(entry); } - for (Map.Entry entry : properties.entrySet()){ + for (Map.Entry entry : properties.entrySet()){ if (!blockedProperties.contains(entry.getKey())){ - entityModel.addProperty(entry.getValue()); + entityType.addProperty(entry.getValue()); } } - return entityModel; + return entityType; } - public EntityModel handleProjectionType(TypeElement e) { - TypeModel c = typeFactory.create(e.asType()); - EntityModel entityModel = new EntityModel(configuration.getNamePrefix(), c.as(TypeCategory.ENTITY)); + public EntityType handleProjectionType(TypeElement e) { + Type c = typeFactory.create(e.asType()); + EntityType entityModel = new EntityType(configuration.getNamePrefix(), c.as(TypeCategory.ENTITY)); List elements = e.getEnclosedElements(); handleConstructors(entityModel, elements); return entityModel; } - public void handleQueryMethod(EntityModel entityModel, ExecutableElement method, Set queryMethods) { + public void handleQueryMethod(EntityType entityModel, ExecutableElement method, Set queryMethods) { String name = method.getSimpleName().toString(); QueryMethod queryMethod = method.getAnnotation(QueryMethod.class); - TypeModel returnType = typeFactory.create(method.getReturnType()); - MethodModel methodModel = new MethodModel(entityModel, name, queryMethod.value(), transformParams(method.getParameters()), returnType); + Type returnType = typeFactory.create(method.getReturnType()); + Method methodModel = new Method(entityModel, name, queryMethod.value(), transformParams(method.getParameters()), returnType); queryMethods.add(methodModel); } - private List transformParams(List params){ - List parameters = new ArrayList(params.size()); + private List transformParams(List params){ + List parameters = new ArrayList(params.size()); for (VariableElement param : params){ - TypeModel paramType = getType(param); - parameters.add(new ParameterModel(param.getSimpleName().toString(), paramType)); + Type paramType = getType(param); + parameters.add(new Parameter(param.getSimpleName().toString(), paramType)); } return parameters; } diff --git a/querydsl-apt/src/main/java/com/mysema/query/apt/Processor.java b/querydsl-apt/src/main/java/com/mysema/query/apt/Processor.java index ccd17b92e..9289e8fed 100644 --- a/querydsl-apt/src/main/java/com/mysema/query/apt/Processor.java +++ b/querydsl-apt/src/main/java/com/mysema/query/apt/Processor.java @@ -16,7 +16,6 @@ import java.util.Map; import java.util.Set; import java.util.Stack; -import javax.annotation.Nullable; import javax.annotation.processing.Messager; import javax.annotation.processing.ProcessingEnvironment; import javax.annotation.processing.RoundEnvironment; @@ -36,13 +35,12 @@ import com.mysema.query.annotations.QueryExtensions; import com.mysema.query.annotations.QueryMethod; import com.mysema.query.annotations.QueryProjection; import com.mysema.query.annotations.QuerydslVariables; -import com.mysema.query.codegen.EntityModel; -import com.mysema.query.codegen.EntityModelFactory; -import com.mysema.query.codegen.MethodModel; +import com.mysema.query.codegen.EntityType; +import com.mysema.query.codegen.Method; import com.mysema.query.codegen.Serializer; import com.mysema.query.codegen.SerializerConfig; +import com.mysema.query.codegen.TypeFactory; import com.mysema.query.codegen.TypeMappings; -import com.mysema.query.codegen.TypeModelFactory; import com.mysema.util.JavaWriter; /** @@ -53,29 +51,27 @@ import com.mysema.util.JavaWriter; */ public class Processor { - private final Map actualSupertypes = new HashMap(); + private final Map actualSupertypes = new HashMap(); - private final Map allSupertypes = new HashMap(); + private final Map allSupertypes = new HashMap(); private final Configuration configuration; - private final Map dtos = new HashMap(); + private final Map dtos = new HashMap(); - private final Map extensionTypes = new HashMap(); + private final Map extensionTypes = new HashMap(); - private final Map embeddables = new HashMap(); + private final Map embeddables = new HashMap(); - private final EntityModelFactory entityModelFactory; + private final Map entityTypes = new HashMap(); - private final Map entityTypes = new HashMap(); - - private final ElementHandler entityVisitor; + private final ElementHandler elementHandler; private final ProcessingEnvironment env; private final RoundEnvironment roundEnv; - private final APTTypeModelFactory typeFactory; + private final APTTypeFactory typeModelFactory; public Processor(ProcessingEnvironment env, RoundEnvironment roundEnv, Configuration configuration) { this.env = Assert.notNull(env); @@ -91,53 +87,21 @@ public class Processor { anns.add(configuration.getEmbeddableAnn()); } - TypeModelFactory factory = new TypeModelFactory(anns); - this.typeFactory = new APTTypeModelFactory(env, configuration, factory, anns); - if (configuration.getSkipAnn() != null){ - this.entityModelFactory = new EntityModelFactory(factory, configuration.getSkipAnn()); - }else{ - this.entityModelFactory = new EntityModelFactory(factory); - } - - this.entityVisitor = new ElementHandler(configuration, typeFactory); + TypeFactory factory = new TypeFactory(anns); + this.typeModelFactory = new APTTypeFactory(env, configuration, factory, anns); + this.elementHandler = new ElementHandler(configuration, typeModelFactory); } - private void addSupertypeFields(EntityModel model, Map superTypes) { - boolean singleSuperType = model.getSuperTypes().size() == 1; - for (String stype : model.getSuperTypes()) { - // iterate over supertypes - if (superTypes.containsKey(stype)) { - Stack stypeStack = new Stack(); - stypeStack.push(stype); - while (!stypeStack.isEmpty()) { - String top = stypeStack.pop(); - if (superTypes.containsKey(top)) { - EntityModel sdecl = superTypes.get(top); - if (singleSuperType && model.getSuperTypes().contains(top)) { - model.setSuperModel(sdecl); - } - model.include(sdecl); - for (String type : sdecl.getSuperTypes()) { - stypeStack.push(type); - } - } - } - } - } - - // create super class model via reflection - if (model.getSuperModel() == null && singleSuperType) { - String stype = model.getSuperTypes().iterator().next(); - Class superClass = safeClassForName(stype); - if (superClass != null && !superClass.equals(Object.class)) { - // handle the supertype only, if it has the proper annotations - if ((configuration.getSuperTypeAnn() == null - || superClass.getAnnotation(configuration.getSuperTypeAnn()) != null) - || superClass.getAnnotation(configuration.getEntityAnn()) != null) { - EntityModel type = entityModelFactory.create(superClass, configuration.getNamePrefix()); - // include fields of supertype - model.include(type); + private void addSupertypeFields(EntityType model, Map superTypes) { + Stack stypeStack = new Stack(); + for (EntityType stype : model.getSuperTypes()) { + stypeStack.push(stype); + while (!stypeStack.isEmpty()) { + EntityType sdecl = stypeStack.pop(); + model.include(sdecl); + for (EntityType type : sdecl.getSuperTypes()) { + stypeStack.push(type); } } } @@ -184,8 +148,8 @@ public class Processor { if (element instanceof PackageElement){ QuerydslVariables vars = element.getAnnotation(QuerydslVariables.class); PackageElement packageElement = (PackageElement)element; - List models = new ArrayList(); - for (EntityModel model : entityTypes.values()){ + List models = new ArrayList(); + for (EntityType model : entityTypes.values()){ if (model.getPackageName().equals(packageElement.getQualifiedName().toString())){ models.add(model); } @@ -213,15 +177,15 @@ public class Processor { private void handleExtensionType(TypeMirror type, Element element) { - EntityModel entityModel = typeFactory.createEntityModel(type); + EntityType entityModel = typeModelFactory.createEntityType(type); // handle methods - Set queryMethods = new HashSet(); + Set queryMethods = new HashSet(); for (ExecutableElement method : ElementFilter.methodsIn(element.getEnclosedElements())){ if (method.getAnnotation(QueryMethod.class) != null){ - entityVisitor.handleQueryMethod(entityModel, method, queryMethods); + elementHandler.handleQueryMethod(entityModel, method, queryMethods); } } - for (MethodModel method : queryMethods){ + for (Method method : queryMethods){ entityModel.addMethod(method); } extensionTypes.put(entityModel.getFullName(), entityModel); @@ -254,7 +218,7 @@ public class Processor { if (parent.getAnnotation(configuration.getEntityAnn()) == null && parent.getAnnotation(configuration.getEmbeddableAnn()) == null && !visitedDTOTypes.contains(parent)){ - EntityModel model = entityVisitor.handleProjectionType((TypeElement)parent); + EntityType model = elementHandler.handleProjectionType((TypeElement)parent); dtos.put(model.getFullName(), model); visitedDTOTypes.add(parent); @@ -264,30 +228,44 @@ public class Processor { private void processEmbeddables() { for (Element element : roundEnv.getElementsAnnotatedWith(configuration.getEmbeddableAnn())) { - EntityModel model = entityVisitor.handleNormalType((TypeElement) element); + EntityType model = elementHandler.handleNormalType((TypeElement) element); embeddables.put(model.getFullName(), model); } allSupertypes.putAll(embeddables); // add super type fields - for (EntityModel embeddable : embeddables.values()) { + for (EntityType embeddable : embeddables.values()) { addSupertypeFields(embeddable, allSupertypes); } } private void processEntities() { // populate entity type mappings - + Set superTypes = new HashSet(); + for (Element element : roundEnv.getElementsAnnotatedWith(configuration.getEntityAnn())) { if (configuration.getEmbeddableAnn() == null || element.getAnnotation(configuration.getEmbeddableAnn()) == null){ - EntityModel model = entityVisitor.handleNormalType((TypeElement) element); - entityTypes.put(model.getFullName(), model); + EntityType model = elementHandler.handleNormalType((TypeElement) element); + entityTypes.put(model.getFullName(), model); + if (model.getSuperType() != null){ + superTypes.add(model.getSuperType()); + } } } + + for (EntityType superType : superTypes){ + if (!allSupertypes.containsKey(superType.getFullName()) + && !entityTypes.containsKey(superType.getFullName())){ + TypeElement typeElement = env.getElementUtils().getTypeElement(superType.getFullName()); + elementHandler.handleNormalType(superType, typeElement); + entityTypes.put(superType.getFullName(), superType); + } + } + allSupertypes.putAll(entityTypes); // add super type fields - for (EntityModel entityType : entityTypes.values()) { + for (EntityType entityType : entityTypes.values()) { addSupertypeFields(entityType, allSupertypes); } } @@ -295,26 +273,17 @@ public class Processor { private void processSupertypes() { for (Element element : roundEnv.getElementsAnnotatedWith(configuration.getSuperTypeAnn())) { if (configuration.getEmbeddableAnn() == null || element.getAnnotation(configuration.getEmbeddableAnn()) == null){ - EntityModel model = entityVisitor.handleNormalType((TypeElement) element); + EntityType model = elementHandler.handleNormalType((TypeElement) element); actualSupertypes.put(model.getFullName(), model); } } // add supertype fields - for (EntityModel superType : actualSupertypes.values()) { + for (EntityType superType : actualSupertypes.values()) { addSupertypeFields(superType, actualSupertypes); } } - - @Nullable - private Class safeClassForName(String stype) { - try { - return Class.forName(stype); - } catch (ClassNotFoundException e) { - return null; - } - } - - private void serializeVariableList(String packageName, QuerydslVariables vars, List models){ + + private void serializeVariableList(String packageName, QuerydslVariables vars, List models){ String className = packageName + "." + vars.value(); TypeMappings typeMappings = configuration.getTypeMappings(); try{ @@ -329,7 +298,7 @@ public class Processor { }else{ writer.beginClass(vars.value(), null); } - for (EntityModel model : models){ + for (EntityType model : models){ String queryType = typeMappings.getPathType(model, model, true); String simpleName = model.getUncapSimpleName(); writer.publicStaticFinal(queryType, simpleName, "new " + queryType + "(\"" + simpleName + "\")"); @@ -345,9 +314,9 @@ public class Processor { } - private void serialize(Serializer serializer, Map models) { + private void serialize(Serializer serializer, Map models) { Messager msg = env.getMessager(); - for (EntityModel model : models.values()) { + for (EntityType model : models.values()) { msg.printMessage(Kind.NOTE, model.getFullName() + " is processed"); try { String packageName = model.getPackageName(); diff --git a/querydsl-apt/src/test/java/com/mysema/query/apt/QuerydslAnnotationProcessorTest.java b/querydsl-apt/src/test/java/com/mysema/query/apt/QuerydslAnnotationProcessorTest.java new file mode 100644 index 000000000..a4bbc93d8 --- /dev/null +++ b/querydsl-apt/src/test/java/com/mysema/query/apt/QuerydslAnnotationProcessorTest.java @@ -0,0 +1,69 @@ +package com.mysema.query.apt; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import javax.tools.JavaCompiler; +import javax.tools.ToolProvider; + +import junit.framework.Assert; + +import org.apache.commons.io.FileUtils; +import org.junit.Ignore; +import org.junit.Test; + +public class QuerydslAnnotationProcessorTest { + + private static final String packagePath = "src/test/java/com/mysema/query/domain/"; + + private void process(List classes) throws IOException{ + File out = new File("target/out"); + FileUtils.deleteDirectory(out); + if (!out.mkdirs()){ + Assert.fail("Creation of " + out.getPath() + " failed"); + } + + JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); + System.out.println(compiler.getClass().getName()); + List options = new ArrayList(classes.size() + 3); + options.add("-s"); + options.add("target/out"); + options.add("-proc:only"); + options.add("-processor"); + options.add(QuerydslAnnotationProcessor.class.getName()); + options.addAll(classes); + int compilationResult = compiler.run(null, null, null, options.toArray(new String[options.size()])); + if(compilationResult == 0){ + System.out.println("Compilation is successful"); + }else{ + Assert.fail("Compilation Failed"); + } + } + + @Test + @Ignore + public void processAll() throws IOException{ + // works only in Eclipse for the moment + List classes = new ArrayList(); + for (File file : new File(packagePath).listFiles()){ + if (file.getName().endsWith(".java")){ + classes.add(file.getPath()); + } + } + process(classes); + } + +// @Test +// public void inheritance2Test() { +// process(Collections.singletonList(packagePath + "Inheritance2Test.java")); +// } +// +// @Test +// @Ignore +// public void inheritanceTest() { +// process(Collections.singletonList(packagePath + "InheritanceTest.java")); +// } + +} diff --git a/querydsl-apt/src/test/java/com/mysema/query/domain/Inheritance2Test$Base.class b/querydsl-apt/src/test/java/com/mysema/query/domain/Inheritance2Test$Base.class new file mode 100644 index 0000000000000000000000000000000000000000..078e9ba8dbf93ff3d4e8f54c1b35f9df958bdff0 GIT binary patch literal 839 zcmb7CT}vB56g`uyS(BzF^`m~(ui`_xqAS5C69QHglwheYzE9$yBiUKHJ6p)l>VpVA z^au1uiD!aP5FZkjx%bZ8d(PfDcm6#;{RPm(RvASsSKwjA#}^-K0$xvM%E!9E)OSWr zf$EttDm@;^EK`}lez%{*VLZ%KEW=;9N{8W15=(8uGjpd>ZKdg}W~4H^JtAn4$#IgY ze5G%Vw0Wuo4kn~&2SJBaC3~l{?R|k@Y`jCYwb8aCu-h0P_U)Q#949wyw${}~UF303 zrIG9nc;dOc37og1!?77hdbFdc)oFFQ_wu(42h!YzKYI77Z`oz#D#_EnI@Rt63vboj za|nUu%iLHUt81NUc5-A)Vx`rI;b`8`ME=i*Ki#lSh_=I46(2EEMGYH1HmS=*GZm=6 zZC_w-A_~5SV#6ui7#HSk@vVA%wneTflxcwqy}$=X1yt*GcPYk#Uk!EIPuzWFuHb5e vod<~E5rsdanpxTsYrtCXm17S5dOA}jjd5@wf=ihJk*Mf^k_;!MWIj>HG1F1#cpXfnB53H`bZu`@ZbaZ zP~s#Cf_SJ5yED5p-~7LSyuJZwVxx#WswG%hw6Sbsg`r^jQg81w)Vo0xy5UHRkh}MZ zh)3>i6mqHDj_Qk88m4O967lhnYb~^mRnl}$c|aDAE&pKbz}uO-mhXH1wb%Bp5B>qo z;(6`vfIo0|$km;D-W!M@?Lp}(O5#AA$~67z?_9n1qU|PY^*ah#vRpH=?vxH`TxhqchB>+bbz&SLtC4)YZk2? zE0@#kQ;EpNB;7@NZ6QYllS5dOBtq^Z%?pKAR(h&j|28||?v1r>#Y2-@I%TNhnvHkfRLzK(C;K?Dyz zfDa{3gCK~9$g(rLGxN>=$LHHSfHt;m%wV+y18Wx6Eo?BD`c5Y90Yl?_6opIR)o?j+pIuiwiL z$Rc(BX-}DTgTU|k8DS_5qBI_fGdV4_`n#d6d;Z87)~`~fWhky?BB>`wN=2G$87V6K zkLmCqy>~gC*D0a(#CI?Y(}9Jeg)N4|ykm8LdfNIQh9N)Td#?4o5sV#LS%bEhRVvfM zrY|~F9Z{QpyC~2B<{HfxutxJ0h3CwuMARfBz$FKB#0yx&QpT6D@~y2BU!c1|VI0&j QZ`x#CL)l;?si9)9FO6I5c>n+a literal 0 HcmV?d00001 diff --git a/querydsl-apt/src/test/java/com/mysema/query/domain/Inheritance2Test$BaseSub.class b/querydsl-apt/src/test/java/com/mysema/query/domain/Inheritance2Test$BaseSub.class new file mode 100644 index 0000000000000000000000000000000000000000..24b48f63711e006f8914609cd6ece35b57d38659 GIT binary patch literal 696 zcmb7CUrPc(5dW=hUh0)*Y3W-A%Y(I0DY)v z?g)bD;bhpE*_rw6{Mq^Zdj9~>MLmZt9Ol7Mv2bMJm?3MHDr|HZnq$}Z9B&;;PdHDJ z4A#!V_k_~UNH1lejL@#^PGx9%gz77;%z&YNmL7IKW8g!7AsLEerR8np&1EnZ^A%Zg z6ZN2li2~C3l?X}LBdujHT!}E0A%hiLC()e2O`Wq5WBQwgQ;ObzddyG!C~)PCip#6~ z9m2(L}SZ-i04rh@;OsQC3eckzs`32oLr8{5d*u&`sH#?VRo z6-j@|Oxhbk7|znh^Ap+`PV2);rMSviBcf7?=je8d3=vRhwqC)Stv6&|lAt{CECm5| hdZ0iugCa_a+(-Gxdq8rRPMN$MRoI+S!YcMS`v&?y!Q%h` literal 0 HcmV?d00001 diff --git a/querydsl-apt/src/test/java/com/mysema/query/domain/Inheritance2Test$BaseSub2.class b/querydsl-apt/src/test/java/com/mysema/query/domain/Inheritance2Test$BaseSub2.class new file mode 100644 index 0000000000000000000000000000000000000000..e57ddda33fc1d173a6de5be2c7bfe63948207304 GIT binary patch literal 711 zcmb7C-Ae*N5dW=So*!45Wo0iB`Cv+2`Phk2QXoiB9=@--zqr z70uZfL=VcaGqXGMo1L$>_m@`y4QywS#CjG6N+vcYcb#_h#}ka zqhKg5WSng2Z%Ynu`2%MtUq?zyPxNIdsj5?@e9g7=6{Y@9fBCQ7zKT13PG~)KEG!{q z!9?0bnc;Ze!TeN8b6E((P@UJ`*rgRRXq#A}5T_YyM3gJ>4BhsSAOdo=`V&~K{*1)q p%qdGeMNYsD1;~+1AdkXKuA=y5T_d?nr%2W$HeeYvb&@Lv`v9U)#nk`+ literal 0 HcmV?d00001 diff --git a/querydsl-apt/src/test/java/com/mysema/query/domain/Inheritance2Test$IFace.class b/querydsl-apt/src/test/java/com/mysema/query/domain/Inheritance2Test$IFace.class new file mode 100644 index 0000000000000000000000000000000000000000..b188d25134cab4cf2ecac0494cbad9396dc48bd7 GIT binary patch literal 228 zcmX^0Z`VEs1_mPrZgvJXb_PyH2Cm@z(xT*4x6GVWMg~#Oyo}VM%#y^sae2;?&$k{le1JqDuXg{M^LMJbiR6DxPkM$w0GMp)`+YUS4XE zb53G$acVImg8;}x{hY+SbbbG%tkmQZMg|RHjb>wHU}Rtdx*r6X7?{B%3j+s`<^sw9 K?POqQ;{*WclRd)# literal 0 HcmV?d00001 diff --git a/querydsl-apt/src/test/java/com/mysema/query/domain/Inheritance2Test.class b/querydsl-apt/src/test/java/com/mysema/query/domain/Inheritance2Test.class new file mode 100644 index 0000000000000000000000000000000000000000..2156c9f8d2249af8a6676cf82b1f705cddd852c5 GIT binary patch literal 784 zcmb7CT}vB56g_v{WK5b?+Zt`E{YdRYTBu|5S`joL1f+tB?~`?~6SA|o9|eC_p9+2G z5Aa7x&nzi|Pi7zPxgY1;J9Bq#@BaJ+FvNBnOL(oYsj#K+M$i}^nZyb@WAAM~nwg@o zg~D6G@}Vj0@T{6ByqiZ1h6?WmD%9#ypDk*l!UsVdTtRcsc~|ZWmIj|Lm>p%8%&r_e zZ@*XR#OCK_GGit#ZBYt(r(MVu34dS?8U zKAB8y!ei|`R{e3l!>^AP{9mnLF-`aZg58DYP_xKg>Z1w1EHndsM0{A`iy&e7v@aR; zi9&3A{tfv>N3cfQCJpEy#(c-2idiqL4b Zpoq({phavGpAb95r^IK(72;|v{{WV+#&7@t literal 0 HcmV?d00001 diff --git a/querydsl-apt/src/test/java/com/mysema/query/domain/Inheritance2Test.java b/querydsl-apt/src/test/java/com/mysema/query/domain/Inheritance2Test.java index 68ff8fd20..89d7407c8 100644 --- a/querydsl-apt/src/test/java/com/mysema/query/domain/Inheritance2Test.java +++ b/querydsl-apt/src/test/java/com/mysema/query/domain/Inheritance2Test.java @@ -16,12 +16,12 @@ public class Inheritance2Test { Base2 base; Base2 base2; } - + @QueryEntity public abstract class Base2,U extends IFace>{ } - + @QueryEntity public abstract class BaseSub extends Base{ diff --git a/querydsl-apt/src/test/java/com/mysema/query/domain/InheritanceTest.java b/querydsl-apt/src/test/java/com/mysema/query/domain/InheritanceTest.java index 385cfe522..1429ae3ce 100644 --- a/querydsl-apt/src/test/java/com/mysema/query/domain/InheritanceTest.java +++ b/querydsl-apt/src/test/java/com/mysema/query/domain/InheritanceTest.java @@ -65,6 +65,7 @@ public class InheritanceTest { } + @QueryEntity public abstract class Storable extends Merchandise{ } diff --git a/querydsl-apt/src/test/java/com/mysema/query/domain/Superclass3Test.java b/querydsl-apt/src/test/java/com/mysema/query/domain/Superclass3Test.java new file mode 100644 index 000000000..8067f57a0 --- /dev/null +++ b/querydsl-apt/src/test/java/com/mysema/query/domain/Superclass3Test.java @@ -0,0 +1,22 @@ +package com.mysema.query.domain; + +import org.junit.Assert; +import org.junit.Test; + +import com.mysema.query.DefaultQueryMetadata; +import com.mysema.query.annotations.QueryEntity; + +public class Superclass3Test { + + @QueryEntity + public static class Subtype extends DefaultQueryMetadata{ + + private static final long serialVersionUID = -218949941713252847L; + + } + + @Test + public void test(){ + Assert.assertNotNull(QSuperclass3Test_Subtype.subtype.distinct); + } +} diff --git a/querydsl-core/src/main/java/com/mysema/query/SimpleProjectable.java b/querydsl-core/src/main/java/com/mysema/query/SimpleProjectable.java new file mode 100644 index 000000000..976d792ee --- /dev/null +++ b/querydsl-core/src/main/java/com/mysema/query/SimpleProjectable.java @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2009 Mysema Ltd. + * All rights reserved. + * + */ +package com.mysema.query; + +import java.util.List; + +/** + * @author tiwe + * + */ +public interface SimpleProjectable { + + List list(); + + List listDistinct(); + + T uniqueResult(); + + SearchResults listResults(); + + SearchResults listDistinctResults(); + + long count(); + + long countDistinct(); + +} diff --git a/querydsl-core/src/main/java/com/mysema/query/SimpleQuery.java b/querydsl-core/src/main/java/com/mysema/query/SimpleQuery.java new file mode 100644 index 000000000..b7f5659b8 --- /dev/null +++ b/querydsl-core/src/main/java/com/mysema/query/SimpleQuery.java @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2009 Mysema Ltd. + * All rights reserved. + * + */ +package com.mysema.query; + +import com.mysema.query.types.expr.EBoolean; + +/** + * @author tiwe + * + * @param + */ +public interface SimpleQuery> { + + Q where(EBoolean... e); + + Q limit(long limit); + + Q offset(long offset); + + Q restrict(QueryModifiers modifiers); + +} diff --git a/querydsl-core/src/main/java/com/mysema/query/codegen/AbstractTypeModel.java b/querydsl-core/src/main/java/com/mysema/query/codegen/AbstractType.java similarity index 71% rename from querydsl-core/src/main/java/com/mysema/query/codegen/AbstractTypeModel.java rename to querydsl-core/src/main/java/com/mysema/query/codegen/AbstractType.java index a04d473fc..15d6c6cd9 100644 --- a/querydsl-core/src/main/java/com/mysema/query/codegen/AbstractTypeModel.java +++ b/querydsl-core/src/main/java/com/mysema/query/codegen/AbstractType.java @@ -8,15 +8,15 @@ package com.mysema.query.codegen; import java.io.IOException; /** - * AbstractTypeModel is an abstract base class for TypeModel implementations + * AbstractType is an abstract base class for Type implementations * * @author tiwe * */ -public abstract class AbstractTypeModel implements TypeModel{ +public abstract class AbstractType implements Type{ @Override - public String getLocalGenericName(TypeModel context, boolean asArgType){ + public String getLocalGenericName(Type context, boolean asArgType){ try { StringBuilder builder = new StringBuilder(); appendLocalGenericName(context, builder, asArgType); @@ -27,7 +27,7 @@ public abstract class AbstractTypeModel implements TypeModel{ } @Override - public String getLocalRawName(TypeModel context){ + public String getLocalRawName(Type context){ try { StringBuilder builder = new StringBuilder(); appendLocalRawName(context, builder); diff --git a/querydsl-core/src/main/java/com/mysema/query/codegen/ClassTypeModel.java b/querydsl-core/src/main/java/com/mysema/query/codegen/ClassType.java similarity index 74% rename from querydsl-core/src/main/java/com/mysema/query/codegen/ClassTypeModel.java rename to querydsl-core/src/main/java/com/mysema/query/codegen/ClassType.java index 86ae27ffd..181af6567 100644 --- a/querydsl-core/src/main/java/com/mysema/query/codegen/ClassTypeModel.java +++ b/querydsl-core/src/main/java/com/mysema/query/codegen/ClassType.java @@ -20,17 +20,17 @@ import org.apache.commons.lang.ClassUtils; import com.mysema.commons.lang.Assert; /** - * ClassTypeModel is a minimal implementation of the TypeModel interface + * ClassType is a minimal implementation of the Type interface * * @author tiwe * */ @Immutable -public final class ClassTypeModel extends AbstractTypeModel{ +public final class ClassType extends AbstractType{ private final Class clazz; - private final List parameters; + private final List parameters; @Nullable private final Class primitiveClass; @@ -38,12 +38,12 @@ public final class ClassTypeModel extends AbstractTypeModel{ private final TypeCategory typeCategory; private final boolean visible; - - public ClassTypeModel(TypeCategory typeCategory, Class clazz, TypeModel... params){ + + public ClassType(TypeCategory typeCategory, Class clazz, Type... params){ this(typeCategory, clazz, ClassUtils.wrapperToPrimitive(clazz), params); } - - public ClassTypeModel(TypeCategory typeCategory, Class clazz, @Nullable Class primitiveClass, TypeModel... params){ + + public ClassType(TypeCategory typeCategory, Class clazz, @Nullable Class primitiveClass, Type... params){ this.typeCategory = Assert.notNull(typeCategory); this.clazz = Assert.notNull(clazz); this.primitiveClass = primitiveClass; @@ -56,23 +56,23 @@ public final class ClassTypeModel extends AbstractTypeModel{ } @Override - public TypeModel asArrayType() { - return new ClassTypeModel(TypeCategory.ARRAY, Array.newInstance(clazz, 0).getClass(), this); + public Type asArrayType() { + return new ClassType(TypeCategory.ARRAY, Array.newInstance(clazz, 0).getClass(), this); } @Override - public TypeModel as(TypeCategory category) { + public Type as(TypeCategory category) { if (typeCategory == category){ return this; }else{ - return new ClassTypeModel(category, clazz); + return new ClassType(category, clazz); } } @Override public boolean equals(Object o){ - if (o instanceof TypeModel){ - TypeModel t = (TypeModel)o; + if (o instanceof Type){ + Type t = (Type)o; return clazz.getName().equals(t.getFullName()); }else{ return false; @@ -90,12 +90,12 @@ public final class ClassTypeModel extends AbstractTypeModel{ } @Override - public void appendLocalGenericName(TypeModel context, Appendable builder, boolean asArgType) throws IOException { + public void appendLocalGenericName(Type context, Appendable builder, boolean asArgType) throws IOException { appendLocalRawName(context, builder); } @Override - public void appendLocalRawName(TypeModel context, Appendable builder) throws IOException { + public void appendLocalRawName(Type context, Appendable builder) throws IOException { String packageName; String name; if (clazz.isArray()){ @@ -122,7 +122,7 @@ public final class ClassTypeModel extends AbstractTypeModel{ } @Override - public TypeModel getParameter(int i) { + public Type getParameter(int i) { return parameters.get(i); } @@ -137,7 +137,7 @@ public final class ClassTypeModel extends AbstractTypeModel{ } @Override - public TypeModel getSelfOrValueType() { + public Type getSelfOrValueType() { if (typeCategory.isSubCategoryOf(TypeCategory.COLLECTION) || typeCategory.isSubCategoryOf(TypeCategory.MAP)){ return parameters.get(parameters.size()-1); diff --git a/querydsl-core/src/main/java/com/mysema/query/codegen/ConstructorModel.java b/querydsl-core/src/main/java/com/mysema/query/codegen/Constructor.java similarity index 58% rename from querydsl-core/src/main/java/com/mysema/query/codegen/ConstructorModel.java rename to querydsl-core/src/main/java/com/mysema/query/codegen/Constructor.java index fa3787e6c..6c8de07a0 100644 --- a/querydsl-core/src/main/java/com/mysema/query/codegen/ConstructorModel.java +++ b/querydsl-core/src/main/java/com/mysema/query/codegen/Constructor.java @@ -12,17 +12,17 @@ import net.jcip.annotations.Immutable; import com.mysema.commons.lang.Assert; /** - * ConstructorModel represents a constructor for a DTO query type. + * Constructor represents a constructor for a DTO query type. * * @author tiwe * @version $Id$ */ @Immutable -public final class ConstructorModel { +public final class Constructor { - private final Collection parameters; + private final Collection parameters; - public ConstructorModel(Collection params) { + public Constructor(Collection params) { parameters = Assert.notNull(params,"params was null"); } @@ -30,14 +30,14 @@ public final class ConstructorModel { public boolean equals(Object o){ if (o == this){ return true; - }else if (o instanceof ConstructorModel){ - return ((ConstructorModel)o).parameters.equals(parameters); + }else if (o instanceof Constructor){ + return ((Constructor)o).parameters.equals(parameters); }else{ return false; } } - public Collection getParameters() { + public Collection getParameters() { return parameters; } diff --git a/querydsl-core/src/main/java/com/mysema/query/codegen/DTOSerializer.java b/querydsl-core/src/main/java/com/mysema/query/codegen/DTOSerializer.java index 331d7d086..215adbe4c 100644 --- a/querydsl-core/src/main/java/com/mysema/query/codegen/DTOSerializer.java +++ b/querydsl-core/src/main/java/com/mysema/query/codegen/DTOSerializer.java @@ -25,12 +25,12 @@ import com.mysema.util.CodeWriter; public final class DTOSerializer implements Serializer{ private final TypeMappings typeMappings; - + public DTOSerializer(TypeMappings typeMappings){ this.typeMappings = Assert.notNull(typeMappings); } - protected void intro(EntityModel model, CodeWriter writer) throws IOException { + protected void intro(EntityType model, CodeWriter writer) throws IOException { String simpleName = model.getSimpleName(); String queryType = typeMappings.getPathType(model, model, false); String localName = model.getLocalRawName(); @@ -50,22 +50,22 @@ public final class DTOSerializer implements Serializer{ writer.beginClass(queryType, "EConstructor<" + localName + ">"); } - protected void outro(EntityModel model, CodeWriter writer) throws IOException { + protected void outro(EntityType model, CodeWriter writer) throws IOException { writer.end(); } @Override - public void serialize(final EntityModel model, SerializerConfig serializerConfig, CodeWriter writer) throws IOException{ + public void serialize(final EntityType model, SerializerConfig serializerConfig, CodeWriter writer) throws IOException{ // intro intro(model, writer); final String localName = model.getLocalRawName(); - for (ConstructorModel c : model.getConstructors()){ + for (Constructor c : model.getConstructors()){ // begin - writer.beginConstructor(c.getParameters(), new Transformer(){ + writer.beginConstructor(c.getParameters(), new Transformer(){ @Override - public String transform(ParameterModel p) { + public String transform(Parameter p) { return typeMappings.getExprType(p.getType(), model, false, false, true) + " " + p.getName(); } }); @@ -74,7 +74,7 @@ public final class DTOSerializer implements Serializer{ writer.beginLine("super(" + localName + ".class"); writer.append(", new Class[]{"); boolean first = true; - for (ParameterModel p : c.getParameters()){ + for (Parameter p : c.getParameters()){ if (!first){ writer.append(", "); } @@ -88,7 +88,7 @@ public final class DTOSerializer implements Serializer{ } writer.append("}"); - for (ParameterModel p : c.getParameters()){ + for (Parameter p : c.getParameters()){ writer.append(", " + p.getName()); } diff --git a/querydsl-core/src/main/java/com/mysema/query/codegen/EmbeddableSerializer.java b/querydsl-core/src/main/java/com/mysema/query/codegen/EmbeddableSerializer.java index 812d2d714..dce99f6b3 100644 --- a/querydsl-core/src/main/java/com/mysema/query/codegen/EmbeddableSerializer.java +++ b/querydsl-core/src/main/java/com/mysema/query/codegen/EmbeddableSerializer.java @@ -20,28 +20,28 @@ import com.mysema.util.CodeWriter; * */ public final class EmbeddableSerializer extends EntitySerializer{ - + public EmbeddableSerializer(TypeMappings typeMappings) { super(typeMappings); } @Override - protected void constructorsForVariables(CodeWriter writer, EntityModel model) { + protected void constructorsForVariables(CodeWriter writer, EntityType model) { // no root constructors } @Override - protected void introDefaultInstance(CodeWriter writer, EntityModel model) { + protected void introDefaultInstance(CodeWriter writer, EntityType model) { // no default instance } @Override - protected void introFactoryMethods(CodeWriter writer, EntityModel model) throws IOException { + protected void introFactoryMethods(CodeWriter writer, EntityType model) throws IOException { // no factory methods } @Override - protected void introImports(CodeWriter writer, SerializerConfig config, EntityModel model) throws IOException { + protected void introImports(CodeWriter writer, SerializerConfig config, EntityType model) throws IOException { writer.imports(Path.class.getPackage()); if ((model.hasLists() && config.useListAccessors()) || !model.getMethods().isEmpty() diff --git a/querydsl-core/src/main/java/com/mysema/query/codegen/EntityModelFactory.java b/querydsl-core/src/main/java/com/mysema/query/codegen/EntityModelFactory.java deleted file mode 100644 index ce0227f04..000000000 --- a/querydsl-core/src/main/java/com/mysema/query/codegen/EntityModelFactory.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright (c) 2009 Mysema Ltd. - * All rights reserved. - * - */ -package com.mysema.query.codegen; - -import java.lang.annotation.Annotation; -import java.lang.reflect.Field; -import java.lang.reflect.Modifier; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; - -import net.jcip.annotations.Immutable; - -import com.mysema.query.annotations.QueryInit; -import com.mysema.query.annotations.QueryTransient; -import com.mysema.query.annotations.QueryType; - -/** - * A Reflection based Factory implementation for EntityModel instances - * - * @author tiwe - * - */ -@Immutable -public class EntityModelFactory { - - private final Class skipAnn; - - private final TypeModelFactory typeModelFactory; - - public EntityModelFactory(TypeModelFactory typeModelFactory){ - this(typeModelFactory, QueryTransient.class); - } - - public EntityModelFactory(TypeModelFactory typeModelFactory, Class skipAnn){ - this.typeModelFactory = typeModelFactory; - this.skipAnn = skipAnn; - } - - public EntityModel create(Class key, String prefix){ - Collection superTypes; - if (key.isInterface()){ - superTypes = new ArrayList(); - for (Class iface : key.getInterfaces()){ - if (!iface.getName().startsWith("java")){ - superTypes.add(iface.getName()); - } - } - }else{ - superTypes = Collections.singleton(key.getSuperclass().getName()); - } - EntityModel entityModel = new EntityModel(prefix, - new ClassTypeModel(TypeCategory.ENTITY, key), - superTypes); - for (Field f : key.getDeclaredFields()) { - if (isValidField(f)){ - TypeModel typeModel = typeModelFactory.create(f.getType(), f.getGenericType()); - if (f.getAnnotation(QueryType.class) != null){ - TypeCategory typeCategory = TypeCategory.get(f.getAnnotation(QueryType.class).value()); - if (typeCategory == null){ - continue; - } - typeModel = typeModel.as(typeCategory); - } - String[] inits = new String[0]; - if (f.getAnnotation(QueryInit.class) != null){ - inits = f.getAnnotation(QueryInit.class).value(); - } - entityModel.addProperty(new PropertyModel(entityModel, f.getName(), typeModel, inits)); - } - } - return entityModel; - } - - protected boolean isValidField(Field field) { - return field.getAnnotation(skipAnn) == null - && !Modifier.isTransient(field.getModifiers()) - && !Modifier.isStatic(field.getModifiers()); - } - -} diff --git a/querydsl-core/src/main/java/com/mysema/query/codegen/EntitySerializer.java b/querydsl-core/src/main/java/com/mysema/query/codegen/EntitySerializer.java index fc1c04562..21ab13574 100644 --- a/querydsl-core/src/main/java/com/mysema/query/codegen/EntitySerializer.java +++ b/querydsl-core/src/main/java/com/mysema/query/codegen/EntitySerializer.java @@ -42,12 +42,12 @@ public class EntitySerializer implements Serializer{ private static final String PATH_METADATA = "PathMetadata metadata"; private final TypeMappings typeMappings; - + public EntitySerializer(TypeMappings mappings){ this.typeMappings = Assert.notNull(mappings); } - protected void constructors(EntityModel model, SerializerConfig config, CodeWriter writer) throws IOException { + protected void constructors(EntityType model, SerializerConfig config, CodeWriter writer) throws IOException { String localName = model.getLocalRawName(); String genericName = model.getLocalGenericName(); @@ -99,7 +99,7 @@ public class EntitySerializer implements Serializer{ } - protected void constructorsForVariables(CodeWriter writer, EntityModel model) throws IOException { + protected void constructorsForVariables(CodeWriter writer, EntityType model) throws IOException { String localName = model.getLocalRawName(); String genericName = model.getLocalGenericName(); @@ -115,7 +115,7 @@ public class EntitySerializer implements Serializer{ writer.end(); } - protected void entityAccessor(PropertyModel field, CodeWriter writer) throws IOException { + protected void entityAccessor(Property field, CodeWriter writer) throws IOException { String queryType = typeMappings.getPathType(field.getType(), field.getContext(), false); writer.beginMethod(queryType, field.getEscapedName()); writer.line("if (", field.getEscapedName(), " == null){"); @@ -126,7 +126,7 @@ public class EntitySerializer implements Serializer{ } - protected void entityField(PropertyModel field, SerializerConfig config, CodeWriter writer) throws IOException { + protected void entityField(Property field, SerializerConfig config, CodeWriter writer) throws IOException { String queryType = typeMappings.getPathType(field.getType(), field.getContext(), false); if (field.isInherited()){ writer.line("// inherited"); @@ -139,9 +139,9 @@ public class EntitySerializer implements Serializer{ } - protected boolean hasOwnEntityProperties(EntityModel model){ + protected boolean hasOwnEntityProperties(EntityType model){ if (model.hasEntityFields()){ - for (PropertyModel property : model.getProperties()){ + for (Property property : model.getProperties()){ if (!property.isInherited() && property.getType().getCategory() == TypeCategory.ENTITY){ return true; } @@ -150,14 +150,14 @@ public class EntitySerializer implements Serializer{ return false; } - protected void initEntityFields(CodeWriter writer, SerializerConfig config, EntityModel model) throws IOException { - EntityModel superModel = model.getSuperModel(); - if (superModel != null && superModel.hasEntityFields()){ - String superQueryType = typeMappings.getPathType(superModel, model, false); + protected void initEntityFields(CodeWriter writer, SerializerConfig config, EntityType model) throws IOException { + EntityType superType = model.getSuperType(); + if (superType != null && superType.hasEntityFields()){ + String superQueryType = typeMappings.getPathType(superType, model, false); writer.line("this._super = new " + superQueryType + "(type, metadata, inits);"); } - for (PropertyModel field : model.getProperties()){ + for (Property field : model.getProperties()){ if (field.getType().getCategory() == TypeCategory.ENTITY){ String queryType = typeMappings.getPathType(field.getType(), model, false); if (!field.isInherited()){ @@ -170,13 +170,13 @@ public class EntitySerializer implements Serializer{ writer.line("this.", field.getEscapedName(), ASSIGN, "_super.", field.getEscapedName(), SEMICOLON); } - }else if (field.isInherited() && superModel != null && superModel.hasEntityFields()){ + }else if (field.isInherited() && superType != null && superType.hasEntityFields()){ writer.line("this.", field.getEscapedName(), " = _super.", field.getEscapedName(), SEMICOLON); } } } - protected void intro(EntityModel model, SerializerConfig config, CodeWriter writer) throws IOException { + protected void intro(EntityType model, SerializerConfig config, CodeWriter writer) throws IOException { introPackage(writer, model); introImports(writer, config, model); writer.nl(); @@ -189,13 +189,13 @@ public class EntitySerializer implements Serializer{ if (config.createDefaultVariable()){ introDefaultInstance(writer, model); } - if (model.getSuperModel() != null){ + if (model.getSuperType() != null){ introSuper(writer, model); } } @SuppressWarnings(UNCHECKED) - protected void introClassHeader(CodeWriter writer, EntityModel model) throws IOException { + protected void introClassHeader(CodeWriter writer, EntityType model) throws IOException { String queryType = typeMappings.getPathType(model, model, true); String localName = model.getLocalGenericName(); @@ -216,25 +216,25 @@ public class EntitySerializer implements Serializer{ writer.beginClass(queryType, pathType.getSimpleName() + "<" + localName + ">"); } - protected void introDefaultInstance(CodeWriter writer, EntityModel model) throws IOException { + protected void introDefaultInstance(CodeWriter writer, EntityType model) throws IOException { String simpleName = model.getUncapSimpleName(); String queryType = typeMappings.getPathType(model, model, true); writer.publicStaticFinal(queryType, simpleName, NEW + queryType + "(\"" + simpleName + "\")"); } - protected void introFactoryMethods(CodeWriter writer, final EntityModel model) throws IOException { + protected void introFactoryMethods(CodeWriter writer, final EntityType model) throws IOException { String localName = model.getLocalRawName(); String genericName = model.getLocalGenericName(); - for (ConstructorModel c : model.getConstructors()){ + for (Constructor c : model.getConstructors()){ // begin if (!localName.equals(genericName)){ writer.suppressWarnings(UNCHECKED); } - writer.beginStaticMethod("EConstructor<" + genericName + ">", "create", c.getParameters(), new Transformer(){ + writer.beginStaticMethod("EConstructor<" + genericName + ">", "create", c.getParameters(), new Transformer(){ @Override - public String transform(ParameterModel p) { + public String transform(Parameter p) { return typeMappings.getExprType(p.getType(), model, false, false, true) + SPACE + p.getName(); } }); @@ -247,7 +247,7 @@ public class EntitySerializer implements Serializer{ writer.append(localName + DOT_CLASS); writer.append(", new Class[]{"); boolean first = true; - for (ParameterModel p : c.getParameters()){ + for (Parameter p : c.getParameters()){ if (!first){ writer.append(COMMA); } @@ -261,7 +261,7 @@ public class EntitySerializer implements Serializer{ } writer.append("}"); - for (ParameterModel p : c.getParameters()){ + for (Parameter p : c.getParameters()){ writer.append(COMMA + p.getName()); } @@ -271,7 +271,7 @@ public class EntitySerializer implements Serializer{ } } - protected void introImports(CodeWriter writer, SerializerConfig config, EntityModel model) throws IOException { + protected void introImports(CodeWriter writer, SerializerConfig config, EntityType model) throws IOException { writer.imports(Path.class.getPackage()); writer.staticimports(PathMetadataFactory.class); @@ -287,10 +287,10 @@ public class EntitySerializer implements Serializer{ } } - protected void introInits(CodeWriter writer, EntityModel model) throws IOException { + protected void introInits(CodeWriter writer, EntityType model) throws IOException { if (model.hasEntityFields()){ List inits = new ArrayList(); - for (PropertyModel property : model.getProperties()){ + for (Property property : model.getProperties()){ if (property.getType().getCategory() == TypeCategory.ENTITY){ for (String init : property.getInits()){ inits.add(property.getEscapedName() + DOT + init); @@ -307,29 +307,29 @@ public class EntitySerializer implements Serializer{ } } - protected void introJavadoc(CodeWriter writer, EntityModel model) throws IOException { + protected void introJavadoc(CodeWriter writer, EntityType model) throws IOException { String simpleName = model.getSimpleName(); String queryType = model.getPrefix() + simpleName; writer.javadoc(queryType + " is a Querydsl query type for " + simpleName); } - protected void introPackage(CodeWriter writer, EntityModel model) throws IOException { + protected void introPackage(CodeWriter writer, EntityType model) throws IOException { writer.packageDecl(model.getPackageName()); writer.nl(); } - protected void introSuper(CodeWriter writer, EntityModel model) throws IOException { - EntityModel superModel = model.getSuperModel(); - String superQueryType = typeMappings.getPathType(superModel, model, false); + protected void introSuper(CodeWriter writer, EntityType model) throws IOException { + EntityType superType = model.getSuperType(); + String superQueryType = typeMappings.getPathType(superType, model, false); - if (!superModel.hasEntityFields()){ + if (!superType.hasEntityFields()){ writer.publicFinal(superQueryType, "_super", NEW + superQueryType + "(this)"); }else{ writer.publicFinal(superQueryType, "_super"); } } - protected void listAccessor(PropertyModel field, CodeWriter writer) throws IOException { + protected void listAccessor(Property field, CodeWriter writer) throws IOException { String escapedName = field.getEscapedName(); String queryType = typeMappings.getPathType(field.getParameter(0), field.getContext(), false); @@ -340,7 +340,7 @@ public class EntitySerializer implements Serializer{ writer.line(RETURN + escapedName +".get(index);").end(); } - protected void mapAccessor(PropertyModel field, CodeWriter writer) throws IOException { + protected void mapAccessor(Property field, CodeWriter writer) throws IOException { String escapedName = field.getEscapedName(); String queryType = typeMappings.getPathType(field.getParameter(1), field.getContext(), false); String keyType = field.getParameter(0).getLocalGenericName(field.getContext(), false); @@ -353,12 +353,12 @@ public class EntitySerializer implements Serializer{ writer.line(RETURN + escapedName + ".get(key);").end(); } - protected void method(final EntityModel model, MethodModel method, SerializerConfig config, CodeWriter writer) throws IOException { + protected void method(final EntityType model, Method method, SerializerConfig config, CodeWriter writer) throws IOException { // header String type = typeMappings.getExprType(method.getReturnType(), model, false, true, false); - writer.beginMethod(type, method.getName(), method.getParameters(), new Transformer(){ + writer.beginMethod(type, method.getName(), method.getParameters(), new Transformer(){ @Override - public String transform(ParameterModel p) { + public String transform(Parameter p) { return typeMappings.getExprType(p.getType(), model, false, false, true) + SPACE + p.getName(); } }); @@ -373,7 +373,7 @@ public class EntitySerializer implements Serializer{ } writer.append(QUOTE + StringEscapeUtils.escapeJava(method.getTemplate()) + QUOTE); writer.append(", this"); - for (ParameterModel p : method.getParameters()){ + for (Parameter p : method.getParameters()){ writer.append(COMMA + p.getName()); } writer.append(");\n"); @@ -382,11 +382,11 @@ public class EntitySerializer implements Serializer{ writer.end(); } - protected void outro(EntityModel model, CodeWriter writer) throws IOException { + protected void outro(EntityType model, CodeWriter writer) throws IOException { writer.end(); } - public void serialize(EntityModel model, SerializerConfig config, CodeWriter writer) throws IOException{ + public void serialize(EntityType model, SerializerConfig config, CodeWriter writer) throws IOException{ intro(model, config, writer); // properties @@ -396,12 +396,12 @@ public class EntitySerializer implements Serializer{ constructors(model, config, writer); // methods - for (MethodModel method : model.getMethods()){ + for (Method method : model.getMethods()){ method(model, method, config, writer); } // property accessors - for (PropertyModel property : model.getProperties()){ + for (Property property : model.getProperties()){ TypeCategory category = property.getType().getCategory(); if (category == TypeCategory.MAP && config.useMapAccessors()){ mapAccessor(property, writer); @@ -414,12 +414,12 @@ public class EntitySerializer implements Serializer{ outro(model, writer); } - protected void serialize(PropertyModel field, String type, CodeWriter writer, String factoryMethod, String... args) throws IOException{ - EntityModel superModel = field.getContext().getSuperModel(); + protected void serialize(Property field, String type, CodeWriter writer, String factoryMethod, String... args) throws IOException{ + EntityType superType = field.getContext().getSuperType(); // construct value StringBuilder value = new StringBuilder(); - if (field.isInherited() && superModel != null){ - if (!superModel.hasEntityFields()){ + if (field.isInherited() && superType != null){ + if (!superType.hasEntityFields()){ value.append("_super." + field.getEscapedName()); } }else{ @@ -441,8 +441,8 @@ public class EntitySerializer implements Serializer{ } } - private void serializeProperties(EntityModel model, SerializerConfig config, CodeWriter writer) throws IOException { - for (PropertyModel property : model.getProperties()){ + private void serializeProperties(EntityType model, SerializerConfig config, CodeWriter writer) throws IOException { + for (Property property : model.getProperties()){ String queryType = typeMappings.getPathType(property.getType(), model, false); String localGenericName = property.getType().getLocalGenericName(model, true); String localRawName = property.getType().getLocalRawName(model); diff --git a/querydsl-core/src/main/java/com/mysema/query/codegen/EntityModel.java b/querydsl-core/src/main/java/com/mysema/query/codegen/EntityType.java similarity index 56% rename from querydsl-core/src/main/java/com/mysema/query/codegen/EntityModel.java rename to querydsl-core/src/main/java/com/mysema/query/codegen/EntityType.java index d810cbab8..360f65b98 100644 --- a/querydsl-core/src/main/java/com/mysema/query/codegen/EntityModel.java +++ b/querydsl-core/src/main/java/com/mysema/query/codegen/EntityType.java @@ -8,76 +8,68 @@ package com.mysema.query.codegen; import java.io.IOException; import java.lang.annotation.Annotation; import java.util.Collection; -import java.util.Collections; import java.util.HashSet; import java.util.Set; import java.util.TreeSet; -import javax.annotation.Nullable; - import org.apache.commons.lang.StringUtils; import com.mysema.commons.lang.Assert; /** - * EntityModel represents a model of a query domain type with properties + * EntityType represents a model of a query domain type with properties * * @author tiwe * @version $Id$ */ -// TODO : rename this -public final class EntityModel extends TypeModelAdapter implements Comparable { +public final class EntityType extends TypeAdapter implements Comparable { - private final Set constructors = new HashSet(); + private final Set annotations = new HashSet(); + + private final Set constructors = new HashSet(); // mutable private int escapeSuffix = 1; // mutable private boolean hasLists, hasMaps, hasEntityFields; - - private final Set annotations = new HashSet(); - private final Set methods = new HashSet(); + private final Set methods = new HashSet(); private final String prefix; - private final Set properties = new TreeSet(); + private final Set properties = new TreeSet(); - // mutable - @Nullable - private EntityModel superModel; - - private final Collection superTypes; + private final Collection superTypes; // mutable private String uncapSimpleName; - - public EntityModel(String prefix, TypeModel typeModel) { - this(prefix, typeModel, Collections.emptyList()); + + public EntityType(String prefix, Type type) { + this(prefix, type, new HashSet()); } - - public EntityModel(String prefix, TypeModel typeModel, Collection superTypes) { - super(typeModel); + + public EntityType(String prefix, Type type, Set superTypes) { + super(type); this.prefix = Assert.notNull(prefix); - this.uncapSimpleName = StringUtils.uncapitalize(typeModel.getSimpleName()); + this.uncapSimpleName = StringUtils.uncapitalize(type.getSimpleName()); this.superTypes = superTypes; } - public void addConstructor(ConstructorModel co) { - constructors.add(co); - } - public void addAnnotation(Annotation annotation){ annotations.add(annotation); } - public void addMethod(MethodModel method){ + public void addConstructor(Constructor co) { + constructors.add(co); + } + + public void addMethod(Method method){ methods.add(method); } - public void addProperty(PropertyModel field) { - properties.add(validateField(field)); + public void addProperty(Property field) { + properties.add(validateField(field)); switch(field.getType().getCategory()){ case MAP: hasMaps = true; @@ -90,23 +82,31 @@ public final class EntityModel extends TypeModelAdapter implements Comparable getAnnotations() { + return annotations; + } + public TypeCategory getCategory() { return TypeCategory.ENTITY; } - public Set getConstructors() { + public Set getConstructors() { return constructors; } public String getLocalGenericName(){ try { StringBuilder builder = new StringBuilder(); - getTypeModel().appendLocalGenericName(this, builder, false); + getType().appendLocalGenericName(this, builder, false); return builder.toString(); } catch (IOException e) { throw new CodeGenerationException(e.getMessage(), e); @@ -116,35 +116,34 @@ public final class EntityModel extends TypeModelAdapter implements Comparable getMethods(){ + + public Set getMethods(){ return methods; } - + public TypeCategory getOriginalCategory(){ return super.getCategory(); } - + public String getPrefix(){ return prefix; } - public Set getProperties() { + public Set getProperties() { return properties; } - - @Nullable - public EntityModel getSuperModel() { - return superModel; + + public EntityType getSuperType(){ + return superTypes.size() == 1 ? superTypes.iterator().next() : null; } - public Collection getSuperTypes() { + public Collection getSuperTypes() { return superTypes; } @@ -155,7 +154,7 @@ public final class EntityModel extends TypeModelAdapter implements Comparable getAnnotations() { - return annotations; - } - public void include(EntityModel clazz) { - for (MethodModel method : clazz.methods){ + public void include(EntityType clazz) { + for (Method method : clazz.methods){ addMethod(method); } - for (PropertyModel property : clazz.properties){ + for (Property property : clazz.properties){ if (!property.isInherited()){ addProperty(property.createCopy(this)); } } } - public void setSuperModel(EntityModel superModel) { - this.superModel = superModel; - } - - private PropertyModel validateField(PropertyModel field) { + private Property validateField(Property field) { if (field.getName().equals(this.uncapSimpleName)) { - uncapSimpleName = StringUtils.uncapitalize(getTypeModel().getSimpleName())+ (escapeSuffix++); + uncapSimpleName = StringUtils.uncapitalize(getType().getSimpleName())+ (escapeSuffix++); } return field; } diff --git a/querydsl-core/src/main/java/com/mysema/query/codegen/MethodModel.java b/querydsl-core/src/main/java/com/mysema/query/codegen/Method.java similarity index 66% rename from querydsl-core/src/main/java/com/mysema/query/codegen/MethodModel.java rename to querydsl-core/src/main/java/com/mysema/query/codegen/Method.java index fe0d5e0ec..c0ca43ba1 100644 --- a/querydsl-core/src/main/java/com/mysema/query/codegen/MethodModel.java +++ b/querydsl-core/src/main/java/com/mysema/query/codegen/Method.java @@ -16,19 +16,19 @@ import com.mysema.commons.lang.Assert; * */ @Immutable -public final class MethodModel { +public final class Method { - private final EntityModel context; + private final EntityType context; private final String name; - private final List parameters; + private final List parameters; - private final TypeModel returnType; + private final Type returnType; private final String template; - public MethodModel(EntityModel context, String name, String template, List params, TypeModel returnType) { + public Method(EntityType context, String name, String template, List params, Type returnType) { this.context = Assert.notNull(context); this.name = Assert.notNull(name); this.template = Assert.notNull(template); @@ -40,15 +40,15 @@ public final class MethodModel { public boolean equals(Object o) { if (o == this){ return true; - }else if (o instanceof MethodModel){ - MethodModel m = (MethodModel)o; + }else if (o instanceof Method){ + Method m = (Method)o; return m.name.equals(name) && m.parameters.equals(parameters); }else{ return false; } } - public EntityModel getContext() { + public EntityType getContext() { return context; } @@ -56,11 +56,11 @@ public final class MethodModel { return name; } - public List getParameters() { + public List getParameters() { return parameters; } - public TypeModel getReturnType() { + public Type getReturnType() { return returnType; } diff --git a/querydsl-core/src/main/java/com/mysema/query/codegen/ParameterModel.java b/querydsl-core/src/main/java/com/mysema/query/codegen/Parameter.java similarity index 62% rename from querydsl-core/src/main/java/com/mysema/query/codegen/ParameterModel.java rename to querydsl-core/src/main/java/com/mysema/query/codegen/Parameter.java index 42c653763..27b4b286b 100644 --- a/querydsl-core/src/main/java/com/mysema/query/codegen/ParameterModel.java +++ b/querydsl-core/src/main/java/com/mysema/query/codegen/Parameter.java @@ -8,19 +8,19 @@ package com.mysema.query.codegen; import net.jcip.annotations.Immutable; /** - * ParameterModel represents a parameter in a Constructor + * Parameter represents a parameter in a Constructor * * @author tiwe * @version $Id$ */ @Immutable -public final class ParameterModel { +public final class Parameter { private final String name; - private final TypeModel type; + private final Type type; - public ParameterModel(String name, TypeModel type) { + public Parameter(String name, Type type) { this.name = name; this.type = type; } @@ -29,8 +29,8 @@ public final class ParameterModel { public boolean equals(Object o) { if (o == this){ return true; - }else if (o instanceof ParameterModel){ - return type.equals(((ParameterModel) o).type); + }else if (o instanceof Parameter){ + return type.equals(((Parameter) o).type); }else{ return false; } @@ -40,7 +40,7 @@ public final class ParameterModel { return name; } - public TypeModel getType(){ + public Type getType(){ return type; } diff --git a/querydsl-core/src/main/java/com/mysema/query/codegen/PropertyModel.java b/querydsl-core/src/main/java/com/mysema/query/codegen/Property.java similarity index 59% rename from querydsl-core/src/main/java/com/mysema/query/codegen/PropertyModel.java rename to querydsl-core/src/main/java/com/mysema/query/codegen/Property.java index 4862c1df4..266882325 100644 --- a/querydsl-core/src/main/java/com/mysema/query/codegen/PropertyModel.java +++ b/querydsl-core/src/main/java/com/mysema/query/codegen/Property.java @@ -13,15 +13,15 @@ import com.mysema.commons.lang.Assert; import com.mysema.util.JavaSyntaxUtils; /** - * PropertyModel represents a property in a query domain type. + * Property represents a property in a query domain type. * * @author tiwe * @version $Id$ */ @Immutable -public final class PropertyModel implements Comparable { +public final class Property implements Comparable { - private final EntityModel context; + private final EntityType context; private final boolean inherited; @@ -29,17 +29,23 @@ public final class PropertyModel implements Comparable { private final String name, escapedName; - private final TypeModel type; + private final Type type; - public PropertyModel(EntityModel context, String name, TypeModel type, String[] inits) { + /** + * @param context + * @param name + * @param type + * @param inits + */ + public Property(EntityType context, String name, Type type, String[] inits) { this(context, name, type, inits, false); } - public PropertyModel(EntityModel context, String name, TypeModel type, String[] inits, boolean inherited) { + public Property(EntityType context, String name, Type type, String[] inits, boolean inherited) { this(context, name, JavaSyntaxUtils.isReserved(name) ? (name + "_") : name, type, inits, inherited); } - - public PropertyModel(EntityModel context, String name, String escapedName, TypeModel type, String[] inits, boolean inherited) { + + public Property(EntityType context, String name, String escapedName, Type type, String[] inits, boolean inherited) { this.context = context; this.name = Assert.notNull(name); this.escapedName = escapedName; @@ -48,25 +54,25 @@ public final class PropertyModel implements Comparable { this.inherited = inherited; } - public int compareTo(PropertyModel o) { + public int compareTo(Property o) { return name.compareToIgnoreCase(o.getName()); } - public PropertyModel createCopy(EntityModel model) { - return new PropertyModel(model, name, type, inits, model.getSuperModel() != null); + public Property createCopy(EntityType model) { + return new Property(model, name, type, inits, model.getSuperType() != null); } public boolean equals(Object o) { if (o == this){ return true; - }else if (o instanceof PropertyModel){ - return name.equals(((PropertyModel) o).name); + }else if (o instanceof Property){ + return name.equals(((Property) o).name); }else{ return false; } } - public EntityModel getContext() { + public EntityType getContext() { return context; } @@ -82,11 +88,11 @@ public final class PropertyModel implements Comparable { return name; } - public TypeModel getParameter(int i) { + public Type getParameter(int i) { return type.getParameter(i); } - public TypeModel getType() { + public Type getType() { return type; } diff --git a/querydsl-core/src/main/java/com/mysema/query/codegen/Serializer.java b/querydsl-core/src/main/java/com/mysema/query/codegen/Serializer.java index 5bd0e4d6a..1303cf331 100644 --- a/querydsl-core/src/main/java/com/mysema/query/codegen/Serializer.java +++ b/querydsl-core/src/main/java/com/mysema/query/codegen/Serializer.java @@ -10,7 +10,7 @@ import java.io.IOException; import com.mysema.util.CodeWriter; /** - * Serializer defines a common interface for EntityModel serializers + * Serializer defines a common interface for EntityType serializers * * @author tiwe * @@ -18,14 +18,14 @@ import com.mysema.util.CodeWriter; public interface Serializer { /** - * Serialize the given ClassModel + * Serialize the given EntityType * - * @param type ClassModel to serialize + * @param type EntityType to serialize * @param serializerConfig TODO * @param writer serialization target * @throws IOException */ - void serialize(EntityModel type, SerializerConfig serializerConfig, CodeWriter writer) throws IOException; + void serialize(EntityType type, SerializerConfig serializerConfig, CodeWriter writer) throws IOException; } \ No newline at end of file diff --git a/querydsl-core/src/main/java/com/mysema/query/codegen/SimpleTypeModel.java b/querydsl-core/src/main/java/com/mysema/query/codegen/SimpleType.java similarity index 76% rename from querydsl-core/src/main/java/com/mysema/query/codegen/SimpleTypeModel.java rename to querydsl-core/src/main/java/com/mysema/query/codegen/SimpleType.java index 6161e7b5f..dcde08db8 100644 --- a/querydsl-core/src/main/java/com/mysema/query/codegen/SimpleTypeModel.java +++ b/querydsl-core/src/main/java/com/mysema/query/codegen/SimpleType.java @@ -13,29 +13,29 @@ import com.mysema.commons.lang.Assert; /** - * SimpleTypeModel represents a java type + * SimpleType represents a java type * * @author tiwe * */ @Immutable -public final class SimpleTypeModel extends AbstractTypeModel { +public final class SimpleType extends AbstractType { private final String fullName, packageName, simpleName, localName; - private final TypeModel[] parameters; + private final Type[] parameters; private final TypeCategory typeCategory; private final boolean visible, finalClass; - public SimpleTypeModel( + public SimpleType( TypeCategory typeCategory, String name, String packageName, String simpleName, boolean finalClass, - TypeModel... parameters) { + Type... parameters) { this.typeCategory = Assert.notNull(typeCategory,"typeCategory is null"); this.fullName = Assert.notNull(name,"name is null"); this.packageName = Assert.notNull(packageName,"packageName is null"); @@ -46,25 +46,25 @@ public final class SimpleTypeModel extends AbstractTypeModel { this.finalClass = finalClass; } - public SimpleTypeModel as(TypeCategory category) { + public SimpleType as(TypeCategory category) { if (typeCategory == category){ return this; }else{ - return new SimpleTypeModel(category, fullName, packageName, simpleName, finalClass, parameters); + return new SimpleType(category, fullName, packageName, simpleName, finalClass, parameters); } } @Override - public TypeModel asArrayType() { - return new SimpleTypeModel(TypeCategory.ARRAY, fullName+"[]", packageName, simpleName+"[]", finalClass, this); + public Type asArrayType() { + return new SimpleType(TypeCategory.ARRAY, fullName+"[]", packageName, simpleName+"[]", finalClass, this); } @Override public boolean equals(Object o){ if (o == this){ return true; - }else if (o instanceof TypeModel){ - TypeModel t = (TypeModel)o; + }else if (o instanceof Type){ + Type t = (Type)o; return fullName.equals(t.getFullName()); }else{ return false; @@ -83,7 +83,7 @@ public final class SimpleTypeModel extends AbstractTypeModel { // NOTE: Java serialization aspects mixed into model @Override - public void appendLocalGenericName(TypeModel context, Appendable builder, boolean asArgType) throws IOException { + public void appendLocalGenericName(Type context, Appendable builder, boolean asArgType) throws IOException { appendLocalRawName(context, builder); if (parameters.length > 0){ builder.append("<"); @@ -103,7 +103,7 @@ public final class SimpleTypeModel extends AbstractTypeModel { } @Override - public void appendLocalRawName(TypeModel context, Appendable builder) throws IOException{ + public void appendLocalRawName(Type context, Appendable builder) throws IOException{ if (visible || context.getPackageName().equals(packageName)){ builder.append(localName); }else{ @@ -117,7 +117,7 @@ public final class SimpleTypeModel extends AbstractTypeModel { } @Override - public TypeModel getParameter(int i) { + public Type getParameter(int i) { return parameters[i]; } @@ -132,7 +132,7 @@ public final class SimpleTypeModel extends AbstractTypeModel { } @Override - public TypeModel getSelfOrValueType() { + public Type getSelfOrValueType() { if (typeCategory.isSubCategoryOf(TypeCategory.COLLECTION) || typeCategory.isSubCategoryOf(TypeCategory.MAP)){ return parameters[parameters.length - 1]; diff --git a/querydsl-core/src/main/java/com/mysema/query/codegen/SupertypeSerializer.java b/querydsl-core/src/main/java/com/mysema/query/codegen/SupertypeSerializer.java index 2057a5d47..8dc70a87d 100644 --- a/querydsl-core/src/main/java/com/mysema/query/codegen/SupertypeSerializer.java +++ b/querydsl-core/src/main/java/com/mysema/query/codegen/SupertypeSerializer.java @@ -28,22 +28,22 @@ public final class SupertypeSerializer extends EntitySerializer{ } @Override - protected void constructorsForVariables(CodeWriter writer, EntityModel model) { + protected void constructorsForVariables(CodeWriter writer, EntityType model) { // no constructors for variables } @Override - protected void introDefaultInstance(CodeWriter writer, EntityModel model) { + protected void introDefaultInstance(CodeWriter writer, EntityType model) { // no default instance } @Override - protected void introFactoryMethods(CodeWriter writer, EntityModel model) throws IOException { + protected void introFactoryMethods(CodeWriter writer, EntityType model) throws IOException { // no factory methods } @Override - protected void introImports(CodeWriter writer, SerializerConfig config, EntityModel model) throws IOException { + protected void introImports(CodeWriter writer, SerializerConfig config, EntityType model) throws IOException { writer.imports(Path.class.getPackage()); if ((model.hasLists() && config.useListAccessors()) || !model.getMethods().isEmpty() diff --git a/querydsl-core/src/main/java/com/mysema/query/codegen/TypeModel.java b/querydsl-core/src/main/java/com/mysema/query/codegen/Type.java similarity index 68% rename from querydsl-core/src/main/java/com/mysema/query/codegen/TypeModel.java rename to querydsl-core/src/main/java/com/mysema/query/codegen/Type.java index 56dab91e9..263c93113 100644 --- a/querydsl-core/src/main/java/com/mysema/query/codegen/TypeModel.java +++ b/querydsl-core/src/main/java/com/mysema/query/codegen/Type.java @@ -10,12 +10,12 @@ import java.io.IOException; import javax.annotation.Nullable; /** - * TypeModel represents Java types + * Type represents Java types * * @author tiwe * */ -public interface TypeModel { +public interface Type { /** * @param context @@ -24,7 +24,7 @@ public interface TypeModel { * @return * @throws IOException */ - void appendLocalGenericName(TypeModel context, Appendable builder, boolean asArgType) throws IOException; + void appendLocalGenericName(Type context, Appendable builder, boolean asArgType) throws IOException; /** * @param context @@ -32,18 +32,18 @@ public interface TypeModel { * @return * @throws IOException */ - void appendLocalRawName(TypeModel context, Appendable builder) throws IOException; + void appendLocalRawName(Type context, Appendable builder) throws IOException; /** * @param category * @return */ - TypeModel as(TypeCategory category); + Type as(TypeCategory category); /** * @return */ - TypeModel asArrayType(); + Type asArrayType(); /** * @return @@ -60,13 +60,13 @@ public interface TypeModel { * @param asArgType * @return */ - String getLocalGenericName(TypeModel context, boolean asArgType); + String getLocalGenericName(Type context, boolean asArgType); /** * @param context * @return */ - String getLocalRawName(TypeModel context); + String getLocalRawName(Type context); /** * @return @@ -78,7 +78,7 @@ public interface TypeModel { * @return */ @Nullable - TypeModel getParameter(int i); + Type getParameter(int i); /** * @return @@ -94,7 +94,7 @@ public interface TypeModel { /** * @return */ - TypeModel getSelfOrValueType(); + Type getSelfOrValueType(); /** * @return diff --git a/querydsl-core/src/main/java/com/mysema/query/codegen/TypeAdapter.java b/querydsl-core/src/main/java/com/mysema/query/codegen/TypeAdapter.java new file mode 100644 index 000000000..dacabf479 --- /dev/null +++ b/querydsl-core/src/main/java/com/mysema/query/codegen/TypeAdapter.java @@ -0,0 +1,130 @@ +/* + * Copyright (c) 2009 Mysema Ltd. + * All rights reserved. + * + */ +package com.mysema.query.codegen; + +import java.io.IOException; + +import com.mysema.commons.lang.Assert; + +/** + * TypeAdapter is a basic adapter implementation for the Type interface + * + * @author tiwe + * + */ +public class TypeAdapter implements Type{ + + private final Type type; + + public TypeAdapter(Type type){ + this.type = Assert.notNull(type); + } + + @Override + public void appendLocalGenericName(Type context, Appendable builder, boolean asArgType) throws IOException { + type.appendLocalGenericName(context, builder, false); + } + + @Override + public void appendLocalRawName(Type context, Appendable builder) throws IOException { + type.appendLocalRawName(context, builder); + } + + @Override + public Type as(TypeCategory category) { + return type.as(category); + } + + @Override + public Type asArrayType() { + return type.asArrayType(); + } + + @Override + public boolean equals(Object o){ + return type.equals(o); + } + + @Override + public TypeCategory getCategory() { + return type.getCategory(); + } + + @Override + public String getFullName() { + return type.getFullName(); + } + + @Override + public String getLocalGenericName(Type context, boolean asArgType) { + return type.getLocalGenericName(context, asArgType); + } + + @Override + public String getLocalRawName(Type context) { + return type.getLocalRawName(context); + } + + @Override + public String getPackageName() { + return type.getPackageName(); + } + + @Override + public Type getParameter(int i) { + return type.getParameter(i); + } + + @Override + public int getParameterCount() { + return type.getParameterCount(); + } + + @Override + public String getPrimitiveName() { + return type.getPrimitiveName(); + } + + @Override + public Type getSelfOrValueType() { + return type.getSelfOrValueType(); + } + + @Override + public String getSimpleName() { + return type.getSimpleName(); + } + + protected Type getType(){ + return type; + } + + @Override + public boolean hasEntityFields() { + return type.hasEntityFields(); + } + + @Override + public int hashCode(){ + return type.hashCode(); + } + + @Override + public boolean isFinal() { + return type.isFinal(); + } + + @Override + public boolean isPrimitive() { + return type.isPrimitive(); + } + + @Override + public String toString() { + return type.toString(); + } + +} diff --git a/querydsl-core/src/main/java/com/mysema/query/codegen/TypeExtendsModel.java b/querydsl-core/src/main/java/com/mysema/query/codegen/TypeExtends.java similarity index 50% rename from querydsl-core/src/main/java/com/mysema/query/codegen/TypeExtendsModel.java rename to querydsl-core/src/main/java/com/mysema/query/codegen/TypeExtends.java index e9d8c66e3..8fd4440e5 100644 --- a/querydsl-core/src/main/java/com/mysema/query/codegen/TypeExtendsModel.java +++ b/querydsl-core/src/main/java/com/mysema/query/codegen/TypeExtends.java @@ -10,33 +10,33 @@ import java.io.IOException; import javax.annotation.Nullable; /** - * TypeExtendsModel is a TypeModel for type variables and wildcard types + * TypeExtends is a Type implementation for type variables and wildcard types * * @author tiwe * */ // TODO : take varName into account -public class TypeExtendsModel extends TypeModelAdapter{ +public class TypeExtends extends TypeAdapter{ @Nullable private final String varName; - public TypeExtendsModel(String varName, TypeModel typeModel) { - super(typeModel); + public TypeExtends(String varName, Type type) { + super(type); this.varName = varName; } - public TypeExtendsModel(TypeModel typeModel) { - super(typeModel); + public TypeExtends(Type type) { + super(type); varName = null; } @Override - public void appendLocalGenericName(TypeModel context, Appendable builder, boolean asArgType) throws IOException { + public void appendLocalGenericName(Type context, Appendable builder, boolean asArgType) throws IOException { if (!asArgType){ builder.append("? extends "); } - getTypeModel().appendLocalGenericName(context, builder, true); + getType().appendLocalGenericName(context, builder, true); } public String getVarName(){ diff --git a/querydsl-core/src/main/java/com/mysema/query/codegen/TypeModelFactory.java b/querydsl-core/src/main/java/com/mysema/query/codegen/TypeFactory.java similarity index 61% rename from querydsl-core/src/main/java/com/mysema/query/codegen/TypeModelFactory.java rename to querydsl-core/src/main/java/com/mysema/query/codegen/TypeFactory.java index 6dc47179b..4d50fbc4e 100644 --- a/querydsl-core/src/main/java/com/mysema/query/codegen/TypeModelFactory.java +++ b/querydsl-core/src/main/java/com/mysema/query/codegen/TypeFactory.java @@ -7,7 +7,6 @@ package com.mysema.query.codegen; import java.lang.annotation.Annotation; import java.lang.reflect.Modifier; -import java.lang.reflect.Type; import java.util.Arrays; import java.util.Collection; import java.util.HashMap; @@ -20,39 +19,39 @@ import org.apache.commons.lang.ClassUtils; import com.mysema.util.ReflectionUtils; /** - * TypeModelFactory is a factory class for TypeModel instances + * TypeFactory is a factory class for Type instances * * @author tiwe * */ -public final class TypeModelFactory { +public final class TypeFactory { - private final Map, TypeModel> cache = new HashMap, TypeModel>(); + private final Map, Type> cache = new HashMap, Type>(); private final Collection> entityAnnotations; @SuppressWarnings("unchecked") - public TypeModelFactory(Class... entityAnnotations){ + public TypeFactory(Class... entityAnnotations){ this.entityAnnotations = (List)Arrays.asList(entityAnnotations); } - public TypeModelFactory(List> entityAnnotations){ + public TypeFactory(List> entityAnnotations){ this.entityAnnotations = entityAnnotations; } - public TypeModel create(Class cl){ + public Type create(Class cl){ return create(cl, cl); } - public TypeModel create(Class cl, Type genericType) { - List key = Arrays. asList(cl, genericType); + public Type create(Class cl, java.lang.reflect.Type genericType) { + List key = Arrays. asList(cl, genericType); if (cache.containsKey(key)) { return cache.get(key); }else{ if (cl.isPrimitive()) { cl = ClassUtils.primitiveToWrapper(cl); } - TypeModel value; + Type value; boolean entity= false; for (Class clazz : entityAnnotations){ if (cl.getAnnotation(clazz) != null){ @@ -61,40 +60,40 @@ public final class TypeModelFactory { } } if (entity){ - value = new ClassTypeModel(TypeCategory.ENTITY, cl); + value = new ClassType(TypeCategory.ENTITY, cl); }else if (cl.isArray()) { value = create(cl.getComponentType()).asArrayType(); } else if (cl.isEnum()) { - value = new ClassTypeModel(TypeCategory.SIMPLE, cl); + value = new ClassType(TypeCategory.SIMPLE, cl); } else if (Map.class.isAssignableFrom(cl)) { - TypeModel keyInfo = create(ReflectionUtils.getTypeParameter(genericType, 0)); - TypeModel valueInfo = create(ReflectionUtils.getTypeParameter(genericType, 1)); + Type keyInfo = create(ReflectionUtils.getTypeParameter(genericType, 0)); + Type valueInfo = create(ReflectionUtils.getTypeParameter(genericType, 1)); value = createMapType(keyInfo, valueInfo); } else if (List.class.isAssignableFrom(cl)) { - TypeModel valueInfo = create(ReflectionUtils.getTypeParameter(genericType, 0)); + Type valueInfo = create(ReflectionUtils.getTypeParameter(genericType, 0)); value = createListType(valueInfo); } else if (Set.class.isAssignableFrom(cl)) { - TypeModel valueInfo = create(ReflectionUtils.getTypeParameter(genericType, 0)); + Type valueInfo = create(ReflectionUtils.getTypeParameter(genericType, 0)); value = createSetType(valueInfo); } else if (Collection.class.isAssignableFrom(cl)) { - TypeModel valueInfo = create(ReflectionUtils.getTypeParameter(genericType, 0)); + Type valueInfo = create(ReflectionUtils.getTypeParameter(genericType, 0)); value = createCollectionType(valueInfo); }else if (Number.class.isAssignableFrom(cl) && Comparable.class.isAssignableFrom(cl)){ - value = new ClassTypeModel(TypeCategory.NUMERIC, cl); + value = new ClassType(TypeCategory.NUMERIC, cl); } else { TypeCategory typeCategory = TypeCategory.get(cl.getName()); if (!typeCategory.isSubCategoryOf(TypeCategory.COMPARABLE) && Comparable.class.isAssignableFrom(cl)){ typeCategory = TypeCategory.COMPARABLE; } - value = new ClassTypeModel(typeCategory, cl); + value = new ClassType(typeCategory, cl); } cache.put(key, value); return value; @@ -102,12 +101,12 @@ public final class TypeModelFactory { } - public TypeModel createCollectionType(TypeModel valueType) { + public Type createCollectionType(Type valueType) { return createComposite(TypeCategory.COLLECTION, Collection.class, valueType); } - private TypeModel createComposite(TypeCategory container, Class containerType, TypeModel... parameters) { - return new SimpleTypeModel(container, + private Type createComposite(TypeCategory container, Class containerType, Type... parameters) { + return new SimpleType(container, containerType.getName(), containerType.getPackage().getName(), containerType.getSimpleName(), @@ -116,15 +115,15 @@ public final class TypeModelFactory { } - public TypeModel createListType(TypeModel valueType) { + public Type createListType(Type valueType) { return createComposite(TypeCategory.LIST, List.class, valueType); } - public TypeModel createMapType(TypeModel keyType, TypeModel valueType) { + public Type createMapType(Type keyType, Type valueType) { return createComposite(TypeCategory.MAP, Map.class, keyType, valueType); } - public TypeModel createSetType(TypeModel valueType) { + public Type createSetType(Type valueType) { return createComposite(TypeCategory.SET, Collection.class, valueType); } diff --git a/querydsl-core/src/main/java/com/mysema/query/codegen/TypeMappings.java b/querydsl-core/src/main/java/com/mysema/query/codegen/TypeMappings.java index bc4b11bc1..5183f7c8e 100644 --- a/querydsl-core/src/main/java/com/mysema/query/codegen/TypeMappings.java +++ b/querydsl-core/src/main/java/com/mysema/query/codegen/TypeMappings.java @@ -70,36 +70,36 @@ public class TypeMappings { } - public String getCustomType(TypeModel type, EntityModel model, boolean raw){ + public String getCustomType(Type type, EntityType model, boolean raw){ return getCustomType(type, model, raw, false, false); } - public String getCustomType(TypeModel type, EntityModel model, boolean raw, boolean rawParameters, boolean extend){ + public String getCustomType(Type type, EntityType model, boolean raw, boolean rawParameters, boolean extend){ return getQueryType(customTypes, type, model, raw, rawParameters, extend); } - public String getExprType(TypeModel type, EntityModel model, boolean raw){ + public String getExprType(Type type, EntityType model, boolean raw){ return getExprType(type, model, raw, false, false); } - public String getExprType(TypeModel type, EntityModel model, boolean raw, boolean rawParameters, boolean extend){ + public String getExprType(Type type, EntityType model, boolean raw, boolean rawParameters, boolean extend){ return getQueryType(exprTypes, type, model, raw, rawParameters, extend); } - public String getPathType(TypeModel type, EntityModel model, boolean raw){ + public String getPathType(Type type, EntityType model, boolean raw){ return getPathType(type, model, raw, false, false); } - public String getPathType(TypeModel type, EntityModel model, boolean raw, boolean rawParameters, boolean extend){ + public String getPathType(Type type, EntityType model, boolean raw, boolean rawParameters, boolean extend){ return getQueryType(pathTypes, type, model, raw, rawParameters, extend); } - private String getQueryType(Map> types, TypeModel type, EntityModel model, boolean raw, boolean rawParameters, boolean extend){ + private String getQueryType(Map> types, Type type, EntityType model, boolean raw, boolean rawParameters, boolean extend){ String typeName = types.get(type.getCategory()).getSimpleName(); return getQueryType(type, model, typeName, raw, rawParameters, extend); } - public String getQueryType(TypeModel type, EntityModel model, String typeName, boolean raw, boolean rawParameters, boolean extend){ + public String getQueryType(Type type, EntityType model, String typeName, boolean raw, boolean rawParameters, boolean extend){ String localName = null; TypeCategory category = type.getCategory(); diff --git a/querydsl-core/src/main/java/com/mysema/query/codegen/TypeModelAdapter.java b/querydsl-core/src/main/java/com/mysema/query/codegen/TypeModelAdapter.java deleted file mode 100644 index 7f833411d..000000000 --- a/querydsl-core/src/main/java/com/mysema/query/codegen/TypeModelAdapter.java +++ /dev/null @@ -1,130 +0,0 @@ -/* - * Copyright (c) 2009 Mysema Ltd. - * All rights reserved. - * - */ -package com.mysema.query.codegen; - -import java.io.IOException; - -import com.mysema.commons.lang.Assert; - -/** - * TypeModelAdapter is a basic adapter implementation for the TypeModel interface - * - * @author tiwe - * - */ -public class TypeModelAdapter implements TypeModel{ - - private final TypeModel typeModel; - - public TypeModelAdapter(TypeModel typeModel){ - this.typeModel = Assert.notNull(typeModel); - } - - @Override - public void appendLocalGenericName(TypeModel context, Appendable builder, boolean asArgType) throws IOException { - typeModel.appendLocalGenericName(context, builder, false); - } - - @Override - public void appendLocalRawName(TypeModel context, Appendable builder) throws IOException { - typeModel.appendLocalRawName(context, builder); - } - - @Override - public TypeModel as(TypeCategory category) { - return typeModel.as(category); - } - - @Override - public TypeModel asArrayType() { - return typeModel.asArrayType(); - } - - @Override - public boolean equals(Object o){ - return typeModel.equals(o); - } - - @Override - public TypeCategory getCategory() { - return typeModel.getCategory(); - } - - @Override - public String getFullName() { - return typeModel.getFullName(); - } - - @Override - public String getLocalGenericName(TypeModel context, boolean asArgType) { - return typeModel.getLocalGenericName(context, asArgType); - } - - @Override - public String getLocalRawName(TypeModel context) { - return typeModel.getLocalRawName(context); - } - - @Override - public String getPackageName() { - return typeModel.getPackageName(); - } - - @Override - public TypeModel getParameter(int i) { - return typeModel.getParameter(i); - } - - @Override - public int getParameterCount() { - return typeModel.getParameterCount(); - } - - @Override - public String getPrimitiveName() { - return typeModel.getPrimitiveName(); - } - - @Override - public TypeModel getSelfOrValueType() { - return typeModel.getSelfOrValueType(); - } - - @Override - public String getSimpleName() { - return typeModel.getSimpleName(); - } - - protected TypeModel getTypeModel(){ - return typeModel; - } - - @Override - public boolean hasEntityFields() { - return typeModel.hasEntityFields(); - } - - @Override - public int hashCode(){ - return typeModel.hashCode(); - } - - @Override - public boolean isFinal() { - return typeModel.isFinal(); - } - - @Override - public boolean isPrimitive() { - return typeModel.isPrimitive(); - } - - @Override - public String toString() { - return typeModel.toString(); - } - -} diff --git a/querydsl-core/src/main/java/com/mysema/query/codegen/TypeModels.java b/querydsl-core/src/main/java/com/mysema/query/codegen/TypeModels.java deleted file mode 100644 index e8e28e44b..000000000 --- a/querydsl-core/src/main/java/com/mysema/query/codegen/TypeModels.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (c) 2009 Mysema Ltd. - * All rights reserved. - * - */ -package com.mysema.query.codegen; - -/** - * @author tiwe - * - */ -public final class TypeModels { - - private TypeModels(){} - - public static final TypeModel OBJECTS = new ClassTypeModel(TypeCategory.SIMPLE, Object[].class); - - public static final TypeModel OBJECT = new ClassTypeModel(TypeCategory.SIMPLE, Object.class); - - public static final TypeModel BOOLEAN = new ClassTypeModel(TypeCategory.BOOLEAN, Boolean.class, boolean.class); - - public static final TypeModel BYTE = new ClassTypeModel(TypeCategory.NUMERIC, Byte.class, byte.class); - - public static final TypeModel CHAR = new ClassTypeModel(TypeCategory.COMPARABLE, Character.class, char.class); - - public static final TypeModel DOUBLE = new ClassTypeModel(TypeCategory.NUMERIC, Double.class, double.class); - - public static final TypeModel FLOAT = new ClassTypeModel(TypeCategory.NUMERIC, Float.class, float.class); - - public static final TypeModel INT = new ClassTypeModel(TypeCategory.NUMERIC, Integer.class, int.class); - - public static final TypeModel LONG = new ClassTypeModel(TypeCategory.NUMERIC, Long.class, long.class); - - public static final TypeModel SHORT = new ClassTypeModel(TypeCategory.NUMERIC, Short.class, short.class); - - public static final TypeModel STRING = new ClassTypeModel(TypeCategory.STRING, String.class); - -} diff --git a/querydsl-core/src/main/java/com/mysema/query/codegen/TypeSuper.java b/querydsl-core/src/main/java/com/mysema/query/codegen/TypeSuper.java new file mode 100644 index 000000000..9db68eb29 --- /dev/null +++ b/querydsl-core/src/main/java/com/mysema/query/codegen/TypeSuper.java @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2009 Mysema Ltd. + * All rights reserved. + * + */ +package com.mysema.query.codegen; + +import java.io.IOException; + +import javax.annotation.Nullable; + +/** + * TypeSuper is a Type for type variables and wildcard types + * + * @author tiwe + * + */ +// TODO : take varName into account +public class TypeSuper extends TypeAdapter{ + + private final Type superType; + + @Nullable + private final String varName; + + public TypeSuper(String varName, Type type) { + super(Types.OBJECT); + this.superType = type; + this.varName = varName; + } + + public TypeSuper(Type type) { + super(Types.OBJECT); + this.superType = type; + this.varName = null; + } + + @Override + public void appendLocalGenericName(Type context, Appendable builder, boolean asArgType) throws IOException { + if (!asArgType){ + builder.append("? super "); + superType.appendLocalGenericName(context, builder, true); + }else{ + super.appendLocalGenericName(context, builder, asArgType); + } + } + + public String getVarName(){ + return varName; + } +} diff --git a/querydsl-core/src/main/java/com/mysema/query/codegen/TypeSuperModel.java b/querydsl-core/src/main/java/com/mysema/query/codegen/TypeSuperModel.java deleted file mode 100644 index b91d122b3..000000000 --- a/querydsl-core/src/main/java/com/mysema/query/codegen/TypeSuperModel.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (c) 2009 Mysema Ltd. - * All rights reserved. - * - */ -package com.mysema.query.codegen; - -import java.io.IOException; - -import javax.annotation.Nullable; - -/** - * TypeSuperModel is a TypeModel for type variables and wildcard types - * - * @author tiwe - * - */ -// TODO : take varName into account -public class TypeSuperModel extends TypeModelAdapter{ - - private static final TypeModel objectModel = new ClassTypeModel(TypeCategory.SIMPLE, Object.class); - - private final TypeModel superModel; - - @Nullable - private final String varName; - - public TypeSuperModel(String varName, TypeModel typeModel) { - super(objectModel); - this.superModel = typeModel; - this.varName = varName; - } - - public TypeSuperModel(TypeModel typeModel) { - super(objectModel); - this.superModel = typeModel; - this.varName = null; - } - - @Override - public void appendLocalGenericName(TypeModel context, Appendable builder, boolean asArgType) throws IOException { - if (!asArgType){ - builder.append("? super "); - superModel.appendLocalGenericName(context, builder, true); - }else{ - super.appendLocalGenericName(context, builder, asArgType); - } - } - - public String getVarName(){ - return varName; - } -} diff --git a/querydsl-core/src/main/java/com/mysema/query/codegen/Types.java b/querydsl-core/src/main/java/com/mysema/query/codegen/Types.java new file mode 100644 index 000000000..7d8d742c4 --- /dev/null +++ b/querydsl-core/src/main/java/com/mysema/query/codegen/Types.java @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2009 Mysema Ltd. + * All rights reserved. + * + */ +package com.mysema.query.codegen; + +/** + * @author tiwe + * + */ +public final class Types { + + private Types(){} + + public static final Type OBJECTS = new ClassType(TypeCategory.SIMPLE, Object[].class); + + public static final Type OBJECT = new ClassType(TypeCategory.SIMPLE, Object.class); + + public static final Type BOOLEAN = new ClassType(TypeCategory.BOOLEAN, Boolean.class, boolean.class); + + public static final Type BYTE = new ClassType(TypeCategory.NUMERIC, Byte.class, byte.class); + + public static final Type CHAR = new ClassType(TypeCategory.COMPARABLE, Character.class, char.class); + + public static final Type DOUBLE = new ClassType(TypeCategory.NUMERIC, Double.class, double.class); + + public static final Type FLOAT = new ClassType(TypeCategory.NUMERIC, Float.class, float.class); + + public static final Type INT = new ClassType(TypeCategory.NUMERIC, Integer.class, int.class); + + public static final Type LONG = new ClassType(TypeCategory.NUMERIC, Long.class, long.class); + + public static final Type SHORT = new ClassType(TypeCategory.NUMERIC, Short.class, short.class); + + public static final Type STRING = new ClassType(TypeCategory.STRING, String.class); + +} diff --git a/querydsl-core/src/test/java/com/mysema/query/codegen/EntityModelTest.java b/querydsl-core/src/test/java/com/mysema/query/codegen/EntityTypeTest.java similarity index 84% rename from querydsl-core/src/test/java/com/mysema/query/codegen/EntityModelTest.java rename to querydsl-core/src/test/java/com/mysema/query/codegen/EntityTypeTest.java index 899a3e411..22f84fd12 100644 --- a/querydsl-core/src/test/java/com/mysema/query/codegen/EntityModelTest.java +++ b/querydsl-core/src/test/java/com/mysema/query/codegen/EntityTypeTest.java @@ -14,7 +14,7 @@ import org.junit.Test; import com.mysema.query.annotations.QueryExtensions; import com.mysema.util.JavaWriter; -public class EntityModelTest { +public class EntityTypeTest { public static class QueryExt implements QueryExtensions{ @@ -37,8 +37,8 @@ public class EntityModelTest { @Test public void annotation() throws IOException{ Annotation annotation = new QueryExt(Object.class); - ClassTypeModel typeModel = new ClassTypeModel(TypeCategory.ENTITY, Object.class); - EntityModel entityModel = new EntityModel("Q", typeModel); + ClassType typeModel = new ClassType(TypeCategory.ENTITY, Object.class); + EntityType entityModel = new EntityType("Q", typeModel); entityModel.addAnnotation(annotation); TypeMappings typeMappings = new TypeMappings(); diff --git a/querydsl-core/src/test/java/com/mysema/query/codegen/ParameterModelTest.java b/querydsl-core/src/test/java/com/mysema/query/codegen/ParameterModelTest.java deleted file mode 100644 index c61c2d7ce..000000000 --- a/querydsl-core/src/test/java/com/mysema/query/codegen/ParameterModelTest.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 2009 Mysema Ltd. - * All rights reserved. - * - */ -package com.mysema.query.codegen; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import org.junit.Test; - - -public class ParameterModelTest { - - @Test - public void test(){ - ParameterModel param1 = new ParameterModel("test", new ClassTypeModel(TypeCategory.STRING, String.class)); - ParameterModel param2 = new ParameterModel("test2", new ClassTypeModel(TypeCategory.STRING, String.class)); - ParameterModel param3 = new ParameterModel("test2", new ClassTypeModel(TypeCategory.NUMERIC, Integer.class)); - - assertTrue(param1.equals(param2)); - assertFalse(param1.equals(param3)); - assertFalse(param2.equals(param3)); - } -} diff --git a/querydsl-core/src/test/java/com/mysema/query/codegen/ParameterTest.java b/querydsl-core/src/test/java/com/mysema/query/codegen/ParameterTest.java new file mode 100644 index 000000000..4e1af5d5b --- /dev/null +++ b/querydsl-core/src/test/java/com/mysema/query/codegen/ParameterTest.java @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2009 Mysema Ltd. + * All rights reserved. + * + */ +package com.mysema.query.codegen; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; + + +public class ParameterTest { + + @Test + public void test(){ + Parameter param1 = new Parameter("test", new ClassType(TypeCategory.STRING, String.class)); + Parameter param2 = new Parameter("test2", new ClassType(TypeCategory.STRING, String.class)); + Parameter param3 = new Parameter("test2", new ClassType(TypeCategory.NUMERIC, Integer.class)); + + assertTrue(param1.equals(param2)); + assertFalse(param1.equals(param3)); + assertFalse(param2.equals(param3)); + } +} diff --git a/querydsl-core/src/test/java/com/mysema/query/codegen/SerializerTest.java b/querydsl-core/src/test/java/com/mysema/query/codegen/SerializerTest.java index 3759dc3c1..d259f3ac4 100644 --- a/querydsl-core/src/test/java/com/mysema/query/codegen/SerializerTest.java +++ b/querydsl-core/src/test/java/com/mysema/query/codegen/SerializerTest.java @@ -21,19 +21,19 @@ import com.mysema.util.JavaWriter; */ public class SerializerTest { - private EntityModel type; + private EntityType type; private Writer writer = new StringWriter(); public SerializerTest() { - TypeModelFactory typeFactory = new TypeModelFactory(); - TypeModel typeModel = new SimpleTypeModel(TypeCategory.ENTITY, "com.mysema.query.DomainClass", "com.mysema.query", "DomainClass", false); - type = new EntityModel("Q", typeModel, Collections.singleton("com.mysema.query.DomainSuperClass")); + TypeFactory typeFactory = new TypeFactory(); + Type typeModel = new SimpleType(TypeCategory.ENTITY, "com.mysema.query.DomainClass", "com.mysema.query", "DomainClass", false); + type = new EntityType("Q", typeModel); - PropertyModel field = new PropertyModel(type, "field", typeFactory.create(String.class), new String[0]); + Property field = new Property(type, "field", typeFactory.create(String.class), new String[0]); type.addProperty(field); - ParameterModel param = new ParameterModel("name", new ClassTypeModel(TypeCategory.STRING, String.class)); - type.addConstructor(new ConstructorModel(Collections.singleton(param))); + Parameter param = new Parameter("name", new ClassType(TypeCategory.STRING, String.class)); + type.addConstructor(new Constructor(Collections.singleton(param))); } @Test diff --git a/querydsl-core/src/test/java/com/mysema/query/codegen/TypeModelFactoryTest.java b/querydsl-core/src/test/java/com/mysema/query/codegen/TypeFactoryTest.java similarity index 84% rename from querydsl-core/src/test/java/com/mysema/query/codegen/TypeModelFactoryTest.java rename to querydsl-core/src/test/java/com/mysema/query/codegen/TypeFactoryTest.java index f09f473f0..cad56ea02 100644 --- a/querydsl-core/src/test/java/com/mysema/query/codegen/TypeModelFactoryTest.java +++ b/querydsl-core/src/test/java/com/mysema/query/codegen/TypeFactoryTest.java @@ -17,19 +17,19 @@ import org.junit.Test; -public class TypeModelFactoryTest { +public class TypeFactoryTest { - private TypeModelFactory factory = new TypeModelFactory(); + private TypeFactory factory = new TypeFactory(); @Test public void test(){ - TypeModel blob = factory.create(Blob.class); + Type blob = factory.create(Blob.class); // assertEquals("Blob", blob.getLocalName()); assertEquals("Blob", blob.getSimpleName()); assertEquals("java.sql.Blob", blob.getFullName()); assertEquals("java.sql", blob.getPackageName()); - TypeModel bo = factory.create(boolean.class); + Type bo = factory.create(boolean.class); // assertEquals("Boolean", bo.getLocalName()); assertEquals("Boolean", bo.getSimpleName()); assertEquals("java.lang.Boolean", bo.getFullName()); diff --git a/querydsl-core/src/test/java/com/mysema/query/codegen/TypeModelTest.java b/querydsl-core/src/test/java/com/mysema/query/codegen/TypeTest.java similarity index 62% rename from querydsl-core/src/test/java/com/mysema/query/codegen/TypeModelTest.java rename to querydsl-core/src/test/java/com/mysema/query/codegen/TypeTest.java index 57dd15ae1..5d261c902 100644 --- a/querydsl-core/src/test/java/com/mysema/query/codegen/TypeModelTest.java +++ b/querydsl-core/src/test/java/com/mysema/query/codegen/TypeTest.java @@ -9,11 +9,11 @@ import static org.junit.Assert.assertEquals; import org.junit.Test; -public class TypeModelTest { +public class TypeTest { @Test public void arrayType(){ - assertEquals("Object[]",TypeModels.OBJECTS.getLocalRawName(TypeModels.OBJECT)); + assertEquals("Object[]",Types.OBJECTS.getLocalRawName(Types.OBJECT)); } } diff --git a/querydsl-sql/src/main/java/com/mysema/query/sql/MetaDataExporter.java b/querydsl-sql/src/main/java/com/mysema/query/sql/MetaDataExporter.java index 0ba15fd83..e7c35b0e4 100644 --- a/querydsl-sql/src/main/java/com/mysema/query/sql/MetaDataExporter.java +++ b/querydsl-sql/src/main/java/com/mysema/query/sql/MetaDataExporter.java @@ -21,20 +21,20 @@ import javax.annotation.Nullable; import net.jcip.annotations.Immutable; import com.mysema.commons.lang.Assert; -import com.mysema.query.codegen.ClassTypeModel; -import com.mysema.query.codegen.EntityModel; +import com.mysema.query.codegen.ClassType; +import com.mysema.query.codegen.EntityType; import com.mysema.query.codegen.EntitySerializer; -import com.mysema.query.codegen.MethodModel; -import com.mysema.query.codegen.ParameterModel; -import com.mysema.query.codegen.PropertyModel; +import com.mysema.query.codegen.Method; +import com.mysema.query.codegen.Parameter; +import com.mysema.query.codegen.Property; import com.mysema.query.codegen.Serializer; import com.mysema.query.codegen.SerializerConfig; import com.mysema.query.codegen.SimpleSerializerConfig; -import com.mysema.query.codegen.SimpleTypeModel; +import com.mysema.query.codegen.SimpleType; import com.mysema.query.codegen.TypeCategory; import com.mysema.query.codegen.TypeMappings; -import com.mysema.query.codegen.TypeModel; -import com.mysema.query.codegen.TypeModels; +import com.mysema.query.codegen.Type; +import com.mysema.query.codegen.Types; import com.mysema.util.JavaWriter; /** @@ -87,15 +87,15 @@ public class MetaDataExporter { while (tables.next()) { String tableName = tables.getString(3); String simpleClassName = toClassName(tableName); - TypeModel classTypeModel = new SimpleTypeModel( + Type classTypeModel = new SimpleType( TypeCategory.ENTITY, packageName + "." + namePrefix + simpleClassName, packageName, namePrefix + simpleClassName, false); - EntityModel classModel = new EntityModel("", classTypeModel); - MethodModel wildcard = new MethodModel(classModel, "all", "{0}.*", - Collections.emptyList(), TypeModels.OBJECTS); + EntityType classModel = new EntityType("", classTypeModel); + Method wildcard = new Method(classModel, "all", "{0}.*", + Collections.emptyList(), Types.OBJECTS); classModel.addMethod(wildcard); classModel.addAnnotation(new TableImpl(tableName)); ResultSet columns = md.getColumns(null, schemaPattern, tables.getString(3), null); @@ -118,8 +118,8 @@ public class MetaDataExporter { fieldType = TypeCategory.COMPARABLE; } - TypeModel typeModel = new ClassTypeModel(fieldType, clazz); - classModel.addProperty(new PropertyModel( + Type typeModel = new ClassType(fieldType, clazz); + classModel.addProperty(new Property( classModel, columnName, propertyName, @@ -158,7 +158,7 @@ public class MetaDataExporter { return builder.toString(); } - private void serialize(EntityModel type) { + private void serialize(EntityType type) { String path = packageName.replace('.', '/') + "/" + type.getSimpleName() + ".java"; try { Writer writer = writerFor(new File(targetFolder, path));