List of usage examples for com.google.gwt.user.rebind SourceWriter println
void println(String s);
From source file:com.chrome.gwt.linker.ComponentGenerator.java
License:Apache License
private static String emitBrowserActionCode(TreeLogger logger, GeneratorContext context, JClassType userType, String name, List<String> icons, List<String> iconPaths) { final String subclassName = userType.getSimpleSourceName().replace('.', '_') + "_generated"; final String packageName = userType.getPackage().getName(); final ClassSourceFileComposerFactory f = new ClassSourceFileComposerFactory(packageName, subclassName); f.setSuperclass(userType.getQualifiedSourceName()); final PrintWriter pw = context.tryCreate(logger, packageName, subclassName); if (pw != null) { final SourceWriter sw = f.createSourceWriter(context, pw); // Impl for the getter for name. sw.println("public String getName() {"); // TODO(jaimeyap): Use proper string escaping from generator libs. sw.println(" return \"" + name + "\";"); sw.println("}"); emitIcons(icons, iconPaths, sw); sw.commit(logger);//from w w w .j av a 2 s .co m } return f.getCreatedClassName(); }
From source file:com.chrome.gwt.linker.ComponentGenerator.java
License:Apache License
private static String emitComponentPageCode(TreeLogger logger, GeneratorContext context, JClassType userType) { final String subclassName = userType.getSimpleSourceName().replace('.', '_') + "_generated"; final String packageName = userType.getPackage().getName(); final ClassSourceFileComposerFactory f = new ClassSourceFileComposerFactory(packageName, subclassName); f.setSuperclass(userType.getQualifiedSourceName()); final PrintWriter pw = context.tryCreate(logger, packageName, subclassName); if (pw != null) { final SourceWriter sw = f.createSourceWriter(context, pw); // Write a default constructor that simply calls connect. sw.println("public " + subclassName + "() {"); sw.println(" connect(\"" + userType.getSimpleSourceName() + "\");"); sw.println("}"); sw.commit(logger);/*from w w w. j a v a 2 s .c o m*/ } return f.getCreatedClassName(); }
From source file:com.chrome.gwt.linker.ComponentGenerator.java
License:Apache License
private static void emitIcons(List<String> iconNames, List<String> iconPaths, SourceWriter sw) { // Fill in the methods for kicking back the BrowserAction Icons. for (int i = 0; i < iconNames.size(); i++) { String iconName = Generator.escape(iconNames.get(i)); String iconField = Generator.escape(iconName) + "_field"; sw.println("private " + ICON_USER_TYPE + " " + iconField + " = null;"); sw.println("public " + ICON_USER_TYPE + " " + iconName + "() {"); sw.println(" if (" + iconField + " == null) {"); sw.println(" " + iconField + " = new " + ICON_USER_TYPE + "(" + i + ", \"" + Generator.escape(iconPaths.get(i)) + "\");"); sw.println(" }"); sw.println(" return " + iconField + ";"); sw.println("}"); }/* ww w . j a v a2 s . c o m*/ }
From source file:com.chrome.gwt.linker.ComponentGenerator.java
License:Apache License
private static String emitPageActionCode(TreeLogger logger, GeneratorContext context, JClassType userType, String pageActionId, String name, List<String> icons, List<String> iconPaths) { final String subclassName = userType.getSimpleSourceName().replace('.', '_') + "_generated"; final String packageName = userType.getPackage().getName(); final ClassSourceFileComposerFactory f = new ClassSourceFileComposerFactory(packageName, subclassName); f.setSuperclass(userType.getQualifiedSourceName()); final PrintWriter pw = context.tryCreate(logger, packageName, subclassName); if (pw != null) { final SourceWriter sw = f.createSourceWriter(context, pw); // Impls for the getters for id and name. sw.println("public String getId() {"); sw.println(" return \"" + pageActionId + "\";"); sw.println("}"); sw.println("public String getName() {"); sw.println(" return \"" + name + "\";"); sw.println("}"); emitIcons(icons, iconPaths, sw); sw.commit(logger);/*from w w w . jav a 2 s.c o m*/ } return f.getCreatedClassName(); }
From source file:com.chrome.gwt.linker.ExtensionGenerator.java
License:Apache License
private static String generateExtensionType(TreeLogger logger, GeneratorContext context, JClassType userType, ExtensionArtifact spec) {/* w ww .jav a 2 s . c o m*/ final String subclassName = userType.getSimpleSourceName().replace('.', '_') + "_generated"; final String packageName = userType.getPackage().getName(); final ClassSourceFileComposerFactory f = new ClassSourceFileComposerFactory(packageName, subclassName); f.setSuperclass(userType.getQualifiedSourceName()); final PrintWriter pw = context.tryCreate(logger, packageName, subclassName); if (pw != null) { final SourceWriter sw = f.createSourceWriter(context, pw); final String version = (spec.getVersion() != null) ? spec.getVersion() : ""; sw.println("@Override public String getVersion() {"); sw.println(" return \"" + GeneratorUtils.toJavaLiteral(version) + "\";"); sw.println("}"); sw.commit(logger); } return f.getCreatedClassName(); }
From source file:com.dom_distiller.client.JsTestEntryGenerator.java
License:Open Source License
@Override public String generate(TreeLogger logger, GeneratorContext context, String typename) throws UnableToCompleteException { String packageName = "com.dom_distiller.client"; String outputClassname = "JsTestBuilderImpl"; List<TestCase> testCases = getTestCases(logger, context); ClassSourceFileComposerFactory composer = new ClassSourceFileComposerFactory(packageName, outputClassname); composer.addImplementedInterface("com.dom_distiller.client.JsTestSuiteBuilder"); PrintWriter printWriter = context.tryCreate(logger, packageName, outputClassname); if (printWriter != null) { SourceWriter sourceWriter = composer.createSourceWriter(context, printWriter); sourceWriter.println("JsTestBuilderImpl () {"); sourceWriter.println("}"); sourceWriter.println("public JsTestSuiteBase build() {"); sourceWriter.indent();/* w ww .java2s. c o m*/ sourceWriter.println("JsTestSuiteBase testSuite = new JsTestSuiteBase();"); for (TestCase ts : testCases) { String className = ts.classType.getName(); String qualifiedClassName = ts.classType.getPackage().getName() + "." + className; sourceWriter.println("testSuite.addTestCase("); sourceWriter.println(" new JsTestSuiteBase.TestCaseFactory() {"); sourceWriter.println(" @Override"); sourceWriter.println(" public JsTestCase build() {"); sourceWriter.println(" return new " + className + "();"); sourceWriter.println(" }"); sourceWriter.println(" }, \"" + qualifiedClassName + "\")"); sourceWriter.indent(); for (JMethod test : ts.tests) { String methodName = test.getName(); sourceWriter.println(".addTest("); sourceWriter.println(" new JsTestSuiteBase.TestCaseRunner() {"); sourceWriter.println(" @Override"); sourceWriter.println(" public void run(JsTestCase testCase) throws Exception {"); sourceWriter.println(" ((" + className + ")testCase)." + methodName + "();"); sourceWriter.println(" }"); sourceWriter.println(" }, \"" + methodName + "\")"); } sourceWriter.println(";"); sourceWriter.outdent(); } sourceWriter.println("return testSuite;"); sourceWriter.outdent(); sourceWriter.println("}"); sourceWriter.commit(logger); } return composer.getCreatedClassName(); }
From source file:com.eleven.rebind.SkinBundleGenerator.java
License:Apache License
private void generateImageMethod(final SkinBundleBuilder compositeImage, final SourceWriter sw, final JMethod method, final String imgResName) { String decl = method.getReadableDeclaration(false, true, true, true, true); {//from w w w . j a va 2 s . c om sw.indent(); // Create a singleton that this method can return. There is no need // to // create a new instance every time this method is called, since // ClippedImagePrototype is immutable SkinBundleBuilder.ImageRect imageRect = compositeImage.getMapping(imgResName); String singletonName = method.getName() + "_SINGLETON"; sw.print("private static final ClippedImagePrototype "); sw.print(singletonName); sw.print(" = new ClippedImagePrototype(IMAGE_BUNDLE_URL, "); sw.print(Integer.toString(imageRect.getLeft())); sw.print(", "); sw.print(Integer.toString(imageRect.getTop())); sw.print(", "); sw.print(Integer.toString(imageRect.getWidth())); sw.print(", "); sw.print(Integer.toString(imageRect.getHeight())); sw.println(");"); sw.print(decl); sw.println(" {"); sw.indent(); sw.print("return "); sw.print(singletonName); sw.println(";"); sw.outdent(); sw.println("}"); sw.outdent(); } }
From source file:com.eleven.rebind.SkinBundleGenerator.java
License:Apache License
private void generateImageDef(final SkinBundleBuilder compositeImage, final SourceWriter sw, final List<String> imgResNames) { sw.indent();/* w ww . j av a 2 s .c o m*/ sw.println("private static final HashMap<String, ClippedImagePrototype> imageMap" + "= new HashMap<String, ClippedImagePrototype>() {"); sw.indent(); sw.println("{"); sw.indent(); for (String imgResName : imgResNames) { SkinBundleBuilder.ImageRect imageRect = compositeImage.getMapping(imgResName); sw.print("put (\"" + imgResName.replace(File.separatorChar, '/') + "\", "); sw.print("new ClippedImagePrototype(IMAGE_BUNDLE_URL, "); sw.print(Integer.toString(imageRect.getLeft())); sw.print(", "); sw.print(Integer.toString(imageRect.getTop())); sw.print(", "); sw.print(Integer.toString(imageRect.getWidth())); sw.print(", "); sw.print(Integer.toString(imageRect.getHeight())); sw.println("));"); } sw.outdent(); sw.println("}"); sw.outdent(); sw.println("};"); sw.println("@Override"); sw.println("public void prefetchAll() {"); sw.indent(); for (String imgResName : imgResNames) sw.println("Image.prefetch(\"" + imgResName.replace(File.separatorChar, '/') + "\");"); sw.println("}"); sw.outdent(); sw.println("@Override"); sw.println("public void prefetchBundle() {"); sw.indent(); sw.println("Image.prefetch(IMAGE_BUNDLE_URL);"); sw.println("}"); sw.outdent(); }
From source file:com.eleven.rebind.SkinBundleGenerator.java
License:Apache License
/** * Generates the image bundle implementation class, checking each method for * validity as it is encountered.// w w w . j a v a 2 s. c om */ private String generateImplClass(final TreeLogger logger, final GeneratorContext context, final JClassType userType, final JMethod[] imageMethods) throws UnableToCompleteException { // Lookup the type info for AbstractImagePrototype so that we can check // for // the proper return type // on image bundle methods. final JClassType abstractImagePrototype; try { abstractImagePrototype = userType.getOracle().getType(ABSTRACTIMAGEPROTOTYPE_QNAME); } catch (NotFoundException e) { logger.log(TreeLogger.ERROR, "GWT " + ABSTRACTIMAGEPROTOTYPE_QNAME + " class is not available", e); throw new UnableToCompleteException(); } // Compute the package and class names of the generated class. String pkgName = userType.getPackage().getName(); String subName = computeSubclassName(userType); // 11pc String pkgPrefix = pkgName.replace('.', '/'); if (pkgPrefix.length() > 0) pkgPrefix += "/"; // Begin writing the generated source. ClassSourceFileComposerFactory f = new ClassSourceFileComposerFactory(pkgName, subName); f.addImport(ABSTRACTIMAGEPROTOTYPE_QNAME); f.addImport(CLIPPEDIMAGEPROTOTYPE_QNAME); f.addImport(GWT_QNAME); f.addImport(HASHMAP_QNAME); f.addImport(IMAGE_QNAME); f.addImplementedInterface(userType.getQualifiedSourceName()); PrintWriter pw = context.tryCreate(logger, pkgName, subName); if (pw != null) { SourceWriter sw = f.createSourceWriter(context, pw); // Build a compound image from each individual image. SkinBundleBuilder bulder = new SkinBundleBuilder(); // Store the computed image names so that we don't have to lookup // them up again. // 11pc List<String> imageResNames = getSkinImages(logger); for (String imageName : imageResNames) bulder.assimilate(logger, imageName); /* for (JMethod method : imageMethods) { String branchMsg = "Analyzing method '" + method.getName() + "' in type " + userType.getQualifiedSourceName(); TreeLogger branch = logger.branch(TreeLogger.DEBUG, branchMsg, null); // Verify that this method is valid on an image bundle. if (method.getReturnType() != abstractImagePrototype) { branch.log(TreeLogger.ERROR, "Return type must be " + ABSTRACTIMAGEPROTOTYPE_QNAME, null); throw new UnableToCompleteException(); } if (method.getParameters().length > 0) { branch.log(TreeLogger.ERROR, "Method must have zero parameters", null); throw new UnableToCompleteException(); } // Find the associated imaged resource. String imageResName = getImageResourceName(branch, new JMethodOracleImpl(method)); assert (imageResName != null); imageResNames.add(imageResName); bulder.assimilate(logger, imageResName); } */ // Write the compound image into the output directory. // String bundledImageUrl = bulder.writeBundledImage(logger, context); String bundledImageUrl = "yeayeaa"; // Emit a constant for the composite URL. Note that we prepend the // module's base URL so that the module can reference its own // resources // independently of the host HTML page. sw.print("private static final String IMAGE_BUNDLE_URL = GWT.getModuleBaseURL() + \""); sw.print(escape(bundledImageUrl)); sw.println("\";"); /* // Generate an implementation of each method. int imageResNameIndex = 0; for (JMethod method : imageMethods) { generateImageMethod(bulder, sw, method, imageResNames .get(imageResNameIndex++)); } */ generateImageDef(bulder, sw, imageResNames); sw.println("@Override"); sw.println("public AbstractImagePrototype get(String image) {"); sw.indent(); sw.println("return imageMap.get(image);"); sw.outdent(); sw.print("}"); sw.println("@Override"); sw.println("public HashMap<String, HashMap<String, String>> getProperties() {"); sw.indent(); sw.println("return null;"); sw.outdent(); sw.print("}"); // Finish. sw.commit(logger); } return f.getCreatedClassName(); }
From source file:com.emitrom.pilot.core.shared.rebind.BeanModelGenerator.java
License:Apache License
protected String createBean(JClassType bean, TreeLogger logger, GeneratorContext context) throws Exception { final String genPackageName = bean.getPackage().getName(); final String genClassName = "Bean_" + bean.getQualifiedSourceName().replace(".", "_"); ClassSourceFileComposerFactory composer = new ClassSourceFileComposerFactory(genPackageName, genClassName); composer.setSuperclass(Bean.class.getCanonicalName()); composer.addImport(Bean.class.getName()); composer.addImport(NestedModelUtil.class.getName()); PrintWriter pw = context.tryCreate(logger, genPackageName, genClassName); if (pw != null) { List<JMethod> getters = findGetters(bean); List<JMethod> setters = findSetters(bean); SourceWriter sw = composer.createSourceWriter(context, pw); sw.println("public " + genClassName + "(){"); for (JMethod method : getters) { String s = method.getName(); String p = lowerFirst(s.substring(s.startsWith("g") ? 3 : 2)); // get // or // is sw.println("beanProperties.add(\"" + p + "\");"); }/*w w w . j av a2s . c om*/ sw.println("}"); createGetMethods(getters, sw, bean.getQualifiedSourceName()); createSetMethods(setters, sw, bean.getQualifiedSourceName()); // delegate equals to bean sw.println("public boolean equals(Object obj) {"); sw.println(" if (obj instanceof " + "Bean" + ") {"); sw.println(" obj = ((Bean)obj).getBean();"); sw.println(" }"); sw.println(" return bean.equals(obj);"); sw.println("}"); // delegate hashCode to bean sw.println("public int hashCode(){"); sw.println(" return bean.hashCode();"); sw.println("}"); sw.commit(logger); } return composer.getCreatedClassName(); }