/** * Flattens a parameterized type into a simple list of types. */ private void createTypeList(List<JType> accumulator, JType type) { accumulator.add(type); JParameterizedType hasParams = type.isParameterized(); if (hasParams != null) { for (JClassType arg : hasParams.getTypeArgs()) { createTypeList(accumulator, arg); } } }
private void writeAutoBean(AutoBeanType type) throws UnableToCompleteException { PrintWriter pw = context.tryCreate(logger, type.getPackageNome(), type.getSimpleSourceName()); if (pw == null) { new ClassSourceFileComposerFactory(type.getPackageNome(), type.getSimpleSourceName()); factory.setSuperclass(AbstractAutoBean.class.getCanonicalName() + "<" + type.getPeerType().getQualifiedSourceName() + ">"); SourceWriter sw = factory.createSourceWriter(context, pw); writeShim(sw, type); if (type.isSimpleBean()) { sw.println("public %s(%s factory) {super(factory);}", type.getSimpleSourceName(), AutoBeanFactory.class.getCanonicalName()); sw.println("public %s(%s factory, %s wrapped) {", type.getSimpleSourceName(), AutoBeanFactory.class.getCanonicalName(), type.getPeerType().getQualifiedSourceName()); sw.indentln("super(wrapped, factory);"); sw.println("}"); sw.println("public %s as() {return shim;}", type.getPeerType().getQualifiedSourceName()); type.getPeerType()).getQualifiedSourceName()); if (type.isSimpleBean()) { writeCreateSimpleBean(sw, type); writeTraversal(sw, type); sw.commit(logger);
model = new AutoBeanFactoryModel(logger, toGenerate); factory.addImplementedInterface(typeName); SourceWriter sw = factory.createSourceWriter(context, pw); for (AutoBeanType type : model.getAllTypes()) { writeAutoBean(type); writeDynamicMethods(sw); writeEnumSetup(sw); writeMethods(sw); sw.commit(logger);
sw.println("%1$s as = as();", type.getPeerType().getQualifiedSourceName()); for (AutoBeanMethod method : type.getMethods()) { if (!method.getAction().equals(JBeanMethod.GET)) { continue; if (!type.isSimpleBean()) { for (AutoBeanMethod maybeSetter : type.getMethods()) { boolean isASetter = maybeSetter.getAction().equals(JBeanMethod.SET) || maybeSetter.getAction().equals(JBeanMethod.SET_BUILDER); if (isASetter && maybeSetter.getPropertyName().equals(method.getPropertyName())) { setter = maybeSetter; break; .getCanonicalName(), AutoBeanUtils.class.getCanonicalName(), method.getMethod() .getName()); String visitMethod; String visitVariable = "bean"; if (method.isCollection()) { visitMethod = "Collection"; } else if (method.isMap()) { visitMethod = "Map"; } else if (method.isValueType()) { valueExpression = String.format("value = as.%s();", method.getMethod().getName()); visitMethod = "Value"; visitVariable = "value"; createTypeList(typeList, method.getMethod().getReturnType());
sw.println("@Override protected %s createSimplePeer() {", type.getPeerType() .getQualifiedSourceName()); sw.indent(); sw.println("return new %s() {", type.getPeerType().getQualifiedSourceName()); sw.indent(); sw.println("private final %s data = %s.this.data;", Splittable.class.getCanonicalName(), type .getQualifiedSourceName()); for (AutoBeanMethod method : type.getMethods()) { JMethod jmethod = method.getMethod(); JType returnType = jmethod.getReturnType(); sw.println("public %s {", getBaseMethodDeclaration(jmethod)); sw.indent(); switch (method.getAction()) { case GET: { String castType; .getSimpleSourceName(), method.getPropertyName()); Splittable.class.getCanonicalName()))) { sw.println("return data.isNull(\"%1$s\") ? null : data.get(\"%1$s\");", method .getPropertyName()); } else { .getSimpleSourceName(), method.getPropertyName()); sw.println("%s.this.setProperty(\"%s\", %s);", type.getSimpleSourceName(), method .getPropertyName(), param.getName()); if (JBeanMethod.SET_BUILDER.equals(method.getAction())) {
sw.println("private final %1$s shim = new %1$s() {", type.getPeerType() .getQualifiedSourceName()); sw.indent(); for (AutoBeanMethod method : type.getMethods()) { JMethod jmethod = method.getMethod(); String methodName = jmethod.getName(); JParameter[] parameters = jmethod.getParameters(); if (isObjectMethodImplementedByShim(jmethod)) { sw.println("public %s {", getBaseMethodDeclaration(jmethod)); sw.indent(); switch (method.getAction()) { case GET: .getQualifiedBaseSourceName(jmethod.getReturnType()), type.getSimpleSourceName(), methodName); writeReturnWrapper(sw, type, method); sw.println("return toReturn;"); break; sw.println("%s.this.getWrapped().%s(%s);", type.getSimpleSourceName(), methodName, parameters[0].getName()); sw.println("%s.this.set(\"%s\", %s);", type.getSimpleSourceName(), methodName, parameters[0].getName()); if (JBeanMethod.SET_BUILDER.equals(method.getAction())) { sw.println("return this;");
sw.println("%1$s as = as();", type.getPeerType().getQualifiedSourceName()); for (AutoBeanMethod method : type.getMethods()) { if (!method.getAction().equals(JBeanMethod.GET)) { continue; if (!type.isSimpleBean()) { for (AutoBeanMethod maybeSetter : type.getMethods()) { boolean isASetter = maybeSetter.getAction().equals(JBeanMethod.SET) || maybeSetter.getAction().equals(JBeanMethod.SET_BUILDER); if (isASetter && maybeSetter.getPropertyName().equals(method.getPropertyName())) { setter = maybeSetter; break; .getCanonicalName(), AutoBeanUtils.class.getCanonicalName(), method.getMethod() .getName()); String visitMethod; String visitVariable = "bean"; if (method.isCollection()) { visitMethod = "Collection"; } else if (method.isMap()) { visitMethod = "Map"; } else if (method.isValueType()) { valueExpression = String.format("value = as.%s();", method.getMethod().getName()); visitMethod = "Value"; visitVariable = "value"; createTypeList(typeList, method.getMethod().getReturnType());
sw.println("@Override protected %s createSimplePeer() {", type.getPeerType() .getQualifiedSourceName()); sw.indent(); sw.println("return new %s() {", type.getPeerType().getQualifiedSourceName()); sw.indent(); sw.println("private final %s data = %s.this.data;", Splittable.class.getCanonicalName(), type .getQualifiedSourceName()); for (AutoBeanMethod method : type.getMethods()) { JMethod jmethod = method.getMethod(); JType returnType = jmethod.getReturnType(); sw.println("public %s {", getBaseMethodDeclaration(jmethod)); sw.indent(); switch (method.getAction()) { case GET: { String castType; .getSimpleSourceName(), method.getPropertyName()); Splittable.class.getCanonicalName()))) { sw.println("return data.isNull(\"%1$s\") ? null : data.get(\"%1$s\");", method .getPropertyName()); } else { .getSimpleSourceName(), method.getPropertyName()); sw.println("%s.this.setProperty(\"%s\", %s);", type.getSimpleSourceName(), method .getPropertyName(), param.getName()); if (JBeanMethod.SET_BUILDER.equals(method.getAction())) {
sw.println("private final %1$s shim = new %1$s() {", type.getPeerType() .getQualifiedSourceName()); sw.indent(); for (AutoBeanMethod method : type.getMethods()) { JMethod jmethod = method.getMethod(); String methodName = jmethod.getName(); JParameter[] parameters = jmethod.getParameters(); if (isObjectMethodImplementedByShim(jmethod)) { sw.println("public %s {", getBaseMethodDeclaration(jmethod)); sw.indent(); switch (method.getAction()) { case GET: .getQualifiedBaseSourceName(jmethod.getReturnType()), type.getSimpleSourceName(), methodName); writeReturnWrapper(sw, type, method); sw.println("return toReturn;"); break; sw.println("%s.this.getWrapped().%s(%s);", type.getSimpleSourceName(), methodName, parameters[0].getName()); sw.println("%s.this.set(\"%s\", %s);", type.getSimpleSourceName(), methodName, parameters[0].getName()); if (JBeanMethod.SET_BUILDER.equals(method.getAction())) { sw.println("return this;");
private void writeAutoBean(AutoBeanType type) throws UnableToCompleteException { PrintWriter pw = context.tryCreate(logger, type.getPackageNome(), type.getSimpleSourceName()); if (pw == null) { new ClassSourceFileComposerFactory(type.getPackageNome(), type.getSimpleSourceName()); factory.setSuperclass(AbstractAutoBean.class.getCanonicalName() + "<" + type.getPeerType().getQualifiedSourceName() + ">"); SourceWriter sw = factory.createSourceWriter(context, pw); writeShim(sw, type); if (type.isSimpleBean()) { sw.println("public %s(%s factory) {super(factory);}", type.getSimpleSourceName(), AutoBeanFactory.class.getCanonicalName()); sw.println("public %s(%s factory, %s wrapped) {", type.getSimpleSourceName(), AutoBeanFactory.class.getCanonicalName(), type.getPeerType().getQualifiedSourceName()); sw.indentln("super(wrapped, factory);"); sw.println("}"); sw.println("public %s as() {return shim;}", type.getPeerType().getQualifiedSourceName()); type.getPeerType()).getQualifiedSourceName()); if (type.isSimpleBean()) { writeCreateSimpleBean(sw, type); writeTraversal(sw, type); sw.commit(logger);
model = new AutoBeanFactoryModel(logger, toGenerate); factory.addImplementedInterface(typeName); SourceWriter sw = factory.createSourceWriter(context, pw); for (AutoBeanType type : model.getAllTypes()) { writeAutoBean(type); writeDynamicMethods(sw); writeEnumSetup(sw); writeMethods(sw); sw.commit(logger);
/** * Flattens a parameterized type into a simple list of types. */ private void createTypeList(List<JType> accumulator, JType type) { accumulator.add(type); JParameterizedType hasParams = type.isParameterized(); if (hasParams != null) { for (JClassType arg : hasParams.getTypeArgs()) { createTypeList(accumulator, arg); } } }