Bug 6173: Allow refine statement to have no substatements
[yangtools.git] / yang / yang-parser-impl / src / main / java / org / opendaylight / yangtools / yang / parser / stmt / rfc6020 / NumericalRestrictionsImpl.java
index 2415db62d8f19319f5477331ac374299d45a6fc5..1620774b0db8900afff3bae90b7c6fd434a0a663 100644 (file)
@@ -1,4 +1,4 @@
-/**
+/*
  * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
  *
  * This program and the accompanying materials are made available under the
@@ -9,38 +9,55 @@ package org.opendaylight.yangtools.yang.parser.stmt.rfc6020;
 
 import org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping;
 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
-import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractStatementSupport;
-import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
-import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
-import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractDeclaredStatement;
 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;
+import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type.NumericalRestrictionsEffectiveStatementImpl;
 
-public class NumericalRestrictionsImpl extends AbstractDeclaredStatement<String> implements TypeStatement.NumericalRestrictions{
+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 AbstractStatementSupport<String,TypeStatement.NumericalRestrictions,EffectiveStatement<String,TypeStatement.NumericalRestrictions>> {
+    public static class Definition extends
+            AbstractStatementSupport<String, TypeStatement.NumericalRestrictions, EffectiveStatement<String, TypeStatement.NumericalRestrictions>> {
 
         public Definition() {
-            super(Rfc6020Mapping.RANGE);
+            super(Rfc6020Mapping.TYPE);
         }
 
-        @Override public String parseArgumentValue(StmtContext<?, ?, ?> ctx,
-                String value) throws SourceException {
+        @Override
+        public String parseArgumentValue(final StmtContext<?, ?, ?> ctx, final String value) {
             return value;
         }
 
-        @Override public TypeStatement.NumericalRestrictions createDeclared(
-                StmtContext<String, TypeStatement.NumericalRestrictions, ?> ctx) {
+        @Override
+        public TypeStatement.NumericalRestrictions createDeclared(
+                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) {
-            throw new UnsupportedOperationException();
+        @Override
+        public EffectiveStatement<String, TypeStatement.NumericalRestrictions> createEffective(
+                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);
         }
     }
 
@@ -51,7 +68,7 @@ public class NumericalRestrictionsImpl extends AbstractDeclaredStatement<String>
 
     @Override
     public RangeStatement getRange() {
-       return firstDeclared(RangeStatement.class);
+        return firstDeclared(RangeStatement.class);
     }
 
 }
\ No newline at end of file