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

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


        }
      }
    }

    private StringStatus getStringStatus(JReferenceType type) {
      JClassType stringType = program.getTypeJavaLangString();
      if (type == program.getTypeNull()) {
        return StringStatus.NULL;
      } else if (program.typeOracle.canTriviallyCast(type, stringType)) {
        return StringStatus.STRING;
      } else if (program.typeOracle.canTheoreticallyCast(type, stringType)) {
View Full Code Here


    }

    @Override
    public boolean visit(JMethod x, Context ctx) {
      // Let's do it!
      JClassType enclosingType = (JClassType) x.getEnclosingType();
      JType returnType = x.getType();
      SourceInfo sourceInfo = x.getSourceInfo();
      int myIndexInClass = enclosingType.getMethods().indexOf(x);
      assert (myIndexInClass > 0);

      // Create the new static method
      String newName = "$" + x.getName();

      /*
       * Don't use the JProgram helper because it auto-adds the new method to
       * its enclosing class.
       */
      JMethod newMethod = new JMethod(sourceInfo.makeChild(
          CreateStaticImplsVisitor.class, "Devirtualized function"), newName,
          enclosingType, returnType, false, true, true, x.isPrivate());

      // Setup parameters; map from the old params to the new params
      JParameter thisParam = JParameter.create(sourceInfo.makeChild(
          CreateStaticImplsVisitor.class, "Instance parameter"), "this$static",
          enclosingType, true, true, newMethod);
      Map<JParameter, JParameter> varMap = new IdentityHashMap<JParameter, JParameter>();
      for (int i = 0; i < x.getParams().size(); ++i) {
        JParameter oldVar = x.getParams().get(i);
        JParameter newVar = JParameter.create(oldVar.getSourceInfo(),
            oldVar.getName(), oldVar.getType(), oldVar.isFinal(), false,
            newMethod);
        varMap.put(oldVar, newVar);
      }

      // Set the new original param types based on the old original param types
      List<JType> originalParamTypes = new ArrayList<JType>();
      originalParamTypes.add(enclosingType);
      originalParamTypes.addAll(x.getOriginalParamTypes());
      newMethod.setOriginalTypes(x.getOriginalReturnType(), originalParamTypes);

      // 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
      SourceInfo delegateCallSourceInfo = sourceInfo.makeChild(
          CreateStaticImplsVisitor.class, "Degelgating to devirtualized method");
      JMethodBody newBody = new JMethodBody(delegateCallSourceInfo);
      x.setBody(newBody);
      JMethodCall newCall = new JMethodCall(delegateCallSourceInfo, null,
          newMethod);
      newCall.addArg(new JThisRef(delegateCallSourceInfo, enclosingType));
      for (int i = 0; i < x.getParams().size(); ++i) {
        JParameter param = x.getParams().get(i);
        newCall.addArg(new JParameterRef(delegateCallSourceInfo, param));
      }
      JStatement statement;
      if (returnType == program.getTypeVoid()) {
        statement = newCall.makeStatement();
      } else {
        statement = new JReturnStatement(delegateCallSourceInfo, 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.
       */
      if (newMethod.isNative()) {
        // For natives, we also need to create the JsParameter for this$static,
        // because the jsFunc already has parameters.
        // TODO: Do we really need to do that in BuildTypeMap?
        JsFunction jsFunc = ((JsniMethodBody) movedBody).getFunc();
        JsName paramName = jsFunc.getScope().declareName("this$static");
        jsFunc.getParameters().add(
            0,
            new JsParameter(sourceInfo.makeChild(
                CreateStaticImplsVisitor.class, "Static accessor"), paramName));
        RewriteJsniMethodBody rewriter = new RewriteJsniMethodBody(paramName);
        // Accept the body to avoid the recursion blocker.
        rewriter.accept(jsFunc.getBody());
      } else {
        RewriteMethodBody rewriter = new RewriteMethodBody(thisParam, varMap);
        rewriter.accept(movedBody);
      }

      // Add the new method as a static impl of the old method
      program.putStaticImpl(x, newMethod);
      enclosingType.getMethods().add(myIndexInClass + 1, newMethod);
      return false;
    }
View Full Code Here

    /**
     * Handle special rescues needed implicitly to support concat.
     */
    private void rescueByConcat(JType type) {
      JClassType stringType = program.getTypeJavaLangString();
      JPrimitiveType charType = program.getTypePrimitiveChar();
      if (type instanceof JReferenceType && type != stringType) {
        /*
         * Any reference types (except String, which works by default) that take
         * part in a concat must rescue java.lang.Object.toString().
View Full Code Here

      List/* <JsFunction> */jsFuncs = popList(x.methods.size()); // methods
      List/* <JsStatement> */jsFields = popList(x.fields.size()); // fields

      if (typeOracle.hasDirectClinit(x)) {
        // see if there's a super class we need to chain to
        JClassType superType = x.extnds;
        while (superType != null && !typeOracle.hasDirectClinit(superType)) {
          superType = superType.extnds;
        }
        handleClinit((JsFunction) jsFuncs.get(0), superType);
      } else {
View Full Code Here

      if (!toBeMadeStatic.contains(x)) {
        return false;
      }

      // Let's do it!
      JClassType enclosingType = (JClassType) x.getEnclosingType();
      JType oldReturnType = x.getType();

      // Create the new static method
      String newName = "$" + x.getName();
View Full Code Here

     * for details.
     */
    public boolean visit(ConstructorDeclaration ctorDecl, ClassScope scope) {
      try {
        MethodBinding b = ctorDecl.binding;
        JClassType enclosingType = (JClassType) typeMap.get(scope.enclosingSourceType());
        String name = enclosingType.getShortName();
        SourceInfo info = makeSourceInfo(ctorDecl);
        JMethod newMethod = program.createMethod(info, name.toCharArray(),
            enclosingType, enclosingType, false, false, true, b.isPrivate(),
            false);
        mapThrownExceptions(newMethod, ctorDecl);
View Full Code Here

    private void mapThrownExceptions(JMethod method, AbstractMethodDeclaration x) {
      MethodBinding b = x.binding;
      if (b.thrownExceptions != null) {
        for (int i = 0; i < b.thrownExceptions.length; ++i) {
          ReferenceBinding refBinding = b.thrownExceptions[i];
          JClassType thrownException = (JClassType) typeMap.get(refBinding);
          method.thrownExceptions.add(thrownException);
        }
      }
    }
View Full Code Here

        }

        ReferenceBinding superClassBinding = binding.superclass();
        if (superClassBinding != null) {
          assert (binding.superclass().isClass());
          JClassType superClass = (JClassType) typeMap.get(superClassBinding);
          type.extnds = superClass;
        }

        ReferenceBinding[] superInterfaces = binding.superInterfaces();
        for (int i = 0; i < superInterfaces.length; ++i) {
View Full Code Here

          logger.log(TreeLogger.ERROR, "Module entry point class '"
              + mainClassName + "' must be a class", null);
          throw new UnableToCompleteException();
        }

        JClassType mainClass = (JClassType) referenceType;
        if (mainClass.isAbstract()) {
          logger.log(TreeLogger.ERROR, "Module entry point class '"
              + mainClassName + "' must not be abstract", null);
          throw new UnableToCompleteException();
        }

        mainMethod = findMainMethodRecurse(referenceType);
        if (mainMethod == null) {
          logger.log(TreeLogger.ERROR,
              "Could not find entry method 'onModuleLoad()' method in entry point class '"
                  + mainClassName + "'", null);
          throw new UnableToCompleteException();
        }

        if (mainMethod.isAbstract()) {
          logger.log(TreeLogger.ERROR,
              "Entry method 'onModuleLoad' in entry point class '"
                  + mainClassName + "' must not be abstract", null);
          throw new UnableToCompleteException();
        }

        if (!mainMethod.isStatic()) {
          // Find the appropriate (noArg) constructor
          JMethod noArgCtor = null;
          for (int j = 0; j < mainClass.methods.size(); ++j) {
            JMethod ctor = (JMethod) mainClass.methods.get(j);
            if (ctor.getName().equals(mainClass.getShortName())) {
              if (ctor.params.size() == 0) {
                noArgCtor = ctor;
              }
            }
          }
View Full Code Here

         * initializers.
         */
        boolean hasExplicitThis = (ctorCall != null)
            && !ctorCall.isSuperAccess();

        JClassType enclosingType = (JClassType) ctor.getEnclosingType();

        // Call clinit; $clinit is always in position 0.
        JMethod clinitMethod = (JMethod) enclosingType.methods.get(0);
        JMethodCall clinitCall = new JMethodCall(program, info, null,
            clinitMethod);
View Full Code Here

TOP

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

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.