if (requestReturnType == null) { poison(badContextReturnType(method, requestInterface, instanceRequestInterface)); return false; methodBuilder.setInstanceType(getEntityProxyType(params[0])); invocationReturnType = params[1]; } else if (requestInterface.isAssignableFrom(requestReturnType)) { poison(badContextReturnType(method, requestInterface, instanceRequestInterface)); return false; JParameter param = params[i]; paramsOk = validateTransportableType(new RequestMethod.Builder(), param.getType(), false) && paramsOk; methodBuilder.addExtraSetter(maybeSetter); } else { poison(noSettersAllowed(maybeSetter)); return validateTransportableType(methodBuilder, invocationReturnType, true);
/** * Examine a RequestContext subtype to populate a ContextMethod. */ private void buildContextMethod(ContextMethod.Builder contextBuilder, JClassType contextType) throws UnableToCompleteException { Service serviceAnnotation = contextType.getAnnotation(Service.class); ServiceName serviceNameAnnotation = contextType.getAnnotation(ServiceName.class); JsonRpcService jsonRpcAnnotation = contextType.getAnnotation(JsonRpcService.class); if (serviceAnnotation == null && serviceNameAnnotation == null && jsonRpcAnnotation == null) { poison("RequestContext subtype %s is missing a @%s or @%s annotation", contextType .getQualifiedSourceName(), Service.class.getSimpleName(), JsonRpcService.class .getSimpleName()); return; } List<RequestMethod> requestMethods = new ArrayList<RequestMethod>(); for (JMethod method : contextType.getInheritableMethods()) { if (method.getEnclosingType().equals(requestContextInterface)) { // Ignore methods declared in RequestContext continue; } RequestMethod.Builder methodBuilder = new RequestMethod.Builder(); methodBuilder.setDeclarationMethod(contextType, method); if (!validateContextMethodAndSetDataType(methodBuilder, method, jsonRpcAnnotation != null)) { continue; } requestMethods.add(methodBuilder.build()); } contextBuilder.setExtraTypes(checkExtraTypes(contextType, true)).setRequestMethods( requestMethods); }
public void accept(ModelVisitor visitor) { if (visitor.visit(this)) { for (EntityProxyModel model : getAllProxyModels()) { model.accept(visitor); } for (ContextMethod method : getMethods()) { method.accept(visitor); } } visitor.endVisit(this); }
JClassType proxy = oracle.findType(clazz.getCanonicalName()); if (proxy == null) { poison("Unknown class %s in @%s", clazz.getCanonicalName(), ExtraTypes.class .getSimpleName()); } else { toReturn.add(getEntityProxyType(proxy));
if (supertype != entityProxyType && shouldAttemptProxyValidation(supertype)) { superTypes.add(getEntityProxyType(supertype)); builder.setType(Type.VALUE); } else { poison("The type %s is not assignable to either %s or %s", entityProxyInterface .getQualifiedSourceName(), valueProxyInterface.getQualifiedSourceName()); die(poisonedMessage()); JsonRpcProxy jsonRpcProxy = entityProxyType.getAnnotation(JsonRpcProxy.class); if (proxyFor == null && proxyForName == null && jsonRpcProxy == null) { poison("The %s type does not have a @%s, @%s, or @%s annotation", entityProxyType .getQualifiedSourceName(), ProxyFor.class.getSimpleName(), ProxyForName.class .getSimpleName(), JsonRpcProxy.class.getSimpleName()); duplicatePropertyGetters.put(propertyName, method); } else { poison("Duplicate accessors for property %s: %s() and %s()", propertyName, previouslySeen.getName(), method.getName()); poison("The method %s is neither a getter nor a setter", method.getReadableDeclaration()); continue; validateTransportableType(methodBuilder, transportedType, false); RequestMethod requestMethod = methodBuilder.build(); requestMethods.add(requestMethod); builder.setExtraTypes(checkExtraTypes(entityProxyType, false)).setRequestMethods(
valueProxyInterface = oracle.findType(ValueProxy.class.getCanonicalName()); extraTypes = checkExtraTypes(factoryType, false); for (JMethod method : factoryType.getOverridableMethods()) { if (method.getEnclosingType().equals(requestFactoryInterface)) { poison("Unexpected parameter on method %s", method.getName()); continue; poison("Unexpected return type %s on method %s is not" + " an interface assignable to %s", method.getReturnType().getQualifiedSourceName(), method.getName(), requestContextInterface.getSimpleSourceName()); buildContextMethod(builder, contextType); contextMethods.add(builder.build()); die(poisonedMessage());
if (transportedClass == null) { if (requireObject) { poison("The type %s cannot be transported by RequestFactory as" + " a return type", type .getQualifiedSourceName()); return false; methodBuilder.setEntityType(getEntityProxyType(transportedClass)); } else if (entityProxyIdInterface.isAssignableFrom(transportedClass)) { JParameterizedType parameterized = transportedClass.isParameterized(); if (parameterized == null) { poison("EntityProxyId must be parameterized"); return false; methodBuilder.setEntityType(getEntityProxyType(entityType)); } else if (collectionInterface.isAssignableFrom(transportedClass)) { poison("Requests that return collections of List or Set must be parameterized"); return false; methodBuilder.setCollectionType(CollectionType.SET); } else { poison("Requests that return collections may be declared with" + " %s or %s only", listInterface.getQualifiedSourceName(), setInterface.getQualifiedSourceName()); return false; ModelUtils.findParameterizationOf(collectionInterface, transportedClass)[0]; methodBuilder.setCollectionElementType(elementType); validateTransportableType(methodBuilder, elementType, requireObject); } else if (mapInterface.isAssignableFrom(transportedClass)) {
@Override public String generate(TreeLogger logger, GeneratorContext context, String typeName) throws UnableToCompleteException { this.context = context; this.logger = logger; TypeOracle oracle = context.getTypeOracle(); JClassType toGenerate = oracle.findType(typeName).isInterface(); if (toGenerate == null) { logger.log(TreeLogger.ERROR, typeName + " is not an interface type"); throw new UnableToCompleteException(); } String packageName = toGenerate.getPackage().getName(); String simpleSourceName = toGenerate.getName().replace('.', '_') + "Impl"; PrintWriter pw = context.tryCreate(logger, packageName, simpleSourceName); if (pw == null) { return packageName + "." + simpleSourceName; } model = new RequestFactoryModel(logger, toGenerate); ClassSourceFileComposerFactory factory = new ClassSourceFileComposerFactory(packageName, simpleSourceName); factory.setSuperclass(AbstractClientRequestFactory.class.getCanonicalName()); factory.addImplementedInterface(typeName); SourceWriter sw = factory.createSourceWriter(context, pw); writeAutoBeanFactory(sw, model.getAllProxyModels(), findExtraEnums(model)); writeContextMethods(sw); writeContextImplementations(); writeTypeMap(sw); sw.commit(logger); return factory.getCreatedClassName(); }
sw.println("static {"); sw.indent(); for (EntityProxyModel type : model.getAllProxyModels()) { sw.indentln("return \"%s\";", model.getFactoryType().getQualifiedBinaryName()); sw.println("}"); sw.println("@Override protected Class getTypeFromToken(String typeToken) {");
private void writeContextMethods(SourceWriter sw) { for (ContextMethod method : model.getMethods()) { // public FooService foo() { sw.println("public %s %s() {", method.getQualifiedSourceName(), method.getMethodName()); // return new FooServiceImpl(this); sw.indentln("return new %s(this);", method.getQualifiedSourceName()); sw.println("}"); } }
/** * For debugging use only. */ @Override public String toString() { return getFactoryType().getQualifiedSourceName(); }
@Override void examineTypeOnce(JClassType type) { // Need this to handle List<Foo>, Map<Foo> JParameterizedType parameterized = type.isParameterized(); if (parameterized != null) { for (JClassType arg : parameterized.getTypeArgs()) { maybeVisit(arg); } } JClassType base = ModelUtils.ensureBaseType(type); EntityProxyModel peer = model.getPeer(base); if (peer == null) { return; } peer.accept(this); }
if (supertype != entityProxyType && shouldAttemptProxyValidation(supertype)) { superTypes.add(getEntityProxyType(supertype)); builder.setType(Type.VALUE); } else { poison("The type %s is not assignable to either %s or %s", entityProxyInterface .getQualifiedSourceName(), valueProxyInterface.getQualifiedSourceName()); die(poisonedMessage()); JsonRpcProxy jsonRpcProxy = entityProxyType.getAnnotation(JsonRpcProxy.class); if (proxyFor == null && proxyForName == null && jsonRpcProxy == null) { poison("The %s type does not have a @%s, @%s, or @%s annotation", entityProxyType .getQualifiedSourceName(), ProxyFor.class.getSimpleName(), ProxyForName.class .getSimpleName(), JsonRpcProxy.class.getSimpleName()); duplicatePropertyGetters.put(propertyName, method); } else { poison("Duplicate accessors for property %s: %s() and %s()", propertyName, previouslySeen.getName(), method.getName()); poison("The method %s is neither a getter nor a setter", method.getReadableDeclaration()); continue; validateTransportableType(methodBuilder, transportedType, false); RequestMethod requestMethod = methodBuilder.build(); requestMethods.add(requestMethod); builder.setExtraTypes(checkExtraTypes(entityProxyType, false)).setRequestMethods(
valueProxyInterface = oracle.findType(ValueProxy.class.getCanonicalName()); extraTypes = checkExtraTypes(factoryType, false); for (JMethod method : factoryType.getOverridableMethods()) { if (method.getEnclosingType().equals(requestFactoryInterface)) { poison("Unexpected parameter on method %s", method.getName()); continue; poison("Unexpected return type %s on method %s is not" + " an interface assignable to %s", method.getReturnType().getQualifiedSourceName(), method.getName(), requestContextInterface.getSimpleSourceName()); buildContextMethod(builder, contextType); contextMethods.add(builder.build()); die(poisonedMessage());
if (transportedClass == null) { if (requireObject) { poison("The type %s cannot be transported by RequestFactory as" + " a return type", type .getQualifiedSourceName()); return false; methodBuilder.setEntityType(getEntityProxyType(transportedClass)); } else if (entityProxyIdInterface.isAssignableFrom(transportedClass)) { JParameterizedType parameterized = transportedClass.isParameterized(); if (parameterized == null) { poison("EntityProxyId must be parameterized"); return false; methodBuilder.setEntityType(getEntityProxyType(entityType)); } else if (collectionInterface.isAssignableFrom(transportedClass)) { poison("Requests that return collections of List or Set must be parameterized"); return false; methodBuilder.setCollectionType(CollectionType.SET); } else { poison("Requests that return collections may be declared with" + " %s or %s only", listInterface.getQualifiedSourceName(), setInterface.getQualifiedSourceName()); return false; ModelUtils.findParameterizationOf(collectionInterface, transportedClass)[0]; methodBuilder.setCollectionElementType(elementType); validateTransportableType(methodBuilder, elementType, requireObject); } else if (mapInterface.isAssignableFrom(transportedClass)) {
@Override public String generate(TreeLogger logger, GeneratorContext context, String typeName) throws UnableToCompleteException { this.context = context; this.logger = logger; TypeOracle oracle = context.getTypeOracle(); JClassType toGenerate = oracle.findType(typeName).isInterface(); if (toGenerate == null) { logger.log(TreeLogger.ERROR, typeName + " is not an interface type"); throw new UnableToCompleteException(); } String packageName = toGenerate.getPackage().getName(); String simpleSourceName = toGenerate.getName().replace('.', '_') + "Impl"; PrintWriter pw = context.tryCreate(logger, packageName, simpleSourceName); if (pw == null) { return packageName + "." + simpleSourceName; } model = new RequestFactoryModel(logger, toGenerate); ClassSourceFileComposerFactory factory = new ClassSourceFileComposerFactory(packageName, simpleSourceName); factory.setSuperclass(AbstractClientRequestFactory.class.getCanonicalName()); factory.addImplementedInterface(typeName); SourceWriter sw = factory.createSourceWriter(context, pw); writeAutoBeanFactory(sw, model.getAllProxyModels(), findExtraEnums(model)); writeContextMethods(sw); writeContextImplementations(); writeTypeMap(sw); sw.commit(logger); return factory.getCreatedClassName(); }
JClassType proxy = oracle.findType(clazz.getCanonicalName()); if (proxy == null) { poison("Unknown class %s in @%s", clazz.getCanonicalName(), ExtraTypes.class .getSimpleName()); } else { toReturn.add(getEntityProxyType(proxy));
sw.println("static {"); sw.indent(); for (EntityProxyModel type : model.getAllProxyModels()) { sw.indentln("return \"%s\";", model.getFactoryType().getQualifiedBinaryName()); sw.println("}"); sw.println("@Override protected Class getTypeFromToken(String typeToken) {");
private void writeContextMethods(SourceWriter sw) { for (ContextMethod method : model.getMethods()) { // public FooService foo() { sw.println("public %s %s() {", method.getQualifiedSourceName(), method.getMethodName()); // return new FooServiceImpl(this); sw.indentln("return new %s(this);", method.getQualifiedSourceName()); sw.println("}"); } }
/** * For debugging use only. */ @Override public String toString() { return getFactoryType().getQualifiedSourceName(); }