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

package lombok.ast;

public class Try extends lombok.ast.AbstractNode implements lombok.ast.Statement {
	private lombok.ast.AbstractNode body = null;
	lombok.ast.ListAccessor<Catch, lombok.ast.Try> catches = ListAccessor.of(this, Catch.class, "Try.catches");
	private lombok.ast.AbstractNode finally_ = 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 Block astBody() {
		if (!(this.body instanceof Block)) return null;
		return (Block) this.body;
	}
	
	public lombok.ast.Try astBody(Block body) {
		if (body == null) throw new java.lang.NullPointerException("body is mandatory");
		return this.rawBody(body);
	}
	
	public lombok.ast.Node rawBody() {
		return this.body;
	}
	
	public lombok.ast.Try rawBody(lombok.ast.Node body) {
		if (body == this.body) return this;
		if (body != null) this.adopt((lombok.ast.AbstractNode)body);
		if (this.body != null) this.disown(this.body);
		this.body = (lombok.ast.AbstractNode)body;
		return this;
	}
	
	public lombok.ast.RawListAccessor<Catch, lombok.ast.Try> rawCatches() {
		return this.catches.asRaw();
	}
	
	public lombok.ast.StrictListAccessor<Catch, lombok.ast.Try> astCatches() {
		return this.catches.asStrict();
	}
	
	public Block astFinally() {
		if (!(this.finally_ instanceof Block)) return null;
		return (Block) this.finally_;
	}
	
	public lombok.ast.Try astFinally(Block finally_) {
		return this.rawFinally(finally_);
	}
	
	public lombok.ast.Node rawFinally() {
		return this.finally_;
	}
	
	public lombok.ast.Try rawFinally(lombok.ast.Node finally_) {
		if (finally_ == this.finally_) return this;
		if (finally_ != null) this.adopt((lombok.ast.AbstractNode)finally_);
		if (this.finally_ != null) this.disown(this.finally_);
		this.finally_ = (lombok.ast.AbstractNode)finally_;
		return this;
	}
	
	@java.lang.Override public java.util.List<Node> getChildren() {
		java.util.List<Node> result = new java.util.ArrayList<Node>();
		if (this.body != null) result.add(this.body);
		result.addAll(this.catches.backingList());
		if (this.finally_ != null) result.add(this.finally_);
		return result;
	}
	
	@java.lang.Override public boolean replaceChild(Node original, Node replacement) throws lombok.ast.AstException {
		if (this.body == original) {
			this.rawBody(replacement);
			return true;
		}
		if (this.rawCatches().replace(original, replacement)) return true;
		if (this.finally_ == original) {
			this.rawFinally(replacement);
			return true;
		}
		return false;
	}
	
	@java.lang.Override public boolean detach(Node child) {
		if (this.body == child) {
			this.disown((AbstractNode) child);
			this.body = null;
			return true;
		}
		if (this.rawCatches().remove(child)) return true;
		if (this.finally_ == child) {
			this.disown((AbstractNode) child);
			this.finally_ = null;
			return true;
		}
		return false;
	}
	
	@java.lang.Override public void accept(lombok.ast.AstVisitor visitor) {
		if (visitor.visitTry(this)) return;
		if (this.body != null) this.body.accept(visitor);
		for (lombok.ast.Node child : this.catches.asIterable()) {
			child.accept(visitor);
		}
		if (this.finally_ != null) this.finally_.accept(visitor);
		visitor.afterVisitTry(this);
		visitor.endVisit(this);
	}
	
	@java.lang.Override public Try copy() {
		Try result = new Try();
		if (this.body != null) result.rawBody(this.body.copy());
		for (Node n : this.catches.backingList()) {
			result.rawCatches().addToEnd(n == null ? null : n.copy());
		}
		if (this.finally_ != null) result.rawFinally(this.finally_.copy());
		return result;
	}
	
}
