From: Matti Tahvonen Date: Mon, 28 Sep 2009 13:32:22 +0000 (+0000) Subject: Better code style for generated class + some refactoring X-Git-Tag: 6.7.0.beta1~2433^2~5 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=7ff7d689bf1eac422e63304e3ead4ffc1e7509b8;p=vaadin-framework.git Better code style for generated class + some refactoring svn changeset:8957/svn branch:2009-09-widget-packaging_3332 --- diff --git a/src/com/vaadin/terminal/gwt/rebind/WidgetMapGenerator.java b/src/com/vaadin/terminal/gwt/rebind/WidgetMapGenerator.java index 270ab63702..ba42f4ebaa 100644 --- a/src/com/vaadin/terminal/gwt/rebind/WidgetMapGenerator.java +++ b/src/com/vaadin/terminal/gwt/rebind/WidgetMapGenerator.java @@ -60,7 +60,8 @@ public class WidgetMapGenerator extends Generator { // get print writer that receives the source code PrintWriter printWriter = null; printWriter = context.tryCreate(logger, packageName, className); - // print writer if null, source code has ALREADY been generated, return + // print writer if null, source code has ALREADY been generated, + // return (WidgetMap is equal to all permutations atm) if (printWriter == null) { return; } @@ -77,21 +78,42 @@ public class WidgetMapGenerator extends Generator { SourceWriter sourceWriter = composer.createSourceWriter(context, printWriter); - /* - * TODO we need som sort of mechanims to exclude/include components from - * widgetset. Properties in gwt.xml is one option. Now only possible by - * extending this class, overriding getUsedPaintables() method and - * redefining deferred binding rule. - */ - Collection> paintablesHavingWidgetAnnotation = getUsedPaintables(); + validatePaintables(logger, context, paintablesHavingWidgetAnnotation); + + // generator constructor source code + generateImplementationDetector(sourceWriter, + paintablesHavingWidgetAnnotation); + generateInstantiatorMethod(sourceWriter, + paintablesHavingWidgetAnnotation); + // close generated class + sourceWriter.outdent(); + sourceWriter.println("}"); + // commit generated class + context.commit(logger, printWriter); + logger.log(Type.INFO, "Done. (" + + (new Date().getTime() - date.getTime()) / 1000 + "seconds)"); + + } + + /** + * Verifies that all client side components are available for client side + * GWT module. + * + * @param logger + * @param context + * @param paintablesHavingWidgetAnnotation + */ + private void validatePaintables( + TreeLogger logger, + GeneratorContext context, + Collection> paintablesHavingWidgetAnnotation) { TypeOracle typeOracle = context.getTypeOracle(); - for (Iterator iterator = paintablesHavingWidgetAnnotation.iterator(); iterator - .hasNext();) { - Class class1 = (Class) iterator - .next(); + for (Iterator> iterator = paintablesHavingWidgetAnnotation + .iterator(); iterator.hasNext();) { + Class class1 = iterator.next(); ClientWidget annotation = class1.getAnnotation(ClientWidget.class); @@ -102,28 +124,26 @@ public class WidgetMapGenerator extends Generator { Type.WARN, "Widget implementation for " + class1.getName() - + " not available for GWT compiler. If this is not " + + " not available for GWT compiler (but mapped " + + "for component found in classpath). If this is not " + "intentional, check your gwt module definition file."); iterator.remove(); } } - - // generator constructor source code - generateImplementationDetector(sourceWriter, - paintablesHavingWidgetAnnotation); - generateInstantiatorMethod(sourceWriter, - paintablesHavingWidgetAnnotation); - // close generated class - sourceWriter.outdent(); - sourceWriter.println("}"); - // commit generated class - context.commit(logger, printWriter); - logger.log(Type.INFO, "Done. (" - + (new Date().getTime() - date.getTime()) / 1000 + "seconds)"); - } + /** + * This method is protected to allow easy creation of optimized widgetsets. + *

+ * TODO we need some sort of mechanism to easily exclude/include components + * from widgetset. Properties in gwt.xml is one option. Now only possible by + * extending this class, overriding getUsedPaintables() method and + * redefining deferred binding rule. + * + * @return a collections of Vaadin components that will be added to + * widgetset + */ protected Collection> getUsedPaintables() { return ClassPathExplorer.getPaintablesHavingWidgetAnnotation(); } @@ -151,10 +171,11 @@ public class WidgetMapGenerator extends Generator { sourceWriter.print(".class == classType) return GWT.create("); sourceWriter.print(clientClass.getName()); sourceWriter.println(".class );"); - sourceWriter.print(" else "); + sourceWriter.print("else "); } sourceWriter .println("return GWT.create( com.vaadin.terminal.gwt.client.ui.VUnknownComponent.class );"); + sourceWriter.outdent(); sourceWriter.println("}"); } @@ -168,7 +189,8 @@ public class WidgetMapGenerator extends Generator { SourceWriter sourceWriter, Collection> paintablesHavingWidgetAnnotation) { sourceWriter - .println("public Class getImplementationByServerSideClassName(String fullyQualifiedName) {"); + .println("public Class " + + "getImplementationByServerSideClassName(String fullyQualifiedName) {"); sourceWriter.indent(); sourceWriter .println("fullyQualifiedName = fullyQualifiedName.intern();"); @@ -179,13 +201,14 @@ public class WidgetMapGenerator extends Generator { .value(); sourceWriter.print("if ( fullyQualifiedName == \""); sourceWriter.print(class1.getName()); - sourceWriter.print("\") return "); + sourceWriter.print("\" ) return "); sourceWriter.print(clientClass.getName()); sourceWriter.println(".class;"); - sourceWriter.print(" else "); + sourceWriter.print("else "); } sourceWriter .println("return com.vaadin.terminal.gwt.client.ui.VUnknownComponent.class;"); + sourceWriter.outdent(); sourceWriter.println("}"); }