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

package lombok.ast;

public class CompilationUnit extends lombok.ast.AbstractNode {
	private lombok.ast.AbstractNode packageDeclaration = null;
	lombok.ast.ListAccessor<ImportDeclaration, lombok.ast.CompilationUnit> importDeclarations = ListAccessor.of(this, ImportDeclaration.class, "CompilationUnit.importDeclarations");
	lombok.ast.ListAccessor<TypeDeclaration, lombok.ast.CompilationUnit> typeDeclarations = ListAccessor.of(this, TypeDeclaration.class, "CompilationUnit.typeDeclarations");
	
	public PackageDeclaration astPackageDeclaration() {
		if (!(this.packageDeclaration instanceof PackageDeclaration)) return null;
		return (PackageDeclaration) this.packageDeclaration;
	}
	
	public lombok.ast.CompilationUnit astPackageDeclaration(PackageDeclaration packageDeclaration) {
		return this.rawPackageDeclaration(packageDeclaration);
	}
	
	public lombok.ast.Node rawPackageDeclaration() {
		return this.packageDeclaration;
	}
	
	public lombok.ast.CompilationUnit rawPackageDeclaration(lombok.ast.Node packageDeclaration) {
		if (packageDeclaration == this.packageDeclaration) return this;
		if (packageDeclaration != null) this.adopt((lombok.ast.AbstractNode)packageDeclaration);
		if (this.packageDeclaration != null) this.disown(this.packageDeclaration);
		this.packageDeclaration = (lombok.ast.AbstractNode)packageDeclaration;
		return this;
	}
	
	public lombok.ast.RawListAccessor<ImportDeclaration, lombok.ast.CompilationUnit> rawImportDeclarations() {
		return this.importDeclarations.asRaw();
	}
	
	public lombok.ast.StrictListAccessor<ImportDeclaration, lombok.ast.CompilationUnit> astImportDeclarations() {
		return this.importDeclarations.asStrict();
	}
	
	public lombok.ast.RawListAccessor<TypeDeclaration, lombok.ast.CompilationUnit> rawTypeDeclarations() {
		return this.typeDeclarations.asRaw();
	}
	
	public lombok.ast.StrictListAccessor<TypeDeclaration, lombok.ast.CompilationUnit> astTypeDeclarations() {
		return this.typeDeclarations.asStrict();
	}
	
	@java.lang.Override public java.util.List<Node> getChildren() {
		java.util.List<Node> result = new java.util.ArrayList<Node>();
		if (this.packageDeclaration != null) result.add(this.packageDeclaration);
		result.addAll(this.importDeclarations.backingList());
		result.addAll(this.typeDeclarations.backingList());
		return result;
	}
	
	@java.lang.Override public boolean replaceChild(Node original, Node replacement) throws lombok.ast.AstException {
		if (this.packageDeclaration == original) {
			this.rawPackageDeclaration(replacement);
			return true;
		}
		if (this.rawImportDeclarations().replace(original, replacement)) return true;
		if (this.rawTypeDeclarations().replace(original, replacement)) return true;
		return false;
	}
	
	@java.lang.Override public boolean detach(Node child) {
		if (this.packageDeclaration == child) {
			this.disown((AbstractNode) child);
			this.packageDeclaration = null;
			return true;
		}
		if (this.rawImportDeclarations().remove(child)) return true;
		if (this.rawTypeDeclarations().remove(child)) return true;
		return false;
	}
	
	@java.lang.Override public void accept(lombok.ast.AstVisitor visitor) {
		if (visitor.visitCompilationUnit(this)) return;
		if (this.packageDeclaration != null) this.packageDeclaration.accept(visitor);
		for (lombok.ast.Node child : this.importDeclarations.asIterable()) {
			child.accept(visitor);
		}
		for (lombok.ast.Node child : this.typeDeclarations.asIterable()) {
			child.accept(visitor);
		}
		visitor.afterVisitCompilationUnit(this);
		visitor.endVisit(this);
	}
	
	@java.lang.Override public CompilationUnit copy() {
		CompilationUnit result = new CompilationUnit();
		if (this.packageDeclaration != null) result.rawPackageDeclaration(this.packageDeclaration.copy());
		for (Node n : this.importDeclarations.backingList()) {
			result.rawImportDeclarations().addToEnd(n == null ? null : n.copy());
		}
		for (Node n : this.typeDeclarations.backingList()) {
			result.rawTypeDeclarations().addToEnd(n == null ? null : n.copy());
		}
		return result;
	}
	
}
