Centralize substatement validators
[yangtools.git] / yang / rfc6643-parser-support / src / main / java / org / opendaylight / yangtools / rfc6643 / parser / MaxAccessStatementSupport.java
index 6dd390a159769b1ac073be9c99ce243bf4932ce5..2d50afdea54cadc6ee7e78f1835b743ee37f113a 100644 (file)
@@ -13,33 +13,31 @@ import org.opendaylight.yangtools.rfc6643.model.api.IetfYangSmiv2ExtensionsMappi
 import org.opendaylight.yangtools.rfc6643.model.api.MaxAccess;
 import org.opendaylight.yangtools.rfc6643.model.api.MaxAccessEffectiveStatement;
 import org.opendaylight.yangtools.rfc6643.model.api.MaxAccessStatement;
+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.parser.rfc7950.stmt.BaseStatementSupport;
+import org.opendaylight.yangtools.yang.parser.api.YangParserConfiguration;
+import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractStatementSupport;
+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.SubstatementValidator;
 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
 
 @Beta
 public final class MaxAccessStatementSupport
-        extends BaseStatementSupport<MaxAccess, MaxAccessStatement, MaxAccessEffectiveStatement> {
-    private static final SubstatementValidator SUBSTATEMENT_VALIDATOR =
+        extends AbstractStatementSupport<MaxAccess, MaxAccessStatement, MaxAccessEffectiveStatement> {
+    private static final SubstatementValidator VALIDATOR =
             SubstatementValidator.builder(IetfYangSmiv2ExtensionsMapping.MAX_ACCESS).build();
-    private static final MaxAccessStatementSupport INSTANCE = new MaxAccessStatementSupport();
 
-    private MaxAccessStatementSupport() {
-        super(IetfYangSmiv2ExtensionsMapping.MAX_ACCESS);
-    }
-
-    public static MaxAccessStatementSupport getInstance() {
-        return INSTANCE;
+    public MaxAccessStatementSupport(final YangParserConfiguration config) {
+        super(IetfYangSmiv2ExtensionsMapping.MAX_ACCESS, StatementPolicy.contextIndependent(), config, VALIDATOR);
     }
 
     @Override
     public MaxAccess parseArgumentValue(final StmtContext<?, ?, ?> ctx, final String value) {
         final MaxAccess val = MaxAccess.forStringLiteral(value);
         if (val == null) {
-            throw new SourceException(ctx.getStatementSourceReference(), "Invalid max-access value '%s'", value);
+            throw new SourceException(ctx, "Invalid max-access value '%s'", value);
         }
         return val;
     }
@@ -50,33 +48,21 @@ public final class MaxAccessStatementSupport
         return val == null ? rawArgument : val.stringLiteral();
     }
 
-    @Override
-    protected SubstatementValidator getSubstatementValidator() {
-        return SUBSTATEMENT_VALIDATOR;
-    }
-
     @Override
     protected MaxAccessStatement createDeclared(final StmtContext<MaxAccess, MaxAccessStatement, ?> ctx,
             final ImmutableList<? extends DeclaredStatement<?>> substatements) {
-        return new MaxAccessStatementImpl(ctx.coerceStatementArgument(), substatements);
-    }
-
-    @Override
-    protected MaxAccessStatement createEmptyDeclared(final StmtContext<MaxAccess, MaxAccessStatement, ?> ctx) {
-        return createDeclared(ctx, ImmutableList.of());
+        return new MaxAccessStatementImpl(ctx.getArgument(), substatements);
     }
 
     @Override
-    protected MaxAccessEffectiveStatement createEffective(
-            final StmtContext<MaxAccess, MaxAccessStatement, MaxAccessEffectiveStatement> ctx,
-            final MaxAccessStatement declared, final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
-        return new MaxAccessEffectiveStatementImpl(ctx, substatements);
+    protected MaxAccessStatement attachDeclarationReference(final MaxAccessStatement stmt,
+            final DeclarationReference reference) {
+        return new RefMaxAccessStatement(stmt, reference);
     }
 
     @Override
-    protected MaxAccessEffectiveStatement createEmptyEffective(
-            final StmtContext<MaxAccess, MaxAccessStatement, MaxAccessEffectiveStatement> ctx,
-            final MaxAccessStatement declared) {
-        return createEffective(ctx, declared, ImmutableList.of());
+    protected MaxAccessEffectiveStatement createEffective(final Current<MaxAccess, MaxAccessStatement> stmt,
+            final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
+        return new MaxAccessEffectiveStatementImpl(stmt, substatements);
     }
 }
\ No newline at end of file