Examples of JCastOperation


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

      if (triviallyTrue) {
        // remove the cast operation
        ctx.replaceMe(x.getExpr());
      } else if (triviallyFalse) {
        // replace with a magic NULL cast
        JCastOperation newOp = new JCastOperation(program, x.getSourceInfo(),
            program.getTypeNull(), x.getExpr());
        ctx.replaceMe(newOp);
      } else {
        // If possible, try to use a narrower cast
        JClassType concreteType = getSingleConcreteType(toType);
        if (concreteType != null) {
          JCastOperation newOp = new JCastOperation(program, x.getSourceInfo(),
              concreteType, x.getExpr());
          ctx.replaceMe(newOp);
        }
      }
    }
View Full Code Here

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

    public void endVisit(CastExpression x, BlockScope scope) {
      try {
        SourceInfo info = makeSourceInfo(x);
        JType type = typeMap.get(x.resolvedType);
        JExpression expression = pop(x.expression);
        push(new JCastOperation(info, type, expression));
      } catch (Throwable e) {
        throw translateException(x, e);
      }
    }
View Full Code Here

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

      assert valueOfMethod != null;

      // Add a cast to the correct primitive type if needed.
      JType targetPrimitiveType = typeMap.get(primitiveType);
      if (original.getType() != targetPrimitiveType) {
        original = new JCastOperation(original.getSourceInfo(), targetPrimitiveType, original);
      }

      JMethod boxMethod = typeMap.get(valueOfMethod);
      JMethodCall call = new JMethodCall(original.getSourceInfo(), null, boxMethod);
      call.addArg(original);
View Full Code Here

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

    private JExpression maybeCast(JType expected, JExpression expression) {
      if (expected != expression.getType()) {
        // Must be a generic; insert a cast operation.
        JReferenceType toType = (JReferenceType) expected;
        return new JCastOperation(expression.getSourceInfo(), toType, expression);
      } else {
        return expression;
      }
    }
View Full Code Here

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

        // wrap with a cast operation of the (boxed) expected type.
        int runtimeTypeId = (implicitConversion & TypeIds.IMPLICIT_CONVERSION_MASK) >> 4;
        TypeBinding runtimeTypeBinding = TypeBinding.wellKnownType(scope, runtimeTypeId);
        ReferenceBinding boxType = (ReferenceBinding) scope.boxing(runtimeTypeBinding);
        original =
            new JCastOperation(original.getSourceInfo(), typeMap.get(boxType), original);
        targetBinding = runtimeTypeBinding;
        assert (targetBinding instanceof BaseTypeBinding);
      }

      BaseTypeBinding primitiveType = (BaseTypeBinding) targetBinding;
View Full Code Here

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

          // Synthesize ((EntryPoint)GWT.create(FooEntryPoint.class)).onModuleLoad();
          JClassLiteral entryPointTypeClassLiteral =
              new JClassLiteral(origin, specificEntryPointType);
          JMethodCall createInstanceCall =
              new JMethodCall(origin, null, gwtCreateMethod, entryPointTypeClassLiteral);
          JCastOperation castToEntryPoint =
              new JCastOperation(origin, entryPointType, createInstanceCall);
          JMethodCall instanceOnModuleLoadCall =
              new JMethodCall(origin, castToEntryPoint, onModuleLoadMethod);
          initMethodBlock.addStmt(instanceOnModuleLoadCall.makeStatement());
        }
      }
View Full Code Here

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

      if (triviallyTrue) {
        // remove the cast operation
        ctx.replaceMe(x.getExpr());
      } else if (triviallyFalse && toType != program.getTypeNull()) {
        // replace with a placeholder cast to NULL, unless it's already a cast to NULL
        JCastOperation newOp =
            new JCastOperation(x.getSourceInfo(), program.getTypeNull(), x.getExpr());
        ctx.replaceMe(newOp);
      } else {
        // If possible, try to use a narrower cast
        JReferenceType tighterType = getSingleConcreteType(toType);

        if (tighterType != null && tighterType != toType) {
          JCastOperation newOp = new JCastOperation(x.getSourceInfo(), tighterType, x.getExpr());
          ctx.replaceMe(newOp);
        }
      }
    }
View Full Code Here

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

    // no simplification made
    if (original != null) {
      return original;
    }
    return new JCastOperation(info, type, exp);
  }
View Full Code Here

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

   * <code>primitiveType</code>, then a cast may be necessary.
   */
  public JExpression box(JExpression toBox, JPrimitiveType primitiveType) {
    // Add a cast to toBox if need be
    if (toBox.getType() != primitiveType) {
      toBox = new JCastOperation(toBox.getSourceInfo(), primitiveType, toBox);
    }
    JMethod method = boxMethods.get(primitiveType);
    assert method != null;
    JMethodCall call = new JMethodCall(toBox.getSourceInfo(), null, method);
    call.addArg(toBox);
View Full Code Here

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

     * a new one and do a replacement. Use remap() instead of modRemap() since
     * the ctx.replaceMe() will record a change.
     */
    JType remapCastType = remap(x.getCastType());
    if (remapCastType != x.getCastType()) {
      JCastOperation newX = new JCastOperation(x.getSourceInfo(), remapCastType, x.getExpr());
      ctx.replaceMe(newX);
    }
  }
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.