fixed inner class handling

This commit is contained in:
Timo Westkämper 2011-02-23 13:08:36 +00:00
parent 6237419d24
commit 06fd2ccc4d
2 changed files with 37 additions and 9 deletions

View File

@ -45,7 +45,7 @@ import com.mysema.query.types.template.TimeTemplate;
/**
* TypeMappings defines mappings from Java types to {@link Expression}, {@link Path} and {@link TemplateExpression} types
*
*
* @author tiwe
*
*/
@ -56,7 +56,7 @@ public final class TypeMappings {
private final Map<TypeCategory, ClassType> pathTypes = new HashMap<TypeCategory, ClassType>();
private final Map<TypeCategory, ClassType> templateTypes = new HashMap<TypeCategory, ClassType>();
public TypeMappings(){
register(TypeCategory.STRING, StringExpression.class, StringPath.class, StringTemplate.class);
register(TypeCategory.BOOLEAN, BooleanExpression.class, BooleanPath.class, BooleanTemplate.class);
@ -111,7 +111,7 @@ public final class TypeMappings {
TypeCategory category = type.getCategory();
if (raw && category != TypeCategory.ENTITY && category != TypeCategory.CUSTOM){
return exprType;
}else if (category == TypeCategory.STRING || category == TypeCategory.BOOLEAN){
return exprType;
@ -119,14 +119,14 @@ public final class TypeMappings {
String packageName = type.getPackageName();
String simpleName;
if (type.getPackageName().isEmpty()){
simpleName = model.getPrefix()+type.getFullName().replace('.', '_')+model.getSuffix();
simpleName = model.getPrefix() + normalizeName(type.getFullName()) + model.getSuffix();
return new SimpleType(category, simpleName, "", simpleName, false, false);
}else{
simpleName = model.getPrefix()+type.getFullName().substring(packageName.length()+1).replace('.', '_')+model.getSuffix();
}else{
simpleName = model.getPrefix() + normalizeName(type.getFullName().substring(packageName.length()+1)) + model.getSuffix();
return new SimpleType(category, packageName+"."+simpleName, packageName, simpleName, false, false);
}
}else{
}else{
if (rawParameters){
type = new SimpleType(type);
}
@ -134,10 +134,14 @@ public final class TypeMappings {
type = new TypeExtends(type);
}
return new SimpleType(exprType, type);
}
}
private String normalizeName(String name){
return name.replace('.', '_').replace('$', '_');
}
@SuppressWarnings("unchecked")
public void register(TypeCategory category,
Class<? extends Expression> expr,

View File

@ -0,0 +1,24 @@
package com.mysema.query.codegen;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
import com.mysema.codegen.model.ClassType;
import com.mysema.codegen.model.Type;
public class TypeMappingsTest {
static class Entity{
}
@Test
public void GetPathType_Of_InnerClass(){
TypeMappings typeMappings = new TypeMappings();
EntityType model = new EntityType("Q","", new ClassType(TypeMappingsTest.class));
EntityType type = new EntityType("Q","", new ClassType(Entity.class));
Type pathType = typeMappings.getPathType(type, model, false);
assertEquals("QTypeMappingsTest_Entity", pathType.getSimpleName());
}
}