Reformulate StatementContextFactory.createEffective()
[yangtools.git] / yang / yang-parser-rfc7950 / src / main / java / org / opendaylight / yangtools / yang / parser / rfc7950 / stmt / notification / NotificationStatementRFC7950Support.java
index da275ebdfc24312728e6c26d19f15ce252190292..52c15dadcb0f5f5dab7e8fcd6daf60be0c021fb3 100644 (file)
@@ -9,16 +9,15 @@ package org.opendaylight.yangtools.yang.parser.rfc7950.stmt.notification;
 
 import com.google.common.annotations.Beta;
 import com.google.common.collect.ImmutableSet;
-import java.util.Set;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.model.api.YangStmtMapping;
-import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
 import org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition;
 import org.opendaylight.yangtools.yang.model.api.stmt.NotificationStatement;
-import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
+import org.opendaylight.yangtools.yang.parser.spi.meta.EffectiveStmtCtx.Current;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils;
 import org.opendaylight.yangtools.yang.parser.spi.meta.SubstatementValidator;
 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
+import org.opendaylight.yangtools.yang.parser.spi.source.StatementSourceReference;
 
 /**
  * Class providing necessary support for processing YANG 1.1 Notification
@@ -45,8 +44,8 @@ public final class NotificationStatementRFC7950Support extends AbstractNotificat
             .addAny(YangStmtMapping.USES)
             .build();
 
-    private static final Set<StatementDefinition> ILLEGAL_PARENTS = ImmutableSet.of(YangStmtMapping.NOTIFICATION,
-            YangStmtMapping.RPC, YangStmtMapping.ACTION);
+    private static final ImmutableSet<StatementDefinition> ILLEGAL_PARENTS = ImmutableSet.of(
+            YangStmtMapping.NOTIFICATION, YangStmtMapping.RPC, YangStmtMapping.ACTION);
     private static final NotificationStatementRFC7950Support INSTANCE = new NotificationStatementRFC7950Support();
 
     private NotificationStatementRFC7950Support() {
@@ -58,23 +57,22 @@ public final class NotificationStatementRFC7950Support extends AbstractNotificat
     }
 
     @Override
-    public EffectiveStatement<QName, NotificationStatement> createEffective(
-            final StmtContext<QName, NotificationStatement, EffectiveStatement<QName, NotificationStatement>> ctx) {
-        SourceException.throwIf(StmtContextUtils.hasAncestorOfType(ctx, ILLEGAL_PARENTS),
-            ctx.getStatementSourceReference(),
-            "Notification %s is defined within an rpc, action, or another notification",
-            ctx.getStatementArgument());
-        SourceException.throwIf(!StmtContextUtils.hasAncestorOfTypeWithChildOfType(ctx, YangStmtMapping.LIST,
-            YangStmtMapping.KEY), ctx.getStatementSourceReference(),
-            "Notification %s is defined within a list that has no key statement", ctx.getStatementArgument());
-        SourceException.throwIf(StmtContextUtils.hasParentOfType(ctx, YangStmtMapping.CASE),
-            ctx.getStatementSourceReference(), "Notification %s is defined within a case statement",
-            ctx.getStatementArgument());
-        return new NotificationEffectiveStatementImpl(ctx);
+    protected SubstatementValidator getSubstatementValidator() {
+        return SUBSTATEMENT_VALIDATOR;
     }
 
+
     @Override
-    protected SubstatementValidator getSubstatementValidator() {
-        return SUBSTATEMENT_VALIDATOR;
+    void checkEffective(final Current<QName, NotificationStatement> stmt) {
+        final QName argument = stmt.argument();
+        final StatementSourceReference ref = stmt.sourceReference();
+        final var rabbit = stmt.caerbannog();
+        SourceException.throwIf(StmtContextUtils.hasAncestorOfType(rabbit, ILLEGAL_PARENTS), ref,
+            "Notification %s is defined within an rpc, action, or another notification", argument);
+        SourceException.throwIf(
+            !StmtContextUtils.hasAncestorOfTypeWithChildOfType(rabbit, YangStmtMapping.LIST, YangStmtMapping.KEY), ref,
+            "Notification %s is defined within a list that has no key statement", argument);
+        SourceException.throwIf(StmtContextUtils.hasParentOfType(rabbit, YangStmtMapping.CASE), ref,
+            "Notification %s is defined within a case statement", argument);
     }
 }