Examples of JMethodBody


Examples of com.google.gwt.dev.jjs.ast.JMethodBody

      }
      JField mapField = program.createField(null, "enum$map".toCharArray(),
          type, map.getType(), true, Disposition.FINAL);

      // Initialize in clinit.
      JMethodBody clinitBody = (JMethodBody) type.methods.get(0).getBody();
      JExpressionStatement assignment = program.createAssignmentStmt(null,
          createVariableRef(null, mapField), map);
      clinitBody.getStatements().add(assignment);
      return mapField;
    }
View Full Code Here

Examples of com.google.gwt.dev.jjs.ast.JMethodBody

      return it;
    }

    private void implementMethod(JMethod method, JExpression returnValue) {
      assert method != null;
      JMethodBody body = (JMethodBody) method.getBody();
      List<JStatement> statements = body.getStatements();

      SourceInfo info;
      if (statements.size() > 0) {
        info = statements.get(0).getSourceInfo();
      } else {
View Full Code Here

Examples of com.google.gwt.dev.jjs.ast.JMethodBody

      }

      boolean possibleToInline = false;

      if (method.isStatic() && !method.isNative()) {
        JMethodBody body = (JMethodBody) method.getBody();
        List<JStatement> stmts = body.getStatements();

        if (method.getEnclosingType() != null
            && method.getEnclosingType().methods.get(0) == method
            && !stmts.isEmpty()) {
          // clinit() calls cannot be inlined unless they are empty
View Full Code Here

Examples of com.google.gwt.dev.jjs.ast.JMethodBody

    private void generateClassLiterals(JsVars vars) {
      /*
       * Must execute in clinit statement order, NOT field order, so that back
       * refs to super classes are preserved.
       */
      JMethodBody clinitBody = (JMethodBody) program.getTypeClassLiteralHolder().methods.get(
          0).getBody();
      for (JStatement stmt : clinitBody.getStatements()) {
        if (stmt instanceof JDeclarationStatement) {
          generateClassLiteral((JDeclarationStatement) stmt, vars);
        }
      }
    }
View Full Code Here

Examples of com.google.gwt.dev.jjs.ast.JMethodBody

      // Move the body of the instance method to the static method
      JAbstractMethodBody movedBody = x.getBody();
      newMethod.setBody(movedBody);

      // Create a new body for the instance method that delegates to the static
      JMethodBody newBody = new JMethodBody(program, sourceInfo);
      x.setBody(newBody);
      JMethodCall newCall = new JMethodCall(program, sourceInfo, null,
          newMethod);
      newCall.getArgs().add(program.getExprThisRef(sourceInfo, enclosingType));
      for (int i = 0; i < x.params.size(); ++i) {
        JParameter param = x.params.get(i);
        newCall.getArgs().add(new JParameterRef(program, sourceInfo, param));
      }
      JStatement statement;
      if (returnType == program.getTypeVoid()) {
        statement = newCall.makeStatement();
      } else {
        statement = new JReturnStatement(program, sourceInfo, newCall);
      }
      newBody.getStatements().add(statement);

      /*
       * Rewrite the method body. Update all thisRefs to paramRefs. Update
       * paramRefs and localRefs to target the params/locals in the new method.
       */
 
View Full Code Here

Examples of com.google.gwt.dev.jjs.ast.JMethodBody

      newline();
    }
    for (JMethod it : x.getMethods()) {
      if (JProgram.isClinit(it)) {
        // Suppress empty clinit.
        JMethodBody body = (JMethodBody) it.getBody();
        if (body.getBlock().getStatements().isEmpty()) {
          continue;
        }
      }
      accept(it);
      newline();
View Full Code Here

Examples of com.google.gwt.dev.jjs.ast.JMethodBody

      // Move the body of the instance method to the static method
      JAbstractMethodBody movedBody = x.getBody();
      newMethod.setBody(movedBody);

      JMethodBody newBody = new JMethodBody(sourceInfo);
      x.setBody(newBody);
      JMethodCall newCall = new JMethodCall(sourceInfo, null, newMethod);
      newCall.addArg(new JThisRef(sourceInfo, enclosingType));
      for (int i = 0; i < x.getParams().size(); ++i) {
        JParameter param = x.getParams().get(i);
        newCall.addArg(new JParameterRef(sourceInfo, param));
      }
      JStatement statement;
      if (returnType == program.getTypeVoid()) {
        statement = newCall.makeStatement();
      } else {
        statement = new JReturnStatement(sourceInfo, newCall);
      }
      newBody.getBlock().addStmt(statement);

      /*
       * Rewrite the method body. Update all thisRefs to paramRefs. Update
       * paramRefs and localRefs to target the params/locals in the new method.
       */
 
View Full Code Here

Examples of com.google.gwt.dev.jjs.ast.JMethodBody

      newline();
    }
    for (JMethod method : x.getMethods()) {
      if (JProgram.isClinit(method)) {
        // Suppress empty clinit.
        JMethodBody body = (JMethodBody) method.getBody();
        if (body.getBlock().getStatements().isEmpty()) {
          continue;
        }
      }
      accept(method);
      newline();
View Full Code Here

Examples of com.google.gwt.dev.jjs.ast.JMethodBody

      newline();
    }
    for (JMethod method : x.getMethods()) {
      if (JProgram.isClinit(method)) {
        // Suppress empty clinit.
        JMethodBody body = (JMethodBody) method.getBody();
        if (body.getBlock().getStatements().isEmpty()) {
          continue;
        }
      }
      accept(method);
      newline();
View Full Code Here

Examples of com.google.gwt.dev.jjs.ast.JMethodBody

    info = info.makeChild(SourceOrigin.UNKNOWN);
    // c_g_g_d_c_i_DOMImpl
    toReturn =
        new JMethod(info, requestType.replace("_", "_1").replace('.', '_'), holderType, program
            .getTypeJavaLangObject().getNonNull(), false, true, true, AccessModifier.PUBLIC);
    toReturn.setBody(new JMethodBody(info));
    holderType.addMethod(toReturn);
    toReturn.freezeParamTypes();
    info.addCorrelation(info.getCorrelator().by(toReturn));
    rebindMethods.put(requestType, toReturn);

    // Used in the return statement at the end
    JExpression mostUsedExpression = null;

    JBlock switchBody = new JBlock(info);
    for (int i = 0, j = resultTypes.size(); i < j; i++) {
      String resultType = resultTypes.get(i);
      JExpression instantiation = instantiationExpressions.get(i);

      List<Integer> permutations = resultsToPermutations.get(resultType);
      if (permutations == null) {
        // This rebind result is unused in this permutation
        continue;
      } else if (resultType.equals(mostUsed)) {
        // Save off the fallback expression and go onto the next type
        mostUsedExpression = instantiation;
        continue;
      }

      for (int permutationId : permutations) {
        // case 33:
        switchBody.addStmt(new JCaseStatement(info, program.getLiteralInt(permutationId)));
      }

      // return new FooImpl();
      JReturnStatement ret = new JReturnStatement(info, instantiation);
      switchBody.addStmt(ret);
    }

    assert switchBody.getStatements().size() > 0 : "No case statement emitted "
        + "for supposedly soft-rebind type " + requestType;

    // switch (CollapsedPropertyHolder.getPermutationId()) { ... }
    JSwitchStatement sw =
        new JSwitchStatement(info, new JMethodCall(info, null, permutationIdMethod), switchBody);

    // return new FallbackImpl(); at the very end.
    assert mostUsedExpression != null : "No most-used expression";
    JReturnStatement fallbackReturn = new JReturnStatement(info, mostUsedExpression);

    JMethodBody body = (JMethodBody) toReturn.getBody();
    body.getBlock().addStmt(sw);
    body.getBlock().addStmt(fallbackReturn);

    return toReturn;
  }
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.