BUG-6522: create a specialized CopyHistory object
[yangtools.git] / yang / yang-parser-impl / src / main / java / org / opendaylight / yangtools / yang / parser / spi / meta / StmtContext.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.meta;
9
10 import com.google.common.base.Optional;
11 import java.util.Collection;
12 import java.util.Map;
13 import javax.annotation.Nonnull;
14 import javax.annotation.Nullable;
15 import org.opendaylight.yangtools.yang.common.QNameModule;
16 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
17 import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
18 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
19 import org.opendaylight.yangtools.yang.model.api.meta.IdentifierNamespace;
20 import org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition;
21 import org.opendaylight.yangtools.yang.model.api.meta.StatementSource;
22 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
23 import org.opendaylight.yangtools.yang.parser.spi.source.StatementSourceReference;
24 import org.opendaylight.yangtools.yang.parser.stmt.reactor.StatementContextBase;
25
26 public interface StmtContext<A, D extends DeclaredStatement<A>, E extends EffectiveStatement<A, D>> {
27
28     @Nonnull
29     StatementSource getStatementSource();
30
31     @Nonnull
32     StatementSourceReference getStatementSourceReference();
33
34     @Nonnull
35     StatementDefinition getPublicDefinition();
36
37     @Nullable
38     StmtContext<?, ?, ?> getParentContext();
39
40     @Nullable
41     String rawStatementArgument();
42
43     @Nullable
44     A getStatementArgument();
45
46     /**
47      * Return the {@link SchemaPath} of this statement. Not all statements have a SchemaPath, in which case
48      * {@link Optional#absent()} is returned.
49      *
50      * @return Optional SchemaPath
51      */
52     @Nonnull Optional<SchemaPath> getSchemaPath();
53
54     boolean isConfiguration();
55
56     boolean isEnabledSemanticVersioning();
57
58     @Nonnull
59     <K, V, KT extends K, N extends IdentifierNamespace<K, V>> V getFromNamespace(
60             Class<N> type, KT key) throws NamespaceNotAvailableException;
61
62     <K, V, N extends IdentifierNamespace<K, V>> Map<K, V> getAllFromNamespace(
63             Class<N> type);
64
65     <K, V, N extends IdentifierNamespace<K, V>> Map<K, V> getAllFromCurrentStmtCtxNamespace(Class<N> type);
66
67     @Nonnull
68     StmtContext<?, ?, ?> getRoot();
69
70     @Nonnull
71     Collection<StatementContextBase<?, ?, ?>> declaredSubstatements();
72
73     Collection<StatementContextBase<?, ?, ?>> effectiveSubstatements();
74
75     Collection<StatementContextBase<?, ?, ?>> substatements();
76
77     D buildDeclared();
78
79     E buildEffective();
80
81     boolean isSupportedToBuildEffective();
82
83     void setIsSupportedToBuildEffective(boolean isSupportedToBuild);
84
85     Collection<StatementContextBase<?, ?, ?>> getEffectOfStatement();
86
87     void addAsEffectOfStatement(StatementContextBase<?, ?, ?> ctx);
88
89     StatementContextBase<?, ?, ?> createCopy(
90             StatementContextBase<?, ?, ?> newParent, CopyType typeOfCopy)
91             throws SourceException;
92
93     StatementContextBase<?, ?, ?> createCopy(QNameModule newQNameModule,
94             StatementContextBase<?, ?, ?> newParent, CopyType typeOfCopy)
95             throws SourceException;
96
97     CopyHistory getCopyHistory();
98
99     enum SupportedByFeatures {
100         UNDEFINED, SUPPORTED, NOT_SUPPORTED
101     }
102
103     SupportedByFeatures getSupportedByFeatures();
104
105     void appendCopyHistory(CopyType typeOfCopy, CopyHistory toAppend);
106
107     StatementContextBase<?, ?, ?> getOriginalCtx();
108
109     void setOriginalCtx(StatementContextBase<?, ?, ?> originalCtx);
110
111     boolean isRootContext();
112
113     void setOrder(int order);
114
115     int getOrder();
116
117     void setCompletedPhase(ModelProcessingPhase completedPhase);
118
119     ModelProcessingPhase getCompletedPhase();
120
121     interface Mutable<A, D extends DeclaredStatement<A>, E extends EffectiveStatement<A, D>>
122             extends StmtContext<A, D, E> {
123
124         @Override
125         StmtContext.Mutable<?, ?, ?> getParentContext();
126
127         <K, V, KT extends K, VT extends V, N extends IdentifierNamespace<K, V>> void addToNs(
128                 Class<N> type, KT key, VT value)
129                 throws NamespaceNotAvailableException;
130
131         @Override
132         StmtContext.Mutable<?, ?, ?> getRoot();
133
134         ModelActionBuilder newInferenceAction(ModelProcessingPhase phase);
135
136         <K, KT extends K, N extends StatementNamespace<K, ?, ?>> void addContext(
137                 Class<N> namespace, KT key, StmtContext<?, ?, ?> stmt);
138
139         void setSupportedByFeatures(boolean isSupported);
140     }
141
142 }