Package com.google.gwt.user.rebind

Examples of com.google.gwt.user.rebind.SourceWriter


      JClassType userPrefsType = GadgetUtils.getUserPrefsType(logger,
          typeOracle, sourceType);

      // We really use a SourceWriter since it's convenient
      SourceWriter sw = f.createSourceWriter(context, out);
      sw.println("public " + generatedSimpleSourceName + "() {");
      sw.indent();
      sw.println("initializeFeatures();");
      sw.println("init((" + userPrefsType.getQualifiedSourceName()
          + ")GWT.create(" + userPrefsType.getQualifiedSourceName()
          + ".class));");
      sw.outdent();
      sw.println("}");

      generateFeatureInitializers(logger, typeOracle, sw, sourceType);

      // Write out the manifest
      String manifestName = typeName;
      if (!GadgetUtils.useLongManifestName(logger, typeOracle, sourceType)) {
        int lastIndex = manifestName.lastIndexOf('.');
        if (lastIndex != -1) {
          manifestName = manifestName.substring(lastIndex + 1);
        }
      }
      OutputStream manifestOut = context.tryCreateResource(logger, manifestName
          + ".gadget.xml");
      if (manifestOut == null) {
        logger.log(TreeLogger.ERROR, "Gadget manifest was already created",
            null);
        throw new UnableToCompleteException();
      }

      generateGadgetManifest(logger, typeOracle, sourceType, new PrintWriter(
          new OutputStreamWriter(manifestOut)));
      context.commitResource(logger, manifestOut);

      sw.commit(logger);
    }

    return f.getCreatedClassName();
  }
View Full Code Here


    protected void generateClientRpcMethod(SourceWriter w, SerializableTypeOracle serializableTypeOracle,
                                           TypeOracle typeOracle, JMethod syncMethod, JMethod asyncMethod) {
        JType asyncReturnType = asyncMethod.getReturnType().getErasedType();
        String origSignature = "public " + asyncReturnType.getQualifiedSourceName() + " " + asyncMethod.getName();
        String newSignature = "public " + asyncReturnType.getQualifiedSourceName() + " _realRpcMethod_" + asyncMethod.getName();
        SourceWriter sourceWriter = new StringSourceWriter();
        super.generateProxyMethod(sourceWriter, serializableTypeOracle, typeOracle, syncMethod, asyncMethod);
        String method = sourceWriter.toString().replaceFirst(origSignature, newSignature);
        w.print(method);
    }
View Full Code Here

        factory.setSuperclass(superclass.getQualifiedSourceName() + "<"
                + parser.getOwnerType().getParameterizedQualifiedSourceName()
                + ">");
        factory.addImplementedInterface(typeName);

        SourceWriter sw = factory.createSourceWriter(context, pw);
        writeGenerateAndSetIds(sw, parser.getOwnerType(), statements);
        sw.commit(logger);

        return factory.getCreatedClassName();
    }
View Full Code Here

    composer.addImport(JSONString.class.getName());
    composer.addImport(JSONNumber.class.getName());
    composer.addImport(JSONBoolean.class.getName());
    composer.addImport(JSONObject.class.getName());

    SourceWriter sourceWriter = composer.createSourceWriter(context, printWriter);

    // generator constructor source code
    generateExtensions(context, logger, sourceWriter);
    // close generated class
    sourceWriter.outdent();
    sourceWriter.println("}");


    // commit generated class
    context.commit(logger, printWriter);
  }
View Full Code Here

    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();
  }
View Full Code Here

public class UserAgentPropertyGenerator implements PropertyProviderGenerator {
  @Override
  public String generate(TreeLogger logger, SortedSet<String> possibleValues, String fallback,
      SortedSet<ConfigurationProperty> configProperties) throws UnableToCompleteException {

    SourceWriter sw = new StringSourceWriter();
    sw.println("{");

    sw.println("var ua = navigator.userAgent.toLowerCase();");
    uaContains(sw, "chrome", "chrome");
    uaContains(sw, "opera", "opera");

    sw.println("if (ua.indexOf('msie') != -1) {");
    sw.indent();

    // TODO ChromeFrame?
    docModeGreaterThan(sw, 10, "ie10");
    docModeGreaterThan(sw, 9, "ie9");
    docModeGreaterThan(sw, 8, "ie8");
   
    uaContains(sw, "msie 7", "ie7");
    uaContains(sw, "msie 6", "ie6");
   
    // last assume newest
    sw.println("return 'ie10';");
    sw.outdent();
    sw.println("}");

    sw.println("if (ua.indexOf('safari') != -1) {");
    sw.indent();
    uaContains(sw, "version/3", "safari3");
    uaContains(sw, "version/4", "safari4");
    // else assume newest
    // simpleStatement(sw, "version/5", "safari5");
    sw.println("return 'safari5';");
    sw.outdent();
    sw.println("}");

    sw.println("if (ua.indexOf('gecko') != -1) {");
    sw.indent();
    uaContains(sw, "rv:1.8", "gecko1_8");
    // Don't check for rev 1.9, check instead for the newest version, and treat
    // all
    // gecko browsers that don't match a rule as the newest version
    // simpleStatement(sw, "rv:1.9", "gecko1_9");
    sw.println("return 'gecko1_9';");
    sw.outdent();
    sw.println("}");


    uaContains(sw, "adobeair", "air");

    sw.println("return null;}");
    return sw.toString();
  }
View Full Code Here

    }

    ClassSourceFileComposerFactory factory = new ClassSourceFileComposerFactory(getPackageName(), getSimpleName());
    configureFactory(factory);

    SourceWriter sw = factory.createSourceWriter(getContext(), pw);
    create(sw);

    sw.commit(getLogger());
    return factory.getCreatedClassName();
  }
View Full Code Here

    // Loop through the formatters declared for this type and supertypes
    FormatCollector formatters = new FormatCollector(context, logger, toGenerate);
    MethodCollector invokables = new MethodCollector(context, logger, toGenerate);

    SourceWriter sw = factory.createSourceWriter(context, pw);

    for (JMethod method : toGenerate.getOverridableMethods()) {
      TreeLogger l = logger.branch(Type.DEBUG, "Creating XTemplate method " + method.getName());
      final String template;
      XTemplate marker = method.getAnnotation(XTemplate.class);
      if (marker == null) {
        l.log(Type.ERROR, "Unable to create template for method " + method.getReadableDeclaration()
            + ", this may cause other failures.");
        continue;
      } else {
        if (marker.source().length() != 0) {
          if (marker.value().length() != 0) {
            l.log(Type.WARN, "Found both source file and inline template, using source file");
          }

          InputStream stream = getTemplateResource(context, method.getEnclosingType(), l, marker.source());
          if (stream == null) {
            l.log(Type.ERROR, "No data could be loaded - no data at path " + marker.source());
            throw new UnableToCompleteException();
          }
          template = Util.readStreamAsString(stream);
        } else if (marker.value().length() != 0) {
          template = marker.value();
        } else {
          l.log(Type.ERROR,
              "XTemplate annotation found with no contents, cannot generate method " + method.getName()
                  + ", this may cause other failures.");
          continue;
        }
      }

      XTemplateParser p = new XTemplateParser(l.branch(Type.DEBUG,
          "Parsing provided template for " + method.getReadableDeclaration()));
      TemplateModel m = p.parse(template);
      SafeHtmlTemplatesCreator safeHtml = new SafeHtmlTemplatesCreator(context, l.branch(Type.DEBUG,
          "Building SafeHtmlTemplates"), method);

      sw.println(method.getReadableDeclaration(false, true, true, false, true) + "{");
      sw.indent();

      Map<String, JType> params = new HashMap<String, JType>();
      for (JParameter param : method.getParameters()) {
        params.put(param.getName(), param.getType());
      }
      Context scopeContext = new Context(context, l, params, formatters);
      // if there is only one parameter, wrap the scope up so that properties
      // can be accessed directly
      if (method.getParameters().length == 1) {
        JParameter param = method.getParameters()[0];
        scopeContext = new Context(scopeContext, param.getName(), param.getType());

      }

      String outerSHVar = scopeContext.declareLocalVariable("outer");
      sw.println("SafeHtml %1$s;", outerSHVar);

      buildSafeHtmlTemplates(outerSHVar, sw, m, safeHtml, scopeContext, invokables);

      sw.println("return %1$s;", outerSHVar);

      sw.outdent();
      sw.println("}");

      safeHtml.create();
    }

    // Save the file and return its type name
    sw.commit(logger);
    return factory.getCreatedClassName();
  }
View Full Code Here

      return packageName + "." + simpleSourceName;
    }

    ClassSourceFileComposerFactory factory = new ClassSourceFileComposerFactory(packageName, simpleSourceName);
    factory.addImplementedInterface(typeName);
    SourceWriter sw = factory.createSourceWriter(context, pw);

    for (JMethod method : toGenerate.getMethods()) {
      if (method.getReturnType().isPrimitive() != JPrimitiveType.BOOLEAN
          && !method.getReturnType().isClass().getQualifiedSourceName().equals(
              Name.getSourceNameForClass(Boolean.class))) {
        logger.log(Type.ERROR, "Methods must return boolean or Boolean");
        throw new UnableToCompleteException();
      }
      sw.println("%1$s {", method.getReadableDeclaration(false, true, true, true, true));

      PropertyValue val = method.getAnnotation(PropertyValue.class);
      if (val == null) {
        logger.log(Type.ERROR, "Method must have a @PropertyValue annotation");
        throw new UnableToCompleteException();
      }

      if (!property.getPossibleValues().contains(val.value()) && val.warn()) {
        logger.log(Type.WARN, "Value '" + val
            + "' is not present in the current set of possible values for selection property " + propertyName);
      }
      sw.indentln("return %1$b;", val.value().equals(value));

      sw.println("}");
    }

    sw.commit(logger);

    return factory.getCreatedClassName();
  }
View Full Code Here

        // Interfaces
        composerFactory.addImplementedInterface("org.jboss.as.console.client.ProductConfig");

        // SourceWriter
        SourceWriter sourceWriter = composerFactory.createSourceWriter(context, printWriter);

        // fields
        generateFields(sourceWriter);

        // ctor
        generateConstructor(logger, context, sourceWriter);

        // Methods
        generateMethods(sourceWriter, context);

        // close generated class
        sourceWriter.outdent();
        sourceWriter.println("}");

        // commit generated class
        context.commit(logger, printWriter);
    }
View Full Code Here

TOP

Related Classes of com.google.gwt.user.rebind.SourceWriter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.