Package com.google.gwt.dev.jjs.ast

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


      // Done
      return synthetic;
    }

    private JMethodBody findEnclosingMethod(BlockScope scope) {
      JMethod method;
      MethodScope methodScope = scope.methodScope();
      if (methodScope.isInsideInitializer()) {
        JDeclaredType enclosingType = (JDeclaredType) typeMap.get(scope.classScope().referenceContext.binding);
        if (methodScope.isStatic) {
          // clinit
          method = enclosingType.getMethods().get(0);
        } else {
          // init
          assert (enclosingType instanceof JClassType);
          method = enclosingType.getMethods().get(1);
        }
      } else {
        AbstractMethodDeclaration referenceMethod = methodScope.referenceMethod();
        method = (JMethod) typeMap.get(referenceMethod.binding);
      }
      assert !method.isNative() && !method.isAbstract();
      return (JMethodBody) method.getBody();
    }
View Full Code Here


      try {
        // Create an override for getClass().
        if (type instanceof JClassType
            && type != program.getTypeJavaLangObject()
            && type != program.getIndexedType("Array")) {
          JMethod getClassMethod = program.createMethod(
              type.getSourceInfo().makeChild(BuildDeclMapVisitor.class,
                  "Synthetic getClass()"), "getClass".toCharArray(), type,
              program.getTypeJavaLangClass(), false, false, false, false, false);
          assert (type.getMethods().get(2) == getClassMethod);
          getClassMethod.freezeParamTypes();
        }

        if (binding.isNestedType() && !binding.isStatic()) {
          // add synthetic fields for outer this and locals
          assert (type instanceof JClassType);
View Full Code Here

    private void processEnumType(SourceTypeBinding binding, JEnumType type) {
      // Visit the synthetic values() and valueOf() methods.
      for (MethodBinding methodBinding : binding.methods()) {
        if (methodBinding instanceof SyntheticMethodBinding) {
          JMethod newMethod = processMethodBinding(methodBinding, type,
              type.getSourceInfo());
          TypeBinding[] parameters = methodBinding.parameters;
          if (parameters.length == 0) {
            assert newMethod.getName().equals("values");
          } else if (parameters.length == 1) {
            assert newMethod.getName().equals("valueOf");
            assert typeMap.get(parameters[0]) == program.getTypeJavaLangString();
            program.createParameter(newMethod.getSourceInfo().makeChild(
                BuildDeclMapVisitor.class, "name parameter"),
                "name".toCharArray(), program.getTypeJavaLangString(), true,
                false, newMethod);
          } else {
            assert false;
          }
          newMethod.freezeParamTypes();
        }
      }
    }
View Full Code Here

    }

    private JMethod processMethodBinding(MethodBinding b,
        JDeclaredType enclosingType, SourceInfo info) {
      JType returnType = (JType) typeMap.get(b.returnType);
      JMethod newMethod = program.createMethod(info, b.selector, enclosingType,
          returnType, b.isAbstract(), b.isStatic(), b.isFinal(), b.isPrivate(),
          b.isNative());

      typeMap.put(b, newMethod);
      return newMethod;
View Full Code Here

    if (toBox.getType() != primitiveType) {
      toBox = new JCastOperation(toBox.getSourceInfo(), primitiveType, toBox);
    }

    // Find the correct valueOf() method.
    JMethod valueOfMethod = null;
    for (JMethod method : wrapperType.getMethods()) {
      if ("valueOf".equals(method.getName())) {
        if (method.getParams().size() == 1) {
          JParameter param = method.getParams().get(0);
          if (param.getType() == primitiveType) {
            // Found it.
            valueOfMethod = method;
            break;
          }
        }
      }
    }

    if (valueOfMethod == null || !valueOfMethod.isStatic()
        || valueOfMethod.getType() != wrapperType) {
      throw new InternalCompilerException(toBox,
          "Expected to find a method on '" + wrapperType.getName()
              + "' whose signature matches 'public static "
              + wrapperType.getName() + " valueOf(" + primitiveType.getName()
              + ")'", null);
View Full Code Here

    JClassType jsoType = program.getJavaScriptObject();
    SourceInfo sourceInfo = jsoType.getSourceInfo();

    // Create the new method.
    String name = objectMethod.getName() + "__devirtual$";
    JMethod newMethod = program.createMethod(sourceInfo.makeChild(
        JsoDevirtualizer.class, "Devirtualized method"), name.toCharArray(),
        jsoType, objectMethod.getType(), false, true, true, false, false);

    // Setup parameters.
    JParameter thisParam = program.createParameter(sourceInfo,
        "this$static".toCharArray(), program.getTypeJavaLangObject(), true,
        true, newMethod);
    for (JParameter oldParam : objectMethod.getParams()) {
      program.createParameter(sourceInfo, oldParam.getName().toCharArray(),
          oldParam.getType(), true, false, newMethod);
    }
    newMethod.freezeParamTypes();

    // Build from bottom up.
    JMethodCall condition = new JMethodCall(sourceInfo, null,
        isJavaObjectMethod);
    condition.addArg(new JParameterRef(sourceInfo, thisParam));

    JMethodCall thenValue = new JMethodCall(sourceInfo, new JParameterRef(
        sourceInfo, thisParam), objectMethod);
    for (JParameter param : newMethod.getParams()) {
      if (param != thisParam) {
        thenValue.addArg(new JParameterRef(sourceInfo, param));
      }
    }

    JMethodCall elseValue = new JMethodCall(sourceInfo, null, jsoImpl);
    for (JParameter param : newMethod.getParams()) {
      elseValue.addArg(new JParameterRef(sourceInfo, param));
    }

    JConditional conditional = new JConditional(sourceInfo, objectMethod.getType(),
        condition, thenValue, elseValue);

    JReturnStatement returnStatement = new JReturnStatement(sourceInfo,
        conditional);
    ((JMethodBody) newMethod.getBody()).getBlock().addStmt(returnStatement);
    return newMethod;
  }
View Full Code Here

    }

    CreateStaticImplsVisitor creator = new CreateStaticImplsVisitor(program);
    for (JMethod method : virtualJsoMethods) {
      // Ensure staticImpls exist for any instance methods.
      JMethod jsoStaticImpl = program.getStaticImpl(method);
      if (jsoStaticImpl == null) {
        creator.accept(method);
        jsoStaticImpl = program.getStaticImpl(method);
        assert (jsoStaticImpl != null);
      }

      // Find the object method this instance method overrides.
      JMethod objectOverride = findObjectOverride(method);
      if (objectOverride != null) {
        JMethod devirtualizer = createDevirtualMethod(objectOverride,
            jsoStaticImpl);
        devirtualMethods.add(devirtualizer);
        objectMethodToJsoMethod.put(objectOverride, devirtualizer);
      }
    }
View Full Code Here

  /**
   * Finds the object method this method overrides.
   */
  private JMethod findObjectOverride(JMethod method) {
    Set<JMethod> overrides = program.typeOracle.getAllRealOverrides(method);
    JMethod objectOverride = null;
    for (JMethod override : overrides) {
      if (override.getEnclosingType() == program.getTypeJavaLangObject()) {
        objectOverride = override;
        break;
      }
View Full Code Here

   */
  private class RewriteVirtualDispatches extends JModVisitor {

    @Override
    public void endVisit(JMethodCall x, Context ctx) {
      JMethod method = x.getTarget();
      JMethod newMethod;
      if (virtualJsoMethods.contains(method)) {
        /*
         * Force a JSO call to be static. Really, this should never be necessary
         * as long as MakeCallsStatic runs. However, we would rather not insist
         * that normalization depends on optimization having been done.
View Full Code Here

       */
      if (clazzBinding.syntheticMethods() != null) {
        for (SyntheticMethodBinding synthmeth : clazzBinding.syntheticMethods()) {
          if (synthmeth.purpose == SyntheticMethodBinding.BridgeMethod
              && !synthmeth.isStatic()) {
            JMethod implmeth = (JMethod) typeMap.get(synthmeth.targetMethod);

            createBridgeMethod(clazz, synthmeth, implmeth);
          }
        }
      }
View Full Code Here

TOP

Related Classes of com.google.gwt.dev.jjs.ast.JMethod

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.