Package com.google.gwt.core.ext

Examples of com.google.gwt.core.ext.TreeLogger$HelpInfo


   * @return A Map of Strings to Tasks.
   */
  public static Map<String, Task> extractMethods(TreeLogger logger,
      TypeOracle typeOracle, JClassType clazz, Policy policy)
      throws UnableToCompleteException {
    TreeLogger parentLogger = logger.branch(TreeLogger.DEBUG,
        "Extracting methods from " + clazz.getName(), null);

    // Value to return
    final Map<String, Task> propertyAccessors = new HashMap<String, Task>();

    // Iterate over all methods that the generated subclass could override
    for (JMethod m : policy.getOperableMethods(typeOracle, clazz)) {
      final String methodName = m.getName();
      logger = parentLogger.branch(TreeLogger.DEBUG, "Examining "
          + m.toString(), null);

      // Look for methods that are to be exported by the presence of
      // the gwt.exported annotation.
      if (policy.shouldExport(logger, typeOracle, m)) {
View Full Code Here


  }

  @Override
  void fromJS(FragmentGeneratorContext context)
      throws UnableToCompleteException {
    TreeLogger logger = context.parentLogger.branch(TreeLogger.DEBUG,
        "Building value getter statement", null);

    SourceWriter sw = context.sw;
    TypeOracle typeOracle = context.typeOracle;
    JClassType returnType = context.returnType.isClassOrInterface();

    // Don't use "x || null" expression because the value may be boolean false
    sw.print("(");
    sw.print(context.parameterName);
    sw.print(" == null || ");
    sw.print(context.parameterName);
    sw.print(" == undefined) ? null : ");
    sw.print("@com.google.gwt.jsio.client.impl.JSONWrapperUtil::createWrapper");

    // Just plow through the Boxed types
    if (isAssignable(typeOracle, returnType, Boolean.class)) {
      sw.print("(Z)(");

    } else if (isAssignable(typeOracle, returnType, Byte.class)) {
      sw.print("(B)(");

    } else if (isAssignable(typeOracle, returnType, Character.class)) {
      sw.print("(C)(");

    } else if (isAssignable(typeOracle, returnType, Double.class)) {
      sw.print("(D)(");

    } else if (isAssignable(typeOracle, returnType, Float.class)) {
      sw.print("(F)(");

    } else if (isAssignable(typeOracle, returnType, Integer.class)) {
      sw.print("(I)(");

    } else if (isAssignable(typeOracle, returnType, Long.class)) {
      sw.print("(J)(");

    } else if (isAssignable(typeOracle, returnType, Short.class)) {
      sw.print("(S)(");

    } else {
      logger.log(TreeLogger.ERROR, "Unknown boxed type "
          + returnType.getQualifiedSourceName(), null);
      throw new UnableToCompleteException();
    }

    sw.print(context.parameterName);
View Full Code Here

  }

  protected void writeConstructor(FragmentGeneratorContext context,
      JMethod constructor) throws UnableToCompleteException {

    TreeLogger logger = context.parentLogger.branch(TreeLogger.DEBUG,
        "Writing constructor " + constructor.getName(), null);
    SourceWriter sw = context.sw;

    JParameter[] parameters = constructor.getParameters();
    if (parameters == null) {
      parameters = new JParameter[0];
    }

    // Method declaration
    sw.print("public native ");
    sw.print(constructor.getReturnType().getQualifiedSourceName());
    sw.print(" ");
    sw.print(constructor.getName());
    sw.print("(");
    for (int i = 0; i < parameters.length; i++) {
      JType returnType = parameters[i].getType();
      JParameterizedType pType = returnType.isParameterized();

      if (pType != null) {
        sw.print(pType.getRawType().getQualifiedSourceName());
      } else {
        sw.print(returnType.getQualifiedSourceName());
      }

      sw.print(" ");
      sw.print(parameters[i].getName());

      if (i < parameters.length - 1) {
        sw.print(", ");
      }
    }
    sw.print(")");
    sw.println(" /*-{");
    sw.indent();

    // The return type of the function we're importing.
    JType returnType = constructor.getReturnType();

    sw.print("var jsReturn = ");

    // If the imported method is acting as an invocation of a JavaScript
    // constructor, use the new Foo() syntax, otherwise treat is an an
    // invocation on a field on the underlying JSO.
    sw.print("new ");
    Constructor constructorAnnotation = hasTag(logger, constructor,
        Constructor.class);
    sw.print(constructorAnnotation.value());

    // Write the invocation's parameter list
    sw.print("(");
    for (int i = getImportOffset(); i < parameters.length; i++) {
      // Create a sub-context to generate the wrap/unwrap logic
      JType subType = parameters[i].getType();
      FragmentGeneratorContext subParams = new FragmentGeneratorContext(context);
      subParams.returnType = subType;
      subParams.parameterName = parameters[i].getName();

      FragmentGenerator fragmentGenerator = context.fragmentGeneratorOracle.findFragmentGenerator(
          logger, context.typeOracle, subType);
      if (fragmentGenerator == null) {
        logger.log(TreeLogger.ERROR, "No fragment generator for "
            + returnType.getQualifiedSourceName(), null);
        throw new UnableToCompleteException();
      }

      fragmentGenerator.toJS(subParams);
View Full Code Here

   * return the field value, without having to check it for an undefined value.
   */
  protected void writeEmptyFieldInitializers(FragmentGeneratorContext context)
      throws UnableToCompleteException {
    SourceWriter sw = context.sw;
    TreeLogger logger = context.parentLogger.branch(TreeLogger.DEBUG,
        "Writing field initializers", null);

    for (Task task : context.tasks) {
      final String fieldName = task.getFieldName(logger);

View Full Code Here

  }

  protected void writeGetter(FragmentGeneratorContext context, JMethod getter)
      throws UnableToCompleteException {

    TreeLogger logger = context.parentLogger.branch(TreeLogger.DEBUG,
        "Writing getter " + getter.getName(), null);
    TypeOracle typeOracle = context.typeOracle;
    SourceWriter sw = context.sw;

    final JType returnType = getter.getReturnType();
View Full Code Here

  }

  protected void writeImported(FragmentGeneratorContext context,
      JMethod imported) throws UnableToCompleteException {

    TreeLogger logger = context.parentLogger.branch(TreeLogger.DEBUG,
        "Writing import " + imported.getName(), null);
    SourceWriter sw = context.sw;

    // Simplifies the rest of writeImported
    JParameter[] parameters = imported.getParameters();
    if (parameters == null) {
      parameters = new JParameter[0];
    }

    // Method declaration
    sw.print("public native ");
    sw.print(imported.getReturnType().getQualifiedSourceName());
    sw.print(" ");
    sw.print(imported.getName());
    sw.print("(");
    for (int i = 0; i < parameters.length; i++) {
      JType returnType = parameters[i].getType();
      JParameterizedType pType = returnType.isParameterized();

      if (pType != null) {
        sw.print(pType.getRawType().getQualifiedSourceName());
      } else {
        sw.print(returnType.getQualifiedSourceName());
      }

      sw.print(" ");
      sw.print(parameters[i].getName());

      if (i < parameters.length - 1) {
        sw.print(", ");
      }
    }
    sw.print(")");
    sw.println(" /*-{");
    sw.indent();

    // The return type of the function we're importing.
    final JType returnType = imported.getReturnType();

    // Don't bother recording a return value for void invocations.
    if (!JPrimitiveType.VOID.equals(returnType.isPrimitive())) {
      sw.print("var jsReturn = ");
    }

    sw.print(context.objRef);
    sw.print(".");
    sw.print(context.fieldName);

    // Write the invocation's parameter list
    sw.print("(");
    for (int i = getImportOffset(); i < parameters.length; i++) {
      // Create a sub-context to generate the wrap/unwrap logic
      JType subType = parameters[i].getType();
      FragmentGeneratorContext subParams = new FragmentGeneratorContext(context);
      subParams.returnType = subType;
      subParams.parameterName = parameters[i].getName();

      FragmentGenerator fragmentGenerator = context.fragmentGeneratorOracle.findFragmentGenerator(
          logger, context.typeOracle, subType);
      if (fragmentGenerator == null) {
        logger.log(TreeLogger.ERROR, "No fragment generator for "
            + returnType.getQualifiedSourceName(), null);
        throw new UnableToCompleteException();
      }

      fragmentGenerator.toJS(subParams);
View Full Code Here

  }

  protected void writeMethodBindings(FragmentGeneratorContext context)
      throws UnableToCompleteException {
    SourceWriter sw = context.sw;
    TreeLogger logger = context.parentLogger.branch(TreeLogger.DEBUG,
        "Writing method bindings initializers", null);

    for (Task task : context.tasks) {
      final String fieldName = task.getFieldName(logger);
View Full Code Here

   * Write the field, getter, and setter for the properties we know about. Also
   * write BusObjectImpl methods for Map-style access.
   */
  protected void writeMethods(FragmentGeneratorContext context,
      Map<String, Task> propertyAccessors) throws UnableToCompleteException {
    TreeLogger logger = context.parentLogger.branch(TreeLogger.DEBUG,
        "Writing methods", null);

    for (Task task : propertyAccessors.values()) {
      context.fieldName = task.getFieldName(logger);
      writeSingleTask(context, task);
View Full Code Here

  }

  protected void writeSetter(FragmentGeneratorContext context, JMethod setter)
      throws UnableToCompleteException {

    TreeLogger logger = context.parentLogger.branch(TreeLogger.DEBUG,
        "Writing setter " + setter.getName(), null);
    TypeOracle typeOracle = context.typeOracle;
    SourceWriter sw = context.sw;

    JType parameterType = context.returnType;
View Full Code Here

    sw.println("}-*/;");
  }

  protected void writeSingleTask(FragmentGeneratorContext context, Task task)
      throws UnableToCompleteException {
    TreeLogger logger = context.parentLogger.branch(TreeLogger.DEBUG,
        "Writing Task " + task.getFieldName(context.parentLogger), null);

    context = new FragmentGeneratorContext(context);
    context.parentLogger = logger;

    logger.log(TreeLogger.DEBUG, "Implementing task " + context.fieldName, null);

    if (task.getter != null) {
      context.returnType = task.getter.getReturnType();
      context.parameterName = context.objRef + "." + context.fieldName;
      writeGetter(context, task.getter);
    }

    if (task.imported != null) {
      context.returnType = task.imported.getReturnType();
      writeImported(context, task.imported);
    }

    if (task.setter != null) {
      if (context.readOnly) {
        logger.log(TreeLogger.ERROR,
            "Unable to write property setter on read-only wrapper.", null);
        throw new UnableToCompleteException();
      }

      JParameter parameter = getSetterParameter(task.setter);
View Full Code Here

TOP

Related Classes of com.google.gwt.core.ext.TreeLogger$HelpInfo

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.