Eliminate superfluous onFullDefinitionDeclared overrides
[yangtools.git] / yang / yang-parser-impl / src / main / java / org / opendaylight / yangtools / yang / parser / stmt / rfc6020 / KeyStatementImpl.java
index 6bb9679a142a265afda926caee7b0b887c12fe76..0ba28ac4015304447bf2b73ac226f1182367c703 100644 (file)
@@ -7,11 +7,10 @@
  */
 package org.opendaylight.yangtools.yang.parser.stmt.rfc6020;
 
-import com.google.common.base.Preconditions;
 import com.google.common.collect.ImmutableSet;
 import com.google.common.collect.ImmutableSet.Builder;
 import java.util.Collection;
-import org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping;
+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.KeyStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier;
@@ -25,7 +24,7 @@ import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.KeyEffectiv
 
 public class KeyStatementImpl extends AbstractDeclaredStatement<Collection<SchemaNodeIdentifier>> implements
         KeyStatement {
-    private static final SubstatementValidator SUBSTATEMENT_VALIDATOR = SubstatementValidator.builder(Rfc6020Mapping
+    private static final SubstatementValidator SUBSTATEMENT_VALIDATOR = SubstatementValidator.builder(YangStmtMapping
             .KEY)
             .build();
 
@@ -35,10 +34,11 @@ public class KeyStatementImpl extends AbstractDeclaredStatement<Collection<Schem
 
     public static class Definition
             extends
-            AbstractStatementSupport<Collection<SchemaNodeIdentifier>, KeyStatement, EffectiveStatement<Collection<SchemaNodeIdentifier>, KeyStatement>> {
+            AbstractStatementSupport<Collection<SchemaNodeIdentifier>, KeyStatement,
+                    EffectiveStatement<Collection<SchemaNodeIdentifier>, KeyStatement>> {
 
         public Definition() {
-            super(Rfc6020Mapping.KEY);
+            super(YangStmtMapping.KEY);
         }
 
         @Override
@@ -52,8 +52,8 @@ public class KeyStatementImpl extends AbstractDeclaredStatement<Collection<Schem
 
             // Throws NPE on nulls, retains first inserted value, cannot be modified
             final Collection<SchemaNodeIdentifier> ret = builder.build();
-
-            Preconditions.checkArgument(ret.size() == tokens, "Key argument '%s' contains duplicates", value);
+            SourceException.throwIf(ret.size() != tokens, ctx.getStatementSourceReference(),
+                    "Key argument '%s' contains duplicates", value);
             return ret;
         }
 
@@ -64,15 +64,14 @@ public class KeyStatementImpl extends AbstractDeclaredStatement<Collection<Schem
 
         @Override
         public EffectiveStatement<Collection<SchemaNodeIdentifier>, KeyStatement> createEffective(
-                final StmtContext<Collection<SchemaNodeIdentifier>, KeyStatement, EffectiveStatement<Collection<SchemaNodeIdentifier>, KeyStatement>> ctx) {
+                final StmtContext<Collection<SchemaNodeIdentifier>, KeyStatement,
+                        EffectiveStatement<Collection<SchemaNodeIdentifier>, KeyStatement>> ctx) {
             return new KeyEffectiveStatementImpl(ctx);
         }
 
         @Override
-        public void onFullDefinitionDeclared(StmtContext.Mutable<Collection<SchemaNodeIdentifier>, KeyStatement,
-                EffectiveStatement<Collection<SchemaNodeIdentifier>, KeyStatement>> stmt) throws SourceException {
-            super.onFullDefinitionDeclared(stmt);
-            SUBSTATEMENT_VALIDATOR.validate(stmt);
+        protected SubstatementValidator getSubstatementValidator() {
+            return SUBSTATEMENT_VALIDATOR;
         }
     }
 }