Bug 4646: Parser accepts invalid models
[yangtools.git] / yang / yang-parser-impl / src / main / java / org / opendaylight / yangtools / yang / parser / stmt / rfc6020 / NumericalRestrictionsImpl.java
index aacaa929746cb1bd215432779fe8f513d1b735bb..1620774b0db8900afff3bae90b7c6fd434a0a663 100644 (file)
@@ -11,6 +11,7 @@ import org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping;
 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.RangeStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.TypeStatement;
+import org.opendaylight.yangtools.yang.parser.spi.SubstatementValidator;
 import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractDeclaredStatement;
 import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractStatementSupport;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
@@ -19,13 +20,16 @@ import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type.Numeri
 
 public class NumericalRestrictionsImpl extends AbstractDeclaredStatement<String> implements
         TypeStatement.NumericalRestrictions {
+    private static final SubstatementValidator SUBSTATEMENT_VALIDATOR = SubstatementValidator.builder(Rfc6020Mapping
+            .TYPE)
+            .add(Rfc6020Mapping.RANGE, 1, 1)
+            .build();
 
-    protected NumericalRestrictionsImpl(StmtContext<String, TypeStatement.NumericalRestrictions, ?> context) {
+    protected NumericalRestrictionsImpl(final StmtContext<String, TypeStatement.NumericalRestrictions, ?> context) {
         super(context);
     }
 
-    public static class Definition
-            extends
+    public static class Definition extends
             AbstractStatementSupport<String, TypeStatement.NumericalRestrictions, EffectiveStatement<String, TypeStatement.NumericalRestrictions>> {
 
         public Definition() {
@@ -33,21 +37,28 @@ public class NumericalRestrictionsImpl extends AbstractDeclaredStatement<String>
         }
 
         @Override
-        public String parseArgumentValue(StmtContext<?, ?, ?> ctx, String value) {
+        public String parseArgumentValue(final StmtContext<?, ?, ?> ctx, final String value) {
             return value;
         }
 
         @Override
         public TypeStatement.NumericalRestrictions createDeclared(
-                StmtContext<String, TypeStatement.NumericalRestrictions, ?> ctx) {
+                final StmtContext<String, TypeStatement.NumericalRestrictions, ?> ctx) {
             return new NumericalRestrictionsImpl(ctx);
         }
 
         @Override
         public EffectiveStatement<String, TypeStatement.NumericalRestrictions> createEffective(
-                StmtContext<String, TypeStatement.NumericalRestrictions, EffectiveStatement<String, TypeStatement.NumericalRestrictions>> ctx) {
+                final StmtContext<String, TypeStatement.NumericalRestrictions, EffectiveStatement<String, TypeStatement.NumericalRestrictions>> ctx) {
             return new NumericalRestrictionsEffectiveStatementImpl(ctx);
         }
+
+        @Override
+        public void onFullDefinitionDeclared(StmtContext.Mutable<String, NumericalRestrictions,
+                EffectiveStatement<String, NumericalRestrictions>> stmt) throws SourceException {
+            super.onFullDefinitionDeclared(stmt);
+            SUBSTATEMENT_VALIDATOR.validate(stmt);
+        }
     }
 
     @Override