2 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.yangtools.yang.parser.spi.source;
10 import org.opendaylight.yangtools.yang.model.api.meta.StatementSource;
13 * Reference of statement source present in textual source format. Utility implementation
14 * of {@link StatementSourceReference} for textual sources, this is prefered {@link StatementSourceReference}
15 * for implementations of YANG / YIN statement stream sources.
18 * To create source reference use one of this static factories:
20 * <li>{@link #atPosition(String, int, int)} - provides most specific reference of statement location,
21 * this is most prefered since it provides most context to debug YANG model.
23 * <li>{@link #atLine(String, int)}- provides source and line of statement location.
25 * <li>{@link #inSource(String)} - least specific reference, should be used only if any of previous
26 * references are unable to create / derive from source.
30 public abstract class DeclarationInTextSource implements StatementSourceReference {
31 private static class InSource extends DeclarationInTextSource {
32 InSource(final String sourceName) {
37 public String toString() {
38 return getSourceName();
42 private static class AtLine extends InSource {
43 private final int line;
45 AtLine(final String sourceName, final int line) {
51 public String toString() {
52 return getSourceName() + ':' + line;
60 private static final class AtPosition extends AtLine {
61 private final int character;
63 AtPosition(final String sourceName, final int line, final int character) {
64 super(sourceName, line);
65 this.character = character;
69 public String toString() {
70 return getSourceName() + ':' + getLine() + ':' + character;
74 private final String sourceName;
76 DeclarationInTextSource(final String sourceName) {
77 this.sourceName = sourceName;
80 public static DeclarationInTextSource inSource(final String sourceName) {
81 return new InSource(sourceName);
84 public static DeclarationInTextSource atLine(final String sourceName, final int line) {
85 return new AtLine(sourceName, line);
88 public static DeclarationInTextSource atPosition(final String sourceName, final int line, final int position) {
89 return new AtPosition(sourceName, line, position);
92 public String getSourceName() {
97 public StatementSource getStatementSource() {
98 return StatementSource.DECLARATION;
102 public abstract String toString();