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

package lombok.ast;

public class MethodInvocation extends lombok.ast.AbstractNode implements lombok.ast.Expression, lombok.ast.DescribedNode {
	private java.util.List<lombok.ast.Position> parensPositions = new java.util.ArrayList<lombok.ast.Position>();
	private lombok.ast.AbstractNode operand = null;
	lombok.ast.ListAccessor<TypeReference, lombok.ast.MethodInvocation> methodTypeArguments = ListAccessor.of(this, TypeReference.class, "MethodInvocation.methodTypeArguments");
	private lombok.ast.AbstractNode name = adopt(new lombok.ast.Identifier());
	lombok.ast.ListAccessor<Expression, lombok.ast.MethodInvocation> arguments = ListAccessor.of(this, Expression.class, "MethodInvocation.arguments");
	
	public java.util.List<lombok.ast.Position> astParensPositions() {
		return this.parensPositions;
	}
	
	public Expression astOperand() {
		if (!(this.operand instanceof Expression)) return null;
		return (Expression) this.operand;
	}
	
	public lombok.ast.MethodInvocation astOperand(Expression operand) {
		return this.rawOperand(operand);
	}
	
	public lombok.ast.Node rawOperand() {
		return this.operand;
	}
	
	public lombok.ast.MethodInvocation rawOperand(lombok.ast.Node operand) {
		if (operand == this.operand) return this;
		if (operand != null) this.adopt((lombok.ast.AbstractNode)operand);
		if (this.operand != null) this.disown(this.operand);
		this.operand = (lombok.ast.AbstractNode)operand;
		return this;
	}
	
	public lombok.ast.RawListAccessor<TypeReference, lombok.ast.MethodInvocation> rawMethodTypeArguments() {
		return this.methodTypeArguments.asRaw();
	}
	
	public lombok.ast.StrictListAccessor<TypeReference, lombok.ast.MethodInvocation> astMethodTypeArguments() {
		return this.methodTypeArguments.asStrict();
	}
	
	public Identifier astName() {
		if (!(this.name instanceof Identifier)) return null;
		return (Identifier) this.name;
	}
	
	public lombok.ast.MethodInvocation astName(Identifier name) {
		return this.rawName(name);
	}
	
	private lombok.ast.MethodInvocation rawName(lombok.ast.Node name) {
		if (name == this.name) return this;
		if (name != null) this.adopt((lombok.ast.AbstractNode)name);
		if (this.name != null) this.disown(this.name);
		this.name = (lombok.ast.AbstractNode)name;
		return this;
	}
	
	public lombok.ast.RawListAccessor<Expression, lombok.ast.MethodInvocation> rawArguments() {
		return this.arguments.asRaw();
	}
	
	public lombok.ast.StrictListAccessor<Expression, lombok.ast.MethodInvocation> astArguments() {
		return this.arguments.asStrict();
	}
	
	@java.lang.Override public java.util.List<Node> getChildren() {
		java.util.List<Node> result = new java.util.ArrayList<Node>();
		if (this.operand != null) result.add(this.operand);
		result.addAll(this.methodTypeArguments.backingList());
		if (this.name != null) result.add(this.name);
		result.addAll(this.arguments.backingList());
		return result;
	}
	
	@java.lang.Override public boolean replaceChild(Node original, Node replacement) throws lombok.ast.AstException {
		if (this.operand == original) {
			this.rawOperand(replacement);
			return true;
		}
		if (this.rawMethodTypeArguments().replace(original, replacement)) return true;
		if (this.name == original) {
			if (replacement instanceof Identifier) {
				this.astName((Identifier) replacement);
				return true;
			} else throw new lombok.ast.AstException(this, String.format(
					"Cannot replace node: replacement must be of type %s but is of type %s",
					"Identifier", replacement == null ? "null" : replacement.getClass().getName()));
		}
		if (this.rawArguments().replace(original, replacement)) return true;
		return false;
	}
	
	@java.lang.Override public boolean detach(Node child) {
		if (this.operand == child) {
			this.disown((AbstractNode) child);
			this.operand = null;
			return true;
		}
		if (this.rawMethodTypeArguments().remove(child)) return true;
		if (this.name == child) {
			this.disown((AbstractNode) child);
			this.name = null;
			return true;
		}
		if (this.rawArguments().remove(child)) return true;
		return false;
	}
	
	@java.lang.Override public void accept(lombok.ast.AstVisitor visitor) {
		if (visitor.visitMethodInvocation(this)) return;
		if (this.operand != null) this.operand.accept(visitor);
		for (lombok.ast.Node child : this.methodTypeArguments.asIterable()) {
			child.accept(visitor);
		}
		if (this.name != null) this.name.accept(visitor);
		for (lombok.ast.Node child : this.arguments.asIterable()) {
			child.accept(visitor);
		}
		visitor.afterVisitMethodInvocation(this);
		visitor.endVisit(this);
	}
	
	@java.lang.Override public MethodInvocation copy() {
		MethodInvocation result = new MethodInvocation();
		result.parensPositions = new java.util.ArrayList<lombok.ast.Position>(this.parensPositions);
		if (this.operand != null) result.rawOperand(this.operand.copy());
		for (Node n : this.methodTypeArguments.backingList()) {
			result.rawMethodTypeArguments().addToEnd(n == null ? null : n.copy());
		}
		if (this.name != null) result.rawName(this.name.copy());
		for (Node n : this.arguments.backingList()) {
			result.rawArguments().addToEnd(n == null ? null : n.copy());
		}
		return result;
	}
	
	public java.lang.String getDescription() {
		return lombok.ast.MethodInvocationTemplate.getDescription(this);
	}
	
	public int getParens() {
		return lombok.ast.ExpressionMixin.getParens(this);
	}
	
	public int getIntendedParens() {
		return lombok.ast.ExpressionMixin.getIntendedParens(this);
	}
	
	public boolean needsParentheses() {
		return lombok.ast.ExpressionMixin.needsParentheses(this);
	}
	
	public boolean isStatementExpression() {
		return lombok.ast.ExpressionMixin.isStatementExpression(this);
	}
	
}
