Retain DeclarationReference in DeclaredStatements
[yangtools.git] / yang / yang-parser-rfc7950 / src / main / java / org / opendaylight / yangtools / yang / parser / rfc7950 / stmt / notification / AbstractNotificationStatementSupport.java
index e90d20cdec6fe5899952568a37cedc8a1fe39ae4..ed1cfbeaa00d8c592d06ef5e1083dbd5cdb901ed 100644 (file)
@@ -9,69 +9,57 @@ package org.opendaylight.yangtools.yang.parser.rfc7950.stmt.notification;
 
 import com.google.common.collect.ImmutableList;
 import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.model.api.Status;
 import org.opendaylight.yangtools.yang.model.api.YangStmtMapping;
+import org.opendaylight.yangtools.yang.model.api.meta.DeclarationReference;
 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.NotificationEffectiveStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.NotificationStatement;
-import org.opendaylight.yangtools.yang.model.api.stmt.StatusEffectiveStatement;
-import org.opendaylight.yangtools.yang.parser.rfc7950.namespace.ChildSchemaNodeNamespace;
-import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.BaseQNameStatementSupport;
-import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.EffectiveStatementMixins.EffectiveStatementWithFlags.FlagsBuilder;
+import org.opendaylight.yangtools.yang.model.parser.api.YangParserConfiguration;
+import org.opendaylight.yangtools.yang.model.ri.stmt.DeclaredStatementDecorators;
+import org.opendaylight.yangtools.yang.model.ri.stmt.DeclaredStatements;
+import org.opendaylight.yangtools.yang.model.ri.stmt.EffectiveStatements;
+import org.opendaylight.yangtools.yang.model.spi.meta.EffectiveStatementMixins;
+import org.opendaylight.yangtools.yang.model.spi.meta.SubstatementIndexingException;
+import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractSchemaTreeStatementSupport;
+import org.opendaylight.yangtools.yang.parser.spi.meta.EffectiveStmtCtx.Current;
 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.source.SourceException;
 
 abstract class AbstractNotificationStatementSupport
-        extends BaseQNameStatementSupport<NotificationStatement, NotificationEffectiveStatement> {
-    AbstractNotificationStatementSupport() {
-        super(YangStmtMapping.NOTIFICATION);
-    }
-
-    @Override
-    public final QName parseArgumentValue(final StmtContext<?, ?, ?> ctx, final String value) {
-        return StmtContextUtils.parseIdentifier(ctx, value);
-    }
-
-    @Override
-    public final void onStatementAdded(
-            final Mutable<QName, NotificationStatement, NotificationEffectiveStatement> stmt) {
-        stmt.coerceParentContext().addToNs(ChildSchemaNodeNamespace.class, stmt.coerceStatementArgument(), stmt);
+        extends AbstractSchemaTreeStatementSupport<NotificationStatement, NotificationEffectiveStatement> {
+    AbstractNotificationStatementSupport(final YangParserConfiguration config) {
+        super(YangStmtMapping.NOTIFICATION, uninstantiatedPolicy(), config);
     }
 
     @Override
     protected final NotificationStatement createDeclared(final StmtContext<QName, NotificationStatement, ?> ctx,
             final ImmutableList<? extends DeclaredStatement<?>> substatements) {
-        return new RegularNotificationStatement(ctx.coerceStatementArgument(), substatements);
+        return DeclaredStatements.createNotification(ctx.getArgument(), substatements);
     }
 
     @Override
-    protected final NotificationStatement createEmptyDeclared(final StmtContext<QName, NotificationStatement, ?> ctx) {
-        return new EmptyNotificationStatement(ctx.coerceStatementArgument());
+    protected final NotificationStatement attachDeclarationReference(final NotificationStatement stmt,
+            final DeclarationReference reference) {
+        return DeclaredStatementDecorators.decorateNotification(stmt, reference);
     }
 
     @Override
-    protected final NotificationEffectiveStatement createEffective(
-            final StmtContext<QName, NotificationStatement, NotificationEffectiveStatement> ctx,
-            final NotificationStatement declared,
+    protected final NotificationEffectiveStatement createEffective(final Current<QName, NotificationStatement> stmt,
             final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
-        checkEffective(ctx);
-
-        final int flags = new FlagsBuilder()
-                .setHistory(ctx.getCopyHistory())
-                .setStatus(findFirstArgument(substatements, StatusEffectiveStatement.class, Status.CURRENT))
-                .toFlags();
-
-        return new NotificationEffectiveStatementImpl(declared, flags, ctx, substatements);
+        try {
+            return EffectiveStatements.createNotification(stmt.declared(), stmt.effectivePath(),
+                EffectiveStatementMixins.historyAndStatusFlags(stmt.history(), substatements), substatements);
+        } catch (SubstatementIndexingException e) {
+            throw new SourceException(e.getMessage(), stmt, e);
+        }
     }
 
     @Override
-    protected final NotificationEffectiveStatement createEmptyEffective(
-            final StmtContext<QName, NotificationStatement, NotificationEffectiveStatement> ctx,
-            final NotificationStatement declared) {
-        return createEffective(ctx, declared, ImmutableList.of());
+    // FIXME: propagate original?
+    public final NotificationEffectiveStatement copyEffective(final Current<QName, NotificationStatement> stmt,
+            final NotificationEffectiveStatement original) {
+        return EffectiveStatements.copyNotification(original, stmt.effectivePath(),
+            EffectiveStatementMixins.historyAndStatusFlags(stmt.history(), original.effectiveSubstatements()));
     }
-
-    abstract void checkEffective(StmtContext<QName, NotificationStatement, NotificationEffectiveStatement> ctx);
 }
\ No newline at end of file