Add CopyPolicy.REJECT 04/87404/2
authorRobert Varga <robert.varga@pantheon.tech>
Mon, 3 Feb 2020 16:04:24 +0000 (17:04 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Tue, 4 Feb 2020 06:59:34 +0000 (07:59 +0100)
There are a number of statements which should never be copied and
any such attempt should cause the reactor to fail. This adds the
appropriate copy policy.

JIRA: YANGTOOLS-694
Change-Id: I0c51f2d2b96b2de8a1dc1b287d9dbcef1bd6c463
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
yang/yang-parser-reactor/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/StatementContextBase.java
yang/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/StatementSupport.java

index 79169aa61ab6f40e1c8a8424293f6a228dc0d80f..12e812e24ffb256f2bf265d5c8eb59e7a024d086 100644 (file)
@@ -791,6 +791,8 @@ public abstract class StatementContextBase<A, D extends DeclaredStatement<A>, E
                 return Optional.of(parent.childCopyOf(this, type, targetModule));
             case IGNORE:
                 return Optional.empty();
+            case REJECT:
+                throw new IllegalStateException("Statement " + support.getPublicView() + " should never be copied");
             default:
                 throw new IllegalStateException("Unhandled policy " + policy);
         }
index 79658e8fecde0876d1f4a2fbc77c9e64fa3255ba..60d8a37aff5c576a55551522d8cf1d9eeef8ff8e 100644 (file)
@@ -263,6 +263,11 @@ public interface StatementSupport<A, D extends DeclaredStatement<A>, E extends E
          */
         // TODO: will the copy transition to ModelProcessingPhase.FULL_DECLARATION or which phase?
         DECLARED_COPY,
+        /**
+         * Reject any attempt to copy this statement. This is useful for statements that are defined as top-level
+         * constructs, such as {@code contact}, {@code deviation} and similar.
+         */
+        REJECT,
         /**
          * Ignore this statement's existence for the purposes of the new place -- it is not impacted. This guidance
          * is left here for completeness, as it can have justifiable uses (but I can't think of any). Any substatements