List of usage examples for com.google.gwt.user.rebind SourceWriter println
void println(String s);
From source file:fr.putnami.pwt.core.model.rebind.ModelCreator.java
License:Open Source License
private void generateStaticInitializer(TreeLogger logger, SourceWriter srcWriter) { srcWriter .println("protected static final Map<String, PropertyDescription> PROPERTIES = Maps.newHashMap();"); srcWriter.println("static{"); srcWriter.indent();/*w ww . j a va2s .c o m*/ 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("}"); }
From source file:fr.putnami.pwt.core.mvp.rebind.ProxyViewCreator.java
License:Open Source License
private void generateActivityFactory(TreeLogger logger, SourceWriter srcWriter) { srcWriter.println("@Override"); srcWriter.println("public Activity createActivity(Place place) {"); srcWriter.indent();/* w w w. j ava 2 s.com*/ srcWriter.println("return new ViewActivity(this, place);"); srcWriter.outdent(); srcWriter.println("}"); }
From source file:fr.putnami.pwt.core.mvp.rebind.ProxyViewCreator.java
License:Open Source License
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;/*from w ww.ja v a2 s. c o m*/ } } 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("}"); }
From source file:fr.putnami.pwt.core.mvp.rebind.ProxyViewCreator.java
License:Open Source License
private void generateDelegateTokenizer(TreeLogger logger, SourceWriter srcWriter) { srcWriter.println("@Override"); srcWriter.println("public %s getPlace(String token) {", this.placeType.getSimpleSourceName()); srcWriter.indent();// w w w .jav a2s. co m srcWriter.println("return new %s().getPlace(token);", this.placeTokenizerClass.getSimpleName()); srcWriter.outdent(); srcWriter.println("}"); srcWriter.println("@Override"); srcWriter.println("public String getToken(%s place) {", this.placeType.getSimpleSourceName()); srcWriter.indent(); srcWriter.println("return new %s().getToken(place);", this.placeTokenizerClass.getSimpleName()); srcWriter.outdent(); srcWriter.println("}"); }
From source file:fr.putnami.pwt.core.mvp.rebind.ProxyViewCreator.java
License:Open Source License
private void generateTokenPrefixes(TreeLogger logger, SourceWriter srcWriter) { List<String> tokens = Lists.newArrayList(); tokens.add("\"" + this.placeType.getSimpleSourceName().replaceAll("Place$", "") + "\""); for (String alias : this.activityDescrition.aliases()) { tokens.add("\"" + alias + "\""); }// w w w .j a va 2 s . co m srcWriter.println("@Override"); srcWriter.println("public String[] getPlacePrefixes(){"); srcWriter.indent(); srcWriter.println("return new String[]{ %s };", Joiner.on(", ").join(tokens)); srcWriter.outdent(); srcWriter.println("}"); }
From source file:fr.putnami.pwt.core.mvp.rebind.ProxyViewCreator.java
License:Open Source License
private void generateProxyResult(TreeLogger logger, SourceWriter srcWriter) { if (this.viewDecoratorClass == null) { srcWriter.println("callback.showView(view);"); } else {/*from w w w .j a v a2s .com*/ String decoratorName = this.viewDecoratorClass.getSimpleName(); srcWriter.println("%s decorator = %s.get();", decoratorName, decoratorName); srcWriter.println("decorator.setView(view);"); srcWriter.println("callback.showView(decorator);"); } }
From source file:fr.putnami.pwt.core.service.rebind.ServiceBinderCreator.java
License:Open Source License
private void writeStartMethod(SourceWriter srcWriter, JMethod method) { srcWriter.print("public %s %s(", this.typeAsString(method.getReturnType(), false), method.getName()); int i = 0;/* w ww. j a v a 2s .c om*/ 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(); }
From source file:fr.putnami.pwt.core.service.rebind.ServiceBinderCreator.java
License:Open Source License
private void writeEndMethod(SourceWriter srcWriter, JMethod method) { srcWriter.println("CommandController.get().invokeCommand(commandDefinition, commandParam);"); 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;"); }//from ww w . j a v a2s . c om srcWriter.outdent(); srcWriter.println("}"); }
From source file:fr.putnami.pwt.core.service.rebind.ServiceBinderCreator.java
License:Open Source License
private void writeCommandDefinition(TreeLogger logger, SourceWriter srcWriter, JMethod method, JParameter callbackParameter) throws UnableToCompleteException { srcWriter.print("CommandDefinition commandDefinition = new CommandDefinition("); srcWriter.print("\"%s\", ", this.serviceType.getQualifiedSourceName()); srcWriter.print("\"%s\", ", method.getName()); if (callbackParameter != null) { JParameterizedType parameterizedCallback = callbackParameter.getType().isParameterized(); if (parameterizedCallback != null) { srcWriter.print("\"%s\" ", parameterizedCallback.getTypeArgs()[0].getQualifiedSourceName()); } else {// ww w. ja v a2 s. c o m logger.branch(TreeLogger.ERROR, "Callback argument type for method " + method.getName() + " is not parametrized", null); throw new UnableToCompleteException(); } } else { srcWriter.print("\"%s\" ", method.getReturnType().getQualifiedSourceName()); } for (JParameter parameter : method.getParameters()) { if (!parameter.equals(callbackParameter)) { srcWriter.print(", \"%s\"", parameter.getType().getQualifiedSourceName()); } } srcWriter.println(");"); }
From source file:fr.putnami.pwt.core.service.rebind.ServiceBinderCreator.java
License:Open Source License
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;/*from ww w. ja v a2 s . c o m*/ 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(); }