Add RootStmtContext marker interface 73/93473/9
authorRobert Varga <robert.varga@pantheon.tech>
Thu, 29 Oct 2020 20:19:15 +0000 (21:19 +0100)
committerRobert Varga <nite@hq.sk>
Fri, 6 Nov 2020 12:22:12 +0000 (12:22 +0000)
This is a useful marker which we can expose in APIs, i.e. for
users which already have a RootStmtContext available. The thinking
here is that, for example, Lookups in global context are shorter
from root than from any old context.

JIRA: YANGTOOLS-1158
Change-Id: Ib69d70ded9d4b46524be21fb5524311b427d9245
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
yang/yang-parser-reactor/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/RootStatementContext.java
yang/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/RootStmtContext.java [new file with mode: 0644]
yang/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/StmtContext.java

index 0a1baff79c4c9e78d806421f5269be8d38d0dd91..e9089250d6d065786606111a1ed9ff46ffe1ecf1 100644 (file)
@@ -34,6 +34,7 @@ import org.opendaylight.yangtools.yang.parser.spi.meta.MutableStatement;
 import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour.NamespaceStorageNode;
 import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour.Registry;
 import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour.StorageNodeType;
+import org.opendaylight.yangtools.yang.parser.spi.meta.RootStmtContext;
 import org.opendaylight.yangtools.yang.parser.spi.source.IncludedModuleContext;
 import org.opendaylight.yangtools.yang.parser.spi.source.StatementSourceReference;
 
@@ -42,7 +43,7 @@ import org.opendaylight.yangtools.yang.parser.spi.source.StatementSourceReferenc
  * of this class, hence recursive lookups from them cross this class.
  */
 public final class RootStatementContext<A, D extends DeclaredStatement<A>, E extends EffectiveStatement<A, D>>
-        extends AbstractResumedStatement<A, D, E> {
+        extends AbstractResumedStatement<A, D, E> implements RootStmtContext.Mutable<A, D, E> {
 
     public static final YangVersion DEFAULT_VERSION = YangVersion.VERSION_1;
 
diff --git a/yang/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/RootStmtContext.java b/yang/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/RootStmtContext.java
new file mode 100644 (file)
index 0000000..8c1c484
--- /dev/null
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2020 PANTHEON.tech, s.r.o. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.yang.parser.spi.meta;
+
+import com.google.common.annotations.Beta;
+import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
+import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
+
+/**
+ * A marker interface for a {@link StmtContext}. Useful for operations which make assumption about the context's
+ * hierarchy.
+ *
+ * @param <A> Argument type
+ * @param <D> Declared Statement representation
+ * @param <E> Effective Statement representation
+ */
+@Beta
+public interface RootStmtContext<A, D extends DeclaredStatement<A>, E extends EffectiveStatement<A, D>>
+        extends StmtContext<A, D, E> {
+
+    interface Mutable<A, D extends DeclaredStatement<A>, E extends EffectiveStatement<A, D>>
+            extends StmtContext.Mutable<A, D, E>, RootStmtContext<A, D, E> {
+
+        @Override
+        RootStmtContext.Mutable<?, ?, ?> getRoot();
+    }
+}
index 337a5fba1a64da4313e4a0b9e8c30d1a94dd133b..8419a5f517a42b6f228b0e26883c037d08f239be 100644 (file)
@@ -151,7 +151,7 @@ public interface StmtContext<A, D extends DeclaredStatement<A>, E extends Effect
 
     <K, V, N extends IdentifierNamespace<K, V>> Map<K, V> getAllFromCurrentStmtCtxNamespace(Class<N> type);
 
-    @NonNull StmtContext<?, ?, ?> getRoot();
+    @NonNull RootStmtContext<?, ?, ?> getRoot();
 
     /**
      * Return declared substatements. These are the statements which are explicitly written in the source model.
@@ -271,7 +271,7 @@ public interface StmtContext<A, D extends DeclaredStatement<A>, E extends Effect
                 T key, U value);
 
         @Override
-        Mutable<?, ?, ?> getRoot();
+        RootStmtContext.Mutable<?, ?, ?> getRoot();
 
         /**
          * Create a child sub-statement, which is a child of this statement, inheriting all attributes from specified