Introduce ImplicitParentAwareStatementSupport 44/69244/2
authorRobert Varga <robert.varga@pantheon.tech>
Thu, 8 Mar 2018 01:35:15 +0000 (02:35 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Thu, 8 Mar 2018 09:47:47 +0000 (10:47 +0100)
Augment statement would like to know if it needs to adapt itself to
its target node -- which is based on whether the target node would
like to wrap any of its children.

Most of the statements do not want to do this, with the notable
excteption if choice statement. Separate getImplicitParentFor()
into a separate interface, so we can optimize this in future.

Change-Id: I1e1e2d8b1fd52d67b1c2f06838670af69e40f99e
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
yang/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/AbstractStatementSupport.java
yang/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/ImplicitParentAwareStatementSupport.java [new file with mode: 0644]
yang/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/StatementSupport.java

index 389f6e73221d635231276c62fe2e0d1d3069cc1c..3b9a8bd6060d2a984b88ee7a7cc5ffdff042227d 100644 (file)
@@ -10,7 +10,6 @@ package org.opendaylight.yangtools.yang.parser.spi.meta;
 import static com.google.common.base.Preconditions.checkArgument;
 import static java.util.Objects.requireNonNull;
 
-import java.util.Optional;
 import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
 import org.opendaylight.yangtools.yang.common.QName;
@@ -67,12 +66,6 @@ public abstract class AbstractStatementSupport<A, D extends DeclaredStatement<A>
         return type;
     }
 
-    @Override
-    public Optional<StatementSupport<?, ?, ?>> getImplicitParentFor(final StatementDefinition stmtDef) {
-        // NOOP for most implementations and also no implicit parent
-        return Optional.empty();
-    }
-
     @Override
     public void onStatementAdded(final StmtContext.Mutable<A, D, E> stmt) {
         // NOOP for most implementations
diff --git a/yang/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/ImplicitParentAwareStatementSupport.java b/yang/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/ImplicitParentAwareStatementSupport.java
new file mode 100644 (file)
index 0000000..4baf0d3
--- /dev/null
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2018 Pantheon Technologies, 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 java.util.Optional;
+import org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition;
+
+/**
+ * {@link StatementSupport} trait for statements which create intermediate parent node for some of its child nodes.
+ * An example of this is RFC6020/RFC7950 choice statement, which creates implicit case statements for child containers
+ * and others.
+ *
+ * @author Robert Varga
+ */
+@Beta
+// FIXME: 3.0.0: make this interface extend StatementSupport
+public interface ImplicitParentAwareStatementSupport {
+    /**
+     * Returns implicit parent statement support for supplied statement definition, if it is defined. This allows
+     * implementations of this interface add implicit parent to the build context hierarchy before a substatement
+     * is created.
+     *
+     * @param stmtDef statement definition of substatement
+     * @return optional of implicit parent statement support
+     */
+    Optional<StatementSupport<?, ?, ?>> getImplicitParentFor(StatementDefinition stmtDef);
+}
index fbb7f449cf3561ca30f7dd30a71d8ee4aa12ed66..8465e3881eb6badef2a0657a31b1232b5237e2da 100644 (file)
@@ -32,8 +32,9 @@ import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
  * @param <E>
  *            Effective Statement representation
  */
+// FIXME: 3.0.0: do not extends ImplicitParentAwareStatementSupport
 public interface StatementSupport<A, D extends DeclaredStatement<A>, E extends EffectiveStatement<A, D>>
-        extends StatementDefinition, StatementFactory<A, D, E> {
+        extends StatementDefinition, StatementFactory<A, D, E>, ImplicitParentAwareStatementSupport {
 
     /**
      * Returns public statement definition, which will be present in built statements.
@@ -86,16 +87,11 @@ public interface StatementSupport<A, D extends DeclaredStatement<A>, E extends E
      */
     void onStatementAdded(StmtContext.Mutable<A, D, E> stmt);
 
-    /**
-     * Returns implicit parent statement support for supplied statement definition, if it is defined. This allows
-     * implementations of this interface add implicit parent to the build context hierarchy before a substatement
-     * is created.
-     *
-     * @param stmtDef
-     *            statement definition of substatement
-     * @return optional of implicit parent statement support
-     */
-    Optional<StatementSupport<?, ?, ?>> getImplicitParentFor(StatementDefinition stmtDef);
+    // FIXME: 3.0.0: remove this default method
+    @Override
+    default Optional<StatementSupport<?, ?, ?>> getImplicitParentFor(final StatementDefinition stmtDef) {
+        return Optional.empty();
+    }
 
     /**
      * Invoked when statement is closed during {@link ModelProcessingPhase#SOURCE_PRE_LINKAGE} phase, only substatements