| /*=============================================================================# |
| # Copyright (c) 2009, 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.yaml.core.ast.YamlAst.NodeType; |
| |
| |
| public abstract class Collection extends NContainer { |
| |
| |
| static abstract class FlowCollection extends Collection { |
| |
| |
| int closeIndicatorOffset= NA_OFFSET; |
| |
| |
| FlowCollection(final YamlAstNode parent, final int offset, final int endOffset) { |
| super(parent, offset, endOffset); |
| } |
| |
| |
| @Override |
| public int getOpenIndicatorOffset() { |
| return this.startOffset; |
| } |
| |
| @Override |
| public int getCloseIndicatorOffset() { |
| return this.closeIndicatorOffset; |
| } |
| |
| |
| } |
| |
| static final class FlowSeq extends FlowCollection { |
| |
| |
| FlowSeq(final YamlAstNode parent, final int offset, final int endOffset) { |
| super(parent, offset, endOffset); |
| } |
| |
| |
| @Override |
| public NodeType getNodeType() { |
| return NodeType.SEQUENCE; |
| } |
| |
| @Override |
| public char getOperator() { |
| return '['; |
| } |
| |
| } |
| |
| static final class FlowMap extends FlowCollection { |
| |
| |
| FlowMap(final YamlAstNode parent, final int offset, final int endOffset) { |
| super(parent, offset, endOffset); |
| } |
| |
| |
| @Override |
| public NodeType getNodeType() { |
| return NodeType.MAP; |
| } |
| |
| @Override |
| public char getOperator() { |
| return '{'; |
| } |
| |
| } |
| |
| static abstract class BlockCollection extends Collection { |
| |
| |
| BlockCollection(final YamlAstNode parent, final int offset, final int endOffset) { |
| super(parent, offset, endOffset); |
| } |
| |
| |
| @Override |
| public int getOpenIndicatorOffset() { |
| return NA_OFFSET; |
| } |
| |
| @Override |
| public int getCloseIndicatorOffset() { |
| return NA_OFFSET; |
| } |
| |
| |
| } |
| |
| static final class BlockSeq extends BlockCollection { |
| |
| |
| BlockSeq(final YamlAstNode parent, final int offset, final int endOffset) { |
| super(parent, offset, endOffset); |
| } |
| |
| |
| @Override |
| public NodeType getNodeType() { |
| return NodeType.SEQUENCE; |
| } |
| |
| @Override |
| public char getOperator() { |
| return '-'; |
| } |
| |
| } |
| |
| static final class BlockMap extends BlockCollection { |
| |
| |
| BlockMap(final YamlAstNode parent, final int offset, final int endOffset) { |
| super(parent, offset, endOffset); |
| } |
| |
| |
| @Override |
| public NodeType getNodeType() { |
| return NodeType.MAP; |
| } |
| |
| @Override |
| public char getOperator() { |
| return ':'; // symbolic |
| } |
| |
| } |
| |
| |
| private Collection(final YamlAstNode parent, final int offset, final int endOffset) { |
| super(parent, offset, endOffset); |
| } |
| |
| |
| @Override |
| public void acceptInYaml(final YamlAstVisitor visitor) throws InvocationTargetException { |
| visitor.visit(this); |
| } |
| |
| |
| public abstract int getOpenIndicatorOffset(); |
| |
| public abstract int getCloseIndicatorOffset(); |
| |
| |
| } |