Java Code Examples for com.google.gwt.user.rebind.ClassSourceFileComposerFactory#createSourceWriter()
The following examples show how to use
com.google.gwt.user.rebind.ClassSourceFileComposerFactory#createSourceWriter() .
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: UiBinderLocalizedCreator.java From putnami-web-toolkit with GNU Lesser General Public License v3.0 | 6 votes |
private SourceWriter getSourceWriter(PrintWriter printWriter, GeneratorContext ctx) { String packageName = this.binderType.getPackage().getName(); String className = this.binderProxySimpleName; ClassSourceFileComposerFactory composerFactory = new ClassSourceFileComposerFactory(packageName, className); composerFactory.addImport(GWT.class.getName()); composerFactory.addImport(UiBinder.class.getName()); composerFactory.addImport(UiBinderLocalized.class.getName()); composerFactory.addImport(UiTemplate.class.getName()); composerFactory.addImport(this.binderType.getQualifiedSourceName()); composerFactory.addImport(this.widgetType.getQualifiedSourceName()); composerFactory.addImport(this.targetType.getQualifiedSourceName()); composerFactory.addImplementedInterface(UiBinderLocalized.class.getSimpleName() + "<" + this.widgetType.getSimpleSourceName() + "," + this.targetType.getSimpleSourceName() + ">"); composerFactory.addImplementedInterface(UiBinder.class.getSimpleName() + "<" + this.widgetType.getSimpleSourceName() + "," + this.targetType.getSimpleSourceName() + ">"); composerFactory.addImplementedInterface(this.binderType.getSimpleSourceName()); return composerFactory.createSourceWriter(ctx, printWriter); }
Example 2
Source File: EventBinderGenerator.java From gwteventbinder with Apache License 2.0 | 6 votes |
private SourceWriter createSourceWriter( TreeLogger logger, GeneratorContext context, JClassType eventBinderType, JClassType targetType) { String simpleName = getSimpleGeneratedClassName(eventBinderType); String packageName = eventBinderType.getPackage().getName(); ClassSourceFileComposerFactory composer = new ClassSourceFileComposerFactory(packageName, simpleName); composer.setSuperclass(AbstractEventBinder.class.getCanonicalName() + "<" + targetType.getQualifiedSourceName() + ">"); composer.addImplementedInterface(eventBinderType.getName()); composer.addImport(EventBinder.class.getCanonicalName()); composer.addImport(EventBus.class.getCanonicalName()); composer.addImport(GenericEvent.class.getCanonicalName()); composer.addImport(GenericEventHandler.class.getCanonicalName()); composer.addImport(HandlerRegistration.class.getCanonicalName()); composer.addImport(LinkedList.class.getCanonicalName()); composer.addImport(List.class.getCanonicalName()); PrintWriter printWriter = context.tryCreate(logger, packageName, simpleName); return (printWriter != null) ? composer.createSourceWriter(context, printWriter) : null; }
Example 3
Source File: Mvp4gGenerator.java From mvp4g with Apache License 2.0 | 5 votes |
private SourceWriter getSourceWriter(TreeLogger logger, GeneratorContext context, JClassType originalType, String packageName, String generatedClassName) throws UnableToCompleteException { logger.log(TreeLogger.INFO, "Generating writer for " + packageName + "." + generatedClassName, null); PrintWriter printWriter = context.tryCreate(logger, packageName, generatedClassName); if (printWriter == null) { return null; } ClassSourceFileComposerFactory classFactory = new ClassSourceFileComposerFactory(packageName, generatedClassName); classFactory.addImplementedInterface(originalType.getName()); String[] classesToImport = getClassesToImport(); for (String classToImport : classesToImport) { classFactory.addImport(classToImport); } return classFactory.createSourceWriter(context, printWriter); }
Example 4
Source File: ModelCreator.java From putnami-web-toolkit with GNU Lesser General Public License v3.0 | 5 votes |
private SourceWriter getSourceWriter(PrintWriter printWriter, GeneratorContext ctx) { String packageName = this.proxyModelQualifiedName.indexOf('.') == -1 ? "" : this.proxyModelQualifiedName.substring(0, this.proxyModelQualifiedName.lastIndexOf('.')); String className = this.proxyModelQualifiedName.indexOf('.') == -1 ? this.proxyModelQualifiedName : this.proxyModelQualifiedName .substring(this.proxyModelQualifiedName.lastIndexOf('.') + 1, this.proxyModelQualifiedName.length()); ClassSourceFileComposerFactory composerFactory = new ClassSourceFileComposerFactory(packageName, className); composerFactory.addImport(Map.class.getName()); composerFactory.addImport(Maps.class.getName()); composerFactory.addImport(GWT.class.getName()); composerFactory.addImport(Model.class.getName()); composerFactory.addImport(AbstractModel.class.getName()); composerFactory.addImport(ModelCollection.class.getName()); composerFactory.addImport(PropertyDescription.class.getName()); composerFactory.addImport(PrimitiveUtils.class.getName()); composerFactory.addImport(this.beanType.getQualifiedSourceName()); composerFactory.addImport("fr.putnami.pwt.core.editor.client.validator.*"); for (JType jType : this.imports) { if (jType.isPrimitive() != null) { continue; } composerFactory.addImport(jType.getQualifiedSourceName()); } for (String submodel : this.subModels.values()) { composerFactory.addImport(submodel); } composerFactory .setSuperclass(AbstractModel.class.getSimpleName() + "<" + this.beanType.getSimpleSourceName() + ">"); return composerFactory.createSourceWriter(ctx, printWriter); }
Example 5
Source File: ProxyViewCreator.java From putnami-web-toolkit with GNU Lesser General Public License v3.0 | 5 votes |
private SourceWriter getSourceWriter(PrintWriter printWriter, GeneratorContext ctx) { ClassSourceFileComposerFactory composerFactory = new ClassSourceFileComposerFactory(this.packageName, this.viewProxySimpleName); composerFactory.setSuperclass(this.placeType.getSimpleSourceName()); composerFactory.addImport(GWT.class.getName()); composerFactory.addImport(RunAsyncCallback.class.getName()); composerFactory.addImport(ViewProxy.class.getName()); composerFactory.addImport(Place.class.getName()); composerFactory.addImport(ViewPlace.class.getName()); composerFactory.addImport(Activity.class.getName()); composerFactory.addImport(ViewActivity.class.getName()); composerFactory.addImport(ApplicationUnreachableException.class.getName()); composerFactory.addImport(this.placeType.getQualifiedSourceName()); composerFactory.addImport(this.activityDescrition.view().getCanonicalName()); if (this.placeTokenizerClass != null) { composerFactory.addImport(this.placeTokenizerClass.getCanonicalName()); } if (this.viewDecoratorClass != null) { composerFactory.addImport(this.viewDecoratorClass.getCanonicalName()); } composerFactory.addImplementedInterface( ViewProxy.class.getSimpleName() + "<" + this.placeType.getSimpleSourceName() + ">"); return composerFactory.createSourceWriter(ctx, printWriter); }
Example 6
Source File: ServiceBinderCreator.java From putnami-web-toolkit with GNU Lesser General Public License v3.0 | 5 votes |
private SourceWriter getSourceWriter(PrintWriter printWriter, GeneratorContext ctx) { String packageName = this.handlerType.getPackage().getName(); String className = this.proxyModelQualifiedName.indexOf('.') == -1 ? this.proxyModelQualifiedName : this.proxyModelQualifiedName.substring( this.proxyModelQualifiedName.lastIndexOf('.') + 1, this.proxyModelQualifiedName.length()); ClassSourceFileComposerFactory composerFactory = new ClassSourceFileComposerFactory(packageName, className); composerFactory.addImport(AsyncCallback.class.getName()); composerFactory.addImport(AbstractServiceBinder.class.getName()); composerFactory.addImport(Arrays.class.getName()); composerFactory.addImport(Lists.class.getName()); composerFactory.addImport(CommandDefinition.class.getName()); composerFactory.addImport(CommandParam.class.getName()); composerFactory.addImport(CallbackAdapter.class.getName()); composerFactory.addImport(CommandController.class.getName()); composerFactory.addImport(this.serviceType.getQualifiedSourceName()); composerFactory.addImport(this.serviceBinderType.getQualifiedSourceName()); for (JType jType : this.imports) { if (jType.isPrimitive() != null) { continue; } composerFactory.addImport(jType.getQualifiedSourceName()); } composerFactory.setSuperclass(AbstractServiceBinder.class.getSimpleName() + "<" + this.handlerType.getSimpleSourceName() + ", " + this.serviceType.getSimpleSourceName() + ">"); composerFactory.addImplementedInterface(this.serviceType.getSimpleSourceName()); composerFactory.addImplementedInterface(this.serviceBinderType.getSimpleSourceName()); return composerFactory.createSourceWriter(ctx, printWriter); }
Example 7
Source File: AbstractInjectorCreator.java From putnami-web-toolkit with GNU Lesser General Public License v3.0 | 5 votes |
private SourceWriter getSourceWriter(PrintWriter printWriter, GeneratorContext ctx) { ClassSourceFileComposerFactory composerFactory = new ClassSourceFileComposerFactory(this.packageName, this.proxyName); composerFactory.addImport(GWT.class.getName()); composerFactory.addImport(this.injectableType.getQualifiedSourceName()); composerFactory.setSuperclass(this.injectableType.getSimpleSourceName()); for (InjectorWritterInit delegate : Iterables.filter(this.delegates, InjectorWritterInit.class)) { delegate.initComposer(composerFactory); } return composerFactory.createSourceWriter(ctx, printWriter); }
Example 8
Source File: RestServiceBinderCreator.java From putnami-web-toolkit with GNU Lesser General Public License v3.0 | 5 votes |
private SourceWriter getSourceWriter(PrintWriter printWriter, GeneratorContext ctx) { String packageName = this.handlerType.getPackage().getName(); String className = this.proxyModelQualifiedName.indexOf('.') == -1 ? this.proxyModelQualifiedName : this.proxyModelQualifiedName.substring( this.proxyModelQualifiedName.lastIndexOf('.') + 1, this.proxyModelQualifiedName.length()); ClassSourceFileComposerFactory composerFactory = new ClassSourceFileComposerFactory(packageName, className); composerFactory.addImport(AbstractServiceBinder.class.getName()); composerFactory.addImport(Arrays.class.getName()); composerFactory.addImport(Lists.class.getName()); composerFactory.addImport(MethodCallbackAdapter.class.getName()); composerFactory.addImport(Method.class.getName()); composerFactory.addImport(CompositeMethodCallback.class.getName()); composerFactory.addImport(CallbackAdapter.class.getName()); composerFactory.addImport(REST.class.getName()); composerFactory.addImport(GWT.class.getName()); composerFactory.addImport(this.serviceType.getQualifiedSourceName()); composerFactory.addImport(this.serviceBinderType.getQualifiedSourceName()); for (JType jType : this.imports) { if (jType.isPrimitive() != null) { continue; } composerFactory.addImport(jType.getQualifiedSourceName()); } composerFactory.setSuperclass(AbstractServiceBinder.class.getSimpleName() + "<" + this.handlerType.getSimpleSourceName() + ", " + this.serviceType.getSimpleSourceName() + ">"); composerFactory.addImplementedInterface(this.serviceType.getSimpleSourceName()); composerFactory.addImplementedInterface(this.serviceBinderType.getSimpleSourceName()); return composerFactory.createSourceWriter(ctx, printWriter); }
Example 9
Source File: ProductConfigGenerator.java From core with GNU Lesser General Public License v2.1 | 5 votes |
/** * Generate source code for new class. Class extends * <code>HashMap</code>. * * @param logger Logger object * @param context Generator context */ private void generateClass(TreeLogger logger, GeneratorContext context) throws Throwable { // get print writer that receives the source code PrintWriter printWriter = context.tryCreate(logger, packageName, className); // print writer if null, source code has ALREADY been generated, return if (printWriter == null) { return; } // init composer, set class properties, create source writer ClassSourceFileComposerFactory composerFactory = new ClassSourceFileComposerFactory(packageName, className); // Imports composerFactory.addImport("org.jboss.as.console.client.Console"); composerFactory.addImport("org.jboss.as.console.client.ProductConfig"); composerFactory.addImport("java.util.*"); // Interfaces composerFactory.addImplementedInterface("org.jboss.as.console.client.ProductConfig"); // SourceWriter SourceWriter sourceWriter = composerFactory.createSourceWriter(context, printWriter); // ctor generateConstructor(sourceWriter); // Methods generateMethods(logger, sourceWriter, context); // close generated class sourceWriter.outdent(); sourceWriter.println("}"); // commit generated class context.commit(logger, printWriter); }
Example 10
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 11
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 12
Source File: JsonAutoBeanGenerator.java From requestor with Apache License 2.0 | 4 votes |
private SourceWriter getSourceWriter(TreeLogger logger, GeneratorContext ctx, JClassType intfType) { JPackage serviceIntfPkg = intfType.getPackage(); String packageName = serviceIntfPkg == null ? "" : serviceIntfPkg.getName(); PrintWriter printWriter = ctx.tryCreate(logger, packageName, getTypeSimpleName()); if (printWriter == null) { return null; } ClassSourceFileComposerFactory composerFactory = new ClassSourceFileComposerFactory(packageName, getTypeSimpleName()); String[] imports = new String[]{ // java.util ArrayList.class.getCanonicalName(), Collection.class.getCanonicalName(), List.class.getCanonicalName(), Iterator.class.getCanonicalName(), Set.class.getCanonicalName(), // com.google.gwt.core.client GWT.class.getCanonicalName(), // com.google.web.bindery.autobean.shared AutoBean.class.getCanonicalName(), AutoBeanCodex.class.getCanonicalName(), AutoBeanFactory.class.getCanonicalName(), AutoBeanUtils.class.getCanonicalName(), // io.reinert.requestor.serialization DeserializationContext.class.getCanonicalName(), Deserializer.class.getCanonicalName(), HasImpl.class.getCanonicalName(), Serdes.class.getCanonicalName(), Serializer.class.getCanonicalName(), SerializationContext.class.getCanonicalName(), UnableToDeserializeException.class.getName(), UnableToSerializeException.class.getName(), // io.reinert.requestor.serialization.json JsonObjectSerdes.class.getCanonicalName(), JsonRecordReader.class.getCanonicalName(), JsonRecordWriter.class.getCanonicalName(), }; for (String imp : imports) { composerFactory.addImport(imp); } composerFactory.addImplementedInterface(intfType.getErasedType().getQualifiedSourceName()); return composerFactory.createSourceWriter(ctx, printWriter); }
Example 13
Source File: JsonGwtJacksonGenerator.java From requestor with Apache License 2.0 | 4 votes |
private SourceWriter getSourceWriter(TreeLogger logger, GeneratorContext ctx, JClassType intfType) { JPackage serviceIntfPkg = intfType.getPackage(); String packageName = serviceIntfPkg == null ? "" : serviceIntfPkg.getName(); PrintWriter printWriter = ctx.tryCreate(logger, packageName, getTypeSimpleName()); if (printWriter == null) { return null; } ClassSourceFileComposerFactory composerFactory = new ClassSourceFileComposerFactory(packageName, getTypeSimpleName()); String[] imports = new String[]{ // java ArrayList.class.getCanonicalName(), Collection.class.getCanonicalName(), HashSet.class.getCanonicalName(), Iterator.class.getCanonicalName(), LinkedHashSet.class.getCanonicalName(), LinkedList.class.getCanonicalName(), List.class.getCanonicalName(), Set.class.getCanonicalName(), TreeSet.class.getCanonicalName(), // com.github.nmorel.gwtjackson ObjectMapper.class.getCanonicalName(), ObjectReader.class.getCanonicalName(), ObjectWriter.class.getCanonicalName(), // com.google.gwt GWT.class.getCanonicalName(), // io.reinert.requestor DeserializationContext.class.getCanonicalName(), Deserializer.class.getCanonicalName(), JsonObjectSerdes.class.getCanonicalName(), JsonRecordReader.class.getCanonicalName(), JsonRecordWriter.class.getCanonicalName(), UnableToDeserializeException.class.getName(), UnableToSerializeException.class.getName(), Serdes.class.getCanonicalName(), Serializer.class.getCanonicalName(), SerializationContext.class.getCanonicalName() }; for (String imp : imports) { composerFactory.addImport(imp); } composerFactory.addImplementedInterface(intfType.getErasedType().getQualifiedSourceName()); return composerFactory.createSourceWriter(ctx, printWriter); }
Example 14
Source File: ApplicationMetaDataGenerator.java From core with GNU Lesser General Public License v2.1 | 4 votes |
/** * Generate source code for new class. Class extends * <code>HashMap</code>. * * @param logger Logger object * @param context Generator context */ private void generateClass(TreeLogger logger, GeneratorContext context) { // get print writer that receives the source code PrintWriter printWriter = context.tryCreate(logger, packageName, className); // print writer if null, source code has ALREADY been generated, return if (printWriter == null) return; // init composer, set class properties, create source writer ClassSourceFileComposerFactory composerFactory = new ClassSourceFileComposerFactory(packageName, className); // Imports composerFactory.addImport("org.jboss.as.console.client.Console"); composerFactory.addImport("org.jboss.as.console.client.widgets.forms.*"); composerFactory.addImport("java.util.*"); // Interfaces composerFactory.addImplementedInterface("org.jboss.as.console.client.widgets.forms.ApplicationMetaData"); // SourceWriter SourceWriter sourceWriter = composerFactory.createSourceWriter(context, printWriter); // fields generateFields(sourceWriter); // ctor generateConstructor(logger, context, sourceWriter); // Methods generateMethods(sourceWriter); // close generated class sourceWriter.outdent(); sourceWriter.println("}"); // commit generated class context.commit(logger, printWriter); }