Add the ability to retain DeclarationReference
[yangtools.git] / yang / yang-parser-spi / src / main / java / org / opendaylight / yangtools / yang / parser / spi / source / StatementSourceReference.java
1 /*
2  * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.yangtools.yang.parser.spi.source;
9
10 import org.eclipse.jdt.annotation.NonNull;
11 import org.eclipse.jdt.annotation.Nullable;
12 import org.opendaylight.yangtools.concepts.Immutable;
13 import org.opendaylight.yangtools.yang.model.api.meta.DeclarationReference;
14 import org.opendaylight.yangtools.yang.model.api.meta.StatementOrigin;
15
16 /**
17  * Reference of statement source. Statement source reference serves to provide information, why a statement was defined
18  * and introduced in model.
19  *
20  * <p>
21  * Reasons for introduction of statement could be various, but most obvious one is explicit declaration in model source
22  * text such as {@link ExplicitStatement}.
23  */
24 public abstract class StatementSourceReference implements Immutable {
25     /**
26      * Returns the {@link StatementOrigin} associated with this reference.
27      *
28      * @return {@link StatementOrigin#DECLARATION} if statement was explicitly declared in YANG model source,
29      *         {@link StatementOrigin#CONTEXT} if statement was inferred.
30      */
31     public abstract @NonNull StatementOrigin statementOrigin();
32
33     /**
34      * Returns the {@link DeclarationReference} associated with this reference, if available.
35      *
36      * @return A {@link DeclarationReference} or null.
37      */
38     public abstract @Nullable DeclarationReference declarationReference();
39
40     /**
41      * Returns human readable representation of statement source.
42      *
43      * <p>
44      * Implementations of this interface should override {@link #toString()}, since it may be used in error reporting
45      * to provide context information for model designer to debug errors in its mode.
46      *
47      * @return human readable representation of statement source.
48      */
49     @Override
50     public abstract @NonNull String toString();
51 }