use of org.stjs.generator.javascript.UnaryOperator in project st-js by st-js.
the class SetterUnaryTemplate method doVisit.
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);
return context.js().functionCall(context.js().property(context.js().name("stjs"), "setField"), arguments);
}
return context.js().functionCall(context.js().property(target, "set"), arguments);
}
use of org.stjs.generator.javascript.UnaryOperator in project st-js by st-js.
the class DefaultUnaryTemplate method visit.
@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);
}
Aggregations