Java Code Examples for com.google.gwt.user.rebind.SourceWriter#outdent()
The following examples show how to use
com.google.gwt.user.rebind.SourceWriter#outdent() .
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: InjectMvpDescriptionCreator.java From putnami-web-toolkit with GNU Lesser General Public License v3.0 | 6 votes |
@Override public void writeEntryPoint(SourceWriter srcWriter) { srcWriter.println("MvpController mvpController = MvpController.get();"); srcWriter.println("AcceptsOneWidget mvpDisplay = null;"); if (this.display != null && !AcceptsOneWidget.class.equals(this.display)) { srcWriter.println("mvpDisplay = GWT.create(%s.class);", InjectCreatorUtil.toClassName(this.display)); } srcWriter.println("if(mvpDisplay != null){"); srcWriter.indent(); srcWriter.println("mvpController.setDisplay(mvpDisplay);"); srcWriter.outdent(); srcWriter.println("}"); srcWriter.println("if(mvpDisplay instanceof IsWidget){"); srcWriter.indent(); srcWriter.println("RootPanel.get().add((IsWidget) mvpDisplay);"); srcWriter.outdent(); srcWriter.println("}"); if (this.defaultPlace != null && !Place.class.equals(this.defaultPlace)) { srcWriter.println("mvpController.setDefaultPlace(new %s());", InjectCreatorUtil.toClassName(this.defaultPlace)); } for (Class<?> activity : this.activities) { srcWriter.println("mvpController.registerActivity(GWT.<ActivityFactory> create(%s.class));", InjectCreatorUtil.toClassName(activity)); } }
Example 2
Source File: InjectStopActivityCreator.java From putnami-web-toolkit with GNU Lesser General Public License v3.0 | 6 votes |
@Override public void writePresent(SourceWriter srcWriter) { srcWriter.println("final HandlerRegistrationCollection stopRegistrations = new HandlerRegistrationCollection();"); for (JMethod mayStopMethod : this.presenterMethods) { srcWriter.println("stopRegistrations.add(EventBus.get()" + ".addHandlerToSource(StopActivityEvent.TYPE, place, new StopActivityEvent.Handler() {"); srcWriter.indent(); srcWriter.println("@Override public void onStopActivity(StopActivityEvent event) {"); srcWriter.indent(); srcWriter.println("%s.this.%s();", this.injectorName, mayStopMethod.getName()); srcWriter.outdent(); srcWriter.outdent(); srcWriter.println("}}));"); } srcWriter.println("stopRegistrations.add(EventBus.get()" + ".addHandlerToSource(StopActivityEvent.TYPE, place, new StopActivityEvent.Handler() {"); srcWriter.indent(); srcWriter.println("@Override public void onStopActivity(StopActivityEvent event) {"); srcWriter.indent(); srcWriter.println("stopRegistrations.removeHandler();"); srcWriter.outdent(); srcWriter.outdent(); srcWriter.println("}}));"); }
Example 3
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 4
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 5
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 6
Source File: SuspendServiceOnPresentCreator.java From putnami-web-toolkit with GNU Lesser General Public License v3.0 | 6 votes |
@Override public void writeAfterPresent(SourceWriter srcWriter) { if (!this.hasService) { srcWriter.println("displayer.setWidget(%s.this);", this.injectorName); } else { srcWriter.println("commandController.flush(new CallbackAdapter<List<CommandResponse>>() {"); srcWriter.indent(); srcWriter.println("@Override"); srcWriter.println("public void onSuccess(List<CommandResponse> result) {"); srcWriter.indent(); srcWriter.println("displayer.setWidget(%s.this);", this.injectorName); srcWriter.outdent(); srcWriter.println("};"); srcWriter.outdent(); srcWriter.println("});"); srcWriter.println("commandController.setSuspended(isSuspended);"); } }
Example 7
Source File: UiBinderLocalizedCreator.java From putnami-web-toolkit with GNU Lesser General Public License v3.0 | 6 votes |
private void generateProxy(TreeLogger logger, SourceWriter srcWriter) { srcWriter.println("@UiTemplate(\"%s\")", this.templateName); srcWriter.println("interface Binder extends UiBinder<%s, %s> {", this.widgetType.getSimpleSourceName(), this.targetType.getSimpleSourceName()); srcWriter.indent(); srcWriter.println("UiBinder<%s, %s> BINDER = GWT.create(Binder.class);", this.widgetType.getSimpleSourceName(), this.targetType.getSimpleSourceName()); srcWriter.outdent(); srcWriter.println("}"); srcWriter.println(); srcWriter.println("@Override"); srcWriter .println("public %s createAndBindUi(%s owner) {", this.widgetType.getSimpleSourceName(), this.targetType .getSimpleSourceName()); srcWriter.indent(); srcWriter.println("return Binder.BINDER.createAndBindUi(owner);"); srcWriter.outdent(); srcWriter.println("}"); }
Example 8
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 9
Source File: InjectDecoratorPresenterCreator.java From putnami-web-toolkit with GNU Lesser General Public License v3.0 | 5 votes |
@Override public void writeMethods(SourceWriter srcWriter) { srcWriter.println("public void presentDecoratedView(Place place) {"); srcWriter.indent(); srcWriter.println("if (view instanceof Presenter) {"); srcWriter.indent(); srcWriter.println("Presenter presenter = (Presenter) view;"); srcWriter.println("presenter.present(place, this);"); srcWriter.outdent(); srcWriter.println("}"); srcWriter.outdent(); srcWriter.println("}"); }
Example 10
Source File: AbstractInjectorCreator.java From putnami-web-toolkit with GNU Lesser General Public License v3.0 | 5 votes |
protected void writeConstructor(TreeLogger logger, GeneratorContext context, SourceWriter srcWriter) { srcWriter.println("public %s() {", this.proxyName); srcWriter.indent(); for (InjectorWritterConstructor delegate : Iterables.filter(this.delegates, InjectorWritterConstructor.class)) { delegate.writeConstructor(srcWriter); } srcWriter.outdent(); srcWriter.println("}"); }
Example 11
Source File: RestServiceBinderCreator.java From putnami-web-toolkit with GNU Lesser General Public License v3.0 | 5 votes |
private void writeEndMethod(SourceWriter srcWriter, JMethod method) { if (method.getReturnType().equals(JPrimitiveType.BOOLEAN)) { srcWriter.println("return false;"); } else if (method.getReturnType().equals(JPrimitiveType.BYTE) || method.getReturnType().equals(JPrimitiveType.CHAR) || method.getReturnType().equals(JPrimitiveType.DOUBLE) || method.getReturnType().equals(JPrimitiveType.FLOAT) || method.getReturnType().equals(JPrimitiveType.INT) || method.getReturnType().equals(JPrimitiveType.LONG) || method.getReturnType().equals(JPrimitiveType.SHORT)) { srcWriter.println("return 0;"); } else if (!method.getReturnType().equals(JPrimitiveType.VOID)) { srcWriter.println("return null;"); } srcWriter.outdent(); srcWriter.println("}"); }
Example 12
Source File: GssResourceGenerator.java From gss.gwt with Apache License 2.0 | 5 votes |
@Override public String createAssignment(TreeLogger logger, ResourceContext context, JMethod method) throws UnableToCompleteException { ExtendedCssTree extendedCssTree = cssTreeMap.get(method); RenamingResult renamingResult = doClassRenaming(extendedCssTree.tree, method, logger, context); // TODO : Should we foresee configuration properties for simplifyCss and eliminateDeadCode // booleans ? ConstantDefinitions constantDefinitions = optimize(extendedCssTree, context, true, true); checkErrors(); Set<String> externalClasses = revertRenamingOfExternalClasses(extendedCssTree.tree, renamingResult.mapping); // Validate that classes not assigned to one of the interface methods are external validateExternalClasses(externalClasses, renamingResult.externalClassCandidate, method, logger); SourceWriter sw = new StringSourceWriter(); sw.println("new " + method.getReturnType().getQualifiedSourceName() + "() {"); sw.indent(); writeMethods(logger, context, method, sw, constantDefinitions, extendedCssTree.originalConstantNameMapping, renamingResult.mapping); sw.outdent(); sw.println("}"); return sw.toString(); }
Example 13
Source File: ProxyViewCreator.java From putnami-web-toolkit with GNU Lesser General Public License v3.0 | 5 votes |
private void generateInternalTokenizer(TreeLogger logger, SourceWriter srcWriter) { boolean hasTokeConstructor = false; for (JConstructor constructor : this.placeType.getConstructors()) { if (constructor.getParameters().length == 1 && constructor.getParameters()[0].getType().getSimpleSourceName().equals(String.class.getSimpleName())) { hasTokeConstructor = true; } } srcWriter.println("@Override"); srcWriter.println("public %s getPlace(String token) {", this.placeType.getSimpleSourceName()); srcWriter.indent(); if (hasTokeConstructor) { srcWriter.println("return new %s(token);", this.placeType.getSimpleSourceName()); } else { srcWriter.println("%s place = new %s();", this.placeType.getSimpleSourceName(), this.placeType.getSimpleSourceName()); srcWriter.println("place.setToken(token);"); srcWriter.println("return place;"); } srcWriter.outdent(); srcWriter.println("}"); srcWriter.println("@Override"); srcWriter.println("public String getToken(%s place) {", this.placeType.getSimpleSourceName()); srcWriter.indent(); srcWriter.println("if(place instanceof ViewPlace){"); srcWriter.indent(); srcWriter.println("return ((ViewPlace)place).getToken();"); srcWriter.outdent(); srcWriter.println("}"); srcWriter.println("return null;"); srcWriter.outdent(); srcWriter.println("}"); }
Example 14
Source File: ProxyViewCreator.java From putnami-web-toolkit with GNU Lesser General Public License v3.0 | 5 votes |
private void generateActivityFactory(TreeLogger logger, SourceWriter srcWriter) { srcWriter.println("@Override"); srcWriter.println("public Activity createActivity(Place place) {"); srcWriter.indent(); srcWriter.println("return new ViewActivity(this, place);"); srcWriter.outdent(); srcWriter.println("}"); }
Example 15
Source File: ModelCreator.java From putnami-web-toolkit with GNU Lesser General Public License v3.0 | 5 votes |
private void generateInternalSet(TreeLogger logger, SourceWriter srcWriter) { srcWriter.println("protected <P> void internalSet(%s bean, String fieldName, P value){", this.beanType.getSimpleSourceName()); srcWriter.indent(); for (String propertyName : this.propertyTypes.keySet()) { JType propertyType = this.propertyTypes.get(propertyName); JPrimitiveType primitiveType = propertyType.isPrimitive(); JMethod setter = this.setters.get(propertyName); if (setter != null) { if (primitiveType != null) { srcWriter.println( "if(\"%s\".equals(fieldName)){ bean.%s((%s) PrimitiveUtils.asPrimitive((%s)value)); }", propertyName, setter.getName(), propertyType.getSimpleSourceName(), primitiveType.getQualifiedBoxedSourceName()); } else { srcWriter.println("if(\"%s\".equals(fieldName)){ bean.%s((%s) value); }", propertyName, setter.getName(), propertyType.getSimpleSourceName()); } } else if (this.publicFields.containsKey(propertyName)) { if (primitiveType != null) { srcWriter .println("if(\"%s\".equals(fieldName)){ bean.%s = PrimitiveUtils.asPrimitive((%s) value); }", propertyName, propertyName, primitiveType.getQualifiedBoxedSourceName()); } else { srcWriter .println("if(\"%s\".equals(fieldName)){ bean.%s = (%s) value; }", propertyName, propertyName, propertyType.getSimpleSourceName()); } } } srcWriter.outdent(); srcWriter.println("}"); }
Example 16
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 17
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); }
Example 18
Source File: ServiceBinderCreator.java From putnami-web-toolkit with GNU Lesser General Public License v3.0 | 4 votes |
private void writeCommandParam(SourceWriter srcWriter, JMethod method, Collection<CallbackMethod> callbackSuccess, JParameter callbackParameter) { boolean lazy = method.getAnnotation(LazyCommand.class) != null; boolean quiet = method.getAnnotation(QuietCommand.class) != null; srcWriter.print("CommandParam commandParam = new CommandParam("); srcWriter.print("%s, ", lazy); srcWriter.print("%s, ", quiet); srcWriter.print("this.serializer, "); srcWriter.print("Lists.newArrayList(Arrays.asList("); int i = 0; for (JParameter parameter : method.getParameters()) { if (!parameter.equals(callbackParameter)) { if (i++ > 0) { srcWriter.print(", "); } srcWriter.print("$%d_%s", i, parameter.getName()); } } srcWriter.println(")), "); srcWriter.indent(); srcWriter.println("Lists.newArrayList("); srcWriter.indent(); i = 0; if (callbackParameter != null) { srcWriter.print("$%d_%s", method.getParameters().length, callbackParameter.getName()); i++; } if (callbackSuccess != null) { for (CallbackMethod callbackMethod : callbackSuccess) { if (i++ > 0) { srcWriter.print(", "); } srcWriter.println("new CallbackAdapter<%s>(){", this.typeAsString(method.getReturnType(), true)); srcWriter.indent(); if (callbackMethod.successMethodName != null) { srcWriter.println("public void onSuccess(%s result){", this.typeAsString(method.getReturnType(), true)); srcWriter.indent(); srcWriter.println("getHandler().%s(result);", callbackMethod.successMethodName); srcWriter.outdent(); srcWriter.println("}"); } if (callbackMethod.failureMethodName != null) { srcWriter .println("public void onFailure(Throwable caught){", this.typeAsString(method.getReturnType(), true)); srcWriter.indent(); srcWriter.println("getHandler().%s(caught);", callbackMethod.failureMethodName); srcWriter.outdent(); srcWriter.println("}"); } srcWriter.outdent(); srcWriter.print("}"); } } srcWriter.outdent(); srcWriter.println("));"); srcWriter.outdent(); }
Example 19
Source File: EventBinderWriter.java From gwteventbinder with Apache License 2.0 | 4 votes |
private void writeBindMethodFooter(SourceWriter writer) { writer.println("return registrations;"); writer.outdent(); writer.println("}"); }
Example 20
Source File: ModelCreator.java From putnami-web-toolkit with GNU Lesser General Public License v3.0 | 4 votes |
private void generateStaticInitializer(TreeLogger logger, SourceWriter srcWriter) { srcWriter.println("protected static final Map<String, PropertyDescription> PROPERTIES = Maps.newHashMap();"); srcWriter.println("static{"); srcWriter.indent(); for (String propertyName : this.propertyTypes.keySet()) { JType propertyType = this.propertyTypes.get(propertyName); String simplePropertyTypeName = propertyType.getSimpleSourceName(); String modelName = this.subModels.get(propertyType); if (modelName != null) { modelName += ".INSTANCE"; } try { if (propertyType.isPrimitive() == null) { Class<?> propertyClass = Class.forName(propertyType.getQualifiedSourceName()); if (Collection.class.isAssignableFrom(propertyClass)) { JParameterizedType parametrizedType = propertyType.isParameterized(); JType subType = propertyType; if (parametrizedType != null) { subType = parametrizedType.getTypeArgs()[0]; String submodelName = this.subModels.get(subType); if (submodelName != null) { submodelName += ".INSTANCE"; } else { submodelName = subType.getSimpleSourceName() + ".class"; } modelName = String.format("new ModelCollection<%s>(%s.class, %s)", subType.getSimpleSourceName(), propertyType.getSimpleSourceName(), submodelName); } else { logger.branch(Type.WARN, String.format( "Property [%s] on bean %s is a raw collection type. You cannot use it on editors.", propertyName, this.beanType.getQualifiedSourceName())); modelName = "new ModelCollection((Model) null)"; } } } } catch (ClassNotFoundException e) { logger.branch(Type.WARN, String.format( "%s class not found.", propertyType.getQualifiedSourceName())); } Boolean getter = this.getters.containsKey(propertyName); Boolean setter = this.setters.containsKey(propertyName); srcWriter.print("PROPERTIES.put(\"%s\", newPropertyDescription(\"%s\", %s.class, %s, %s, %s", propertyName, propertyName, simplePropertyTypeName, modelName, getter, setter); this.generateValidators(srcWriter, propertyName); srcWriter.println("));"); } srcWriter.outdent(); srcWriter.println("}"); srcWriter.println("protected Map<String, PropertyDescription> getProperties(){"); srcWriter.println(" return PROPERTIES;"); srcWriter.println("}"); }