BUG-7052: Move qnameFromArgument to StmtContextUtils
[yangtools.git] / yang / yang-parser-impl / src / main / java / org / opendaylight / yangtools / yang / parser / stmt / rfc6020 / LeafrefSpecificationImpl.java
index c5dd0af72c197672cea7c2748c2cd622e5f2e79b..2526258c3993bc31c8dc1b0873c36aa43e005c4f 100644 (file)
@@ -7,10 +7,13 @@
  */
 package org.opendaylight.yangtools.yang.parser.stmt.rfc6020;
 
-import org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+import org.opendaylight.yangtools.yang.model.api.YangStmtMapping;
 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.PathStatement;
-import org.opendaylight.yangtools.yang.model.api.stmt.TypeStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.RequireInstanceStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.TypeStatement.LeafrefSpecification;
 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;
@@ -18,59 +21,63 @@ import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type.LeafrefSpecificationEffectiveStatementImpl;
 
 public class LeafrefSpecificationImpl extends AbstractDeclaredStatement<String>
-        implements TypeStatement.LeafrefSpecification {
-    private static final SubstatementValidator SUBSTATEMENT_VALIDATOR = SubstatementValidator.builder(Rfc6020Mapping
+        implements LeafrefSpecification {
+    private static final SubstatementValidator SUBSTATEMENT_VALIDATOR = SubstatementValidator.builder(YangStmtMapping
             .TYPE)
-            .add(Rfc6020Mapping.PATH, 1, 1)
-            .add(Rfc6020Mapping.REQUIRE_INSTANCE, 0, 1)
+            .addMandatory(YangStmtMapping.PATH)
             .build();
 
     protected LeafrefSpecificationImpl(
-            StmtContext<String, TypeStatement.LeafrefSpecification, ?> context) {
+            final StmtContext<String, LeafrefSpecification, ?> context) {
         super(context);
     }
 
     public static class Definition
             extends
-            AbstractStatementSupport<String, TypeStatement.LeafrefSpecification, EffectiveStatement<String, TypeStatement.LeafrefSpecification>> {
+            AbstractStatementSupport<String, LeafrefSpecification, EffectiveStatement<String, LeafrefSpecification>> {
 
         public Definition() {
-            super(Rfc6020Mapping.TYPE);
+            super(YangStmtMapping.TYPE);
         }
 
         @Override
-        public String parseArgumentValue(StmtContext<?, ?, ?> ctx, String value) {
+        public String parseArgumentValue(final StmtContext<?, ?, ?> ctx, final String value) {
             return value;
         }
 
         @Override
-        public TypeStatement.LeafrefSpecification createDeclared(
-                StmtContext<String, TypeStatement.LeafrefSpecification, ?> ctx) {
+        public LeafrefSpecification createDeclared(final StmtContext<String, LeafrefSpecification, ?> ctx) {
             return new LeafrefSpecificationImpl(ctx);
         }
 
         @Override
-        public EffectiveStatement<String, TypeStatement.LeafrefSpecification> createEffective(
-                StmtContext<String, TypeStatement.LeafrefSpecification, EffectiveStatement<String, TypeStatement.LeafrefSpecification>> ctx) {
+        public EffectiveStatement<String, LeafrefSpecification> createEffective(
+                final StmtContext<String, LeafrefSpecification, EffectiveStatement<String, LeafrefSpecification>> ctx) {
             return new LeafrefSpecificationEffectiveStatementImpl(ctx);
         }
 
         @Override
-        public void onFullDefinitionDeclared(StmtContext.Mutable<String, LeafrefSpecification,
-                EffectiveStatement<String, LeafrefSpecification>> stmt) {
-            super.onFullDefinitionDeclared(stmt);
-            SUBSTATEMENT_VALIDATOR.validate(stmt);
+        protected SubstatementValidator getSubstatementValidator() {
+            return SUBSTATEMENT_VALIDATOR;
         }
     }
 
+    @Nonnull
     @Override
     public String getName() {
         return argument();
     }
 
+    @Nonnull
     @Override
     public PathStatement getPath() {
         return firstDeclared(PathStatement.class);
     }
 
+    @Nullable
+    @Override
+    public RequireInstanceStatement getRequireInstance() {
+        return firstDeclared(RequireInstanceStatement.class);
+    }
+
 }