Package com.google.gwt.user.rebind

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


  @Override
  public String createAssignment(TreeLogger logger, ResourceContext context,
      JMethod method) throws UnableToCompleteException {
    String name = method.getName();

    SourceWriter sw = new StringSourceWriter();
    sw
        .println("new " + ExternalSVGResourcePrototype.class.getName()
            + "(");
    sw.indent();
    sw.println('"' + name + "\",");
    // These are field names
    sw.println(externalSVGUrlIdent + ", " + externalSVGCacheIdent + ", ");
    sw.println(offsets.get(method.getName()).toString());
    sw.outdent();
    sw.print(")");

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


    }
    // make sure that the # of ua in VALID_VALUES
    // is the same of predicates. maybe should iterate
    // to make sure each one has a match.
    assert predicates.length == VALID_VALUES.size();
    StringSourceWriter body = new StringSourceWriter();
    body.println("{");
    body.indent();
    writeUserAgentPropertyJavaScript(body, possibleValues);
    body.outdent();
    body.println("}");

    return body.toString();
  }
View Full Code Here

  @Override
  public String createAssignment(TreeLogger logger, ResourceContext context,
      JMethod method) throws UnableToCompleteException {
    String name = method.getName();

    SourceWriter sw = new StringSourceWriter();
    sw
        .println("new " + ExternalSVGResourcePrototype.class.getName()
            + "(");
    sw.indent();
    sw.println('"' + name + "\",");
    // These are field names
    sw.println(externalSVGUrlIdent + ", " + externalSVGCacheIdent + ", ");
    sw.println(offsets.get(method.getName()).toString());
    sw.outdent();
    sw.print(")");

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

    // xxx = new SVGResource() {
    //   public OMSVGSVGElement getSvg() {
    //     return OMSVGParser.parse("...");
    //   }
    // };
    SourceWriter sw = new StringSourceWriter();
    sw.println("new " + SVGResource.class.getName() + "() {");
    sw.indent();

    // Convenience when examining the generated code.
    sw.println("// " + resource.toExternalForm());

    sw.println("public " + OMSVGSVGElement.class.getName() + " getSvg() {");
    sw.indent();
    String toWrite = Util.readURLAsString(resource);
    if (getValidated(method)) {
      SVGValidator.validate(toWrite, resource.toExternalForm(), logger, null);
    }
    sw.println("return " + OMSVGParser.class.getName() + ".parse(\"" + Generator.escape(toWrite) + "\");");
    sw.outdent();
    sw.println("}");

      sw.println("public String getName() {");
      sw.indent();
      sw.println("return \"" + method.getName() + "\";");
      sw.outdent();
      sw.println("}");

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

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

    Context buildContext = bootStrapClass.getContext();

    BlockBuilder<?> blockBuilder =
            classStructureBuilder.publicMethod(InterfaceInjectionContext.class, "bootstrapContainer");

    SourceWriter sourceWriter = new StringSourceWriter();

    procContext = new IOCProcessingContext(logger, context, sourceWriter, buildContext, bootStrapClass, blockBuilder);
    injectFactory = new InjectorFactory(procContext);
    procFactory = new IOCProcessorFactory(injectFactory);

    MetaDataScanner scanner = ScannerSingleton.getOrCreateInstance();
    Properties props = scanner.getProperties("ErraiApp.properties");
    if (props != null) {
      logger.log(TreeLogger.Type.INFO, "Checking ErraiApp.properties for configured types ...");

      for (Object o : props.keySet()) {
        String key = (String) o;
        if (key.equals(QUALIFYING_METADATA_FACTORY_PROPERTY)) {
          String fqcnQualifyingMetadataFactory = String.valueOf(props.get(key));

          try {
            QualifyingMetadataFactory factory = (QualifyingMetadataFactory)
                    Class.forName
                            (fqcnQualifyingMetadataFactory).newInstance();

            procContext.setQualifyingMetadataFactory(factory);
          }
          catch (ClassNotFoundException e) {
            e.printStackTrace();
          }
          catch (InstantiationException e) {
            e.printStackTrace();
          }
          catch (IllegalAccessException e) {
            e.printStackTrace();
          }
        }
      }
    }

    procContext.setPackages(packages);

    defaultConfigureProcessor();

    // generator constructor source code
    initializeProviders();
    generateExtensions(sourceWriter, classStructureBuilder, blockBuilder);
    // close generated class

    return sourceWriter.toString();
  }
View Full Code Here

  protected String getResourceImplAsString(TreeLogger logger, ResourceContext context,
      JMethod method, Map<JMethod, String> actualReplacements,
      JClassType cssResourceSubtype,
      CssStylesheet stylesheet) throws UnableToCompleteException {
    SourceWriter sw = new StringSourceWriter();
    // Write the expression to create the subtype.
    sw.println("new " + method.getReturnType().getQualifiedSourceName()
        + "() {");
    sw.indent();

    // Methods defined by CssResource interface
    writeEnsureInjected(sw);
    writeGetName(method, sw);

    // Create the Java expression that generates the CSS
    writeGetText(logger, context, method, sw);

    // getOverridableMethods is used to handle CssResources extending
    // non-CssResource types. See the discussion in computeReplacementsForType.
    writeUserMethods(logger, sw, stylesheet,
        cssResourceSubtype.getOverridableMethods(), actualReplacements);

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

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

  @Override
  public String generate(TreeLogger logger, SortedSet<String> possibleValues, String fallback,
      SortedSet<ConfigurationProperty> configProperties) {
    assertUserAgents(logger, possibleValues);

    StringSourceWriter body = new StringSourceWriter();
    body.println("{");
    body.indent();
    writeUserAgentPropertyJavaScript(body, possibleValues, fallback);
    body.outdent();
    body.println("}");

    return body.toString();
  }
View Full Code Here

    checkErrors();

    // Validate that classes not assigned to one of the interface methods are external
    validateExternalClasses(externalClasses, renamingResult.externalClassCandidate, method, logger);

    SourceWriter sw = new StringSourceWriter();
    sw.println("new " + method.getReturnType().getQualifiedSourceName() + "() {");
    sw.indent();

    writeMethods(logger, context, method, sw, constantDefinitions,
        cssParsingResult.originalConstantNameMapping, renamingResult.mapping);

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

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

    }

    URL resource = resources[0];
    String outputUrlExpression = context.deploy(resource, null, true);

    SourceWriter sw = new StringSourceWriter();
    // Write the expression to create the subtype.
    sw.println("new " + StaticDataResource.class.getName() + "() {");
    sw.indent();

    // Convenience when examining the generated code.
    sw.println("// " + resource.toExternalForm());

    sw.println("public String getUrl() {");
    sw.indent();
    sw.println("return " + outputUrlExpression + ";");
    sw.outdent();
    sw.println("}");

    sw.println("public com.google.gwt.safehtml.shared.SafeUri getSafeUri() {");
    sw.indent();
    sw.println("return new org.rstudio.core.client.SafeUriStringImpl(" + outputUrlExpression + ");");
    sw.outdent();
    sw.println("}");

    sw.println("public String getName() {");
    sw.indent();
    sw.println("return \"" + method.getName() + "\";");
    sw.outdent();
    sw.println("}");

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

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

         w.println("public void forceLoad(boolean downloadCodeOnly, Command continuation) {");
         w.indentln("load(downloadCodeOnly ? -1 : 0, new Object[] {continuation});");
         w.println("}");
         w.println();

         StringSourceWriter w_switch = new StringSourceWriter();

         int methodNum = 0;

         for (JMethod method : baseType_.getOverridableMethods())
         {
            if (!method.isAbstract())
               continue;

            doAssert(method.getReturnType().equals(JPrimitiveType.VOID),
                     "Async method had a non-void return type");

            w.print("public final void ");
            w.print(method.getName() + "(");
            String delim = "";
            for (JParameter param : method.getParameters())
            {
               w.print(delim);
               delim = ", ";
               w.print(param.getType().getQualifiedSourceName());
               w.print(" " + param.getName());
            }
            w.print(") ");
            if (method.getThrows().length > 0)
            {
               w.print("throws ");
               String delim2 = "";
               for (JType eType : method.getThrows())
               {
                  w.print(delim2);
                  delim2 = ", ";
                  w.print(eType.getQualifiedSourceName());
               }
            }
            w.println("{");
            w.indent();

            methodNum++;
            if (method.getParameters().length == 0)
            {
               w.println("load(" + methodNum + ", null);");
            }
            else
            {
               w.println("load(" + methodNum + ", new Object[] {");
               w.indent();
               String delim3 = "";
               for (JParameter p : method.getParameters())
               {
                  w.print(delim3);
                  delim3 = ", ";
                  w.print(p.getName());
               }
               w.outdent();
               w.println("});");
            }
           
            w.outdent();
            w.println("}");
            w.println();


            w_switch.println("case " + methodNum + ":");
            w_switch.indent();
            w_switch.print("o." + method.getName() + "(");
            String delim4 = "";
            for (int i = 0; i < method.getParameters().length; i++)
            {
               w_switch.print(delim4);
               delim4 = ", ";
               w_switch.print("(");
               w_switch.print(method.getParameters()[i].getType().getQualifiedSourceName());
               w_switch.print(")");
               w_switch.print("args[" + i + "]");
            }
            w_switch.println(");");
            w_switch.println("break;");
            w_switch.outdent();
         }

         w.println("private void load(final int method, final Object[] args) {");
         w.indent();
         w.println("GWT.runAsync(new RunAsyncCallback() {");
         w.indent();
         w.println("public void onFailure(Throwable reason) {");
         w.indent();
         w.println("try {");
         w.indentln("onDelayLoadFailure(reason);");
         w.println("} finally {");
         w.indentln("if (method <= 0 && args[0] != null) ((Command)args[0]).execute();");
         w.println("}");
         w.outdent();
         w.println("}");
         w.println("public void onSuccess() {");
         w.indent();
         w.println("preInstantiationHook(new Command() {");
         w.indent();
         w.println("public void execute() {");
         w.indent();
         w.println("onSuccess2();");
         w.outdent();
         w.println("}");
         w.outdent();
         w.println("});");
         w.outdent();
         w.println("}");
         w.println("private void onSuccess2() {");
         w.indent();
         w.println("try {");
         w.indent();
         w.println("if (method < 0) return; // download code only");
         w.println("if (o == null) {");
         w.indent();
         w.println("o = po.get();");
         w.println("onDelayLoadSuccess(o);");
         w.outdent();
         w.println("}");
         w.println("switch (method) {");
         w.println("case 0: break;");
         w.println(w_switch.toString());
         w.println("}");
         w.outdent();
         w.println("} finally {");
         w.indentln("if (method <= 0 && args[0] != null) ((Command)args[0]).execute();");
         w.println("}");
View Full Code Here

TOP

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

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.