aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/zwobble/couscous/backends/python/ast/PythonIfStatementNode.java
blob: 313f722e7a6d0ec1793908703d0b79880e5f8bb6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package org.zwobble.couscous.backends.python.ast;

import java.util.List;

import org.zwobble.couscous.backends.python.ast.visitors.PythonNodeVisitor;

public class PythonIfStatementNode implements PythonStatementNode {
    public static PythonIfStatementNode pythonIfStatement(
            PythonExpressionNode condition,
            List<PythonStatementNode> trueBranch,
            List<PythonStatementNode> falseBranch) {
        return new PythonIfStatementNode(
            condition,
            new PythonBlock(trueBranch),
            new PythonBlock(falseBranch));
    }

    private final PythonExpressionNode condition;
    private final PythonBlock trueBranch;
    private final PythonBlock falseBranch;

    private PythonIfStatementNode(
            PythonExpressionNode condition,
            PythonBlock trueBranch,
            PythonBlock falseBranch) {
        this.condition = condition;
        this.trueBranch = trueBranch;
        this.falseBranch = falseBranch;
    }
    
    public PythonExpressionNode getCondition() {
        return condition;
    }
    
    public PythonBlock getTrueBranch() {
        return trueBranch;
    }
    
    public PythonBlock getFalseBranch() {
        return falseBranch;
    }

    @Override
    public String toString() {
        return "PythonIfStatementNode(condition=" + condition + ", trueBranch="
               + trueBranch + ", falseBranch=" + falseBranch + ")";
    }

    @Override
    public void accept(PythonNodeVisitor visitor) {
        visitor.visit(this);
    }
}