Examples of StringSourceWriter


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

         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

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

      throw new UnableToCompleteException();
    }

    URL resource = resources[0];

    SourceWriter sw = new StringSourceWriter();
    sw.println("new " + CustomDataResourcePrototype.class.getName() + "(");
    sw.indent();
    sw.println('"' + method.getName() + "\",");
    // We don't care about it actually working, so just use the resource URL
    sw.println(UriUtils.class.getName() + ".fromTrustedString(\"" + resource.toExternalForm() + "\")");
    sw.outdent();
    sw.print(")");

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

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

      throw new UnableToCompleteException();
    }

    URL resource = resources[0];

    SourceWriter sw = new StringSourceWriter();
    sw.println("new " + CustomImageResourcePrototype.class.getName() + "(");
    sw.indent();
    sw.println('"' + method.getName() + "\",");
    // We don't care about it actually working, so just use the resource URL
    sw.println(UriUtils.class.getName() + ".fromTrustedString(\"" + resource.toExternalForm() + "\")");
    sw.outdent();
    sw.print(")");

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

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

      JMethod method) throws UnableToCompleteException {
    String name = "ExternalImageResourceGenerator.createAssignment";
    URL[] resources = ResourceGeneratorUtil.findResources(logger, context,
        method);
   
    SourceWriter sw = new StringSourceWriter();
    // Write the expression to create the subtype.
    sw.println("new " + ExternalImageResource.class.getName() + "() {");
    sw.indent();
   
    sw.println(String.format("public void getImage(%s<%s> callback) {",
        ResourceCallback.class.getName(),
        ImageElementResource.class.getName()));
    sw.indent();
   
    int index = 0;
    String abstractImageElementResourceClassName =
        AbstractImageElementResource.class.getName();
    for (URL resource : resources) {
      String outputUrlExpression = context.deploy(resource, false);
      sw.println("{");
      sw.println(abstractImageElementResourceClassName + " imgResource = new "
          + abstractImageElementResourceClassName + "() {");
     
      sw.indent();
     
      sw.println("public String getName() {");
      sw.indent();
      sw.println("return \"" + name + "\";");
      sw.outdent();
      sw.println("}");
     
      sw.println("public String getBaseUrl() {");
      sw.indent();
      sw.println("return \"" + ResourceGeneratorUtil.baseName(resource) + "\";");
      sw.outdent();
      sw.println("}");
     
      sw.println("public int getIndex() {");
      sw.indent();
      sw.println("return " + index + ";");
      sw.outdent();
      sw.println("}");
     
      sw.outdent();
      sw.println("};");
     
      sw.println(ImageLoader.class.getName() + ".loadImageAsync("
          + outputUrlExpression + ", imgResource, callback);");
      sw.println("}");
      index++;
    }
    sw.outdent();
    sw.println("}");
   
    sw.println("public String getName() {");
    sw.indent();
    sw.println("return \"" + name + "\";");
    sw.outdent();
    sw.println("}");

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

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

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

    BlockBuilder<?> blockBuilder =
            classStructureBuilder.publicMethod(BootstrapperInjectionContext.class, "bootstrapContainer")
                    .methodComment("The main IOC bootstrap method.");

    SourceWriter sourceWriter = new StringSourceWriter();

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

    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();
          }
        }
        else if (key.equals(ENABLED_ALTERNATIVES_PROPERTY)) {
          String[] alternatives = String.valueOf(props.get(ENABLED_ALTERNATIVES_PROPERTY)).split("\\s");
          for (String alternative : alternatives) {
            injectionContext.addEnabledAlternative(alternative.trim());
          }
        }
      }
    }

    procContext.setPackages(packages);

    defaultConfigureProcessor();

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

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

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

    final BlockBuilder<?> blockBuilder =
        classStructureBuilder.publicMethod(BootstrapperInjectionContext.class, "bootstrapContainer")
            .methodComment("The main IOC bootstrap method.");

    final SourceWriter sourceWriter = new StringSourceWriter();

    final IOCProcessingContext.Builder iocProcContextBuilder
        = IOCProcessingContext.Builder.create();

    iocProcContextBuilder.blockBuilder(blockBuilder);
    iocProcContextBuilder.generatorContext(context);
    iocProcContextBuilder.context(buildContext);
    iocProcContextBuilder.bootstrapClassInstance(bootStrapClass);
    iocProcContextBuilder.bootstrapBuilder(classStructureBuilder);
    iocProcContextBuilder.logger(logger);
    iocProcContextBuilder.sourceWriter(sourceWriter);
    iocProcContextBuilder.gwtTarget(!useReflectionStubs);

    final InjectionContext.Builder injectionContextBuilder
        = InjectionContext.Builder.create();

    final MetaDataScanner scanner = ScannerSingleton.getOrCreateInstance();
    final Multimap<String, String> props = scanner.getErraiProperties();

    if (props != null) {
      logger.log(TreeLogger.Type.INFO, "Checking ErraiApp.properties for configured types ...");

      final Collection<String> qualifyingMetadataFactoryProperties = props.get(QUALIFYING_METADATA_FACTORY_PROPERTY);

      if (qualifyingMetadataFactoryProperties.size() > 1) {
        throw new RuntimeException("the property '" + QUALIFYING_METADATA_FACTORY_PROPERTY + "' is set in more than one place");
      }
      else if (qualifyingMetadataFactoryProperties.size() == 1) {
        final String fqcnQualifyingMetadataFactory = qualifyingMetadataFactoryProperties.iterator().next().trim();

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

          iocProcContextBuilder.qualifyingMetadata(factory);
        }
        catch (ClassNotFoundException e) {
          e.printStackTrace();
        }
        catch (InstantiationException e) {
          e.printStackTrace();
        }
        catch (IllegalAccessException e) {
          e.printStackTrace();
        }
      }

      final Collection<String> enabledAlternativesProperties = props.get(ENABLED_ALTERNATIVES_PROPERTY);

      for (final String prop : enabledAlternativesProperties) {
          final String[] alternatives = prop.split("\\s");
          for (final String alternative : alternatives) {
            injectionContextBuilder.enabledAlternative(alternative.trim());
          }
      }
    }

    iocProcContextBuilder.packages(packages);

    final IOCProcessingContext procContext = iocProcContextBuilder.build();

    injectionContextBuilder.processingContext(procContext);
    injectionContextBuilder.reachableTypes(allDeps);
    final InjectionContext injectionContext = injectionContextBuilder.build();

    defaultConfigureProcessor(injectionContext);

    // generator constructor source code
    final IOCProcessorFactory procFactory = new IOCProcessorFactory(injectionContext);
    processExtensions(context, procContext, injectionContext, procFactory, beforeTasks, afterTasks);
    generateExtensions(procContext, procFactory, injectionContext, sourceWriter, classStructureBuilder, blockBuilder);

    // close generated class
    return sourceWriter.toString();
  }
View Full Code Here

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

  @Override
  public String createAssignment(TreeLogger logger, ResourceContext context,
      JMethod method) throws UnableToCompleteException {

    SourceWriter sw = new StringSourceWriter();
    // Write the expression to create the subtype.
    sw.println("new " + method.getReturnType().getQualifiedSourceName()
        + "() {");
    sw.indent();

    JClassType cssResourceSubtype = method.getReturnType().isInterface();
    assert cssResourceSubtype != null;
    Map<String, Map<JMethod, String>> replacementsWithPrefix = new HashMap<String, Map<JMethod, String>>();

    replacementsWithPrefix.put("",
        computeReplacementsForType(cssResourceSubtype));
    Import imp = method.getAnnotation(Import.class);
    if (imp != null) {
      boolean fail = false;
      for (Class<? extends CssResource> clazz : imp.value()) {
        JClassType importType = context.getGeneratorContext().getTypeOracle().findType(
            clazz.getName().replace('$', '.'));
        assert importType != null;
        String prefix = importType.getSimpleSourceName();
        ImportedWithPrefix exp = importType.getAnnotation(ImportedWithPrefix.class);
        if (exp != null) {
          prefix = exp.value();
        }

        if (replacementsWithPrefix.put(prefix + "-",
            computeReplacementsForType(importType)) != null) {
          logger.log(TreeLogger.ERROR,
              "Multiple imports that would use the prefix " + prefix);
          fail = true;
        }
      }
      if (fail) {
        throw new UnableToCompleteException();
      }
    }

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

    sw.println("public String getText() {");
    sw.indent();
    boolean strict = isStrict(logger, context, method);
    Map<JMethod, String> actualReplacements = new IdentityHashMap<JMethod, String>();
    String cssExpression = makeExpression(logger, context, cssResourceSubtype,
        stylesheetMap.get(method), replacementsWithPrefix, strict,
        actualReplacements);
    sw.println("return " + cssExpression + ";");
    sw.outdent();
    sw.println("}");

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

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

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

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 " + ImageResourcePrototype.class.getName() + "(");
    sw.indent();
    sw.println('"' + name + "\",");

    ImageRect rect = imageRectsByName.get(name);
    assert rect != null : "No ImageRect ever computed for " + name;

    String[] urlExpressions;
    {
      ImageBundleBuilder builder = buildersByImageRect.get(rect);
      if (builder == null) {
        urlExpressions = urlsByExternalImageRect.get(rect);
      } else {
        urlExpressions = urlsByBuilder.get(builder);
      }
    }
    assert urlExpressions != null : "No URL expression for " + name;
    assert urlExpressions.length == 2;

    if (urlExpressions[1] == null) {
      sw.println(urlExpressions[0] + ",");
    } else {
      sw.println("com.google.gwt.i18n.client.LocaleInfo.getCurrentLocale().isRTL() ?"
          + urlExpressions[1] + " : " + urlExpressions[0] + ",");
    }
    sw.println(rect.getLeft() + ", " + rect.getTop() + ", " + rect.getWidth()
        + ", " + rect.getHeight() + ", " + rect.isAnimated());

    sw.outdent();
    sw.print(")");

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

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

  @Override
  public String createAssignment(TreeLogger logger, ResourceContext context,
      JMethod method) throws UnableToCompleteException {

    TypeOracle typeOracle = context.getGeneratorContext().getTypeOracle();
    SourceWriter sw = new StringSourceWriter();
    // Write the expression to create the subtype.
    sw.println("new " + method.getReturnType().getQualifiedSourceName()
        + "() {");
    sw.indent();

    JClassType cssResourceSubtype = method.getReturnType().isInterface();
    assert cssResourceSubtype != null;
    Map<String, Map<JMethod, String>> replacementsWithPrefix = new HashMap<String, Map<JMethod, String>>();

    replacementsWithPrefix.put("",
        computeReplacementsForType(cssResourceSubtype));
    Import imp = method.getAnnotation(Import.class);
    if (imp != null) {
      boolean fail = false;
      for (Class<? extends CssResource> clazz : imp.value()) {
        JClassType importType = typeOracle.findType(clazz.getName().replace(
            '$', '.'));
        assert importType != null : "TypeOracle does not have type "
            + clazz.getName();

        String prefix = getImportPrefix(importType);

        if (replacementsWithPrefix.put(prefix,
            computeReplacementsForType(importType)) != null) {
          logger.log(TreeLogger.ERROR,
              "Multiple imports that would use the prefix " + prefix);
          fail = true;
        }
      }
      if (fail) {
        throw new UnableToCompleteException();
      }
    }

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

    sw.println("public String getText() {");
    sw.indent();
    boolean strict = isStrict(logger, method);
    Map<JMethod, String> actualReplacements = new IdentityHashMap<JMethod, String>();
    String cssExpression = makeExpression(logger, context, cssResourceSubtype,
        stylesheetMap.get(method), replacementsWithPrefix, strict,
        actualReplacements);
    sw.println("return " + cssExpression + ";");
    sw.outdent();
    sw.println("}");

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

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

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

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

    }

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

    SourceWriter sw = new StringSourceWriter();
    // Write the expression to create the subtype.
    sw.println("new " + DataResource.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 String getName() {");
    sw.indent();
    sw.println("return \"" + method.getName() + "\";");
    sw.outdent();
    sw.println("}");

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

    return sw.toString();
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.