Package org.stjs.generator.javascript

Examples of org.stjs.generator.javascript.UnaryOperator


public class DefaultUnaryTemplate<JS> implements WriterContributor<UnaryTree, JS> {

  @Override
  public JS visit(WriterVisitor<JS> visitor, UnaryTree tree, GenerationContext<JS> context) {
    JS operand = visitor.scan(tree.getExpression(), context);
    UnaryOperator op = UnaryOperator.valueOf(tree.getKind());
    assert op != null : "Unknow operator:" + tree.getKind();

    return context.js().unary(op, operand);
  }
View Full Code Here


    }
    return null;
  }

  protected JS doVisit(WriterVisitor<JS> visitor, UnaryTree tree, GenerationContext<JS> context, boolean global) {
    UnaryOperator op = UnaryOperator.valueOf(tree.getKind());
    assert op != null : "Unknow operator:" + tree.getKind();

    BinaryOperator binaryOp = getBinaryOperator(op);

    if (binaryOp == null) {
      return super.visit(visitor, tree, context);
    }

    JS operand = visitor.scan(tree.getExpression(), context);
    TreeWrapper<ExpressionTree, JS> twOperand = context.getCurrentWrapper().child(tree.getExpression());
    JS target = SetterAssignmentTemplate.getTarget(visitor, twOperand, context);
    JS field = SetterAssignmentTemplate.getField(twOperand, context);

    JS value = context.js().binary(binaryOp, Arrays.asList(operand, context.js().number(1)));

    List<JS> arguments = new ArrayList<JS>();
    arguments.add(field);
    arguments.add(value);
    if (op.isPostfix()) {
      arguments.add(context.js().keyword(Keyword.TRUE));
    }

    if (global) {
      arguments.add(0, target);
View Full Code Here

TOP

Related Classes of org.stjs.generator.javascript.UnaryOperator

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.