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

package lombok.ast;

public class ClassDeclaration extends lombok.ast.AbstractNode implements lombok.ast.TypeMember, lombok.ast.Statement, lombok.ast.TypeDeclaration, lombok.ast.JavadocContainer {
	private lombok.ast.AbstractNode javadoc = null;
	private lombok.ast.AbstractNode modifiers = adopt(new lombok.ast.Modifiers());
	private lombok.ast.AbstractNode name = adopt(new lombok.ast.Identifier());
	lombok.ast.ListAccessor<TypeVariable, lombok.ast.ClassDeclaration> typeVariables = ListAccessor.of(this, TypeVariable.class, "ClassDeclaration.typeVariables");
	private lombok.ast.AbstractNode extending = null;
	lombok.ast.ListAccessor<TypeReference, lombok.ast.ClassDeclaration> implementing = ListAccessor.of(this, TypeReference.class, "ClassDeclaration.implementing");
	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 Block upToBlock() {
		if (!(this.getParent() instanceof Block)) return null;
		Block out = (Block)this.getParent();
		if (!out.rawContents().contains(this)) return null;
		return out;
	}
	
	public CompilationUnit upIfTopLevelToCompilationUnit() {
		if (!(this.getParent() instanceof CompilationUnit)) return null;
		CompilationUnit out = (CompilationUnit)this.getParent();
		if (!out.rawTypeDeclarations().contains(this)) return null;
		return out;
	}
	
	
	public Comment astJavadoc() {
		if (!(this.javadoc instanceof Comment)) return null;
		return (Comment) this.javadoc;
	}
	
	public lombok.ast.ClassDeclaration astJavadoc(Comment javadoc) {
		return this.rawJavadoc(javadoc);
	}
	
	public lombok.ast.Node rawJavadoc() {
		return this.javadoc;
	}
	
	public lombok.ast.ClassDeclaration 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.ClassDeclaration astModifiers(Modifiers modifiers) {
		return this.rawModifiers(modifiers);
	}
	
	private lombok.ast.ClassDeclaration 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 Identifier astName() {
		if (!(this.name instanceof Identifier)) return null;
		return (Identifier) this.name;
	}
	
	public lombok.ast.ClassDeclaration astName(Identifier name) {
		return this.rawName(name);
	}
	
	private lombok.ast.ClassDeclaration 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<TypeVariable, lombok.ast.ClassDeclaration> rawTypeVariables() {
		return this.typeVariables.asRaw();
	}
	
	public lombok.ast.StrictListAccessor<TypeVariable, lombok.ast.ClassDeclaration> astTypeVariables() {
		return this.typeVariables.asStrict();
	}
	
	public TypeReference astExtending() {
		if (!(this.extending instanceof TypeReference)) return null;
		return (TypeReference) this.extending;
	}
	
	public lombok.ast.ClassDeclaration astExtending(TypeReference extending) {
		return this.rawExtending(extending);
	}
	
	public lombok.ast.Node rawExtending() {
		return this.extending;
	}
	
	public lombok.ast.ClassDeclaration rawExtending(lombok.ast.Node extending) {
		if (extending == this.extending) return this;
		if (extending != null) this.adopt((lombok.ast.AbstractNode)extending);
		if (this.extending != null) this.disown(this.extending);
		this.extending = (lombok.ast.AbstractNode)extending;
		return this;
	}
	
	public lombok.ast.RawListAccessor<TypeReference, lombok.ast.ClassDeclaration> rawImplementing() {
		return this.implementing.asRaw();
	}
	
	public lombok.ast.StrictListAccessor<TypeReference, lombok.ast.ClassDeclaration> astImplementing() {
		return this.implementing.asStrict();
	}
	
	public NormalTypeBody astBody() {
		if (!(this.body instanceof NormalTypeBody)) return null;
		return (NormalTypeBody) this.body;
	}
	
	public lombok.ast.ClassDeclaration astBody(NormalTypeBody 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.ClassDeclaration 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);
		if (this.name != null) result.add(this.name);
		result.addAll(this.typeVariables.backingList());
		if (this.extending != null) result.add(this.extending);
		result.addAll(this.implementing.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.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.rawTypeVariables().replace(original, replacement)) return true;
		if (this.extending == original) {
			this.rawExtending(replacement);
			return true;
		}
		if (this.rawImplementing().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.name == child) {
			this.disown((AbstractNode) child);
			this.name = null;
			return true;
		}
		if (this.rawTypeVariables().remove(child)) return true;
		if (this.extending == child) {
			this.disown((AbstractNode) child);
			this.extending = null;
			return true;
		}
		if (this.rawImplementing().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.visitClassDeclaration(this)) return;
		if (this.javadoc != null) this.javadoc.accept(visitor);
		if (this.modifiers != null) this.modifiers.accept(visitor);
		if (this.name != null) this.name.accept(visitor);
		for (lombok.ast.Node child : this.typeVariables.asIterable()) {
			child.accept(visitor);
		}
		if (this.extending != null) this.extending.accept(visitor);
		for (lombok.ast.Node child : this.implementing.asIterable()) {
			child.accept(visitor);
		}
		if (this.body != null) this.body.accept(visitor);
		visitor.afterVisitClassDeclaration(this);
		visitor.endVisit(this);
	}
	
	@java.lang.Override public ClassDeclaration copy() {
		ClassDeclaration result = new ClassDeclaration();
		if (this.javadoc != null) result.rawJavadoc(this.javadoc.copy());
		if (this.modifiers != null) result.rawModifiers(this.modifiers.copy());
		if (this.name != null) result.rawName(this.name.copy());
		for (Node n : this.typeVariables.backingList()) {
			result.rawTypeVariables().addToEnd(n == null ? null : n.copy());
		}
		if (this.extending != null) result.rawExtending(this.extending.copy());
		for (Node n : this.implementing.backingList()) {
			result.rawImplementing().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.ClassDeclarationTemplate.getDescription(this);
	}
	
	public boolean isInterface() {
		return lombok.ast.ClassDeclarationTemplate.isInterface(this);
	}
	
	public lombok.ast.TypeDeclaration upUpToTypeDeclaration() {
		return lombok.ast.TypeMemberMixin.upUpToTypeDeclaration(this);
	}
	
}
