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

package lombok.ast;

public class AnnotationElement extends lombok.ast.AbstractNode implements lombok.ast.DescribedNode {
	private lombok.ast.AbstractNode name = null;
	private lombok.ast.AbstractNode value = null;
	
	public Annotation upToAnnotation() {
		if (!(this.getParent() instanceof Annotation)) return null;
		Annotation out = (Annotation)this.getParent();
		if (!out.rawElements().contains(this)) return null;
		return out;
	}
	
	
	public Identifier astName() {
		if (!(this.name instanceof Identifier)) return null;
		return (Identifier) this.name;
	}
	
	public lombok.ast.AnnotationElement astName(Identifier name) {
		return this.rawName(name);
	}
	
	private lombok.ast.AnnotationElement 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 AnnotationValue astValue() {
		if (!(this.value instanceof AnnotationValue)) return null;
		return (AnnotationValue) this.value;
	}
	
	public lombok.ast.AnnotationElement astValue(AnnotationValue value) {
		if (value == null) throw new java.lang.NullPointerException("value is mandatory");
		return this.rawValue(value);
	}
	
	public lombok.ast.Node rawValue() {
		return this.value;
	}
	
	public lombok.ast.AnnotationElement rawValue(lombok.ast.Node value) {
		if (value == this.value) return this;
		if (value != null) this.adopt((lombok.ast.AbstractNode)value);
		if (this.value != null) this.disown(this.value);
		this.value = (lombok.ast.AbstractNode)value;
		return this;
	}
	
	@java.lang.Override public java.util.List<Node> getChildren() {
		java.util.List<Node> result = new java.util.ArrayList<Node>();
		if (this.name != null) result.add(this.name);
		if (this.value != null) result.add(this.value);
		return result;
	}
	
	@java.lang.Override public boolean replaceChild(Node original, Node replacement) throws lombok.ast.AstException {
		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.value == original) {
			this.rawValue(replacement);
			return true;
		}
		return false;
	}
	
	@java.lang.Override public boolean detach(Node child) {
		if (this.name == child) {
			this.disown((AbstractNode) child);
			this.name = null;
			return true;
		}
		if (this.value == child) {
			this.disown((AbstractNode) child);
			this.value = null;
			return true;
		}
		return false;
	}
	
	@java.lang.Override public void accept(lombok.ast.AstVisitor visitor) {
		if (visitor.visitAnnotationElement(this)) return;
		if (this.name != null) this.name.accept(visitor);
		if (this.value != null) this.value.accept(visitor);
		visitor.afterVisitAnnotationElement(this);
		visitor.endVisit(this);
	}
	
	@java.lang.Override public AnnotationElement copy() {
		AnnotationElement result = new AnnotationElement();
		if (this.name != null) result.rawName(this.name.copy());
		if (this.value != null) result.rawValue(this.value.copy());
		return result;
	}
	
	public java.lang.String getDescription() {
		return lombok.ast.AnnotationElementTemplate.getDescription(this);
	}
	
	public java.util.List<lombok.ast.Node> getValues() {
		return lombok.ast.AnnotationElementTemplate.getValues(this);
	}
	
}
