List of usage examples for com.google.gwt.user.rebind SourceWriter outdent
void outdent();
From source file:gwt.g2d.resources.ExternalImageResourceGenerator.java
License:Apache License
@Override public String createAssignment(TreeLogger logger, ResourceContext context, JMethod method) throws UnableToCompleteException { String name = "ExternalImageResourceGenerator.createAssignment"; URL[] resources = ResourceGeneratorUtil.findResources(logger, context, method); SourceWriter sw = new StringSourceWriter(); // Write the expression to create the subtype. sw.println("new " + ExternalImageResource.class.getName() + "() {"); sw.indent();/*w ww . j ava 2s . c o m*/ sw.println(String.format("public void getImage(%s<%s> callback) {", ResourceCallback.class.getName(), ImageElementResource.class.getName())); sw.indent(); int index = 0; String abstractImageElementResourceClassName = AbstractImageElementResource.class.getName(); for (URL resource : resources) { String outputUrlExpression = context.deploy(resource, false); sw.println("{"); sw.println(abstractImageElementResourceClassName + " imgResource = new " + abstractImageElementResourceClassName + "() {"); sw.indent(); sw.println("public String getName() {"); sw.indent(); sw.println("return \"" + name + "\";"); sw.outdent(); sw.println("}"); sw.println("public String getBaseUrl() {"); sw.indent(); sw.println("return \"" + ResourceGeneratorUtil.baseName(resource) + "\";"); sw.outdent(); sw.println("}"); sw.println("public int getIndex() {"); sw.indent(); sw.println("return " + index + ";"); sw.outdent(); sw.println("}"); sw.outdent(); sw.println("};"); sw.println(ImageLoader.class.getName() + ".loadImageAsync(" + outputUrlExpression + ", imgResource, callback);"); sw.println("}"); index++; } sw.outdent(); sw.println("}"); sw.println("public String getName() {"); sw.indent(); sw.println("return \"" + name + "\";"); sw.outdent(); sw.println("}"); sw.outdent(); sw.println("}"); return sw.toString(); }
From source file:gwt.g3d.resources.ExternalMeshResourceGenerator.java
License:Apache License
@Override public String createAssignment(TreeLogger logger, ResourceContext context, JMethod method) throws UnableToCompleteException { URL[] resources = ResourceGeneratorUtil.findResources(logger, context, method); if (resources.length != 1) { logger.log(TreeLogger.ERROR, "Exactly one resource must be specified", null); throw new UnableToCompleteException(); }//w w w .j a va2 s . c o m MeshDataInfo meshDataInfo = getMeshDataInfo(method); String url = null; URL modelUrl = resources[0]; if (modelUrl.getFile().endsWith(".obj")) { try { String content = Util.readURLAsString(modelUrl); File outFile = File.createTempFile("temp", ".json"); BufferedWriter writer = new BufferedWriter(new FileWriter(outFile)); new ObjParser().parse(content).export(meshDataInfo, writer); writer.close(); url = context.deploy(outFile.toURI().toURL(), true); } catch (ParserException e) { e.printStackTrace(); throw new UnableToCompleteException(); } catch (IOException e) { e.printStackTrace(); throw new UnableToCompleteException(); } } else if (modelUrl.getFile().endsWith(".json")) { url = context.deploy(modelUrl, true); } else { // Unsupported format. throw new UnableToCompleteException(); } SourceWriter sw = new StringSourceWriter(); sw.println(String.format("new %s() {", AbstractExternalMeshResource.class.getName())); sw.indent(); // Creates method: void getMesh(ResourceCallback<MeshResource>); sw.println(String.format("public void getMesh(%s<%s> callback) {", ResourceCallback.class.getName(), MeshResource.class.getName())); sw.indent(); // Creates the MeshDataInfo. sw.println(String.format("%s meshDataInfo = new %s();", MeshDataInfo.class.getName(), MeshDataInfo.class.getName())); sw.println(String.format("meshDataInfo.setPositionDataType(%s.%s);", DataType.class.getName(), meshDataInfo.getPositionDataType())); sw.println(String.format("meshDataInfo.setPositionDataSize(%s);", meshDataInfo.getPositionDataSize())); sw.println(String.format("meshDataInfo.setNormalDataType(%s.%s);", DataType.class.getName(), meshDataInfo.getNormalDataType())); sw.println(String.format("meshDataInfo.setNormalDataSize(%s);", meshDataInfo.getNormalDataSize())); sw.println(String.format("meshDataInfo.setNormalized(%s);", meshDataInfo.isNormalized())); sw.println(String.format("meshDataInfo.setTexCoordDataType(%s.%s);", DataType.class.getName(), meshDataInfo.getTexCoordDataType())); sw.println(String.format("meshDataInfo.setTexCoordDataSize(%s);", meshDataInfo.getTexCoordDataSize())); sw.println(String.format("getMesh(%s, meshDataInfo, callback);", url)); sw.outdent(); sw.println("}"); // Creates method: String getName(); sw.println("public String getName() {"); sw.indent(); sw.println("return \"" + method.getName() + "\";"); sw.outdent(); sw.println("}"); sw.outdent(); sw.println("}"); return sw.toString(); }
From source file:gwt.g3d.resources.ExternalTexture2DResourceGenerator.java
License:Apache License
@Override public String createAssignment(TreeLogger logger, ResourceContext context, JMethod method) throws UnableToCompleteException { SourceWriter sw = new StringSourceWriter(); sw.println(String.format("new %s() {", AbstractExternalTexture2DResource.class.getName())); sw.indent();//www. j ava2 s. com // Creates method: void getTexture(ResourceCallback<Texture2DResource>); sw.println(String.format("public void getTexture(%s<%s> textureResource) {", ResourceCallback.class.getName(), Texture2DResource.class.getName())); sw.indent(); String externalImageResourceObjectSrc = new ExternalImageResourceGenerator().createAssignment(logger, context, method); sw.println(String.format("getTexture(%s, textureResource);", externalImageResourceObjectSrc)); sw.outdent(); sw.println("}"); // Creates method: void onImageLoaded(ImageElementResource, // ResourceCallback<Texture2DResource>); sw.println(String.format("protected void onImageLoaded(%s imageResource, %s<%s> textureResource) {", ImageElementResource.class.getName(), ResourceCallback.class.getName(), Texture2DResource.class.getName())); sw.indent(); sw.println(String.format("textureResource.onSuccess(%s);", createAbstractTexture2DImageResource(logger, context, method))); sw.outdent(); sw.println("}"); // Creates method: String getName(); sw.println("public String getName() {"); sw.indent(); sw.println("return \"" + method.getName() + "\";"); sw.outdent(); sw.println("}"); sw.outdent(); sw.println("}"); return sw.toString(); }
From source file:gwt.g3d.resources.ExternalTexture2DResourceGenerator.java
License:Apache License
/** * Creates an assignment for an {@link AbstractTexture2DResource} object. *///from www. j a v a 2 s . c o m private String createAbstractTexture2DImageResource(TreeLogger logger, ResourceContext context, JMethod method) throws UnableToCompleteException { SourceWriter sw = new StringSourceWriter(); sw.println(String.format("new %s(imageResource) {", AbstractTexture2DResource.class.getName())); sw.indent(); // Creates method: void setTextureParameters(Texture2D); String texture2DClassName = Texture2D.class.getName(); sw.println(String.format("protected void setTextureParameters(%s texture2d) {", texture2DClassName)); sw.indent(); // Sets up the parameters as declared. { MagFilter magFilter = method.getAnnotation(MagFilter.class); TextureMagFilter textureMagFilter = magFilter != null ? magFilter.value() : TextureMagFilter.LINEAR; sw.println(String.format("texture2d.setMagFilter(%s.%s);", TextureMagFilter.class.getName(), textureMagFilter)); } { MinFilter minFilter = method.getAnnotation(MinFilter.class); TextureMinFilter textureMinFilter = minFilter != null ? minFilter.value() : TextureMinFilter.LINEAR; sw.println(String.format("texture2d.setMinFilter(%s.%s);", TextureMinFilter.class.getName(), textureMinFilter)); } { WrapMode wrapMode = method.getAnnotation(WrapMode.class); if (wrapMode != null) { sw.println(String.format("texture2d.setWrapMode(%s.%s);", TextureWrapMode.class.getName(), wrapMode.value())); } } if (method.getAnnotation(GenerateMipmap.class) != null) { sw.println("texture2d.generateMipmap();"); } sw.outdent(); sw.println("}"); // Creates method: String getName(); sw.println("public String getName() {"); sw.indent(); sw.println("return \"" + method.getName() + "\";"); sw.outdent(); sw.println("}"); sw.outdent(); sw.println("}"); return sw.toString(); }
From source file:gwt.g3d.resources.ShaderResourceGenerator.java
License:Apache License
@Override public String createAssignment(TreeLogger logger, ResourceContext context, JMethod method) throws UnableToCompleteException { URL[] resources = ResourceGeneratorUtil.findResources(logger, context, method); if (resources.length != 2) { logger.log(TreeLogger.ERROR, "Exactly two resources must be specified", null); throw new UnableToCompleteException(); }/*from www .j a v a 2s . c om*/ SourceWriter sw = new StringSourceWriter(); sw.println("new " + ShaderResource.class.getName() + "() {"); sw.indent(); sw.println("public String getVertexShaderSource() {"); sw.indent(); String vertexSource = Generator.escape(Util.readURLAsString(resources[0])); sw.println("return \"" + vertexSource + "\";"); sw.outdent(); sw.println("}"); sw.println("public String getFragmentShaderSource() {"); sw.indent(); String fragmentSource = Generator.escape(Util.readURLAsString(resources[1])); sw.println("return \"" + fragmentSource + "\";"); sw.outdent(); sw.println("}"); sw.println(String.format("public %s createShader(%s gl) throws %s {", AbstractShader.class.getName(), GL2.class.getName(), ShaderException.class.getName())); sw.indent(); sw.println(String.format("%s shader = %s;", AbstractShader.class.getName(), createAbstractShader(logger, context, method))); sw.println("shader.init(gl);"); sw.println("return shader;"); sw.outdent(); sw.println("}"); sw.println("public String getName() {"); sw.indent(); sw.println("return \"" + method.getName() + "\";"); sw.outdent(); sw.println("}"); sw.outdent(); sw.println("}"); return sw.toString(); }
From source file:gwt.g3d.resources.ShaderResourceGenerator.java
License:Apache License
/** * Creates an assignment for {@link AbstractShader}. *///ww w . ja v a 2s. co m private String createAbstractShader(TreeLogger logger, ResourceContext context, JMethod method) throws UnableToCompleteException { SourceWriter sw = new StringSourceWriter(); sw.println("new " + AbstractShader.class.getName() + "() {"); sw.indent(); sw.println(String.format("protected void initImpl() throws %s {", ShaderException.class.getName())); sw.indent(); sw.println("initProgram(getVertexShaderSource(), getFragmentShaderSource());"); sw.outdent(); sw.println("}"); sw.outdent(); sw.println("}"); return sw.toString(); }
From source file:gwt.ns.webworker.rebind.EmulatedWorkerFactoryGenerator.java
License:Apache License
@Override public void generateWorkerFactory(TreeLogger logger, GeneratorContext context, JClassType sourceType, String genName, PrintWriter out, ModuleDef modDef, JClassType workerEntryType) throws UnableToCompleteException { ClassSourceFileComposerFactory f = new ClassSourceFileComposerFactory(sourceType.getPackage().getName(), genName);/*from ww w .j a v a 2 s . c o m*/ // imports and interface f.addImport(Worker.class.getName()); f.addImport(WorkerImplProxy.class.getName()); f.addImport(workerEntryType.getQualifiedSourceName()); f.addImplementedInterface(sourceType.getName()); // new generated source file SourceWriter sw = f.createSourceWriter(context, out); // @Override // public Worker createAndStart() { // WorkerImplProxy proxy = new WorkerImplProxy(new RationalsWorker()); // return proxy; // } sw.println("@Override"); sw.println("public Worker createAndStart() {"); sw.indent(); sw.print("WorkerImplProxy proxy = new WorkerImplProxy(new "); sw.print(workerEntryType.getSimpleSourceName()); sw.println("());"); sw.println("return proxy;"); sw.outdent(); sw.println("}"); sw.commit(logger); }
From source file:gwt.ns.webworker.rebind.NativeWorkerFactoryGenerator.java
License:Apache License
@Override public void generateWorkerFactory(TreeLogger logger, GeneratorContext context, JClassType sourceType, String genName, PrintWriter out, ModuleDef modDef, JClassType workerEntryType) throws UnableToCompleteException { // native worker, so request worker compilation WorkerRequestArtifact request = new WorkerRequestArtifact(modDef.getCanonicalName(), modDef.getName()); context.commitArtifact(logger, request); ClassSourceFileComposerFactory f = new ClassSourceFileComposerFactory(sourceType.getPackage().getName(), genName);//from w w w . j a v a2s .co m // imports and interface f.addImport(Worker.class.getName()); f.addImport(WorkerImplNative.class.getName()); f.addImplementedInterface(sourceType.getName()); // new generated source file if (out != null) { SourceWriter sw = f.createSourceWriter(context, out); // @Override // public Worker createAndStart() { // return WorkerImplNative.create("PLACEHOLDER_PATH"); } // Note: placeholder path will be replaced by linker sw.println("@Override"); sw.println("public Worker createAndStart() {"); sw.indent(); sw.print("return WorkerImplNative.create(\""); sw.print(request.getRelativePlaceholderUrl()); sw.println("\");"); sw.outdent(); sw.println("}"); sw.commit(logger); } }
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>. * //from w w w . j a v a2 s . c o m * @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. * /* w w w.ja 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("}"); }