Elements eUtils = processingEnv.getElementUtils();
String originalClass = eUtils.getBinaryName((TypeElement) e).toString();
String originalSimpleClass = e.getSimpleName().toString();
String metaClass = factory.getMetaModelClassName(originalClass);
SourceCode source = new SourceCode(metaClass);
comment(source);
annotate(source, originalClass);
TypeElement supCls = handler.getPersistentSupertype(e);
if (supCls != null) {
String superName = factory.getMetaModelClassName(supCls.toString());
source.getTopLevelClass().setSuper(superName);
}
try {
PrintWriter writer = createSourceFile(originalClass, metaClass, e);
SourceCode.Class modelClass = source.getTopLevelClass();
Set<? extends Element> members = handler.getPersistentMembers(e);
for (Element m : members) {
boolean isPersistentCollection = m.getAnnotation(PersistentCollection.class) != null;
TypeMirror decl = handler.getDeclaredType(m);
String fieldName = handler.getPersistentMemberName(m);
String fieldType = handler.getDeclaredTypeName(decl, true, isPersistentCollection);
TypeCategory typeCategory =
toMetaModelTypeCategory(decl, fieldType, isPersistentCollection);
String metaModelType = typeCategory.getMetaModelType();
SourceCode.Field modelField = null;
switch (typeCategory) {
case ATTRIBUTE:
modelField = modelClass.addField(fieldName, metaModelType);
modelField.addParameter(originalSimpleClass)
.addParameter(fieldType);
break;
case COLLECTION:
case LIST:
case SET:
TypeMirror param = handler.getTypeParameter(m, decl, 0, true);
String elementType = handler.getDeclaredTypeName(param);
modelField = modelClass.addField(fieldName, metaModelType);
modelField.addParameter(originalSimpleClass)
.addParameter(elementType);
break;
case MAP:
TypeMirror key = handler.getTypeParameter(m, decl, 0, false);
TypeMirror value = handler.getTypeParameter(m, decl, 1, true);
String keyType = handler.getDeclaredTypeName(key);
String valueType = handler.getDeclaredTypeName(value);
modelField = modelClass.addField(fieldName, metaModelType);
modelField.addParameter(originalSimpleClass)
.addParameter(keyType)
.addParameter(valueType);
break;
}
modelField.makePublic().makeStatic().makeVolatile();
}
source.write(writer);
writer.flush();
writer.close();
return true;
} catch (Exception e1) {
logger.error(_loc.get("mmg-process-error", e.getQualifiedName()), e1);