List of usage examples for com.google.gwt.user.rebind SourceWriter println
void println(String s, Object... args);
From source file:com.sencha.gxt.data.rebind.LabelProviderCreator.java
License:sencha.com license
@Override protected void create(SourceWriter sw) throws UnableToCompleteException { sw.println("public static final %1$s INSTANCE = new %1$s();", getSimpleName()); // @Override/*w w w . java 2 s . co m*/ sw.println("public String getLabel(%1$s item) {", getObjectTypeName()); appendGetterBody(sw, "item"); sw.println("}"); }
From source file:com.sencha.gxt.data.rebind.ModelKeyProviderCreator.java
License:sencha.com license
@Override protected void create(SourceWriter sw) throws UnableToCompleteException { sw.println("public static final %1$s INSTANCE = new %1$s();", getSimpleName()); // @Override//from w ww.j a v a 2 s. com sw.println("public String getKey(%1$s item) {", getObjectTypeName()); appendGetterBody(sw, "item"); sw.println("}"); }
From source file:com.sencha.gxt.data.rebind.ValueProviderCreator.java
License:sencha.com license
@Override protected void create(SourceWriter sw) throws UnableToCompleteException { sw.println("public static final %1$s INSTANCE = new %1$s();", getSimpleName()); // @Override/*from w w w . j a va2 s . com*/ sw.println("public %1$s getValue(%2$s object) {", getValueTypeName(), getObjectTypeName()); appendGetterBody(sw, "object"); sw.println("}"); // @Override sw.println("public void setValue(%1$s object, %2$s value) {", getObjectTypeName(), getValueTypeName()); appendSetterBody(sw, "object", "value"); sw.println("}"); // @Override sw.println("public String getPath() {"); StringBuilder sb = new StringBuilder(); boolean first = true; for (String p : path) { if (!first) { sb.append("."); } sb.append(p); first = false; } sw.indentln("return \"%1$s\";", sb.toString()); sw.println("}"); }
From source file:com.sencha.gxt.state.rebind.StateManagerGenerator.java
License:sencha.com license
@Override public String generate(TreeLogger logger, GeneratorContext context, String typeName) throws UnableToCompleteException { TypeOracle oracle = context.getTypeOracle(); JClassType type = oracle.findType(typeName); JClassType stateMangerType = oracle.findType(Name.getSourceNameForClass(StateManager.class)); if (type == null || type.isClass() == null || !type.isAssignableTo(stateMangerType)) { logger.log(Type.ERROR, "This generator only can function on StateManager subtypes"); throw new UnableToCompleteException(); }//ww w . j ava2 s. c o m String abf; try { abf = context.getPropertyOracle().getConfigurationProperty(STATE_MANAGER_ABF).getValues().get(0); } catch (BadPropertyValueException ex) { logger.log(Type.ERROR, "Could not read property for " + STATE_MANAGER_ABF, ex); throw new UnableToCompleteException(); } JClassType abfType = oracle.findType(abf); if (abfType == null) { logger.log(Type.ERROR, "Cannot find type " + abf + " in gwt classpath"); throw new UnableToCompleteException(); } String packageName = abfType.getPackage().getName(); String simpleSourceName = "StateManagerImpl_" + abfType.getName().replace('.', '_'); PrintWriter pw = context.tryCreate(logger, packageName, simpleSourceName); if (pw == null) { return packageName + "." + simpleSourceName; } ClassSourceFileComposerFactory factory = new ClassSourceFileComposerFactory(packageName, simpleSourceName); factory.setSuperclass(typeName); factory.addImport(Name.getSourceNameForClass(GWT.class)); SourceWriter sw = factory.createSourceWriter(context, pw); sw.println("public %1$s getStateBeanFactory() {", abf); sw.indentln("return GWT.create(%1$s.class);", abf); sw.println("}"); sw.commit(logger); return factory.getCreatedClassName(); }
From source file:com.tyf.gwtphp.linker.PHPRPCLinker.java
License:Open Source License
private void writeArray(SourceWriter src, String[] params) { src.indent();/*from w ww. j av a 2 s.c o m*/ for (String p : params) { src.println("array('type' => '%s'),", p); } src.outdent(); }
From source file:com.webrippers.gwt.dom.event.gwt.rebind.binder.DomEventBinderGenerator.java
License:Apache License
private void write_doBindEventHandlers(JClassType target, TypeOracle typeOracle, SourceWriter writer, TreeLogger logger) {//from w ww. j a v a2s . c om writer.println( "protected List<HandlerRegistration> doBindEventHandlers(final %s target, IsWidget isWidget) {", target.getQualifiedSourceName()); writer.indent(); writer.println("List<HandlerRegistration> registrations = new LinkedList<HandlerRegistration>();"); for (JMethod method : target.getMethods()) { DomEventHandler annotation = method.getAnnotation(DomEventHandler.class); if (annotation != null) { if (method.getParameters().length != 1) break; JType paramJType = method.getParameters()[0].getType(); String paramTypeQualifiedSourceName = paramJType.getQualifiedSourceName(); JClassType paramJClassType = typeOracle.findType(paramTypeQualifiedSourceName); if (!paramJClassType.isAssignableTo(typeOracle.findType(DomEvent.class.getCanonicalName()))) break; JGenericType domEventJGenericType = typeOracle.findType(DomEvent.class.getCanonicalName()) .isGenericType(); JParameterizedType paramJParameterizedType = paramJClassType .asParameterizationOf(domEventJGenericType); JClassType handlerJClassType = paramJParameterizedType.getTypeArgs()[0]; writer.println("registrations.add(isWidget.asWidget().addDomHandler(new " + paramJParameterizedType.getTypeArgs()[0].getParameterizedQualifiedSourceName() + "() {"); writer.indent(); writer.println(handlerJClassType.getOverridableMethods()[0].getReadableDeclaration(false, false, false, false, true) + " {"); writer.indent(); if (annotation.value().length > 0) { writer.println("Element targetElement = Element.as(event.getNativeEvent().getEventTarget());"); if (annotation.value()[0].startsWith("!")) { writer.println("if (targetElement != target." + annotation.value()[0].substring(1) + ") {"); } else { writer.println("if (targetElement == target." + annotation.value()[0] + ") {"); } writer.indent(); writer.println("target." + method.getName() + "(event);"); writer.outdent(); writer.println("}"); } else { writer.println("target." + method.getName() + "(event);"); } writer.outdent(); writer.println("}"); writer.outdent(); writer.println("}, " + paramTypeQualifiedSourceName + ".getType()));"); } } writer.println("return registrations;"); writer.outdent(); writer.println("}"); }
From source file:de.csenk.gwt.commons.bean.rebind.observe.impl.ObservableBeanFactoryCreator.java
License:Apache License
/** * @param typeOracle /*from ww w .j av a 2 s. c o m*/ * @param beanFactoryWriter */ private void writeAutoBeanFactory(TypeOracle typeOracle, SourceWriter beanFactoryWriter) { final JClassType autoBeanFactoryInterface = context.getTypeOracle() .findType(AutoBeanFactory.class.getCanonicalName()); beanFactoryWriter.println("public interface AutoBeanFactory extends %s {", autoBeanFactoryInterface.getQualifiedSourceName()); for (ObservableBeanModel beanModel : model.getBeans().values()) { beanFactoryWriter.indentln("%s<%s> create%s();", AutoBean.class.getSimpleName(), beanModel.getType().getQualifiedSourceName(), beanModel.getTopLevelTypeName()); } beanFactoryWriter.println("}"); beanFactoryWriter.println(); beanFactoryWriter.println( "private static final AutoBeanFactory autoBeanFactory = GWT.create(AutoBeanFactory.class);"); beanFactoryWriter.println(); }
From source file:de.csenk.gwt.commons.bean.rebind.observe.impl.ObservableBeanFactoryCreator.java
License:Apache License
/** * @param beanWriter/*w w w . ja v a 2s . co m*/ * @param beanModel */ private void writeAsMethod(SourceWriter beanWriter, ObservableBeanModel beanModel) { beanWriter.println("public %s as() {", beanModel.getType().getQualifiedSourceName()); beanWriter.indentln("return shim;"); beanWriter.println("}"); beanWriter.println(); }
From source file:de.csenk.gwt.commons.bean.rebind.observe.impl.ObservableBeanFactoryCreator.java
License:Apache License
/** * @param beanWriter // w ww . j av a2 s . co m * @param beanModel * */ private void writeBeanShimField(SourceWriter beanWriter, ObservableBeanModel beanModel) { beanWriter.println("private final %1$s shim = new %1$s() {", beanModel.getType().getQualifiedSourceName()); beanWriter.indent(); beanWriter.println(); writeShimFields(beanWriter, beanModel); writeShimMethods(beanWriter, beanModel); beanWriter.outdent(); beanWriter.println("};"); beanWriter.println(); beanWriter.println("{ %s.set(shim, %s.class.getName(), this); }", WeakMapping.class.getCanonicalName(), ObservableBean.class.getCanonicalName()); beanWriter.println(); }
From source file:de.csenk.gwt.commons.bean.rebind.observe.impl.ObservableBeanFactoryCreator.java
License:Apache License
/** * @param beanWriter// w w w. j ava 2s .c om * @param beanModel */ private void writeShimMethods(SourceWriter beanWriter, ObservableBeanModel beanModel) { for (ObservableBeanPropertyModel propertyModel : beanModel.getProperties().values()) { beanWriter.println("public %s {", SourceGeneration.getBaseMethodDeclaration(propertyModel.getSetter().getMethod())); beanWriter.indentln("this.%s.set(%s);", propertyModel.getName(), propertyModel.getSetter().getMethod().getParameters()[0].getName()); beanWriter.println("}"); beanWriter.println(); beanWriter.println("public %s {", SourceGeneration.getBaseMethodDeclaration(propertyModel.getGetter().getMethod())); beanWriter.indentln("%s.this.lastAccessedProperty = this.%s;", beanModel.getSimpleImplementationTypeName(), propertyModel.getName()); beanWriter.indentln("return %s.get();", propertyModel.getName()); beanWriter.println("}"); beanWriter.println(); } }