private String getTypeName(JType type) { String sType = ""; if (type.isArray() != null) { sType = type.isArray().getQualifiedSourceName(); if (sType.contains("extends")) { sType = sType.substring(sType.indexOf("extends") + 7).trim(); } if (sType.contains("[]") == false) { sType += "[]"; } } else if (type.isGenericType() != null || type.getQualifiedSourceName().contains("extends")) { if (type.isGenericType() != null && type.getQualifiedSourceName().contains("extends")) { sType = type.isGenericType().getQualifiedSourceName(); } else { sType = "Object"; } } else if (type.isPrimitive() != null) { JPrimitiveType primative = type.isPrimitive(); sType = primative.getQualifiedBoxedSourceName(); } else { sType = type.getQualifiedSourceName(); } return sType; }
private String boxReturnType(JMethod method) { if (method.getReturnType().isPrimitive() != null) { JPrimitiveType primative = method.getReturnType().isPrimitive(); return "(" + primative.getQualifiedBoxedSourceName() + ") "; } return ""; }
/** * Returns the String represention of the java type for a primitive for example int/Integer, * float/Float. * * @param type * @return the string representation */ protected static String getJavaObjectTypeFor(JPrimitiveType type) { if (type == JPrimitiveType.INT) { return "Integer"; } else { String s = type.getSimpleSourceName(); return StringCase.toUpper(s.substring(0, 1)) + s.substring(1); } }
private String buildRpcInterfaces( TreeLogger logger, GeneratorContext context, RequestQueueModel model) { String rqType = model.getRequestQueueInterfaceName(); int lastDot = rqType.lastIndexOf('.'); String packageName = rqType.substring(0, lastDot - 1); String serviceSourceName = rqType.substring(lastDot).replace('.', '_') + "_ImplRPC"; String asyncSourceName = serviceSourceName + "Async"; PrintWriter pw = context.tryCreate(logger, packageName, asyncSourceName); if (pw == null) { return packageName + "." + serviceSourceName; } // Create async class ClassSourceFileComposerFactory factory = new ClassSourceFileComposerFactory(packageName, asyncSourceName); factory.addImplementedInterface(ServiceQueueBaseAsync.class.getName()); factory.makeInterface(); SourceWriter asyncSw = factory.createSourceWriter(context, pw); // Create service class pw = context.tryCreate(logger, packageName, serviceSourceName); assert pw != null; factory = new ClassSourceFileComposerFactory(packageName, serviceSourceName); factory.addImplementedInterface(ServiceQueueBase.class.getName()); factory.makeInterface(); SourceWriter serviceSw = factory.createSourceWriter(context, pw); // write out service and async int i = 0; for (AsyncServiceModel service : model.getServices()) { for (AsyncServiceMethodModel method : service.getMethods()) { String methodName = "a" + ++i; asyncSw.println("void %1$s(", methodName); serviceSw.println("%2$s %1$s(", methodName, method.getReturnTypeName()); asyncSw.indent(); serviceSw.indent(); boolean firstArgument = true; int argIndex = 0; for (JType arg : method.getArgTypes()) { if (!firstArgument) { asyncSw.println(","); serviceSw.println(","); } firstArgument = false; if (arg.isPrimitive() != null) { JPrimitiveType t = arg.isPrimitive(); asyncSw.println("%2$s arg%1$d", argIndex, t.getQualifiedBoxedSourceName()); serviceSw.println("%2$s arg%1$d", argIndex, t.getQualifiedBoxedSourceName()); } else { asyncSw.println("%2$s arg%1$d", argIndex, arg.getParameterizedQualifiedSourceName()); serviceSw.println("%2$s arg%1$d", argIndex, arg.getParameterizedQualifiedSourceName()); } argIndex++; } if (!firstArgument) { asyncSw.print(", "); } // TODO return type boxing asyncSw.println( "%1$s<%2$s>callback);", AsyncCallback.class.getName(), method.getReturnTypeName()); serviceSw.print(")"); if (!method.getThrowables().isEmpty()) { serviceSw.print(" throws "); boolean firstThrowable = true; for (JClassType throwable : method.getThrowables()) { if (!firstThrowable) { serviceSw.print(", "); } firstThrowable = false; serviceSw.print(throwable.getQualifiedSourceName()); } } serviceSw.println(";"); asyncSw.outdent(); serviceSw.outdent(); } } asyncSw.commit(logger); serviceSw.commit(logger); return factory.getCreatedClassName(); }