mirror of
https://github.com/querydsl/querydsl.git
synced 2026-06-30 21:08:30 +08:00
improved primitive handling
This commit is contained in:
parent
e2612fb9e1
commit
246fbbbe64
@ -204,34 +204,25 @@ public class APTModelFactory implements TypeVisitor<TypeModel,Elements> {
|
||||
|
||||
@Override
|
||||
public TypeModel visitPrimitive(PrimitiveType t, Elements p) {
|
||||
Class<?> cl = null;
|
||||
switch (t.getKind()) {
|
||||
case BOOLEAN:
|
||||
cl = Boolean.class;
|
||||
break;
|
||||
return new ClassTypeModel(TypeCategory.BOOLEAN, Boolean.class, boolean.class);
|
||||
case BYTE:
|
||||
cl = Byte.class;
|
||||
break;
|
||||
return new ClassTypeModel(TypeCategory.NUMERIC, Byte.class, byte.class);
|
||||
case CHAR:
|
||||
cl = Character.class;
|
||||
break;
|
||||
return new ClassTypeModel(TypeCategory.COMPARABLE, Character.class, char.class);
|
||||
case DOUBLE:
|
||||
cl = Double.class;
|
||||
break;
|
||||
return new ClassTypeModel(TypeCategory.NUMERIC, Double.class, double.class);
|
||||
case FLOAT:
|
||||
cl = Float.class;
|
||||
break;
|
||||
return new ClassTypeModel(TypeCategory.NUMERIC, Float.class, float.class);
|
||||
case INT:
|
||||
cl = Integer.class;
|
||||
break;
|
||||
return new ClassTypeModel(TypeCategory.NUMERIC, Integer.class, int.class);
|
||||
case LONG:
|
||||
cl = Long.class;
|
||||
break;
|
||||
return new ClassTypeModel(TypeCategory.NUMERIC, Long.class, long.class);
|
||||
case SHORT:
|
||||
cl = Short.class;
|
||||
break;
|
||||
return new ClassTypeModel(TypeCategory.NUMERIC, Short.class, short.class);
|
||||
}
|
||||
return new ClassTypeModel(TypeCategory.get(cl.getName()), cl);
|
||||
throw new IllegalArgumentException("Unsupported type " + t);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -17,11 +17,15 @@ public class ClassTypeModel implements TypeModel{
|
||||
private final Class<?> primitiveClass;
|
||||
|
||||
public ClassTypeModel(TypeCategory typeCategory, Class<?> clazz){
|
||||
this(typeCategory, clazz, ClassUtils.wrapperToPrimitive(clazz));
|
||||
}
|
||||
|
||||
public ClassTypeModel(TypeCategory typeCategory, Class<?> clazz, Class<?> primitiveClass){
|
||||
this.typeCategory = Assert.notNull(typeCategory);
|
||||
this.clazz = Assert.notNull(clazz);
|
||||
this.primitiveClass = ClassUtils.wrapperToPrimitive(clazz);
|
||||
this.primitiveClass = primitiveClass;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public TypeModel as(TypeCategory category) {
|
||||
if (typeCategory == category){
|
||||
|
||||
@ -5,8 +5,6 @@
|
||||
*/
|
||||
package com.mysema.query.codegen;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.BigInteger;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
@ -30,9 +28,9 @@ public enum TypeCategory {
|
||||
*/
|
||||
SIMPLE(null),
|
||||
/**
|
||||
* Comparable literal fields
|
||||
* Comparable literal fields (? extends Comparable)
|
||||
*/
|
||||
COMPARABLE(SIMPLE, Comparable.class.getName(), Character.class.getName(), "org.joda.time.Partial"),
|
||||
COMPARABLE(SIMPLE, Comparable.class.getName(),"org.joda.time.Partial"),
|
||||
/**
|
||||
* Boolean files
|
||||
*/
|
||||
@ -68,12 +66,9 @@ public enum TypeCategory {
|
||||
*/
|
||||
ENTITYMAP(null),
|
||||
/**
|
||||
* Numeric fields
|
||||
* Numeric fields (? extends Number & Comparable)
|
||||
*/
|
||||
NUMERIC(COMPARABLE,
|
||||
Long.class.getName(), Integer.class.getName(), Byte.class.getName(),
|
||||
Double.class.getName(), Float.class.getName(), Short.class.getName(),
|
||||
BigDecimal.class.getName(), BigInteger.class.getName()),
|
||||
NUMERIC(COMPARABLE),
|
||||
/**
|
||||
* Simple collection fields
|
||||
*/
|
||||
|
||||
Loading…
Reference in New Issue
Block a user