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

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


          coerceTo = rhsType;
        }
        lhsType = rhsType = coerceTo;
      }

      JExpression newLhs = checkAndReplace(x.getLhs(), lhsType);
      JExpression newRhs = checkAndReplace(x.getRhs(), rhsType);
      if (newLhs != x.getLhs() || newRhs != x.getRhs()) {
        JBinaryOperation binOp = new JBinaryOperation(x.getSourceInfo(),
            resultType, op, newLhs, newRhs);
        ctx.replaceMe(binOp);
      }
View Full Code Here


      }
    }

    @Override
    public void endVisit(JConditional x, Context ctx) {
      JExpression newThen = checkAndReplace(x.getThenExpr(), x.getType());
      JExpression newElse = checkAndReplace(x.getElseExpr(), x.getType());
      if (newThen != x.getThenExpr() || newElse != x.getElseExpr()) {
        JConditional newCond = new JConditional(x.getSourceInfo(), x.getType(),
            x.getIfTest(), newThen, newElse);
        ctx.replaceMe(newCond);
      }
View Full Code Here

      }
    }

    @Override
    public void endVisit(JDeclarationStatement x, Context ctx) {
      JExpression init = x.getInitializer();
      if (init != null) {
        init = checkAndReplace(init, x.getVariableRef().getType());
        if (init != x.getInitializer()) {
          JDeclarationStatement newStmt = new JDeclarationStatement(x.getSourceInfo(),
              x.getVariableRef(), init);
View Full Code Here

    @Override
    public void endVisit(JMethodCall x, Context ctx) {
      List<JParameter> params = x.getTarget().getParams();
      for (int i = 0; i < params.size(); ++i) {
        JParameter param = params.get(i);
        JExpression arg = x.getArgs().get(i);
        JExpression newArg = checkAndReplace(arg, param.getType());
        if (arg != newArg) {
          x.setArg(i, newArg);
          this.didChange = true;
        }
      }
View Full Code Here

    public void endVisit(JNewArray x, Context ctx) {
      JType elementType = x.getArrayType().getElementType();
      List<JExpression> initializers = x.initializers;
      if (initializers != null) {
        for (int i = 0; i < initializers.size(); ++i) {
          JExpression initializer = initializers.get(i);
          JExpression newInitializer = checkAndReplace(initializer, elementType);
          if (initializer != newInitializer) {
            initializers.set(i, newInitializer);
            this.didChange = true;
          }
        }
View Full Code Here

      }
    }

    @Override
    public void endVisit(JReturnStatement x, Context ctx) {
      JExpression expr = x.getExpr();
      if (expr != null) {
        JExpression newExpr = checkAndReplace(expr, currentMethod.getType());
        if (expr != newExpr) {
          JReturnStatement newStmt = new JReturnStatement(x.getSourceInfo(),
              newExpr);
          ctx.replaceMe(newStmt);
        }
View Full Code Here

            JBinaryOperator.AND, condExpr, thenExpr);
        return binOp;
      }
    } else {
      // e.g. (!cond ? then : else) -> (cond ? else : then)
      JExpression unflipped = maybeUnflipBoolean(condExpr);
      if (unflipped != null) {
        return new JConditional(sourceInfo, type, unflipped, elseExpr, thenExpr);
      }
    }
View Full Code Here

      return condExpr.makeStatement();
    }

    if (!isEmpty(elseStmt)) {
      // if (!cond) foo else bar -> if (cond) bar else foo
      JExpression unflipped = Simplifier.maybeUnflipBoolean(condExpr);
      if (unflipped != null) {
        // Force sub-parts to blocks, otherwise we break else-if chains.
        // TODO: this goes away when we normalize the Java AST properly.
        thenStmt = ensureBlock(thenStmt);
        elseStmt = ensureBlock(elseStmt);
View Full Code Here

    if (thenStmt instanceof JReturnStatement
        && elseStmt instanceof JReturnStatement && currentMethod != null) {
      // Special case
      // if () { return ..; } else { return ..; } =>
      // return ... ? ... : ...;
      JExpression thenExpression = ((JReturnStatement) thenStmt).getExpr();
      JExpression elseExpression = ((JReturnStatement) elseStmt).getExpr();
      if (thenExpression == null || elseExpression == null) {
        // empty returns are not supported.
        return null;
      }

      JConditional conditional = new JConditional(sourceInfo,
          currentMethod.getType(), condExpr, thenExpression, elseExpression);

      JReturnStatement returnStatement = new JReturnStatement(sourceInfo,
          conditional);
      return returnStatement;
    }

    if (elseStmt != null) {
      // if () { } else { } -> ... ? ... : ... ;
      JExpression thenExpression = extractExpression(thenStmt);
      JExpression elseExpression = extractExpression(elseStmt);

      if (thenExpression != null && elseExpression != null) {
        JConditional conditional = new JConditional(sourceInfo,
            JPrimitiveType.VOID, condExpr, thenExpression, elseExpression);

        return conditional.makeStatement();
      }
    } else {
      // if () { } -> ... && ...;
      JExpression thenExpression = extractExpression(thenStmt);

      if (thenExpression != null) {
        JBinaryOperator binaryOperator = JBinaryOperator.AND;

        JExpression unflipExpression = maybeUnflipBoolean(condExpr);
        if (unflipExpression != null) {
          condExpr = unflipExpression;
          binaryOperator = JBinaryOperator.OR;
        }
View Full Code Here

      throw new UnableToCompleteException();
    }
    SourceInfo sourceInfo = reboundEntryType.getSourceInfo().makeChild(
        JavaToJavaScriptCompiler.class, "Rebound entry point");

    JExpression qualifier = null;
    if (!entryMethod.isStatic()) {
      qualifier = JGwtCreate.createInstantiationExpression(sourceInfo,
          entryClass);

      if (qualifier == null) {
View Full Code Here

TOP

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

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.