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

package lombok.ast;

public class MethodDeclaration extends lombok.ast.AbstractNode implements lombok.ast.TypeMember, lombok.ast.DescribedNode, lombok.ast.JavadocContainer {
	private lombok.ast.AbstractNode javadoc = null;
	private lombok.ast.AbstractNode modifiers = adopt(new lombok.ast.Modifiers());
	lombok.ast.ListAccessor<TypeVariable, lombok.ast.MethodDeclaration> typeVariables = ListAccessor.of(this, TypeVariable.class, "MethodDeclaration.typeVariables");
	private lombok.ast.AbstractNode returnTypeReference = null;
	private lombok.ast.AbstractNode methodName = adopt(new lombok.ast.Identifier());
	lombok.ast.ListAccessor<VariableDefinition, lombok.ast.MethodDeclaration> parameters = ListAccessor.of(this, VariableDefinition.class, "MethodDeclaration.parameters");
	lombok.ast.ListAccessor<TypeReference, lombok.ast.MethodDeclaration> thrownTypeReferences = ListAccessor.of(this, TypeReference.class, "MethodDeclaration.thrownTypeReferences");
	private lombok.ast.AbstractNode body = null;
	
	public TypeBody upToTypeBody() {
		if (!(this.getParent() instanceof TypeBody)) return null;
		TypeBody out = (TypeBody)this.getParent();
		if (!out.rawMembers().contains(this)) return null;
		return out;
	}
	
	
	public Comment astJavadoc() {
		if (!(this.javadoc instanceof Comment)) return null;
		return (Comment) this.javadoc;
	}
	
	public lombok.ast.MethodDeclaration astJavadoc(Comment javadoc) {
		return this.rawJavadoc(javadoc);
	}
	
	public lombok.ast.Node rawJavadoc() {
		return this.javadoc;
	}
	
	public lombok.ast.MethodDeclaration rawJavadoc(lombok.ast.Node javadoc) {
		if (javadoc == this.javadoc) return this;
		if (javadoc != null) this.adopt((lombok.ast.AbstractNode)javadoc);
		if (this.javadoc != null) this.disown(this.javadoc);
		this.javadoc = (lombok.ast.AbstractNode)javadoc;
		return this;
	}
	
	public Modifiers astModifiers() {
		if (!(this.modifiers instanceof Modifiers)) return null;
		return (Modifiers) this.modifiers;
	}
	
	public lombok.ast.MethodDeclaration astModifiers(Modifiers modifiers) {
		return this.rawModifiers(modifiers);
	}
	
	private lombok.ast.MethodDeclaration rawModifiers(lombok.ast.Node modifiers) {
		if (modifiers == this.modifiers) return this;
		if (modifiers != null) this.adopt((lombok.ast.AbstractNode)modifiers);
		if (this.modifiers != null) this.disown(this.modifiers);
		this.modifiers = (lombok.ast.AbstractNode)modifiers;
		return this;
	}
	
	public lombok.ast.RawListAccessor<TypeVariable, lombok.ast.MethodDeclaration> rawTypeVariables() {
		return this.typeVariables.asRaw();
	}
	
	public lombok.ast.StrictListAccessor<TypeVariable, lombok.ast.MethodDeclaration> astTypeVariables() {
		return this.typeVariables.asStrict();
	}
	
	public TypeReference astReturnTypeReference() {
		if (!(this.returnTypeReference instanceof TypeReference)) return null;
		return (TypeReference) this.returnTypeReference;
	}
	
	public lombok.ast.MethodDeclaration astReturnTypeReference(TypeReference returnTypeReference) {
		if (returnTypeReference == null) throw new java.lang.NullPointerException("returnTypeReference is mandatory");
		return this.rawReturnTypeReference(returnTypeReference);
	}
	
	public lombok.ast.Node rawReturnTypeReference() {
		return this.returnTypeReference;
	}
	
	public lombok.ast.MethodDeclaration rawReturnTypeReference(lombok.ast.Node returnTypeReference) {
		if (returnTypeReference == this.returnTypeReference) return this;
		if (returnTypeReference != null) this.adopt((lombok.ast.AbstractNode)returnTypeReference);
		if (this.returnTypeReference != null) this.disown(this.returnTypeReference);
		this.returnTypeReference = (lombok.ast.AbstractNode)returnTypeReference;
		return this;
	}
	
	public Identifier astMethodName() {
		if (!(this.methodName instanceof Identifier)) return null;
		return (Identifier) this.methodName;
	}
	
	public lombok.ast.MethodDeclaration astMethodName(Identifier methodName) {
		return this.rawMethodName(methodName);
	}
	
	private lombok.ast.MethodDeclaration rawMethodName(lombok.ast.Node methodName) {
		if (methodName == this.methodName) return this;
		if (methodName != null) this.adopt((lombok.ast.AbstractNode)methodName);
		if (this.methodName != null) this.disown(this.methodName);
		this.methodName = (lombok.ast.AbstractNode)methodName;
		return this;
	}
	
	public lombok.ast.RawListAccessor<VariableDefinition, lombok.ast.MethodDeclaration> rawParameters() {
		return this.parameters.asRaw();
	}
	
	public lombok.ast.StrictListAccessor<VariableDefinition, lombok.ast.MethodDeclaration> astParameters() {
		return this.parameters.asStrict();
	}
	
	public lombok.ast.RawListAccessor<TypeReference, lombok.ast.MethodDeclaration> rawThrownTypeReferences() {
		return this.thrownTypeReferences.asRaw();
	}
	
	public lombok.ast.StrictListAccessor<TypeReference, lombok.ast.MethodDeclaration> astThrownTypeReferences() {
		return this.thrownTypeReferences.asStrict();
	}
	
	public Block astBody() {
		if (!(this.body instanceof Block)) return null;
		return (Block) this.body;
	}
	
	public lombok.ast.MethodDeclaration astBody(Block body) {
		return this.rawBody(body);
	}
	
	public lombok.ast.Node rawBody() {
		return this.body;
	}
	
	public lombok.ast.MethodDeclaration 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;
	}
	
	@java.lang.Override public java.util.List<Node> getChildren() {
		java.util.List<Node> result = new java.util.ArrayList<Node>();
		if (this.javadoc != null) result.add(this.javadoc);
		if (this.modifiers != null) result.add(this.modifiers);
		result.addAll(this.typeVariables.backingList());
		if (this.returnTypeReference != null) result.add(this.returnTypeReference);
		if (this.methodName != null) result.add(this.methodName);
		result.addAll(this.parameters.backingList());
		result.addAll(this.thrownTypeReferences.backingList());
		if (this.body != null) result.add(this.body);
		return result;
	}
	
	@java.lang.Override public boolean replaceChild(Node original, Node replacement) throws lombok.ast.AstException {
		if (this.javadoc == original) {
			this.rawJavadoc(replacement);
			return true;
		}
		if (this.modifiers == original) {
			if (replacement instanceof Modifiers) {
				this.astModifiers((Modifiers) 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",
					"Modifiers", replacement == null ? "null" : replacement.getClass().getName()));
		}
		if (this.rawTypeVariables().replace(original, replacement)) return true;
		if (this.returnTypeReference == original) {
			this.rawReturnTypeReference(replacement);
			return true;
		}
		if (this.methodName == original) {
			if (replacement instanceof Identifier) {
				this.astMethodName((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.rawParameters().replace(original, replacement)) return true;
		if (this.rawThrownTypeReferences().replace(original, replacement)) return true;
		if (this.body == original) {
			this.rawBody(replacement);
			return true;
		}
		return false;
	}
	
	@java.lang.Override public boolean detach(Node child) {
		if (this.javadoc == child) {
			this.disown((AbstractNode) child);
			this.javadoc = null;
			return true;
		}
		if (this.modifiers == child) {
			this.disown((AbstractNode) child);
			this.modifiers = null;
			return true;
		}
		if (this.rawTypeVariables().remove(child)) return true;
		if (this.returnTypeReference == child) {
			this.disown((AbstractNode) child);
			this.returnTypeReference = null;
			return true;
		}
		if (this.methodName == child) {
			this.disown((AbstractNode) child);
			this.methodName = null;
			return true;
		}
		if (this.rawParameters().remove(child)) return true;
		if (this.rawThrownTypeReferences().remove(child)) return true;
		if (this.body == child) {
			this.disown((AbstractNode) child);
			this.body = null;
			return true;
		}
		return false;
	}
	
	@java.lang.Override public void accept(lombok.ast.AstVisitor visitor) {
		if (visitor.visitMethodDeclaration(this)) return;
		if (this.javadoc != null) this.javadoc.accept(visitor);
		if (this.modifiers != null) this.modifiers.accept(visitor);
		for (lombok.ast.Node child : this.typeVariables.asIterable()) {
			child.accept(visitor);
		}
		if (this.returnTypeReference != null) this.returnTypeReference.accept(visitor);
		if (this.methodName != null) this.methodName.accept(visitor);
		for (lombok.ast.Node child : this.parameters.asIterable()) {
			child.accept(visitor);
		}
		for (lombok.ast.Node child : this.thrownTypeReferences.asIterable()) {
			child.accept(visitor);
		}
		if (this.body != null) this.body.accept(visitor);
		visitor.afterVisitMethodDeclaration(this);
		visitor.endVisit(this);
	}
	
	@java.lang.Override public MethodDeclaration copy() {
		MethodDeclaration result = new MethodDeclaration();
		if (this.javadoc != null) result.rawJavadoc(this.javadoc.copy());
		if (this.modifiers != null) result.rawModifiers(this.modifiers.copy());
		for (Node n : this.typeVariables.backingList()) {
			result.rawTypeVariables().addToEnd(n == null ? null : n.copy());
		}
		if (this.returnTypeReference != null) result.rawReturnTypeReference(this.returnTypeReference.copy());
		if (this.methodName != null) result.rawMethodName(this.methodName.copy());
		for (Node n : this.parameters.backingList()) {
			result.rawParameters().addToEnd(n == null ? null : n.copy());
		}
		for (Node n : this.thrownTypeReferences.backingList()) {
			result.rawThrownTypeReferences().addToEnd(n == null ? null : n.copy());
		}
		if (this.body != null) result.rawBody(this.body.copy());
		return result;
	}
	
	public java.lang.String getDescription() {
		return lombok.ast.MethodDeclarationTemplate.getDescription(this);
	}
	
	public lombok.ast.TypeDeclaration upUpToTypeDeclaration() {
		return lombok.ast.TypeMemberMixin.upUpToTypeDeclaration(this);
	}
	
}
