#628838 : made sure that entity annotated enum Q-types extends PEnum

This commit is contained in:
Timo Westkämper 2010-09-02 14:08:34 +00:00
parent 9cc22068f1
commit 209f89ea99
5 changed files with 133 additions and 34 deletions

View File

@ -155,13 +155,6 @@ public final class APTTypeFactory {
}
private Type createClassType(DeclaredType t, TypeElement typeElement) {
// entity type
for (Class<? extends Annotation> entityAnn : entityAnnotations){
if (typeElement.getAnnotation(entityAnn) != null){
return create(typeElement, TypeCategory.ENTITY, t.getTypeArguments());
}
}
// other
String name = typeElement.getQualifiedName().toString();
TypeCategory typeCategory = TypeCategory.get(name);
@ -175,7 +168,25 @@ public final class APTTypeFactory {
&& isImplemented(typeElement, comparableType)){
typeCategory = TypeCategory.COMPARABLE;
}
return create(typeElement, typeCategory, t.getTypeArguments());
if (typeCategory == TypeCategory.SIMPLE){
for (Class<? extends Annotation> entityAnn : entityAnnotations){
if (typeElement.getAnnotation(entityAnn) != null){
typeCategory = TypeCategory.ENTITY;
}
}
}
Type type = create(typeElement, typeCategory, t.getTypeArguments());
// entity type
for (Class<? extends Annotation> entityAnn : entityAnnotations){
if (typeElement.getAnnotation(entityAnn) != null){
return new EntityType(configuration.getNamePrefix(), type);
}
}
return type;
}
private Type createCollectionType(String simpleName,
@ -196,7 +207,12 @@ public final class APTTypeFactory {
entityTypeCache.put(key, null);
Type value = handle(type);
if (value != null){
EntityType entityModel = new EntityType(configuration.getNamePrefix(), value);
EntityType entityModel = null;
if (value instanceof EntityType){
entityModel = (EntityType)value;
}else{
entityModel = new EntityType(configuration.getNamePrefix(), value);
}
entityTypeCache.put(key, entityModel);
if (key.size() > 1 && key.get(0).equals(entityModel.getFullName()) && doubleIndexEntities){
@ -221,14 +237,15 @@ public final class APTTypeFactory {
}
private Type createEnumType(DeclaredType t, TypeElement typeElement) {
// fallback
Type enumType = create(typeElement, TypeCategory.ENUM, t.getTypeArguments());
for (Class<? extends Annotation> entityAnn : entityAnnotations){
if (typeElement.getAnnotation(entityAnn) != null){
return create(typeElement, TypeCategory.ENTITY, t.getTypeArguments());
return new EntityType(configuration.getNamePrefix(), enumType);
}
}
// fallback
return create(typeElement, TypeCategory.ENUM, t.getTypeArguments());
}
return enumType;
}
private Type createInterfaceType(DeclaredType t, TypeElement typeElement) {

View File

@ -0,0 +1,37 @@
package com.mysema.query.domain;
import static org.junit.Assert.*;
import org.junit.Test;
import com.mysema.query.annotations.QueryEmbeddable;
import com.mysema.query.annotations.QueryEntity;
public class ComparableTest {
@QueryEntity
public class CustomComparable implements Comparable<CustomComparable>{
@Override
public int compareTo(CustomComparable o) {
return 0;
}
}
@QueryEmbeddable
public class CustomComparable2 implements Comparable<CustomComparable2>{
@Override
public int compareTo(CustomComparable2 o) {
return 0;
}
}
@Test
public void test(){
assertNotNull(QComparableTest_CustomComparable.customComparable.asc());
}
}

View File

@ -0,0 +1,36 @@
package com.mysema.query.domain;
import static org.junit.Assert.*;
import org.junit.Test;
import com.mysema.query.annotations.QueryEmbeddable;
import com.mysema.query.annotations.QueryEntity;
public class EnumTest {
@QueryEntity
public enum Gender {
MALE,
FEMALE
}
@QueryEmbeddable
public enum Gender2 {
MALE,
FEMALE
}
@QueryEntity
public class Bean {
Gender gender;
}
@Test
public void test(){
assertNotNull(QEnumTest_Gender.gender.asc());
assertNotNull(QEnumTest_Gender.gender.ordinal().asc());
}
}

View File

@ -43,16 +43,20 @@ public final class EmbeddableSerializer extends EntitySerializer{
TypeCategory category = model.getOriginalCategory();
Class<? extends Path> pathType;
switch(category){
case COMPARABLE : pathType = PComparable.class; break;
case ENUM: pathType = PEnum.class; break;
case DATE: pathType = PDate.class; break;
case DATETIME: pathType = PDateTime.class; break;
case TIME: pathType = PTime.class; break;
case NUMERIC: pathType = PNumber.class; break;
case STRING: pathType = PString.class; break;
case BOOLEAN: pathType = PBoolean.class; break;
default : pathType = BeanPath.class;
if (model.getProperties().isEmpty()){
switch(category){
case COMPARABLE : pathType = PComparable.class; break;
case ENUM: pathType = PEnum.class; break;
case DATE: pathType = PDate.class; break;
case DATETIME: pathType = PDateTime.class; break;
case TIME: pathType = PTime.class; break;
case NUMERIC: pathType = PNumber.class; break;
case STRING: pathType = PString.class; break;
case BOOLEAN: pathType = PBoolean.class; break;
default : pathType = BeanPath.class;
}
}else{
pathType = BeanPath.class;
}
for (Annotation annotation : model.getAnnotations()){

View File

@ -238,16 +238,21 @@ public class EntitySerializer implements Serializer{
TypeCategory category = model.getOriginalCategory();
Class<? extends Path> pathType;
switch(category){
case COMPARABLE : pathType = PComparable.class; break;
case ENUM: pathType = PEnum.class; break;
case DATE: pathType = PDate.class; break;
case DATETIME: pathType = PDateTime.class; break;
case TIME: pathType = PTime.class; break;
case NUMERIC: pathType = PNumber.class; break;
case STRING: pathType = PString.class; break;
case BOOLEAN: pathType = PBoolean.class; break;
default : pathType = EntityPathBase.class;
if (model.getProperties().isEmpty()){
switch(category){
case COMPARABLE : pathType = PComparable.class; break;
case ENUM: pathType = PEnum.class; break;
case DATE: pathType = PDate.class; break;
case DATETIME: pathType = PDateTime.class; break;
case TIME: pathType = PTime.class; break;
case NUMERIC: pathType = PNumber.class; break;
case STRING: pathType = PString.class; break;
case BOOLEAN: pathType = PBoolean.class; break;
default : pathType = EntityPathBase.class;
}
}else{
pathType = EntityPathBase.class;
}
for (Annotation annotation : model.getAnnotations()){