Java Code Examples for com.google.gwt.user.rebind.SourceWriter#commit()
The following examples show how to use
com.google.gwt.user.rebind.SourceWriter#commit() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ProxyViewCreator.java From putnami-web-toolkit with GNU Lesser General Public License v3.0 | 6 votes |
public String create(TreeLogger logger, GeneratorContext context) { PrintWriter printWriter = context.tryCreate(logger, this.packageName, this.viewProxySimpleName); if (printWriter == null) { return this.viewProxyQualifiedName; } SourceWriter srcWriter = this.getSourceWriter(printWriter, context); srcWriter.indent(); this.generateProxy(logger, srcWriter); srcWriter.println(); this.generateTokenPrefixes(logger, srcWriter); srcWriter.println(); if (this.placeTokenizerClass == null) { this.generateInternalTokenizer(logger, srcWriter); } else { this.generateDelegateTokenizer(logger, srcWriter); } this.generateActivityFactory(logger, srcWriter); srcWriter.outdent(); srcWriter.commit(logger); return this.viewProxyQualifiedName; }
Example 2
Source File: ServiceBinderCreator.java From putnami-web-toolkit with GNU Lesser General Public License v3.0 | 6 votes |
public String create(TreeLogger logger, GeneratorContext context) throws UnableToCompleteException, NotFoundException { PrintWriter printWriter = this.getPrintWriter(logger, context); if (printWriter == null) { return this.proxyModelQualifiedName; } this.serializerTypeName = this.createSerializer(logger, context); this.collectImports(); SourceWriter srcWriter = this.getSourceWriter(printWriter, context); srcWriter.indent(); srcWriter.println(); this.generateSerializer(srcWriter); srcWriter.println(); this.generateServiceImplementation(logger, srcWriter); this.generateServiceImplementationWithCallback(logger, srcWriter); srcWriter.outdent(); srcWriter.commit(logger); return this.proxyModelQualifiedName; }
Example 3
Source File: AbstractInjectorCreator.java From putnami-web-toolkit with GNU Lesser General Public License v3.0 | 6 votes |
public String create(TreeLogger logger, GeneratorContext context) { PrintWriter writer = context.tryCreate(logger, this.packageName, this.proxyName); if (writer == null) { return this.proxyQualifiedName; } SourceWriter srcWriter = this.getSourceWriter(writer, context); srcWriter.indent(); this.doCreate(logger, context, srcWriter); srcWriter.outdent(); srcWriter.commit(logger); return this.proxyQualifiedName; }
Example 4
Source File: RestServiceBinderCreator.java From putnami-web-toolkit with GNU Lesser General Public License v3.0 | 6 votes |
public String create(TreeLogger logger, GeneratorContext context) { PrintWriter printWriter = this.getPrintWriter(logger, context); if (printWriter == null) { return this.proxyModelQualifiedName; } this.collectImports(); SourceWriter srcWriter = this.getSourceWriter(printWriter, context); srcWriter.indent(); srcWriter.println(); this.generateCreateService(srcWriter); srcWriter.println(); this.generateServiceImplementation(logger, srcWriter); this.generateServiceImplementationWithCallback(srcWriter); srcWriter.outdent(); srcWriter.commit(logger); return this.proxyModelQualifiedName; }
Example 5
Source File: EventBinderGenerator.java From gwteventbinder with Apache License 2.0 | 6 votes |
@Override public String generate(TreeLogger logger, GeneratorContext context, String typeName) throws UnableToCompleteException { try { JClassType eventBinderType = context.getTypeOracle().getType(typeName); JClassType targetType = getTargetType(eventBinderType, context.getTypeOracle()); SourceWriter writer = createSourceWriter(logger, context, eventBinderType, targetType); if (writer != null) { // Otherwise the class was already created new EventBinderWriter( logger, context.getTypeOracle().getType(GenericEvent.class.getCanonicalName())) .writeDoBindEventHandlers(targetType, writer, context.getTypeOracle()); writer.commit(logger); } return getFullyQualifiedGeneratedClassName(eventBinderType); } catch (NotFoundException e) { logger.log(Type.ERROR, "Error generating " + typeName, e); throw new UnableToCompleteException(); } }
Example 6
Source File: ModelCreator.java From putnami-web-toolkit with GNU Lesser General Public License v3.0 | 5 votes |
public String create(TreeLogger logger, GeneratorContext context) { PrintWriter printWriter = this.getPrintWriter(logger, context, this.proxyModelQualifiedName); if (printWriter == null) { return this.proxyModelQualifiedName; } JField[] fields = this.beanType.getFields(); JMethod[] methods = this.beanType.getMethods(); this.parentType = this.beanType.getSuperclass(); this.imports.add(this.parentType); this.listPublicFields(fields); this.listGetters(methods); this.listSetters(methods); this.createSubModels(logger, context); SourceWriter srcWriter = this.getSourceWriter(printWriter, context); srcWriter.indent(); srcWriter.println(); this.generateSingleton(logger, srcWriter); srcWriter.println(); srcWriter.println(); this.generateStaticInitializer(logger, srcWriter); srcWriter.println(); this.generateConstructor(logger, srcWriter); srcWriter.println(); this.generateCreate(logger, srcWriter); srcWriter.println(); this.generateInternalSet(logger, srcWriter); srcWriter.println(); this.generateInternalGet(logger, srcWriter); srcWriter.outdent(); srcWriter.commit(logger); return this.proxyModelQualifiedName; }
Example 7
Source File: UiBinderLocalizedCreator.java From putnami-web-toolkit with GNU Lesser General Public License v3.0 | 5 votes |
public String create(TreeLogger logger, GeneratorContext context) { Resource templateResource = this.getTemplateResource(context); if (templateResource == null) { throw new NullPointerException("no template found"); } this.binderProxySimpleName = this.targetType.getSimpleSourceName() + "_" + this.binderType.getSimpleSourceName() + UiBinderLocalizedCreator.PROXY_SUFFIX; if (this.locale != null) { this.binderProxySimpleName += "_" + this.locale.toString(); } this.binderProxyQualifiedName = this.targetType.getPackage().getName() + "." + this.binderProxySimpleName; PrintWriter printWriter = this.getPrintWriter(logger, context, this.binderProxyQualifiedName); if (printWriter == null) { return this.binderProxyQualifiedName; } SourceWriter srcWriter = this.getSourceWriter(printWriter, context); srcWriter.println(); srcWriter.indent(); this.generateProxy(logger, srcWriter); srcWriter.println(); srcWriter.outdent(); srcWriter.commit(logger); return this.binderProxyQualifiedName; }
Example 8
Source File: TextBinderGenerator.java From EasyML with Apache License 2.0 | 4 votes |
@Override public String generate(TreeLogger logger, GeneratorContext context, String requestedClass) throws UnableToCompleteException { TypeOracle typeOracle = context.getTypeOracle(); JClassType objectType = typeOracle.findType(requestedClass); if (objectType == null) { logger.log(TreeLogger.ERROR, "Could not find type: " + requestedClass); throw new UnableToCompleteException(); } implTypeName = objectType.getSimpleSourceName() + "Impl"; implPackageName = objectType.getPackage().getName(); JClassType[] implementedTypes = objectType.getImplementedInterfaces(); // Can only implement one interface if (implementedTypes == null || implementedTypes.length != 1 || !implementedTypes[0].getQualifiedSourceName().equals( TextBinder.class.getName())) { logger .log( TreeLogger.ERROR, "The type: " + requestedClass + " Must implement only one interface: " + TextBinder.class.getName()); throw new UnableToCompleteException(); } // Get parameterized type JParameterizedType parameterType = implementedTypes[0].isParameterized(); if (parameterType == null) { logger.log(TreeLogger.ERROR, "The type: " + requestedClass + " Must implement only one parameterized interface: " + TextBinder.class.getName()); throw new UnableToCompleteException(); } if (parameterType.getTypeArgs() == null || parameterType.getTypeArgs().length != 2) { logger.log(TreeLogger.ERROR, "The type: " + requestedClass + " Must implement two parameterized interface: " + TextBinder.class.getName() + " with two Parameter"); throw new UnableToCompleteException(); } parameterizedType1 = parameterType.getTypeArgs()[0]; parameterizedType2 = parameterType.getTypeArgs()[1]; // logger.log(TreeLogger.INFO , // parameterizedType2.getParameterizedQualifiedSourceName() +"\n" // + parameterizedType2.getQualifiedSourceName()); ClassSourceFileComposerFactory composerFactory = new ClassSourceFileComposerFactory( implPackageName, implTypeName); composerFactory.addImport(Map.class.getCanonicalName()); composerFactory.addImport(List.class.getCanonicalName()); // composerFactory.addImport(Field.class.getCanonicalName()); composerFactory .addImplementedInterface(objectType.getQualifiedSourceName()); PrintWriter printWriter = context.tryCreate(logger, implPackageName, implTypeName); if (printWriter != null) { SourceWriter sourceWriter = composerFactory.createSourceWriter(context, printWriter); composeBindMethod(logger, sourceWriter); composeSyncMethod(logger, sourceWriter); sourceWriter.commit(logger); } return implPackageName + "." + implTypeName; }
Example 9
Source File: Mvp4gRunAsyncGenerator.java From mvp4g with Apache License 2.0 | 4 votes |
private RebindResult create(JClassType originalType, TreeLogger logger, GeneratorContext context, String typeName) throws UnableToCompleteException { Date start = new Date(); String packageName = originalType.getPackage() .getName(); String originalClassName = originalType.getSimpleSourceName(); String generatedClassName = originalClassName + "Impl"; String generatedClassQualifiedName = packageName + "." + generatedClassName; // check weather there is a usual version or not. if (checkAlreadyGenerated(logger, context, generatedClassQualifiedName)) { // Log logger.log(TreeLogger.INFO, "reuse already generated files", null); // stop generating return new RebindResult(RebindMode.USE_EXISTING, generatedClassQualifiedName); } logger.log(TreeLogger.INFO, "Generating writer for " + packageName + "." + generatedClassName, null); PrintWriter printWriter = context.tryCreate(logger, packageName, generatedClassName); ClassSourceFileComposerFactory classFactory = new ClassSourceFileComposerFactory(packageName, generatedClassName); classFactory.addImplementedInterface(originalType.getName()); String[] classesToImport = getClassesToImport(); for (String classToImport : classesToImport) { classFactory.addImport(classToImport); } if (printWriter != null) { SourceWriter sourceWriter = classFactory.createSourceWriter(context, printWriter); logger.log(TreeLogger.INFO, "Generating source for " + generatedClassQualifiedName + " ", null); writeClass(sourceWriter, getRunAsync(originalType)); sourceWriter.commit(logger); } Date end = new Date(); logger.log(TreeLogger.INFO, "Mvp4g Module Cretor: " + (end.getTime() - start.getTime()) + "ms."); return new RebindResult(RebindMode.USE_ALL_NEW_WITH_NO_CACHING, generatedClassQualifiedName); }
Example 10
Source File: Mvp4gGenerator.java From mvp4g with Apache License 2.0 | 4 votes |
private RebindResult create(TreeLogger logger, GeneratorContext context, String moduleName) throws UnableToCompleteException { Date start = new Date(); String generatedClassQualifiedName; try { TypeOracle typeOracle = context.getTypeOracle(); JClassType module = typeOracle.findType(moduleName); if (module == null) { logger.log(TreeLogger.ERROR, "Unable to find metadata for type '" + moduleName + "'", null); throw new UnableToCompleteException(); } @SuppressWarnings("unchecked") Map<Class<? extends Annotation>, List<JClassType>> scanResult = AnnotationScanner.scan(logger, typeOracle, new Class[] { Presenter.class, History.class, Events.class, Service.class, EventHandler.class }); Mvp4gConfiguration configuration = new Mvp4gConfiguration(logger, context); String suffix = "Impl" + configuration.load(module, scanResult); generatedClassQualifiedName = module.getParameterizedQualifiedSourceName() + suffix; String packageName = module.getPackage() .getName(); String originalClassName = module.getSimpleSourceName(); String generatedClassName = originalClassName + suffix; // check weather there is a usual version or not. if (checkAlreadyGenerated(logger, context, configuration)) { // Log logger.log(TreeLogger.INFO, "Reuse already generated files", null); // stop generating return new RebindResult(RebindMode.USE_EXISTING, packageName + "." + generatedClassName); } // Log logger.log(TreeLogger.INFO, "Start generate files ... ", null); // No, there is non. Create a new one. SourceWriter sourceWriter = getSourceWriter(logger, context, module, packageName, generatedClassName); if (sourceWriter != null) { logger.log(TreeLogger.INFO, "Generating source for " + generatedClassQualifiedName + " ", null); Mvp4gConfigurationFileWriter writer = new Mvp4gConfigurationFileWriter(sourceWriter, configuration); writer.writeConf(); sourceWriter.commit(logger); } else { // don't expect this to occur, but could happen if an instance was // recently generated but not yet committed new RebindResult(RebindMode.USE_EXISTING, generatedClassQualifiedName); } Date end = new Date(); logger.log(TreeLogger.INFO, "Mvp4g Compilation: " + (end.getTime() - start.getTime()) + "ms."); return new RebindResult(RebindMode.USE_ALL_NEW_WITH_NO_CACHING, packageName + "." + generatedClassName); } catch (InvalidMvp4gConfigurationException e) { logger.log(TreeLogger.ERROR, e.getMessage(), e); throw new UnableToCompleteException(); } }