//Generated by lombok.ast.template.TemplateProcessor. DO NOT EDIT, DO NOT CHECK IN!

package lombok.ast;

public class ForEach extends lombok.ast.AbstractNode implements lombok.ast.Statement {
	private lombok.ast.AbstractNode variable = null;
	private lombok.ast.AbstractNode iterable = null;
	private lombok.ast.AbstractNode statement = null;
	
	public Block upToBlock() {
		if (!(this.getParent() instanceof Block)) return null;
		Block out = (Block)this.getParent();
		if (!out.rawContents().contains(this)) return null;
		return out;
	}
	
	
	public VariableDefinition astVariable() {
		if (!(this.variable instanceof VariableDefinition)) return null;
		return (VariableDefinition) this.variable;
	}
	
	public lombok.ast.ForEach astVariable(VariableDefinition variable) {
		if (variable == null) throw new java.lang.NullPointerException("variable is mandatory");
		return this.rawVariable(variable);
	}
	
	public lombok.ast.Node rawVariable() {
		return this.variable;
	}
	
	public lombok.ast.ForEach rawVariable(lombok.ast.Node variable) {
		if (variable == this.variable) return this;
		if (variable != null) this.adopt((lombok.ast.AbstractNode)variable);
		if (this.variable != null) this.disown(this.variable);
		this.variable = (lombok.ast.AbstractNode)variable;
		return this;
	}
	
	public Expression astIterable() {
		if (!(this.iterable instanceof Expression)) return null;
		return (Expression) this.iterable;
	}
	
	public lombok.ast.ForEach astIterable(Expression iterable) {
		if (iterable == null) throw new java.lang.NullPointerException("iterable is mandatory");
		return this.rawIterable(iterable);
	}
	
	public lombok.ast.Node rawIterable() {
		return this.iterable;
	}
	
	public lombok.ast.ForEach rawIterable(lombok.ast.Node iterable) {
		if (iterable == this.iterable) return this;
		if (iterable != null) this.adopt((lombok.ast.AbstractNode)iterable);
		if (this.iterable != null) this.disown(this.iterable);
		this.iterable = (lombok.ast.AbstractNode)iterable;
		return this;
	}
	
	public Statement astStatement() {
		if (!(this.statement instanceof Statement)) return null;
		return (Statement) this.statement;
	}
	
	public lombok.ast.ForEach astStatement(Statement statement) {
		if (statement == null) throw new java.lang.NullPointerException("statement is mandatory");
		return this.rawStatement(statement);
	}
	
	public lombok.ast.Node rawStatement() {
		return this.statement;
	}
	
	public lombok.ast.ForEach rawStatement(lombok.ast.Node statement) {
		if (statement == this.statement) return this;
		if (statement != null) this.adopt((lombok.ast.AbstractNode)statement);
		if (this.statement != null) this.disown(this.statement);
		this.statement = (lombok.ast.AbstractNode)statement;
		return this;
	}
	
	@java.lang.Override public java.util.List<Node> getChildren() {
		java.util.List<Node> result = new java.util.ArrayList<Node>();
		if (this.variable != null) result.add(this.variable);
		if (this.iterable != null) result.add(this.iterable);
		if (this.statement != null) result.add(this.statement);
		return result;
	}
	
	@java.lang.Override public boolean replaceChild(Node original, Node replacement) throws lombok.ast.AstException {
		if (this.variable == original) {
			this.rawVariable(replacement);
			return true;
		}
		if (this.iterable == original) {
			this.rawIterable(replacement);
			return true;
		}
		if (this.statement == original) {
			this.rawStatement(replacement);
			return true;
		}
		return false;
	}
	
	@java.lang.Override public boolean detach(Node child) {
		if (this.variable == child) {
			this.disown((AbstractNode) child);
			this.variable = null;
			return true;
		}
		if (this.iterable == child) {
			this.disown((AbstractNode) child);
			this.iterable = null;
			return true;
		}
		if (this.statement == child) {
			this.disown((AbstractNode) child);
			this.statement = null;
			return true;
		}
		return false;
	}
	
	@java.lang.Override public void accept(lombok.ast.AstVisitor visitor) {
		if (visitor.visitForEach(this)) return;
		if (this.variable != null) this.variable.accept(visitor);
		if (this.iterable != null) this.iterable.accept(visitor);
		if (this.statement != null) this.statement.accept(visitor);
		visitor.afterVisitForEach(this);
		visitor.endVisit(this);
	}
	
	@java.lang.Override public ForEach copy() {
		ForEach result = new ForEach();
		if (this.variable != null) result.rawVariable(this.variable.copy());
		if (this.iterable != null) result.rawIterable(this.iterable.copy());
		if (this.statement != null) result.rawStatement(this.statement.copy());
		return result;
	}
	
}
