List of usage examples for com.google.gwt.user.rebind SourceWriter println
void println(String s);
From source file:org.drools.guvnor.gwtutil.PerspectiveFactoryGenerator.java
License:Apache License
private void generateGetModuleEditorActionToolbarMethod(SourceWriter sourceWriter, Map<String, List<ModuleEditorConfiguration>> registeredEditors) { sourceWriter.println( "public Widget getModuleEditorActionToolbar(Module data, ClientFactory clientFactory, EventBus eventBus, boolean readOnly, Command refreshCommand) {"); sourceWriter.indent();/*from w w w .ja v a 2 s.c o m*/ sourceWriter.println("if(\"soaservice\".equals(data.getFormat())) {"); sourceWriter.indent(); sourceWriter.println( "return new org.drools.guvnor.client.widgets.soa.toolbar.PackageEditorActionToolbar(data, clientFactory, eventBus, readOnly, refreshCommand);"); sourceWriter.outdent(); sourceWriter.println("}"); sourceWriter.println( "return new org.drools.guvnor.client.widgets.soa.toolbar.PackageEditorActionToolbar(data, clientFactory, eventBus, readOnly, refreshCommand);"); sourceWriter.outdent(); sourceWriter.println("}"); }
From source file:org.drools.guvnor.gwtutil.PerspectiveFactoryGenerator.java
License:Apache License
private void generateGetAssetEditorActionToolbarMethod(SourceWriter sourceWriter, Map<String, List<ModuleEditorConfiguration>> registeredEditors) { sourceWriter.println( "public Widget getAssetEditorActionToolbar(String perspectiveType, Asset asset, Widget editor, ClientFactory clientFactory, EventBus eventBus, boolean readOnly) {"); sourceWriter.indent();// w w w.ja va 2 s . c o m sourceWriter.println("if(\"soaservice\".equals(perspectiveType)) {"); sourceWriter.indent(); sourceWriter.println( "return new org.drools.guvnor.client.widgets.soa.toolbar.AssetEditorActionToolbar(asset, editor, clientFactory, eventBus, readOnly);"); sourceWriter.outdent(); sourceWriter.println("}"); sourceWriter.println( "return new org.drools.guvnor.client.widgets.soa.toolbar.AssetEditorActionToolbar(asset, editor, clientFactory, eventBus, readOnly);"); sourceWriter.outdent(); sourceWriter.println("}"); }
From source file:org.eclipse.che.util.ExtensionRegistryGenerator.java
License:Open Source License
/** * Generate the content of the class//from w ww . j a va 2 s .c o m * * @param logger * @param context * @param packageName * @param className * @param extensions * @throws UnableToCompleteException */ private void generateClass(TreeLogger logger, GeneratorContext context, String packageName, String className, List<JClassType> extensions) throws UnableToCompleteException { PrintWriter pw = context.tryCreate(logger, packageName, className); if (pw == null) { return; } ClassSourceFileComposerFactory composerFactory = new ClassSourceFileComposerFactory(packageName, className); // generate imports generateImports(extensions, composerFactory); // interface composerFactory.addImplementedInterface(ExtensionRegistry.class.getCanonicalName()); // get source writer SourceWriter sw = composerFactory.createSourceWriter(context, pw); // begin class definition // fields sw.println("private final Map<String, ExtensionDescription> extensions = new HashMap<>();"); generateConstructor(className, extensions, sw); // methods generateGetExtensionsMethod(sw); // close it out sw.outdent(); sw.println("}"); context.commit(logger, pw); }
From source file:org.eclipse.che.util.ExtensionRegistryGenerator.java
License:Open Source License
/** * Generate constructor with dependencies added into field * * @param className//from w ww .ja v a2 s .c o m * @param extensions * @param sw * @throws UnableToCompleteException */ private void generateConstructor(String className, List<JClassType> extensions, SourceWriter sw) throws UnableToCompleteException { // constructor sw.indent(); sw.print("public %s()", className); sw.println("{"); sw.indent(); { for (JClassType extension : extensions) { sw.println("{"); sw.indent(); /* Array<DependencyDescription> deps = Collections.<DependencyDescription> createArray(); */ generateDependenciesForExtension(sw, extension); Extension annotation = extension.getAnnotation(Extension.class); /* extensions.put("ide.ext.demo", new ExtensionDescription("ide.ext.demo", "1.0.0", "Demo extension", deps, demoExtProvider)); */ // the class's fqn String extensionId = extension.getQualifiedSourceName(); sw.println("extensions.put(\"%s\", new ExtensionDescription(\"%s\",\"%s\",\"%s\",\"%s\",deps));", escape(extensionId), escape(extensionId), escape(annotation.version()), escape(annotation.title()), escape(annotation.description())); sw.outdent(); sw.println("}"); } } sw.outdent(); sw.println("}"); }
From source file:org.eclipse.che.util.ExtensionRegistryGenerator.java
License:Open Source License
/** * Writes dependency gathering code, like: * <p/>//from w ww .ja v a 2 s .co m * Array<DependencyDescription> deps = Collections.<DependencyDescription> createArray(); * deps.add(new DependencyDescription("ide.api.ui.menu", "")); * deps.add(new DependencyDescription("extension.demo", "1.0.0-alpha")); * * @param sw * @param extension * @throws UnableToCompleteException */ private void generateDependenciesForExtension(SourceWriter sw, JClassType extension) throws UnableToCompleteException { // expected code /* Array<DependencyDescription> deps = Collections.<DependencyDescription> createArray(); deps.add(new DependencyDescription("ide.api.ui.menu", "")); */ if (extension.getConstructors().length == 0) { throw new UnableToCompleteException(); } sw.println("List<DependencyDescription> deps = new ArrayList<>();"); JConstructor jConstructor = extension.getConstructors()[0]; JType[] parameterTypes = jConstructor.getParameterTypes(); for (JType jType : parameterTypes) { JClassType argType = jType.isClassOrInterface(); if (argType != null && (argType.isAnnotationPresent(SDK.class) || argType.isAnnotationPresent(Extension.class))) { String id = ""; String version = ""; if (argType.isAnnotationPresent(SDK.class)) { id = argType.getAnnotation(SDK.class).title(); } else if (argType.isAnnotationPresent(Extension.class)) { id = argType.getQualifiedSourceName(); version = argType.getAnnotation(Extension.class).version(); } sw.println("deps.add(new DependencyDescription(\"%s\", \"%s\"));", escape(id), escape(version)); } } }
From source file:org.eclipse.che.util.ExtensionRegistryGenerator.java
License:Open Source License
/** * Generate the code for {@link ExtensionRegistry#getExtensionDescriptions()} * * @param sw//from ww w . j av a2 s .c o m */ private void generateGetExtensionsMethod(SourceWriter sw) { /* @Override public StringMap<ExtensionDescription> getExtensionDescriptions() { return extensions; } */ sw.println("@Override"); sw.println("public Map<String, ExtensionDescription> getExtensionDescriptions()"); sw.println("{"); sw.indent(); sw.println("return extensions;"); sw.outdent(); sw.println("}"); }
From source file:org.example.modular_mvp.base.rebind.ExtensionManagerGenerator.java
License:Open Source License
private void generateClass(TreeLogger logger, GeneratorContext context, String packageName, String className, List<ExtensionDefinition> extensions) { PrintWriter pw = context.tryCreate(logger, packageName, className); if (pw == null) { return;/*from ww w. jav a 2s .c o m*/ } ClassSourceFileComposerFactory composerFactory = new ClassSourceFileComposerFactory(packageName, className); // imports composerFactory.addImport(ArrayList.class.getCanonicalName()); composerFactory.addImport(List.class.getCanonicalName()); composerFactory.addImport(ExtensionDefinition.class.getCanonicalName()); composerFactory.addImport(ExtensionManager.class.getCanonicalName()); // interface composerFactory.addImplementedInterface(ExtensionManager.class.getCanonicalName()); SourceWriter sw = composerFactory.createSourceWriter(context, pw); // begin class definition sw.indent(); // fields sw.println("private final List<NavigatorItem> items = new ArrayList<NavigatorItem>();"); // constructor sw.println("public " + className + "() {"); sw.indent(); for (ExtensionDefinition extension : extensions) { for (ExtensionDefinition.NavigatorItem item : extension.value()) { sw.println("items.add(new NavigatorItem(\"%s\", \"%s\"));", escape(item.name()), escape(item.token())); } } sw.outdent(); sw.println("}"); // methods // getNavigatorItems sw.println("public List<NavigatorItem> getNavigatorItems() {"); sw.indentln("return items;"); sw.println("}"); // close it out sw.outdent(); sw.println("}"); context.commit(logger, pw); }
From source file:org.gwt.beansbinding.core.rebind.BeanPropertyDescriptorGenerator.java
License:Apache License
private void write(SourceWriter w, JClassType _type, JClassType[] types) { w.println("public static void setupBeanInfo() throws " + IntrospectionException.class.getName()); w.println("{"); w.indent();/* ww w.j a v a 2 s . com*/ w.println("GwtBeanInfo beanInfo;"); for (JClassType type : types) { Collection<Property> properties = lookupJavaBeanPropertyAccessors(type); w.println("\n// " + type.getName()); w.println("beanInfo = new GwtBeanInfo();"); for (Property property : properties) { w.print("beanInfo.addPropertyDescriptor( "); writePropertyDescriptor(w, type, property.name, property.propertyType, property.getter, property.setter); w.println(" );"); } w.println("GwtIntrospector.setBeanInfo( " + type.getQualifiedSourceName() + ".class, beanInfo );"); } w.outdent(); w.println("}"); // automatically invoke setupBeanInfo() w.println("static {"); w.indent(); w.println( "try{setupBeanInfo();}catch(Exception ex){com.google.gwt.user.client.Window.alert(ex.getMessage());}"); w.outdent(); w.println("}"); }
From source file:org.gwt.beansbinding.core.rebind.BeanPropertyDescriptorGenerator.java
License:Apache License
private void writePropertyDescriptor(SourceWriter sw, JClassType type, String propertyName, String propertyType, JMethod getter, JMethod setter) { sw.print("new PropertyDescriptor( \"" + propertyName + "\", " + propertyType + ".class, "); if (getter != null) { sw.println("new Method() "); sw.println("{"); sw.indent();//from w w w . ja v a2 s . com sw.println("public Object invoke( Object bean, Object... args )"); sw.println("{"); sw.indent(); sw.println("return ( (" + type.getQualifiedSourceName() + ") bean)." + getter.getName() + "();"); sw.outdent(); sw.println("}"); sw.outdent(); sw.print("}, "); } else { sw.print("null, "); } if (setter != null) { sw.println("new Method() "); sw.println("{"); sw.indent(); sw.println("public Object invoke( Object bean, Object... args )"); sw.println("{"); sw.indent(); JType argType = setter.getParameters()[0].getType().getErasedType(); String argTypeName; if (argType.isPrimitive() != null) { argTypeName = argType.isPrimitive().getQualifiedBoxedSourceName(); } else { argTypeName = argType.getQualifiedSourceName(); } sw.println("( (" + type.getQualifiedSourceName() + ") bean)." + setter.getName() + "( (" + argTypeName + ") args[0] );"); sw.println("return null;"); sw.outdent(); sw.println("}"); sw.outdent(); sw.print("} )"); } else { sw.print("null )"); } }
From source file:org.gwt.json.serialization.InternalArraySerializerGenerator.java
License:Apache License
public String generateSerializers(SourceWriter writer) throws NotFoundException { String serializerName = jArrayType.getQualifiedSourceName().replaceAll("\\.", "\\$").replaceAll("\\[\\]", "_1") + "_SerializableImpl"; writer.println("public class " + serializerName + " extends JsonSimpleTypeSerializer<" + jArrayType.getQualifiedSourceName() + "> { "); writer.indent();//from ww w. j a v a 2 s . c om writer.println("public " + serializerName + "(){}"); writer.println("public JSONValue serialize(" + jArrayType.getQualifiedSourceName() + " obj) {"); writer.indent(); writer.println("if (obj == null) return JSONNull.getInstance();"); writer.println("JSONArray jsonArray = new JSONArray();"); writer.println("for (int i=0; i< obj.length; i++) {"); writer.indent(); JType componentType = jArrayType.getComponentType(); String fieldType = GenericGenerationUtils.resolveType(componentType); if (componentType.isArray() != null) { writer.println( "jsonArray.set(i, getSerializerForType(\"" + fieldType + "\").serialize(obj[i], null));"); registerArraySerializer(componentType.isArray()); } else { JParameterizedType parametrizedType = componentType.isParameterized(); writer.println("jsonArray.set(i, getSerializerForType(\"" + fieldType + "\").serialize(obj[i], " + GenericGenerationUtils.getGenericTypesParam(componentType, parametrizedType != null ? parametrizedType.getTypeArgs() : null) + "));"); } writer.outdent(); writer.println("}"); writer.println("return jsonArray;"); writer.outdent(); writer.println("} "); writer.println(); writer.println("public " + jArrayType.getQualifiedSourceName() + " deSerialize(JSONValue jsonObj) throws JSONException {"); writer.indent(); writer.println("if (jsonObj == null) return null;"); writer.println("JSONArray arr = jsonObj.isArray();"); writer.println(jArrayType.getQualifiedSourceName() + " response = new " + insertAsFirstArray(jArrayType.getComponentType().getQualifiedSourceName(), "[arr.size()]") + ";"); writer.println("JsonGenericTypeSerializer<" + fieldType + "> serializer = getSerializerForType(\"" + fieldType + "\");"); writer.println("for (int i=0; i<arr.size(); i++) {"); writer.indent(); if (componentType.isArray() != null) { writer.print("response[i] = serializer.deSerialize(arr.get(i), null);"); registerArraySerializer(componentType.isArray()); } else { JParameterizedType parametrizedType = componentType.isParameterized(); writer.print("response[i] = serializer.deSerialize(arr.get(i), " + GenericGenerationUtils.getGenericTypesParam(componentType, parametrizedType != null ? parametrizedType.getTypeArgs() : null) + ");"); } writer.outdent(); writer.println("}"); writer.println("return response;"); writer.outdent(); writer.println("}"); writer.outdent(); writer.println("}"); return serializerName; }