From d70b100c4c74cc5f2a11103d00c8a42cb7dbcaf4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20Westk=C3=A4mper?= Date: Fri, 17 Apr 2009 13:53:26 +0000 Subject: [PATCH] added stub for improved supertype handling in APT class generation --- .../query/apt/general/GeneralProcessor.java | 52 +++++++++++++++---- 1 file changed, 42 insertions(+), 10 deletions(-) diff --git a/querydsl-apt/src/main/java/com/mysema/query/apt/general/GeneralProcessor.java b/querydsl-apt/src/main/java/com/mysema/query/apt/general/GeneralProcessor.java index 070c4168e..94e26b840 100644 --- a/querydsl-apt/src/main/java/com/mysema/query/apt/general/GeneralProcessor.java +++ b/querydsl-apt/src/main/java/com/mysema/query/apt/general/GeneralProcessor.java @@ -16,6 +16,7 @@ import java.util.HashMap; import java.util.Map; import com.mysema.query.apt.FreeMarkerSerializer; +import com.mysema.query.apt.model.Field; import com.mysema.query.apt.model.Type; import com.sun.mirror.apt.AnnotationProcessor; import com.sun.mirror.apt.AnnotationProcessorEnvironment; @@ -56,17 +57,48 @@ public abstract class GeneralProcessor implements AnnotationProcessor { private void addSupertypeFields(Type typeDecl, Map entityTypes, Map mappedSupertypes) { String stype = typeDecl.getSupertypeName(); - while (true) { - Type sdecl; - if (entityTypes.containsKey(stype)) { - sdecl = entityTypes.get(stype); - } else if (mappedSupertypes.containsKey(stype)) { - sdecl = mappedSupertypes.get(stype); - } else { - return; + Class superClass = safeClassForName(stype); + if (superClass == null){ + while (true) { + Type sdecl; + if (entityTypes.containsKey(stype)) { + sdecl = entityTypes.get(stype); + } else if (mappedSupertypes.containsKey(stype)) { + sdecl = mappedSupertypes.get(stype); + } else { + return; + } + typeDecl.include(sdecl); + stype = sdecl.getSupertypeName(); + } + + }else if (!superClass.equals(Object.class)){ + /*// TODO : recursively up ? + Type type = new Type(superClass.getSuperclass().getName(), + superClass.getPackage().getName(), + superClass.getName(), + superClass.getSimpleName()); + for (java.lang.reflect.Field f : superClass.getDeclaredFields()){ + Field field = new Field( + FieldHelper.javaSafe(f.getName()), // name + FieldHelper.realName(f.getName()), // realName + null, // keyTypeName + f.getType().getPackage().getName(), + f.getType().getName(), + f.getType().getSimpleName(), + null); + type.addField(field); } - typeDecl.include(sdecl); - stype = sdecl.getSupertypeName(); + // include fields of supertype + typeDecl.include(type);*/ + } + } + + private Class safeClassForName(String stype) { + try { + return stype != null ? Class.forName(stype) : null; + } catch (ClassNotFoundException e) { + return null; } }