Reformulate StatementContextFactory.createEffective()
[yangtools.git] / yang / odlext-parser-support / src / main / java / org / opendaylight / yangtools / odlext / parser / AnyxmlSchemaLocationStatementSupport.java
index 2b77f4f894d695dbf66ba7a8607844406d1b02f4..771a46b264a23b4dd42f5fe6a64e8d3c49416f7d 100644 (file)
@@ -9,19 +9,23 @@ package org.opendaylight.yangtools.odlext.parser;
 
 import static org.opendaylight.yangtools.odlext.model.api.OpenDaylightExtensionsStatements.ANYXML_SCHEMA_LOCATION;
 
+import com.google.common.collect.ImmutableList;
+import org.opendaylight.yangtools.odlext.model.api.AnyxmlSchemaLocationEffectiveStatement;
 import org.opendaylight.yangtools.odlext.model.api.AnyxmlSchemaLocationStatement;
+import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
 import org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition;
 import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier;
 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.ArgumentUtils;
-import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractStatementSupport;
+import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.BaseStatementSupport;
+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.StmtContext.Mutable;
 import org.opendaylight.yangtools.yang.parser.spi.meta.SubstatementValidator;
 
 public final class AnyxmlSchemaLocationStatementSupport
-        extends AbstractStatementSupport<SchemaNodeIdentifier, AnyxmlSchemaLocationStatement,
-            EffectiveStatement<SchemaNodeIdentifier, AnyxmlSchemaLocationStatement>> {
+        extends BaseStatementSupport<SchemaNodeIdentifier, AnyxmlSchemaLocationStatement,
+            AnyxmlSchemaLocationEffectiveStatement> {
     private static final AnyxmlSchemaLocationStatementSupport INSTANCE =
             new AnyxmlSchemaLocationStatementSupport(ANYXML_SCHEMA_LOCATION);
 
@@ -43,26 +47,34 @@ public final class AnyxmlSchemaLocationStatementSupport
 
     @Override
     public void onFullDefinitionDeclared(final Mutable<SchemaNodeIdentifier, AnyxmlSchemaLocationStatement,
-            EffectiveStatement<SchemaNodeIdentifier, AnyxmlSchemaLocationStatement>> stmt) {
+            AnyxmlSchemaLocationEffectiveStatement> stmt) {
         super.onFullDefinitionDeclared(stmt);
-        stmt.getParentContext().addToNs(AnyxmlSchemaLocationNamespace.class, ANYXML_SCHEMA_LOCATION, stmt);
+        stmt.coerceParentContext().addToNs(AnyxmlSchemaLocationNamespace.class, ANYXML_SCHEMA_LOCATION, stmt);
     }
 
     @Override
-    public AnyxmlSchemaLocationStatement createDeclared(
-            final StmtContext<SchemaNodeIdentifier, AnyxmlSchemaLocationStatement, ?> ctx) {
-        return new AnyxmlSchemaLocationStatementImpl(ctx);
+    protected SubstatementValidator getSubstatementValidator() {
+        return validator;
     }
 
     @Override
-    public EffectiveStatement<SchemaNodeIdentifier, AnyxmlSchemaLocationStatement> createEffective(
-            final StmtContext<SchemaNodeIdentifier, AnyxmlSchemaLocationStatement,
-            EffectiveStatement<SchemaNodeIdentifier, AnyxmlSchemaLocationStatement>> ctx) {
-        return new AnyxmlSchemaLocationEffectiveStatementImpl(ctx);
+    protected AnyxmlSchemaLocationStatement createDeclared(
+            final StmtContext<SchemaNodeIdentifier, AnyxmlSchemaLocationStatement, ?> ctx,
+            final ImmutableList<? extends DeclaredStatement<?>> substatements) {
+        return new AnyxmlSchemaLocationStatementImpl(ctx.coerceRawStatementArgument(), ctx.coerceStatementArgument(),
+            substatements);
     }
 
     @Override
-    protected SubstatementValidator getSubstatementValidator() {
-        return validator;
+    protected AnyxmlSchemaLocationStatement createEmptyDeclared(
+            final StmtContext<SchemaNodeIdentifier, AnyxmlSchemaLocationStatement, ?> ctx) {
+        return createDeclared(ctx, ImmutableList.of());
+    }
+
+    @Override
+    protected AnyxmlSchemaLocationEffectiveStatement createEffective(
+            final Current<SchemaNodeIdentifier, AnyxmlSchemaLocationStatement> stmt,
+            final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
+        return new AnyxmlSchemaLocationEffectiveStatementImpl(stmt, substatements);
     }
 }
\ No newline at end of file