Defer copy decisions to StatementSupport
[yangtools.git] / yang / yang-parser-rfc7950 / src / main / java / org / opendaylight / yangtools / yang / parser / rfc7950 / stmt / description / DescriptionStatementSupport.java
index 501b9c4d65326315f359e767bbddd0b9a11f71bc..2fdc3de240241ac92fbc55722ed13ea207c74ea0 100644 (file)
@@ -7,15 +7,23 @@
  */
 package org.opendaylight.yangtools.yang.parser.rfc7950.stmt.description;
 
+import com.google.common.collect.ImmutableList;
+import java.util.Optional;
+import org.opendaylight.yangtools.yang.common.QNameModule;
 import org.opendaylight.yangtools.yang.model.api.YangStmtMapping;
+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.stmt.DescriptionEffectiveStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.DescriptionStatement;
-import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractStatementSupport;
+import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.BaseStringStatementSupport;
+import org.opendaylight.yangtools.yang.parser.spi.meta.CopyType;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.Mutable;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils;
 import org.opendaylight.yangtools.yang.parser.spi.meta.SubstatementValidator;
 
-public final class DescriptionStatementSupport extends AbstractStatementSupport<String, DescriptionStatement,
-        EffectiveStatement<String, DescriptionStatement>> {
+public final class DescriptionStatementSupport
+        extends BaseStringStatementSupport<DescriptionStatement, DescriptionEffectiveStatement> {
     private static final SubstatementValidator SUBSTATEMENT_VALIDATOR = SubstatementValidator.builder(
         YangStmtMapping.DESCRIPTION).build();
     private static final DescriptionStatementSupport INSTANCE = new DescriptionStatementSupport();
@@ -34,18 +42,40 @@ public final class DescriptionStatementSupport extends AbstractStatementSupport<
     }
 
     @Override
-    public DescriptionStatement createDeclared(final StmtContext<String, DescriptionStatement, ?> ctx) {
-        return new DescriptionStatementImpl(ctx);
+    public Optional<? extends Mutable<?, ?, ?>> copyAsChildOf(final Mutable<?, ?, ?> stmt,
+            final Mutable<?, ?, ?> parent, final CopyType type, final QNameModule targetModule) {
+        return StmtContextUtils.isChildOfGrouping(stmt) ? Optional.empty()
+                : super.copyAsChildOf(stmt, parent, type, targetModule);
     }
 
     @Override
-    public EffectiveStatement<String, DescriptionStatement> createEffective(
-            final StmtContext<String, DescriptionStatement, EffectiveStatement<String, DescriptionStatement>> ctx) {
-        return new DescriptionEffectiveStatementImpl(ctx);
+    protected SubstatementValidator getSubstatementValidator() {
+        return SUBSTATEMENT_VALIDATOR;
     }
 
     @Override
-    protected SubstatementValidator getSubstatementValidator() {
-        return SUBSTATEMENT_VALIDATOR;
+    protected DescriptionStatement createDeclared(final StmtContext<String, DescriptionStatement, ?> ctx,
+            final ImmutableList<? extends DeclaredStatement<?>> substatements) {
+        return new RegularDescriptionStatement(ctx, substatements);
+    }
+
+    @Override
+    protected DescriptionStatement createEmptyDeclared(final StmtContext<String, DescriptionStatement, ?> ctx) {
+        return new EmptyDescriptionStatement(ctx);
+    }
+
+    @Override
+    protected DescriptionEffectiveStatement createEffective(
+            final StmtContext<String, DescriptionStatement, DescriptionEffectiveStatement> ctx,
+            final DescriptionStatement declared,
+            final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
+        return new RegularDescriptionEffectiveStatement(declared, substatements);
+    }
+
+    @Override
+    protected DescriptionEffectiveStatement createEmptyEffective(
+            final StmtContext<String, DescriptionStatement, DescriptionEffectiveStatement> ctx,
+            final DescriptionStatement declared) {
+        return new EmptyDescriptionEffectiveStatement(declared);
     }
-}
\ No newline at end of file
+}