1/*
2 * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
3 * Copyright (C) 2011, 2013-2016 The JavaParser Team.
4 *
5 * This file is part of JavaParser.
6 *
7 * JavaParser can be used either under the terms of
8 * a) the GNU Lesser General Public License as published by
9 *     the Free Software Foundation, either version 3 of the License, or
10 *     (at your option) any later version.
11 * b) the terms of the Apache License
12 *
13 * You should have received a copy of both licenses in LICENCE.LGPL and
14 * LICENCE.APACHE. Please refer to those files for details.
15 *
16 * JavaParser is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 * GNU Lesser General Public License for more details.
20 */
21
22package com.github.javaparser.ast.expr;
23
24import com.github.javaparser.Range;
25import com.github.javaparser.ast.visitor.GenericVisitor;
26import com.github.javaparser.ast.visitor.VoidVisitor;
27
28/**
29 * @author Julio Vilmar Gesser
30 */
31public final class AssignExpr extends Expression {
32
33    public enum Operator {
34        assign, // =
35        plus, // +=
36        minus, // -=
37        star, // *=
38        slash, // /=
39        and, // &=
40        or, // |=
41        xor, // ^=
42        rem, // %=
43        lShift, // <<=
44        rSignedShift, // >>=
45        rUnsignedShift, // >>>=
46    }
47
48    private Expression target;
49
50    private Expression value;
51
52    private Operator op;
53
54    public AssignExpr() {
55    }
56
57    public AssignExpr(Expression target, Expression value, Operator op) {
58        setTarget(target);
59        setValue(value);
60        setOperator(op);
61    }
62
63    public AssignExpr(Range range, Expression target, Expression value, Operator op) {
64        super(range);
65        setTarget(target);
66        setValue(value);
67        setOperator(op);
68    }
69
70    @Override
71    public <R, A> R accept(GenericVisitor<R, A> v, A arg) {
72        return v.visit(this, arg);
73    }
74
75    @Override
76    public <A> void accept(VoidVisitor<A> v, A arg) {
77        v.visit(this, arg);
78    }
79
80    public Operator getOperator() {
81        return op;
82    }
83
84    public Expression getTarget() {
85        return target;
86    }
87
88    public Expression getValue() {
89        return value;
90    }
91
92    public AssignExpr setOperator(Operator op) {
93        this.op = op;
94        return this;
95    }
96
97    public AssignExpr setTarget(Expression target) {
98        this.target = target;
99		setAsParentNodeOf(this.target);
100        return this;
101    }
102
103    public AssignExpr setValue(Expression value) {
104        this.value = value;
105		setAsParentNodeOf(this.value);
106        return this;
107    }
108}
109