Revert "Check for nested augmentations" 91/83291/1
authorRobert Varga <robert.varga@pantheon.tech>
Mon, 29 Jul 2019 08:41:59 +0000 (10:41 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Mon, 29 Jul 2019 08:42:18 +0000 (10:42 +0200)
This reverts commit 759e69d85991edb987a760165adb83fa3f2ab67b.

JIRA: YANGTOOLS-956
Change-Id: I3c80751043a101de77292bc91e0c1c4178d16f44
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/augment/AbstractAugmentStatementSupport.java
yang/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/YT956Test.java [deleted file]
yang/yang-parser-rfc7950/src/test/resources/bugs/YT956/another-module.yang [deleted file]
yang/yang-parser-rfc7950/src/test/resources/bugs/YT956/mainmodule.yang [deleted file]
yang/yang-parser-rfc7950/src/test/resources/bugs/YT956/sub-module-1.yang [deleted file]
yang/yang-parser-rfc7950/src/test/resources/bugs/YT956/sub-module-2.yang [deleted file]

index b0a276928bd4f063b375982168711f0a34ff3b40..fdf68e03c4108de6a1ebfd92094d85c9c4fda135 100644 (file)
@@ -212,11 +212,8 @@ abstract class AbstractAugmentStatementSupport extends AbstractStatementSupport<
      *         statement, otherwise false
      */
     private static boolean isConditionalAugmentStmt(final StmtContext<?, ?, ?> ctx) {
-        return ctx.getPublicDefinition() == YangStmtMapping.AUGMENT && hasWhenSubstatement(ctx);
-    }
-
-    private static boolean hasWhenSubstatement(final StmtContext<?, ?, ?> ctx) {
-        return StmtContextUtils.findFirstSubstatement(ctx, WhenStatement.class) != null;
+        return ctx.getPublicDefinition() == YangStmtMapping.AUGMENT
+                && StmtContextUtils.findFirstSubstatement(ctx, WhenStatement.class) != null;
     }
 
     private static void copyStatement(final Mutable<?, ?, ?> original, final StatementContextBase<?, ?, ?> target,
@@ -240,7 +237,7 @@ abstract class AbstractAugmentStatementSupport extends AbstractStatementSupport<
         }
 
         if (!skipCheckOfMandatoryNodes && typeOfCopy == CopyType.ADDED_BY_AUGMENTATION
-                && requireCheckOfMandatoryNodes(sourceCtx, targetCtx)) {
+                && reguiredCheckOfMandatoryNodes(sourceCtx, targetCtx)) {
             checkForMandatoryNodes(sourceCtx);
         }
 
@@ -279,25 +276,23 @@ abstract class AbstractAugmentStatementSupport extends AbstractStatementSupport<
                 sourceCtx.rawStatementArgument());
     }
 
-    private static boolean requireCheckOfMandatoryNodes(final StmtContext<?, ?, ?> sourceCtx,
+    private static boolean reguiredCheckOfMandatoryNodes(final StmtContext<?, ?, ?> sourceCtx,
             Mutable<?, ?, ?> targetCtx) {
         /*
          * If the statement argument is not QName, it cannot be mandatory
          * statement, therefore return false and skip mandatory nodes validation
          */
-        final Object arg = sourceCtx.getStatementArgument();
-        if (!(arg instanceof QName)) {
+        if (!(sourceCtx.getStatementArgument() instanceof QName)) {
             return false;
         }
-        final QName sourceStmtQName = (QName) arg;
+        final QName sourceStmtQName = (QName) sourceCtx.getStatementArgument();
 
         // RootStatementContext, for example
         final Mutable<?, ?, ?> root = targetCtx.getRoot();
         do {
-            final Object targetArg = targetCtx.getStatementArgument();
-            Verify.verify(targetArg instanceof QName, "Argument of augment target statement must be QName, not %s",
-                targetArg);
-            final QName targetStmtQName = (QName) targetArg;
+            Verify.verify(targetCtx.getStatementArgument() instanceof QName,
+                    "Argument of augment target statement must be QName.");
+            final QName targetStmtQName = (QName) targetCtx.getStatementArgument();
             /*
              * If target is from another module, return true and perform mandatory nodes validation
              */
@@ -318,22 +313,6 @@ abstract class AbstractAugmentStatementSupport extends AbstractStatementSupport<
                     || StmtContextUtils.isNotMandatoryNodeOfType(targetCtx, YangStmtMapping.LIST)) {
                 return false;
             }
-
-            // This could be an augmentation stacked on top of a previous augmentation from the same module, which is
-            // conditional -- in which case we do not run further checks
-            if (targetCtx.getCopyHistory().getLastOperation() == CopyType.ADDED_BY_AUGMENTATION) {
-                final Optional<StmtContext<?, ?, ?>> optOriginal = targetCtx.getOriginalCtx();
-                if (optOriginal.isPresent()) {
-                    final StmtContext<?, ?, ?> original = optOriginal.get();
-                    final Object origArg = original.coerceStatementArgument();
-                    Verify.verify(origArg instanceof QName, "Unexpected statement argument %s", origArg);
-
-                    if (sourceStmtQName.getModule().equals(((QName) origArg).getModule())
-                            && hasWhenSubstatement(getParentAugmentation(original))) {
-                        return false;
-                    }
-                }
-            }
         } while ((targetCtx = targetCtx.getParentContext()) != root);
 
         /*
@@ -343,14 +322,6 @@ abstract class AbstractAugmentStatementSupport extends AbstractStatementSupport<
         return false;
     }
 
-    private static StmtContext<?, ?, ?> getParentAugmentation(final StmtContext<?, ?, ?> child) {
-        StmtContext<?, ?, ?> parent = Verify.verifyNotNull(child.getParentContext(), "Child %s has not parent", child);
-        while (parent.getPublicDefinition() != YangStmtMapping.AUGMENT) {
-            parent = Verify.verifyNotNull(parent.getParentContext(), "Failed to find augmentation parent of %s", child);
-        }
-        return parent;
-    }
-
     private static final ImmutableSet<YangStmtMapping> NOCOPY_DEF_SET = ImmutableSet.of(YangStmtMapping.USES,
         YangStmtMapping.WHEN, YangStmtMapping.DESCRIPTION, YangStmtMapping.REFERENCE, YangStmtMapping.STATUS);
 
diff --git a/yang/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/YT956Test.java b/yang/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/YT956Test.java
deleted file mode 100644 (file)
index 2a1e218..0000000
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * 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.stmt;
-
-import static org.hamcrest.Matchers.isA;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertThat;
-
-import org.junit.Test;
-import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
-
-public class YT956Test {
-    private static final QName ANOTHER_CONTAINER = QName.create("http://www.example.com/anothermodule",
-        "another-container");
-    private static final QName FIRST_AUGMENT = QName.create("http://www.example.com/mainmodule", "first-augment");
-
-    @Test
-    public void testAugmentationConditional() throws Exception {
-        final DataSchemaNode another = StmtTestUtils.parseYangSources("/bugs/YT956/")
-                .findDataChildByName(ANOTHER_CONTAINER).get();
-        assertThat(another, isA(ContainerSchemaNode.class));
-        final ContainerSchemaNode anotherContainer = (ContainerSchemaNode) another;
-
-        final DataSchemaNode first = anotherContainer.findDataChildByName(FIRST_AUGMENT).get();
-        assertThat(first, isA(ContainerSchemaNode.class));
-        final ContainerSchemaNode firstAugment = (ContainerSchemaNode) first;
-
-        // Augmentation needs to be added
-        assertEquals(1, firstAugment.getChildNodes().size());
-    }
-}
diff --git a/yang/yang-parser-rfc7950/src/test/resources/bugs/YT956/another-module.yang b/yang/yang-parser-rfc7950/src/test/resources/bugs/YT956/another-module.yang
deleted file mode 100644 (file)
index da47533..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-module another-module {
-    yang-version 1.1;
-    namespace "http://www.example.com/anothermodule";
-    prefix am;
-
-    container another-container {
-        leaf type {
-            type string;
-            mandatory true;
-        }
-    }
-}
diff --git a/yang/yang-parser-rfc7950/src/test/resources/bugs/YT956/mainmodule.yang b/yang/yang-parser-rfc7950/src/test/resources/bugs/YT956/mainmodule.yang
deleted file mode 100644 (file)
index 4fa4166..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-module mainmodule {
-    yang-version 1.1;
-    namespace "http://www.example.com/mainmodule";
-    prefix mm;
-
-    include sub-module-1;
-    include sub-module-2;
-}
diff --git a/yang/yang-parser-rfc7950/src/test/resources/bugs/YT956/sub-module-1.yang b/yang/yang-parser-rfc7950/src/test/resources/bugs/YT956/sub-module-1.yang
deleted file mode 100644 (file)
index 6e401c7..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-submodule sub-module-1 {
-  yang-version 1.1;
-
-  belongs-to mainmodule {
-      prefix mm;
-  }
-
-  import another-module {
-      prefix am;
-  }
-
-  augment '/am:another-container' {
-      when "am:type = 'test'";
-      container first-augment {
-
-      }
-  }
-}
diff --git a/yang/yang-parser-rfc7950/src/test/resources/bugs/YT956/sub-module-2.yang b/yang/yang-parser-rfc7950/src/test/resources/bugs/YT956/sub-module-2.yang
deleted file mode 100644 (file)
index 99186f8..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-submodule sub-module-2 {
-    yang-version 1.1;
-
-    belongs-to mainmodule {
-        prefix mm;
-    }
-
-    import another-module {
-        prefix am;
-    }
-
-    include sub-module-1;
-
-    grouping dummygrouping {
-        leaf dummyleaf {
-            type string;
-            mandatory true;
-        }
-    }
-
-    augment '/am:another-container/mm:first-augment' {
-        uses dummygrouping;
-    }
-}