blob: 4424484722f6ed5d37fac080658451e6f0176bc9 [file] [log] [blame]
/*=============================================================================#
# Copyright (c) 2015, 2018 Stephan Wahlbrink and others.
#
# This program and the accompanying materials are made available under the
# terms of the Eclipse Public License 2.0 which is available at
# https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
# which is available at https://www.apache.org/licenses/LICENSE-2.0.
#
# SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
#
# Contributors:
# Stephan Wahlbrink <sw@wahlbrink.eu> - initial API and implementation
#=============================================================================*/
package org.eclipse.statet.yaml.core.ast;
import java.lang.reflect.InvocationTargetException;
import org.eclipse.statet.ltk.ast.core.AstNode;
import org.eclipse.statet.ltk.ast.core.AstVisitor;
import org.eclipse.statet.yaml.core.ast.YamlAst.NodeType;
public class Tuple extends YamlAstNode {
int keyIndicatorOffset= NA_OFFSET;
YamlAstNode keyNode;
int valueIndicatorOffset= NA_OFFSET;
YamlAstNode valueNode;
Tuple(final YamlAstNode parent, final int startOffset, final int endOffset) {
super(parent, startOffset, endOffset);
}
@Override
public NodeType getNodeType() {
return NodeType.MAP_ENTRY;
}
@Override
public boolean hasChildren() {
return true;
}
@Override
public int getChildCount() {
return 2;
}
public int getKeyIndicatorOffset() {
return this.keyIndicatorOffset;
}
public YamlAstNode getKeyNode() {
return this.keyNode;
}
public int getValueIndicatorOffset() {
return this.valueIndicatorOffset;
}
public YamlAstNode getValueNode() {
return this.valueNode;
}
@Override
public YamlAstNode getChild(final int index) {
switch (index) {
case 0:
return this.keyNode;
case 1:
return this.valueNode;
default:
throw new IndexOutOfBoundsException(Integer.toString(index));
}
}
@Override
public int getChildIndex(final AstNode element) {
if (element == this.keyNode) {
return 0;
}
if (element == this.valueNode) {
return 1;
}
return -1;
}
@Override
public void acceptInChildren(final AstVisitor visitor) throws InvocationTargetException {
visitor.visit(this.keyNode);
visitor.visit(this.valueNode);
}
@Override
public void acceptInYaml(final YamlAstVisitor visitor) throws InvocationTargetException {
visitor.visit(this);
}
@Override
public void acceptInYamlChildren(final YamlAstVisitor visitor) throws InvocationTargetException {
this.keyNode.acceptInYaml(visitor);
this.valueNode.acceptInYaml(visitor);
}
}