Java Code Examples for com.google.gwt.user.rebind.SourceWriter#indent()
The following examples show how to use
com.google.gwt.user.rebind.SourceWriter#indent() .
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: InjectMayStopActivityCreator.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 mayStopRegistrations = new HandlerRegistrationCollection();"); for (JMethod mayStopMethod : this.presenterMethods) { srcWriter.println("mayStopRegistrations.add(EventBus.get()" + ".addHandlerToSource(MayStopActivityEvent.TYPE, place, new MayStopActivityEvent.Handler() {"); srcWriter.indent(); srcWriter.println("@Override public void onMayStopActivity(MayStopActivityEvent event) {"); srcWriter.indent(); srcWriter.println("if (event.getMessage() == null) { event.setMessage(%s.this.%s()); }", this.injectorName, mayStopMethod.getName()); srcWriter.outdent(); srcWriter.outdent(); srcWriter.println("}}));"); } srcWriter.println("mayStopRegistrations.add(EventBus.get()" + ".addHandlerToSource(StopActivityEvent.TYPE, place, new StopActivityEvent.Handler() {"); srcWriter.indent(); srcWriter.println("@Override public void onStopActivity(StopActivityEvent event) {"); srcWriter.indent(); srcWriter.println("mayStopRegistrations.removeHandler();"); srcWriter.outdent(); srcWriter.outdent(); srcWriter.println("}}));"); }
Example 2
Source File: ModelCreator.java From putnami-web-toolkit with GNU Lesser General Public License v3.0 | 6 votes |
private void generateConstructor(TreeLogger logger, SourceWriter srcWriter) { int lastIndex = this.proxyModelQualifiedName.lastIndexOf('.'); String className = lastIndex == -1 ? this.proxyModelQualifiedName : this.proxyModelQualifiedName.substring(lastIndex + 1, this.proxyModelQualifiedName.length()); srcWriter.println("public %s(){", className); srcWriter.indent(); if (this.subModels.get(this.parentType) != null) { srcWriter.println("super(%s.INSTANCE, %s.class);", this.subModels.get(this.parentType), this.beanType.getSimpleSourceName()); srcWriter.println(); } else { srcWriter.println("super(%s.class);", this.beanType.getSimpleSourceName()); srcWriter.println(); } srcWriter.outdent(); srcWriter.println("}"); }
Example 3
Source File: InjectErrorManagerCreator.java From putnami-web-toolkit with GNU Lesser General Public License v3.0 | 6 votes |
@Override public void writeEntryPoint(SourceWriter srcWriter) { srcWriter.println("ErrorManager.get();"); if (!ErrorDisplayer.class.equals(this.errorDisplay)) { srcWriter.println("ErrorManager.get().setErrorDisplayer(GWT.<ErrorDisplayer> create(%s.class));", InjectCreatorUtil.toClassName(this.errorDisplay)); } if (this.errorHandlers != null) { for (Class<? extends ErrorHandler> handlerClass : this.errorHandlers) { srcWriter.println("ErrorManager.get().registerErrorHandler(new %s());", InjectCreatorUtil.toClassName(handlerClass)); } } if (this.errorHandlers != null) { for (JMethod handlerMethod : this.handlerMethods) { srcWriter.println("ErrorManager.get().registerErrorHandler(" + "new fr.putnami.pwt.core.error.client.ErrorHandler() {"); srcWriter.indent(); srcWriter.println("@Override public boolean handle(Throwable error) { return %s.this.%s(error); }", this.injectorName, handlerMethod.getName()); srcWriter.println("@Override public int getPriority() { return HIGH_PRIORITY; }"); srcWriter.outdent(); srcWriter.println("});"); } } }
Example 4
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 5
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 6
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 7
Source File: RestServiceBinderCreator.java From putnami-web-toolkit with GNU Lesser General Public License v3.0 | 5 votes |
private void writeStartMethod(SourceWriter srcWriter, JMethod method) { srcWriter.print("public %s %s(", this.typeAsString(method.getReturnType(), false), method.getName()); int i = 0; for (JParameter parameter : method.getParameters()) { if (i++ > 0) { srcWriter.print(", "); } srcWriter.print("%s $%d_%s", this.typeAsString(parameter.getType(), false), i, parameter.getName()); } srcWriter.println("){"); srcWriter.indent(); }
Example 8
Source File: InjectPresenterCreator.java From putnami-web-toolkit with GNU Lesser General Public License v3.0 | 5 votes |
@Override public void writePresent(SourceWriter srcWriter) { for (JMethod presenterMethod : this.presenterMethods) { if (presenterMethod.getParameters().length == 0) { srcWriter.println("super.%s();", presenterMethod.getName()); } else if (presenterMethod.getParameters().length > 0) { JType placeType = presenterMethod.getParameters()[0].getType(); srcWriter.println("if(place instanceof %s){", placeType.getSimpleSourceName()); srcWriter.indent(); srcWriter.println("super.%s((%s) place);", presenterMethod.getName(), placeType.getSimpleSourceName()); srcWriter.outdent(); srcWriter.println("}"); } } }
Example 9
Source File: EventBinderWriter.java From gwteventbinder with Apache License 2.0 | 5 votes |
private void writeBindMethodHeader(SourceWriter writer, String targetName) { writer.println("protected List<HandlerRegistration> doBindEventHandlers(" + "final %s target, EventBus eventBus) {", targetName); writer.indent(); writer.println( "List<HandlerRegistration> registrations = new LinkedList<HandlerRegistration>();"); }
Example 10
Source File: Mvp4gRunAsyncGenerator.java From mvp4g with Apache License 2.0 | 5 votes |
void writeClass(SourceWriter sourceWriter, String callBackType) { sourceWriter.print("public void load("); sourceWriter.print(callBackType); sourceWriter.println(" callback) {"); sourceWriter.indent(); sourceWriter.println("GWT.runAsync(callback);"); sourceWriter.outdent(); sourceWriter.println("}"); }
Example 11
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 12
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 13
Source File: ApplicationMetaDataGenerator.java From core with GNU Lesser General Public License v2.1 | 5 votes |
private void generateMethods(SourceWriter sourceWriter) { sourceWriter.println("public List<PropertyBinding> getBindingsForType(Class<?> type) { "); sourceWriter.indent(); sourceWriter.println("return registry.get(type);"); sourceWriter.outdent(); sourceWriter.println("}"); sourceWriter.println("public BeanMetaData getBeanMetaData(Class<?> type) { "); sourceWriter.indent(); sourceWriter.println("return new BeanMetaData(type, addressing.get(type), registry.get(type));"); sourceWriter.outdent(); sourceWriter.println("}"); sourceWriter.println("public FormMetaData getFormMetaData(Class<?> type) { "); sourceWriter.indent(); sourceWriter.println("return new FormMetaData(type, registry.get(type));"); sourceWriter.outdent(); sourceWriter.println("}"); sourceWriter.println("public Mutator getMutator(Class<?> type) { "); sourceWriter.indent(); sourceWriter.println("return mutators.get(type);"); sourceWriter.outdent(); sourceWriter.println("}"); sourceWriter.println("public <T> EntityFactory<T> getFactory(Class<T> type) {"); sourceWriter.indent(); sourceWriter.println("return factories.get(type);"); sourceWriter.outdent(); sourceWriter.println("}"); generateMethodMethods(sourceWriter); }
Example 14
Source File: ModelCreator.java From putnami-web-toolkit with GNU Lesser General Public License v3.0 | 5 votes |
private void generateCreate(TreeLogger logger, SourceWriter srcWriter) { srcWriter.println("public %s newInstance() {", this.beanType.getSimpleSourceName()); srcWriter.indent(); if (!this.beanType.isAbstract()) { srcWriter.println("return new %s();", this.beanType.getSimpleSourceName()); } else { srcWriter.println("throw new RuntimeException(\"Can not instantiate the abstract class %s\");", this.beanType.getSimpleSourceName()); } srcWriter.outdent(); srcWriter.println("}"); }
Example 15
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 16
Source File: ProductConfigGenerator.java From core with GNU Lesser General Public License v2.1 | 4 votes |
private void generateMethods(final TreeLogger logger, SourceWriter sourceWriter, GeneratorContext context) throws Throwable { PropertyOracle propertyOracle = context.getPropertyOracle(); // console.profile - mandatory String consoleProfile = failFastGetProperty(propertyOracle, "console.profile"); sourceWriter.println("public ProductConfig.Profile getProfile() { "); sourceWriter.indent(); if ("product".equals(consoleProfile)) { sourceWriter.println("return ProductConfig.Profile.PRODUCT;"); } else if ("community".equals(consoleProfile)) { sourceWriter.println("return ProductConfig.Profile.COMMUNITY;"); } else { throw new BadPropertyValueException( "Invalid value for 'console.profile'. Valid values are 'community' or 'product'!"); } sourceWriter.outdent(); sourceWriter.println("}"); // console.core.version - mandatory String coreConsoleVersion = failFastGetProperty(propertyOracle, "console.core.version"); sourceWriter.println("public String getCoreVersion() { "); sourceWriter.indent(); sourceWriter.println("return \"%s\";", coreConsoleVersion); sourceWriter.outdent(); sourceWriter.println("}"); // hal.version - optional // If this is not built using the HAL release stream, this property is undefined String consoleVersion = failSafeGetProperty(propertyOracle, "hal.version", null); sourceWriter.println("public String getConsoleVersion() { "); sourceWriter.indent(); if (consoleVersion == null) { sourceWriter.println("return null;"); } else { sourceWriter.println("return \"%s\";", consoleVersion); } sourceWriter.outdent(); sourceWriter.println("}"); // getProductName() - delegates to the BootstrapContext sourceWriter.println("public String getProductName() { "); sourceWriter.indent(); sourceWriter.println("return org.jboss.as.console.client.Console.MODULES.getBootstrapContext().getProductName();"); sourceWriter.outdent(); sourceWriter.println("}"); // getProductVersion() - delegates to the BootstrapContext sourceWriter.println("public String getProductVersion() { "); sourceWriter.indent(); sourceWriter.println("return org.jboss.as.console.client.Console.MODULES.getBootstrapContext().getProductVersion();"); sourceWriter.outdent(); sourceWriter.println("}"); // supported locales LocaleUtils localeUtils = LocaleUtils.getInstance(logger, context.getPropertyOracle(), context); Set<GwtLocale> locales = localeUtils.getAllCompileLocales(); sourceWriter.println("public List<String> getLocales() { "); sourceWriter.indent(); sourceWriter.println("List<String> locales = new LinkedList<String>();"); for (GwtLocale locale : locales) { if (locale.getAsString() != null && locale.getAsString().length() != 0) { sourceWriter.println("locales.add(\"" + locale.getAsString() + "\");"); } } sourceWriter.println("return locales;"); sourceWriter.outdent(); sourceWriter.println("}"); }
Example 17
Source File: ProxyViewCreator.java From putnami-web-toolkit with GNU Lesser General Public License v3.0 | 4 votes |
private void generateProxy(TreeLogger logger, SourceWriter srcWriter) { String viewName = this.activityDescrition.view().getSimpleName(); srcWriter.println(); srcWriter.println("private static %s view;", viewName); srcWriter.println(); srcWriter.println("@Override"); srcWriter.println("public void loadView(final ViewProxy.Callback callback) {"); srcWriter.indent(); if (this.activityDescrition.asyncView()) { srcWriter.println("GWT.runAsync(%s.class, new RunAsyncCallback() {", viewName); srcWriter.indent(); srcWriter.println("public void onFailure(Throwable reason) {"); srcWriter.indent(); srcWriter.println("if (ApplicationUnreachableException.HTTP_DOWNLOAD_FAILURE_EXCEPTION" + ".equals(reason.getClass().getSimpleName())) {"); srcWriter.indent(); srcWriter.println("reason = new ApplicationUnreachableException(reason);"); srcWriter.outdent(); srcWriter.println("}"); srcWriter.println("GWT.reportUncaughtException(reason);"); srcWriter.outdent(); srcWriter.println("}"); srcWriter.println("public void onSuccess() {"); srcWriter.indent(); srcWriter.println("if(view == null || %s){", this.activityDescrition.scope() == Scope.PROTOTYPE); srcWriter.indent(); srcWriter.println("view = GWT.create(%s.class);", viewName); srcWriter.outdent(); srcWriter.println("}"); this.generateProxyResult(logger, srcWriter); srcWriter.outdent(); srcWriter.println("}"); srcWriter.outdent(); srcWriter.println("});"); } else { srcWriter.println("if(view == null || %s){", this.activityDescrition.scope() == Scope.PROTOTYPE); srcWriter.indent(); srcWriter.println("view = GWT.create(%s.class);", viewName); srcWriter.outdent(); srcWriter.println("}"); this.generateProxyResult(logger, srcWriter); } srcWriter.outdent(); srcWriter.println("}"); }
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: ApplicationMetaDataGenerator.java From core with GNU Lesser General Public License v2.1 | 4 votes |
private void generateConstructor(TreeLogger logger, GeneratorContext context, SourceWriter sourceWriter) { // start constructor source generation sourceWriter.println("public " + className + "() { "); sourceWriter.indent(); sourceWriter.println("super();"); /* sourceWriter.println("String label = \"\";"); sourceWriter.println("Class<?> listType = null;"); sourceWriter.println("String subgroup = \"\";"); sourceWriter.println("String localTabName = \"\";"); sourceWriter.println("String[] acceptedValues = null;"); */ try { Class<?> beanFactoryClass = getClass().getClassLoader().loadClass(BEAN_FACTORY_NAME); int idx = 0; for(Method method : beanFactoryClass.getMethods()) { Type returnType = method.getGenericReturnType(); if(!(returnType instanceof ParameterizedType)) continue; ParameterizedType type = (ParameterizedType) returnType; Type[] typeArguments = type.getActualTypeArguments(); if(!(typeArguments[0] instanceof Class)) continue; Class beanTypeClass = (Class) typeArguments[0]; //sourceWriter.println(beanTypeClass.getSimpleName() + "_" + idx + "();"); sourceWriter.println(beanTypeClass.getSimpleName() + "();"); idx++; } } catch (ClassNotFoundException e) { throw new RuntimeException("Failed to load " + BEAN_FACTORY_NAME); } sourceWriter.outdent(); sourceWriter.println("}"); }
Example 20
Source File: RestServiceBinderCreator.java From putnami-web-toolkit with GNU Lesser General Public License v3.0 | 4 votes |
private void writeMethodCallback(SourceWriter srcWriter, JMethod method, Collection<CallbackMethod> callbackSuccess, JParameter callbackParam) { boolean quiet = method.getAnnotation(QuietCommand.class) != null; srcWriter.print("CompositeMethodCallback compositeCallback = new CompositeMethodCallback("); srcWriter.print("%s, ", quiet); srcWriter.println("Lists.newArrayList("); srcWriter.indent(); int i = 0; if (callbackParam != null) { srcWriter.print("$%d_%s", method.getParameters().length, callbackParam); i++; } if (callbackSuccess != null) { for (CallbackMethod callbackMethod : callbackSuccess) { if (i++ > 0) { srcWriter.print(", "); } srcWriter.println("new MethodCallbackAdapter<%s>(){", this.typeAsString(method.getReturnType(), true)); srcWriter.indent(); if (callbackMethod.successMethodName != null) { srcWriter.println("public void onSuccess(Method method, %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(Method method, 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("));"); }