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

package lombok.ast;

public class TypeReferencePart extends lombok.ast.AbstractNode {
	private lombok.ast.AbstractNode identifier = adopt(new lombok.ast.Identifier());
	lombok.ast.ListAccessor<TypeReference, lombok.ast.TypeReferencePart> typeArguments = ListAccessor.of(this, TypeReference.class, "TypeReferencePart.typeArguments");
	
	public TypeReference upToTypeReference() {
		if (!(this.getParent() instanceof TypeReference)) return null;
		TypeReference out = (TypeReference)this.getParent();
		if (!out.rawParts().contains(this)) return null;
		return out;
	}
	
	
	public Identifier astIdentifier() {
		if (!(this.identifier instanceof Identifier)) return null;
		return (Identifier) this.identifier;
	}
	
	public lombok.ast.TypeReferencePart astIdentifier(Identifier identifier) {
		return this.rawIdentifier(identifier);
	}
	
	private lombok.ast.TypeReferencePart rawIdentifier(lombok.ast.Node identifier) {
		if (identifier == this.identifier) return this;
		if (identifier != null) this.adopt((lombok.ast.AbstractNode)identifier);
		if (this.identifier != null) this.disown(this.identifier);
		this.identifier = (lombok.ast.AbstractNode)identifier;
		return this;
	}
	
	public lombok.ast.RawListAccessor<TypeReference, lombok.ast.TypeReferencePart> rawTypeArguments() {
		return this.typeArguments.asRaw();
	}
	
	public lombok.ast.StrictListAccessor<TypeReference, lombok.ast.TypeReferencePart> astTypeArguments() {
		return this.typeArguments.asStrict();
	}
	
	@java.lang.Override public java.util.List<Node> getChildren() {
		java.util.List<Node> result = new java.util.ArrayList<Node>();
		if (this.identifier != null) result.add(this.identifier);
		result.addAll(this.typeArguments.backingList());
		return result;
	}
	
	@java.lang.Override public boolean replaceChild(Node original, Node replacement) throws lombok.ast.AstException {
		if (this.identifier == original) {
			if (replacement instanceof Identifier) {
				this.astIdentifier((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.rawTypeArguments().replace(original, replacement)) return true;
		return false;
	}
	
	@java.lang.Override public boolean detach(Node child) {
		if (this.identifier == child) {
			this.disown((AbstractNode) child);
			this.identifier = null;
			return true;
		}
		if (this.rawTypeArguments().remove(child)) return true;
		return false;
	}
	
	@java.lang.Override public void accept(lombok.ast.AstVisitor visitor) {
		if (visitor.visitTypeReferencePart(this)) return;
		if (this.identifier != null) this.identifier.accept(visitor);
		for (lombok.ast.Node child : this.typeArguments.asIterable()) {
			child.accept(visitor);
		}
		visitor.afterVisitTypeReferencePart(this);
		visitor.endVisit(this);
	}
	
	@java.lang.Override public TypeReferencePart copy() {
		TypeReferencePart result = new TypeReferencePart();
		if (this.identifier != null) result.rawIdentifier(this.identifier.copy());
		for (Node n : this.typeArguments.backingList()) {
			result.rawTypeArguments().addToEnd(n == null ? null : n.copy());
		}
		return result;
	}
	
	public java.lang.String getTypeName() {
		return lombok.ast.TypeReferencePartTemplate.getTypeName(this);
	}
	
}
