List of usage examples for com.google.gwt.user.rebind SourceWriter println
void println(String s);
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);//w w w. j a v a 2 s .co 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 ww w . j a v a 2 s . c om*/ // 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:io.reinert.requestor.rebind.JsonAutoBeanGenerator.java
License:Apache License
private void generateConstructor(SourceWriter srcWriter, Iterable<String> serdes, Iterable<String> providers) { srcWriter.println("public GeneratedJsonSerdesImpl() {"); for (String s : serdes) { srcWriter.println(" serdesList.add(%s);", s); }// w w w . j a v a2 s . c om for (String s : providers) { srcWriter.println(" providersList.add(%s);", s); } srcWriter.println("}"); srcWriter.println(); }
From source file:io.reinert.requestor.rebind.JsonAutoBeanGenerator.java
License:Apache License
private void generateFields(SourceWriter srcWriter) { // Initialize a field with binary name of the remote service interface srcWriter.println("private final ArrayList<Serdes<?>> serdesList = new ArrayList<Serdes<?>>();"); srcWriter.println("private final ArrayList<GeneratedProvider<?>> providersList = " + "new ArrayList<GeneratedProvider<?>>();"); srcWriter.println();//from w w w. j a va 2s.c om }
From source file:io.reinert.requestor.rebind.JsonAutoBeanGenerator.java
License:Apache License
private void generateMethods(SourceWriter srcWriter) { srcWriter.println("@Override"); srcWriter.println("public List<Serdes<?>> getGeneratedSerdes() {"); srcWriter.println(" return serdesList;"); srcWriter.println("}"); srcWriter.println();// w w w . j a v a 2 s .c om srcWriter.println("@Override"); srcWriter.println("public List<GeneratedProvider<?>> getGeneratedProviders() {"); srcWriter.println(" return providersList;"); srcWriter.println("}"); srcWriter.println(); }
From source file:io.reinert.requestor.rebind.JsonGwtJacksonGenerator.java
License:Apache License
private void generateConstructor(SourceWriter srcWriter, ArrayList<String> serdes) { srcWriter.println("public GeneratedJsonSerdesImpl() {"); for (String s : serdes) { srcWriter.println(" serdesList.add(%s);", s); }/*from ww w . ja va 2 s . c om*/ srcWriter.println("}"); srcWriter.println(); }
From source file:io.reinert.requestor.rebind.JsonGwtJacksonGenerator.java
License:Apache License
private void generateFields(SourceWriter srcWriter) { srcWriter.println("private final ArrayList<Serdes<?>> serdesList = new ArrayList<Serdes<?>>();"); srcWriter.println("private final ArrayList<GeneratedProvider<?>> providersList = " + "new ArrayList<GeneratedProvider<?>>();"); srcWriter.println();/*ww w. j a va2s . c o m*/ }
From source file:net.officefloor.plugin.gwt.comet.generate.CometAdapterGenerator.java
License:Open Source License
@Override public String generate(TreeLogger logger, GeneratorContext context, String typeName) throws UnableToCompleteException { final String COMET_LISTENER_CLASS_NAME = CometSubscriber.class.getName(); // Determine if the CometListener if (COMET_LISTENER_CLASS_NAME.equals(typeName)) { logger.log(Type.DEBUG, "Not generating for " + typeName); return typeName; // use CometListener as is }//ww w. j a v a2 s. c om // Obtain the type TypeOracle oracle = context.getTypeOracle(); JClassType type = oracle.findType(typeName); if (type == null) { logger.log(Type.ERROR, "Can not find " + JClassType.class.getSimpleName() + " for " + typeName); throw new UnableToCompleteException(); } // Ensure type has correct signature JMethod[] methods = type.getMethods(); if (methods.length != 1) { logger.log(Type.ERROR, "Interface " + type.getQualifiedSourceName() + " must only have one method declared as the interface is marked with " + CometSubscriber.class.getSimpleName()); throw new UnableToCompleteException(); } JMethod method = methods[0]; // Ensure method has only one parameter JParameter[] parameters = method.getParameters(); JParameter eventParameter = null; JParameter matchKeyParameter = null; switch (parameters.length) { case 2: matchKeyParameter = parameters[1]; case 1: eventParameter = parameters[0]; case 0: break; default: // Too many parameters logger.log(Type.ERROR, "Interface method " + type.getQualifiedSourceName() + "." + method.getName() + " must have no more than two parameters (event and match key) as the interface is marked with " + CometSubscriber.class.getSimpleName()); throw new UnableToCompleteException(); } // Ensure no throws on the method if (method.getThrows().length != 0) { logger.log(Type.ERROR, "Interface method " + type.getQualifiedSourceName() + "." + method.getName() + " must not throw exceptions as the interface is marked with " + CometSubscriber.class.getSimpleName()); throw new UnableToCompleteException(); } // Obtain details to generate adapter class String packageName = type.getPackage().getName(); String simpleName = type.getSimpleSourceName() + "Adapter"; String qualifiedName = packageName + "." + simpleName; String methodName = method.getName(); logger.log(Type.TRACE, "Generating " + CometSubscriber.class.getSimpleName() + " Adapter for " + typeName + " [resulting class " + qualifiedName + "]"); // Generate the adapter ClassSourceFileComposerFactory adapter = new ClassSourceFileComposerFactory(packageName, simpleName); adapter.addImplementedInterface(CometAdapter.class.getName()); adapter.addImport(CometAdapter.class.getName()); adapter.addImport(OfficeFloorComet.class.getName()); PrintWriter src = context.tryCreate(logger, packageName, simpleName); if (src == null) { logger.log(Type.TRACE, qualifiedName + " for adapting " + CometSubscriber.class.getSimpleName() + " already generated."); return qualifiedName; // should already exist } SourceWriter writer = adapter.createSourceWriter(context, src); // Provide handleEvent method writer.println("@Override"); writer.println("public void handleEvent(Object handler, Object event, Object matchKey) {"); writer.print(" ((" + typeName + ") handler)." + methodName + "("); if (eventParameter != null) { writer.print("(" + eventParameter.getType().getQualifiedSourceName() + ") event"); } if (matchKeyParameter != null) { writer.print(", (" + matchKeyParameter.getType().getQualifiedSourceName() + ") matchKey"); } writer.println(");"); writer.println("}"); writer.println(); // Provide createPublisher method writer.println("@Override"); writer.println("public Object createPublisher() {"); writer.println(" return new " + typeName + "() {"); writer.println(" @Override"); writer.print(" public void " + methodName + "("); if (eventParameter != null) { writer.print(eventParameter.getType().getQualifiedSourceName() + " event"); } if (matchKeyParameter != null) { writer.print(", " + matchKeyParameter.getType().getQualifiedSourceName() + " matchKey"); } writer.print(") {"); writer.println(" OfficeFloorComet.publish(" + typeName + ".class, " + (eventParameter == null ? "null" : "event") + ", " + (matchKeyParameter == null ? "null" : "matchKey") + ");"); writer.println(" }"); writer.println(" };"); writer.println("}"); writer.commit(logger); // Return adapter return qualifiedName; }
From source file:net.officefloor.plugin.gwt.comet.generate.CometAdapterMapGenerator.java
License:Open Source License
@Override public String generate(TreeLogger logger, GeneratorContext context, String typeName) throws UnableToCompleteException { // Obtain the type TypeOracle oracle = context.getTypeOracle(); JClassType type = oracle.findType(typeName); if (type == null) { logger.log(Type.ERROR, "Can not find " + JClassType.class.getSimpleName() + " for " + typeName); throw new UnableToCompleteException(); }//from ww w. j av a2s .co m // Obtain details to generate adapter class String packageName = type.getPackage().getName(); String simpleName = type.getSimpleSourceName() + "Impl"; String qualifiedName = packageName + "." + simpleName; logger.log(Type.TRACE, "Generating " + CometAdapterMap.class.getSimpleName() + " implementation"); // Obtain the CometListener type JClassType cometListenerType = oracle.findType(CometSubscriber.class.getName()); if (cometListenerType == null) { logger.log(Type.ERROR, "Can not find " + JClassType.class.getSimpleName() + " for " + CometSubscriber.class.getName()); throw new UnableToCompleteException(); } // Generate the map ClassSourceFileComposerFactory adapter = new ClassSourceFileComposerFactory(packageName, simpleName); adapter.addImplementedInterface(CometAdapterMap.class.getName()); adapter.addImport(CometAdapterMap.class.getName()); adapter.addImport(CometAdapter.class.getName()); adapter.addImport(Map.class.getName()); adapter.addImport(HashMap.class.getName()); adapter.addImport(GWT.class.getName()); PrintWriter src = context.tryCreate(logger, packageName, simpleName); if (src == null) { logger.log(Type.WARN, qualifiedName + " for " + CometAdapterMap.class.getSimpleName() + " implementation already generated."); return qualifiedName; // should already exist } SourceWriter writer = adapter.createSourceWriter(context, src); writer.println("@Override"); writer.println("public Map<Class<?>, " + CometAdapter.class.getSimpleName() + "> getMap() {"); writer.println(" Map<Class<?>, " + CometAdapter.class.getSimpleName() + "> map = new HashMap<Class<?>, " + CometAdapter.class.getSimpleName() + ">();"); // Add all CometListener types to the map for (JClassType check : oracle.getTypes()) { // Determine if a CometListener type if (!(check.getFlattenedSupertypeHierarchy().contains(cometListenerType))) { logger.log(Type.DEBUG, "Type " + check.getQualifiedSourceName() + " not included in map for " + simpleName); continue; // ignore non CometListener type } // Ensure not the actual CometListener type if (cometListenerType.getQualifiedSourceName().equals(check.getQualifiedSourceName())) { logger.log(Type.DEBUG, "Not including " + check.getQualifiedSourceName() + " in map for " + simpleName); continue; // ignore the CometListener } // Add to map String serviceTypeName = check.getQualifiedSourceName(); logger.log(Type.TRACE, "Including " + serviceTypeName + " in map for " + simpleName); writer.println(" map.put(" + serviceTypeName + ".class, (" + CometAdapter.class.getSimpleName() + ") GWT.create(" + serviceTypeName + ".class));"); } writer.println(" return map;"); writer.println("}"); // Committing logger.log(Type.TRACE, "Committing " + CometAdapterMap.class.getSimpleName() + " implementation to have type created"); writer.commit(logger); logger.log(Type.TRACE, CometAdapterMap.class.getSimpleName() + " created"); // Return adapter return qualifiedName; }
From source file:net.sf.gilead.proxy.gwt.AbstractGwtProxyGenerator.java
License:Apache License
/** * Generates an additional attribute// w w w .j a va2 s .c o m * * @param sourceWriter * @param attribute */ protected void generateAttribute(SourceWriter sourceWriter, Attribute attribute) { // Javadoc comment if needed // if (StringUtils.isEmpty(attribute.getJavadoc()) == false) { sourceWriter.beginJavaDocComment(); sourceWriter.println(attribute.getJavadoc()); sourceWriter.endJavaDocComment(); } // Add attribute // sourceWriter.println(attribute.toJava5String()); // }