Introduce formatting methods for SourceException
[yangtools.git] / yang / yang-parser-impl / src / main / java / org / opendaylight / yangtools / yang / parser / spi / meta / StmtContext.java
index 1e24600932d2c5fc4055606154428998d7720490..78d1ef44207c6fa0deff013487e1261fe8f001ab 100644 (file)
@@ -7,20 +7,22 @@
  */
 package org.opendaylight.yangtools.yang.parser.spi.meta;
 
+import com.google.common.base.Optional;
+import java.util.Collection;
 import java.util.List;
 import java.util.Map;
-import org.opendaylight.yangtools.yang.common.QNameModule;
-import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
-import org.opendaylight.yangtools.yang.parser.stmt.reactor.StatementContextBase;
-import java.util.Collection;
 import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
+import org.opendaylight.yangtools.yang.common.QNameModule;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
 import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
 import org.opendaylight.yangtools.yang.model.api.meta.IdentifierNamespace;
 import org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition;
 import org.opendaylight.yangtools.yang.model.api.meta.StatementSource;
+import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
 import org.opendaylight.yangtools.yang.parser.spi.source.StatementSourceReference;
+import org.opendaylight.yangtools.yang.parser.stmt.reactor.StatementContextBase;
 
 public interface StmtContext<A, D extends DeclaredStatement<A>, E extends EffectiveStatement<A, D>> {
 
@@ -42,19 +44,25 @@ public interface StmtContext<A, D extends DeclaredStatement<A>, E extends Effect
     @Nullable
     A getStatementArgument();
 
-    @Nullable
-    List<Object> getArgumentsFromRoot();
+    /**
+     * Return the {@link SchemaPath} of this statement. Not all statements have a SchemaPath, in which case
+     * {@link Optional#absent()} is returned.
+     *
+     * @return Optional SchemaPath
+     */
+    @Nonnull Optional<SchemaPath> getSchemaPath();
+
+    boolean isConfiguration();
 
-    // <K,VT, V extends VT,N extends IdentifierNamespace<K, V>>
-    // <K, VT, V extends VT ,N extends IdentifierNamespace<K, V>> VT
-    // getFromNamespace(Class<N> type, K key)
     @Nonnull
-    <K, V, N extends IdentifierNamespace<K, V>> V getFromNamespace(
-            Class<N> type, K key) throws NamespaceNotAvailableException;
+    <K, V, KT extends K, N extends IdentifierNamespace<K, V>> V getFromNamespace(
+            Class<N> type, KT key) throws NamespaceNotAvailableException;
 
-    <K, V, N extends IdentifierNamespace<K, V>> Map<?, ?> getAllFromNamespace(
+    <K, V, N extends IdentifierNamespace<K, V>> Map<K, V> getAllFromNamespace(
             Class<N> type);
 
+    <K, V, N extends IdentifierNamespace<K, V>> Map<K, V> getAllFromCurrentStmtCtxNamespace(Class<N> type);
+
     @Nonnull
     StmtContext<?, ?, ?> getRoot();
 
@@ -63,21 +71,37 @@ public interface StmtContext<A, D extends DeclaredStatement<A>, E extends Effect
 
     Collection<StatementContextBase<?, ?, ?>> effectiveSubstatements();
 
+    Collection<StatementContextBase<?, ?, ?>> substatements();
+
     D buildDeclared();
 
     E buildEffective();
 
+    boolean isSupportedToBuildEffective();
+
+    void setIsSupportedToBuildEffective(boolean isSupportedToBuild);
+
+    Collection<StatementContextBase<?, ?, ?>> getEffectOfStatement();
+
+    void addAsEffectOfStatement(StatementContextBase<?, ?, ?> ctx);
+
+    StatementContextBase<?, ?, ?> createCopy(
+            StatementContextBase<?, ?, ?> newParent, TypeOfCopy typeOfCopy)
+            throws SourceException;
+
     StatementContextBase<?, ?, ?> createCopy(QNameModule newQNameModule,
             StatementContextBase<?, ?, ?> newParent, TypeOfCopy typeOfCopy)
             throws SourceException;
 
-    public static enum TypeOfCopy {
-        ORIGINAL, ADDED_BY_USES, ADDED_BY_AUGMENTATION
+    enum TypeOfCopy {
+        ORIGINAL, ADDED_BY_USES, ADDED_BY_AUGMENTATION, ADDED_BY_USES_AUGMENTATION
     }
 
-    TypeOfCopy getTypeOfCopy();
+    List<TypeOfCopy> getCopyHistory();
+
+    void addAllToCopyHistory(List<TypeOfCopy> typeOfCopyList);
 
-    void setTypeOfCopy(TypeOfCopy typeOfCopy);
+    void addToCopyHistory(TypeOfCopy typeOfCopy);
 
     StatementContextBase<?, ?, ?> getOriginalCtx();
 
@@ -85,6 +109,10 @@ public interface StmtContext<A, D extends DeclaredStatement<A>, E extends Effect
 
     boolean isRootContext();
 
+    void setOrder(int order);
+
+    int getOrder();
+
     void setCompletedPhase(ModelProcessingPhase completedPhase);
 
     ModelProcessingPhase getCompletedPhase();
@@ -95,10 +123,8 @@ public interface StmtContext<A, D extends DeclaredStatement<A>, E extends Effect
         @Override
         StmtContext.Mutable<?, ?, ?> getParentContext();
 
-        // <K,V,VT extends V,N extends IdentifierNamespace<K, V>> void
-        // addToNs(Class<N> type, K key, VT value)
-        <K, V, VT extends V, N extends IdentifierNamespace<K, V>> void addToNs(
-                Class<N> type, K key, VT value)
+        <K, V, KT extends K, VT extends V, N extends IdentifierNamespace<K, V>> void addToNs(
+                Class<N> type, KT key, VT value)
                 throws NamespaceNotAvailableException;
 
         @Override