convertComplexTypesToSimpleTypes((ClassOutlineImpl) classOutline);
}
}
private void convertComplexTypesToSimpleTypes(final ClassOutlineImpl cc) {
final JDefinedClass implClass = cc.implClass;
// if no fields are present return
if (implClass.fields().isEmpty()) {
return;
}
for (final JFieldVar jFieldVar : implClass.fields().values()) {
if (jFieldVar.name().equals("coordinates")) {
LOG.info("1+++ " + cc.implRef.name() + " " + jFieldVar.type().name() + " " + jFieldVar.name());
final JDefinedClass candidateClass = cc.implClass;
final JClass newInterfaceClass = candidateClass.owner().ref(interfaceClass).narrow(pool.getClassCoordinate());
final JClass newCollectionClass = candidateClass.owner().ref(collectionClass).narrow(pool.getClassCoordinate());
jFieldVar.type(newInterfaceClass);
// Find original getter and setter methods to remove.
final ArrayList<JMethod> methodsToRemove = new ArrayList<JMethod>();
for (final JMethod m : candidateClass.methods()) {
if (m.name().equals("set" + Util.upperFirst(jFieldVar.name())) || m.name().equals("get" + Util.upperFirst(jFieldVar.name()))) {
methodsToRemove.add(m);
}
}
// Remove original getter and setter methods.
for (final JMethod m : methodsToRemove) {
candidateClass.methods().remove(m);
}
// Add a new getter method returning the (wrapped) field added.
// CODE: public I<T> getFieldname() { ... };
final JMethod method = candidateClass.method(JMod.PUBLIC, newInterfaceClass, "get" + Util.upperFirst(jFieldVar.name()));
// CODE: if (fieldName == null) fieldName = new C<T>();
method.body()._if(JExpr.ref(jFieldVar.name()).eq(JExpr._null()))._then().assign(JExpr.ref(jFieldVar.name()),
JExpr._new(newCollectionClass));