List of usage examples for com.google.gwt.user.rebind SourceWriter println
void println(String s);
From source file:net.sf.gilead.proxy.gwt.AbstractGwtProxyGenerator.java
License:Apache License
/** * Generates an additional attribute/* ww w . j av a2s . c o m*/ * * @param sourceWriter * @param attribute */ protected void generateMethod(SourceWriter sourceWriter, Method method) { // Javadoc comment if needed // if (StringUtils.isEmpty(method.getJavadoc()) == false) { sourceWriter.beginJavaDocComment(); sourceWriter.println(method.getJavadoc()); sourceWriter.endJavaDocComment(); } // Add Signature and code // sourceWriter.println(method.computeJava5Signature()); sourceWriter.println(method.getCode()); }
From source file:net.sf.mmm.service.impl.gwt.rpc.client.rebind.RemoteInvocationServiceCallerGenerator.java
License:Apache License
/** * {@inheritDoc}/*from www . j av a2 s . c o m*/ */ @Override protected void generateClassContents(JClassType inputType, TreeLogger logger, SourceWriter sourceWriter, String simpleName, GeneratorContext context) { generateSourcePublicConstructorDeclaration(sourceWriter, simpleName); // generate CDI constructor // sourceWriter.print("@"); // sourceWriter.println(Inject.class.getSimpleName()); // sourceWriter.print("public "); // sourceWriter.print(simpleName); // sourceWriter.print("("); // sourceWriter.print(RemoteInvocationGenericServiceGwtAsync.class.getSimpleName()); // sourceWriter.print(" genericService"); // sourceWriter.println(") {"); // sourceWriter.indent(); // sourceWriter.println("super(genericService);"); // generate service clients and register in constructor... TypeOracle typeOracle = context.getTypeOracle(); JClassType dabayServiceType = typeOracle.findType(RemoteInvocationService.class.getName()); for (JClassType type : typeOracle.getTypes()) { if ((type.isAssignableTo(dabayServiceType)) && (!type.equals(dabayServiceType)) && (type.isInterface() != null)) { sourceWriter.print("registerService("); sourceWriter.print(type.getQualifiedSourceName()); sourceWriter.print(".class, new "); sourceWriter.print(generateServiceClient(type, inputType.getPackage().getName(), logger, context)); sourceWriter.println("());"); } } generateSourceCloseBlock(sourceWriter); }
From source file:net.sf.mmm.service.impl.gwt.rpc.client.rebind.RemoteInvocationServiceCallerGenerator.java
License:Apache License
/** * This method generates a service-client implementation of a {@link RemoteInvocationService}-interface * given by <code>serviceInterface</code>. * /*w w w .j a v a 2 s. c om*/ * @param serviceInterface is the {@link RemoteInvocationService}-interface. * @param packageName is the {@link Package#getName() package name}. * @param logger is the {@link TreeLogger}. * @param context is the {@link GeneratorContext}. * @return the qualified name of the generated class. */ protected String generateServiceClient(JClassType serviceInterface, String packageName, TreeLogger logger, GeneratorContext context) { String simpleName = serviceInterface.getName() + "ClientImpl"; logger.log(TreeLogger.INFO, getClass().getSimpleName() + ": Generating " + simpleName); ClassSourceFileComposerFactory sourceComposerFactory = new ClassSourceFileComposerFactory(packageName, simpleName); // imports sourceComposerFactory.addImport(RemoteInvocationService.class.getName()); sourceComposerFactory.addImport(Serializable.class.getName()); sourceComposerFactory.addImport(GenericRemoteInvocationRpcCall.class.getName()); sourceComposerFactory.addImport(AbstractRemoteInvocationServiceClient.class.getName()); sourceComposerFactory.addImplementedInterface(serviceInterface.getQualifiedSourceName()); sourceComposerFactory.setSuperclass(AbstractRemoteInvocationServiceClient.class.getSimpleName()); PrintWriter writer = context.tryCreate(logger, packageName, simpleName); if (writer != null) { SourceWriter sourceWriter = sourceComposerFactory.createSourceWriter(context, writer); // generate constructor sourceWriter.print("public "); sourceWriter.print(simpleName); sourceWriter.println("() {"); sourceWriter.indent(); sourceWriter.println("super();"); sourceWriter.outdent(); sourceWriter.println("}"); // generate service-interface methods to implement for (JMethod method : serviceInterface.getOverridableMethods()) { generateServiceClientMethod(serviceInterface, sourceWriter, method); } sourceWriter.commit(logger); } return sourceComposerFactory.getCreatedClassName(); }
From source file:net.sf.mmm.service.impl.gwt.rpc.client.rebind.RemoteInvocationServiceCallerGenerator.java
License:Apache License
/** * This method generates the implementation of a method for a service-client. * /*from w w w . j a v a2 s. c o m*/ * @param serviceInterface is the {@link RemoteInvocationService}-interface. * @param sourceWriter is the {@link SourceWriter}. * @param method is the {@link JMethod} to generate. */ private void generateServiceClientMethod(JClassType serviceInterface, SourceWriter sourceWriter, JMethod method) { // generate method declaration... sourceWriter.print("public "); JType returnType = method.getReturnType(); sourceWriter.print(returnType.getQualifiedSourceName()); sourceWriter.print(" "); sourceWriter.print(method.getName()); sourceWriter.print("("); String separator = ""; JParameter[] parameters = method.getParameters(); for (JParameter parameter : parameters) { if (separator.length() == 0) { separator = ", "; } else { sourceWriter.print(separator); } sourceWriter.print(parameter.getType().getQualifiedSourceName()); sourceWriter.print(" "); sourceWriter.print(parameter.getName()); } sourceWriter.println("){"); // generate method body... sourceWriter.indent(); // generate statement for argument array sourceWriter.print(Serializable.class.getSimpleName()); sourceWriter.print("[] _arguments = new "); sourceWriter.print(Serializable.class.getSimpleName()); sourceWriter.print("["); sourceWriter.print(Integer.toString(parameters.length)); sourceWriter.println("];"); String[] signatureArray = new String[parameters.length]; // fill in arguments for (int i = 0; i < parameters.length; i++) { // assign argument statement JParameter parameter = parameters[i]; sourceWriter.print("_arguments["); sourceWriter.print(Integer.toString(i)); sourceWriter.print("] = "); sourceWriter.print(parameter.getName()); sourceWriter.println(";"); // assign argument type for signature signatureArray[i] = parameter.getType().getQualifiedSourceName(); } // generate statement to create call sourceWriter.print(GenericRemoteInvocationRpcCall.class.getSimpleName()); sourceWriter.print(" _call = new "); sourceWriter.print(GenericRemoteInvocationRpcCall.class.getSimpleName()); sourceWriter.print("("); sourceWriter.print(serviceInterface.getQualifiedSourceName()); sourceWriter.print(".class.getName(), \""); sourceWriter.print(method.getName()); sourceWriter.print("\", "); sourceWriter.print(Integer.toString(GenericRemoteInvocationRpcCall.getSignature(signatureArray))); sourceWriter.println(", _arguments);"); // add recorded call sourceWriter.print("addCall(_call, "); sourceWriter.print(returnType.getQualifiedSourceName()); sourceWriter.println(".class);"); // generate dummy return statement JPrimitiveType primitiveReturnType = returnType.isPrimitive(); if (primitiveReturnType == null) { sourceWriter.println("return null;"); } else { switch (primitiveReturnType) { case VOID: // nothing to return break; case BOOLEAN: sourceWriter.println("return false;"); break; case BYTE: case DOUBLE: case FLOAT: case INT: case LONG: case SHORT: sourceWriter.println("return 0;"); break; case CHAR: sourceWriter.println("return ' ';"); break; default: throw new IllegalCaseException(JPrimitiveType.class, primitiveReturnType); } } sourceWriter.outdent(); sourceWriter.println("}"); }
From source file:net.sf.mmm.util.gwt.base.rebind.AbstractIncrementalGenerator.java
License:Apache License
/** * Generates the the default constructor. * /*ww w. jav a2 s. c o m*/ * @param sourceWriter is the {@link SourceWriter}. * @param simpleName is the {@link Class#getSimpleName() simple name}. */ protected void generateDefaultConstructor(SourceWriter sourceWriter, String simpleName) { generateSourcePublicConstructorDeclaration(sourceWriter, simpleName); sourceWriter.println("super();"); generateSourceCloseBlock(sourceWriter); }
From source file:net.sf.mmm.util.gwt.base.rebind.AbstractIncrementalGenerator.java
License:Apache License
/** * This method generates the source code for a public method or constructor including the opening brace and * indentation.//www . jav a2 s. c o m * * @param sourceWriter is the {@link SourceWriter}. * @param returnType is the return type of the method. * @param methodName is the name of the method (or the {@link Class#getSimpleName() simple class name} for a * constructor}. * @param arguments is the source line with the arguments to the method or constructor. * @param override - <code>true</code> if an {@link Override} annotation shall be added. */ protected final void generateSourcePublicMethodDeclaration(SourceWriter sourceWriter, String returnType, String methodName, String arguments, boolean override) { if (override) { sourceWriter.println("@Override"); } sourceWriter.print("public "); if (returnType != null) { sourceWriter.print(returnType); sourceWriter.print(" "); } sourceWriter.print(methodName); sourceWriter.print("("); sourceWriter.print(arguments); sourceWriter.println(") {"); sourceWriter.indent(); }
From source file:net.sf.mmm.util.gwt.base.rebind.AbstractIncrementalGenerator.java
License:Apache License
/** * This method generates the source code to close a block (method body, if-block, while-block, etc.). * /*from ww w.j a va 2 s. c o m*/ * @param sourceWriter is the {@link SourceWriter}. */ protected final void generateSourceCloseBlock(SourceWriter sourceWriter) { sourceWriter.outdent(); sourceWriter.println("}"); sourceWriter.println(); }
From source file:net.sf.mmm.util.nls.impl.rebind.AbstractNlsBundleGenerator.java
License:Apache License
/** * Generates the implementation of {@link NlsBundleWithLookup#getMessage(String, Map)}. * /*from w w w. j a v a 2 s . c o m*/ * @param sourceWriter is the {@link SourceWriter}. * @param logger is the {@link TreeLogger}. * @param context is the {@link GeneratorContext}. * @param method is the {@link NlsBundleWithLookup#getMessage(String, Map)}-method to generate an * implementation for. * @param methods is the list of all declared methods of the bundle. Likely to be ignored but may be used to * generate a switch statement with delegations. */ protected void generateLookupMethod(SourceWriter sourceWriter, TreeLogger logger, GeneratorContext context, JMethod method, JMethod[] methods) { generateSourcePublicMethodDeclaration(sourceWriter, method); sourceWriter.print("String "); sourceWriter.print(VARIABLE_MESSAGE); sourceWriter.println("= null;"); boolean addElse = false; for (JMethod currentMethod : methods) { if (!isLookupMethod(currentMethod)) { if (addElse) { sourceWriter.print(" else "); } else { addElse = true; } sourceWriter.print("if (methodName.equals(\""); String methodName = currentMethod.getName(); sourceWriter.print(methodName); sourceWriter.println("\")) {"); sourceWriter.indent(); generateMethodMessageBlock(sourceWriter, logger, context, methodName); sourceWriter.outdent(); sourceWriter.print("}"); } else { assert (method == currentMethod); } } // methodName not found/present? sourceWriter.println(); sourceWriter.print("if ("); sourceWriter.print(VARIABLE_MESSAGE); sourceWriter.println("== null) {"); sourceWriter.indent(); sourceWriter.println("return null;"); sourceWriter.outdent(); sourceWriter.println("}"); // generate message depending on arguments sourceWriter.print("if (("); sourceWriter.print(VARIABLE_ARGUMENTS); sourceWriter.print(" == null) || ("); sourceWriter.print(VARIABLE_ARGUMENTS); sourceWriter.println(".isEmpty())) {"); sourceWriter.indent(); generateCreateMessageBlock(sourceWriter, false); sourceWriter.outdent(); sourceWriter.println("} else {"); sourceWriter.indent(); generateCreateMessageBlock(sourceWriter, true); sourceWriter.outdent(); sourceWriter.println("}"); generateSourceCloseBlock(sourceWriter); }
From source file:net.sf.mmm.util.nls.impl.rebind.AbstractNlsBundleGenerator.java
License:Apache License
/** * Generates an the body of an {@link NlsBundle}-method. * /*from w w w . j a va 2 s . c o m*/ * @param sourceWriter is the {@link SourceWriter}. * @param logger is the {@link TreeLogger}. * @param context is the {@link GeneratorContext}. * @param method is the {@link NlsBundle}-method to generate an implementation for. */ protected void generateMethodBody(SourceWriter sourceWriter, TreeLogger logger, GeneratorContext context, JMethod method) { JParameter[] methodParameters = method.getParameters(); if (methodParameters.length > 0) { sourceWriter.print("Map<String, Object> "); sourceWriter.print(VARIABLE_ARGUMENTS); sourceWriter.println(" = new HashMap<String, Object>();"); // loop over parameters and generate code that puts the parameters into the arguments map for (JParameter parameter : methodParameters) { String name; Named namedAnnotation = parameter.getAnnotation(Named.class); if (namedAnnotation == null) { name = parameter.getName(); } else { name = namedAnnotation.value(); } sourceWriter.print(VARIABLE_ARGUMENTS); sourceWriter.print(".put(\""); sourceWriter.print(escape(name)); sourceWriter.print("\", "); sourceWriter.print(parameter.getName()); sourceWriter.println(");"); } } sourceWriter.print("String "); generateMethodMessageBlock(sourceWriter, logger, context, method.getName()); generateCreateMessageBlock(sourceWriter, methodParameters.length > 0); }
From source file:net.sf.mmm.util.nls.impl.rebind.AbstractNlsBundleGenerator.java
License:Apache License
/** * Generates the source code block to create a new {@link NlsMessage}. * //from w w w.j a va2 s . com * @param sourceWriter is the {@link SourceWriter}. * @param hasArguments - <code>true</code> if {@link NlsMessage#getArgument(String) arguments} are given, * <code>false</code> otherwise. */ private void generateCreateMessageBlock(SourceWriter sourceWriter, boolean hasArguments) { // return NlsAccess.getFactory().create(message, arguments); if (hasArguments) { sourceWriter.print("return "); sourceWriter.print(NlsAccess.class.getSimpleName()); sourceWriter.print(".getFactory().create("); sourceWriter.print(VARIABLE_MESSAGE); sourceWriter.print(", "); sourceWriter.print(VARIABLE_ARGUMENTS); sourceWriter.println(");"); } else { sourceWriter.print("return new "); sourceWriter.print(NlsMessagePlain.class.getSimpleName()); sourceWriter.print("("); sourceWriter.print(VARIABLE_MESSAGE); sourceWriter.println(");"); } }