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); 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);
public String getQualifiedSourceName() { return getPackageNome() + "." + getSimpleSourceName(); }
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(); .getSimpleSourceName(), method.getPropertyName()); .getSimpleSourceName(), method.getPropertyName()); JParameter param = jmethod.getParameters()[0]; sw.println("%s.this.setProperty(\"%s\", %s);", type.getSimpleSourceName(), method .getPropertyName(), param.getName()); if (JBeanMethod.SET_BUILDER.equals(method.getAction())) { staticImpl.getName(), type.getSimpleSourceName()); for (JParameter param : jmethod.getParameters()) { sw.print(", %s", param.getName());
sw.indent(); for (AutoBeanType type : model.getAllTypes()) { if (type.isNoWrap()) { continue; JClassType peer = type.getPeerType(); String peerName = ModelUtils.ensureBaseType(peer).getQualifiedSourceName(); if (peer.isPublic()) { .getJNISignature(); for (AutoBeanType type : model.getAllTypes()) { String peerName = ModelUtils.ensureBaseType(type.getPeerType()).getQualifiedSourceName(); String peerJNIName = ModelUtils.ensureBaseType(type.getPeerType()).getJNISignature(); sw.indent(); sw.println("return ["); if (type.isSimpleBean()) { sw.indentln("@%s::new(%s),", type.getQualifiedSourceName(), factoryJNIName); } else { sw.indentln(","); sw.indentln("@%s::new(%s%s)", type.getQualifiedSourceName(), factoryJNIName, peerJNIName); sw.println("];"); sw.outdent();
sw.println("%s propertyContext;", ClientPropertyContext.class.getCanonicalName()); 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) .getCanonicalName(), type.getSimpleSourceName(), method.getPropertyName());
private void writeReturnWrapper(SourceWriter sw, AutoBeanType type, AutoBeanMethod method) throws UnableToCompleteException { if (!method.isValueType() && !method.isNoWrap()) { JMethod jmethod = method.getMethod(); JClassType returnClass = jmethod.getReturnType().isClassOrInterface(); AutoBeanType peer = model.getPeer(returnClass); sw.println("if (toReturn != null) {"); sw.indent(); sw.println("if (%s.this.isWrapped(toReturn)) {", type.getSimpleSourceName()); sw.indentln("toReturn = %s.this.getFromWrapper(toReturn);", type.getSimpleSourceName()); sw.println("} else {"); sw.indent(); if (peer != null) { // toReturn = new FooAutoBean(getFactory(), toReturn).as(); sw.println("toReturn = new %s(getFactory(), toReturn).as();", peer.getQualifiedSourceName()); } sw.outdent(); sw.println("}"); sw.outdent(); sw.println("}"); } // Allow return values to be intercepted JMethod interceptor = type.getInterceptor(); if (interceptor != null) { // toReturn = FooCategory.__intercept(FooAutoBean.this, toReturn); sw.println("toReturn = %s.%s(%s.this, toReturn);", interceptor.getEnclosingType() .getQualifiedSourceName(), interceptor.getName(), type.getSimpleSourceName()); } }
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(); .getQualifiedBaseSourceName(jmethod.getReturnType()), type.getSimpleSourceName(), methodName); 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("%s.this.getWrapped().%s(%s);", type.getSimpleSourceName(), methodName, arguments); sw.println("%s.this.call(\"%s\", null%s %s);", type.getSimpleSourceName(), methodName, arguments.length() > 0 ? "," : "", arguments); } else { jmethod.getReturnType()).getQualifiedSourceName(), type.getSimpleSourceName(), methodName, arguments); sw.println("%s.this.call(\"%s\", toReturn%s %s);", type.getSimpleSourceName(), methodName, arguments.length() > 0 ? "," : "", arguments);
if (!autoBeanType.isSimpleBean() && toWrap == null) { if (categoryTypes != null) { poison("The %s parameterization is not simple and the following" + " methods did not have static implementations:", beanType.getQualifiedSourceName()); for (AutoBeanMethod missing : autoBeanType.getMethods()) { if (missing.getAction().equals(JBeanMethod.CALL) && missing.getStaticImpl() == null) {
private void writeMethods(SourceWriter sw) throws UnableToCompleteException { for (AutoBeanFactoryMethod method : model.getMethods()) { AutoBeanType autoBeanType = method.getAutoBeanType(); // public AutoBean<Foo> foo(FooSubtype wrapped) { sw.println("public %s %s(%s) {", method.getReturnType().getQualifiedSourceName(), method .getName(), method.isWrapper() ? (method.getWrappedType().getQualifiedSourceName() + " wrapped") : ""); if (method.isWrapper()) { sw.indent(); // AutoBean<Foo> toReturn = AutoBeanUtils.getAutoBean(wrapped); sw.println("%s toReturn = %s.getAutoBean(wrapped);", method.getReturnType() .getParameterizedQualifiedSourceName(), AutoBeanUtils.class.getCanonicalName()); sw.println("if (toReturn != null) {return toReturn;}"); // return new FooAutoBean(Factory.this, wrapped); sw.println("return new %s(%s.this, wrapped);", autoBeanType.getQualifiedSourceName(), simpleSourceName); sw.outdent(); } else { // return new FooAutoBean(Factory.this); sw.indentln("return new %s(%s.this);", autoBeanType.getQualifiedSourceName(), simpleSourceName); } sw.println("}"); } }
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(); .getSimpleSourceName(), method.getPropertyName()); .getSimpleSourceName(), method.getPropertyName()); JParameter param = jmethod.getParameters()[0]; sw.println("%s.this.setProperty(\"%s\", %s);", type.getSimpleSourceName(), method .getPropertyName(), param.getName()); if (JBeanMethod.SET_BUILDER.equals(method.getAction())) { staticImpl.getName(), type.getSimpleSourceName()); for (JParameter param : jmethod.getParameters()) { sw.print(", %s", param.getName());
sw.indent(); for (AutoBeanType type : model.getAllTypes()) { if (type.isNoWrap()) { continue; JClassType peer = type.getPeerType(); String peerName = ModelUtils.ensureBaseType(peer).getQualifiedSourceName(); if (peer.isPublic()) { .getJNISignature(); for (AutoBeanType type : model.getAllTypes()) { String peerName = ModelUtils.ensureBaseType(type.getPeerType()).getQualifiedSourceName(); String peerJNIName = ModelUtils.ensureBaseType(type.getPeerType()).getJNISignature(); sw.indent(); sw.println("return ["); if (type.isSimpleBean()) { sw.indentln("@%s::new(%s),", type.getQualifiedSourceName(), factoryJNIName); } else { sw.indentln(","); sw.indentln("@%s::new(%s%s)", type.getQualifiedSourceName(), factoryJNIName, peerJNIName); sw.println("];"); sw.outdent();
sw.println("%s propertyContext;", ClientPropertyContext.class.getCanonicalName()); 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) .getCanonicalName(), type.getSimpleSourceName(), method.getPropertyName());
private void writeReturnWrapper(SourceWriter sw, AutoBeanType type, AutoBeanMethod method) throws UnableToCompleteException { if (!method.isValueType() && !method.isNoWrap()) { JMethod jmethod = method.getMethod(); JClassType returnClass = jmethod.getReturnType().isClassOrInterface(); AutoBeanType peer = model.getPeer(returnClass); sw.println("if (toReturn != null) {"); sw.indent(); sw.println("if (%s.this.isWrapped(toReturn)) {", type.getSimpleSourceName()); sw.indentln("toReturn = %s.this.getFromWrapper(toReturn);", type.getSimpleSourceName()); sw.println("} else {"); sw.indent(); if (peer != null) { // toReturn = new FooAutoBean(getFactory(), toReturn).as(); sw.println("toReturn = new %s(getFactory(), toReturn).as();", peer.getQualifiedSourceName()); } sw.outdent(); sw.println("}"); sw.outdent(); sw.println("}"); } // Allow return values to be intercepted JMethod interceptor = type.getInterceptor(); if (interceptor != null) { // toReturn = FooCategory.__intercept(FooAutoBean.this, toReturn); sw.println("toReturn = %s.%s(%s.this, toReturn);", interceptor.getEnclosingType() .getQualifiedSourceName(), interceptor.getName(), type.getSimpleSourceName()); } }
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(); .getQualifiedBaseSourceName(jmethod.getReturnType()), type.getSimpleSourceName(), methodName); 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("%s.this.getWrapped().%s(%s);", type.getSimpleSourceName(), methodName, arguments); sw.println("%s.this.call(\"%s\", null%s %s);", type.getSimpleSourceName(), methodName, arguments.length() > 0 ? "," : "", arguments); } else { jmethod.getReturnType()).getQualifiedSourceName(), type.getSimpleSourceName(), methodName, arguments); sw.println("%s.this.call(\"%s\", toReturn%s %s);", type.getSimpleSourceName(), methodName, arguments.length() > 0 ? "," : "", arguments);
public String getQualifiedSourceName() { return getPackageNome() + "." + getSimpleSourceName(); }
if (!autoBeanType.isSimpleBean() && toWrap == null) { if (categoryTypes != null) { poison("The %s parameterization is not simple and the following" + " methods did not have static implementations:", beanType.getQualifiedSourceName()); for (AutoBeanMethod missing : autoBeanType.getMethods()) { if (missing.getAction().equals(JBeanMethod.CALL) && missing.getStaticImpl() == null) {
private void writeMethods(SourceWriter sw) throws UnableToCompleteException { for (AutoBeanFactoryMethod method : model.getMethods()) { AutoBeanType autoBeanType = method.getAutoBeanType(); // public AutoBean<Foo> foo(FooSubtype wrapped) { sw.println("public %s %s(%s) {", method.getReturnType().getQualifiedSourceName(), method .getName(), method.isWrapper() ? (method.getWrappedType().getQualifiedSourceName() + " wrapped") : ""); if (method.isWrapper()) { sw.indent(); // AutoBean<Foo> toReturn = AutoBeanUtils.getAutoBean(wrapped); sw.println("%s toReturn = %s.getAutoBean(wrapped);", method.getReturnType() .getParameterizedQualifiedSourceName(), AutoBeanUtils.class.getCanonicalName()); sw.println("if (toReturn != null) {return toReturn;}"); // return new FooAutoBean(Factory.this, wrapped); sw.println("return new %s(%s.this, wrapped);", autoBeanType.getQualifiedSourceName(), simpleSourceName); sw.outdent(); } else { // return new FooAutoBean(Factory.this); sw.indentln("return new %s(%s.this);", autoBeanType.getQualifiedSourceName(), simpleSourceName); } sw.println("}"); } }
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); 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);