Remove SchemaPath from TypeDefinition implementations
[yangtools.git] / yang / yang-parser-rfc7950 / src / main / java / org / opendaylight / yangtools / yang / parser / rfc7950 / stmt / type / AbstractLeafrefSpecificationSupport.java
index a889aac7e10ad3f17fb2438c263fbf350c42adff..1a2c910644ebec9cd4e800f446fadfa6158f343a 100644 (file)
@@ -16,14 +16,16 @@ import org.opendaylight.yangtools.yang.model.api.stmt.RequireInstanceEffectiveSt
 import org.opendaylight.yangtools.yang.model.api.stmt.TypeStatement.LeafrefSpecification;
 import org.opendaylight.yangtools.yang.model.util.type.BaseTypes;
 import org.opendaylight.yangtools.yang.model.util.type.LeafrefTypeBuilder;
-import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.BaseStatementSupport;
+import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractStatementSupport;
+import org.opendaylight.yangtools.yang.parser.spi.meta.CommonStmtCtx;
+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.source.SourceException;
 
-abstract class AbstractLeafrefSpecificationSupport
-        extends BaseStatementSupport<String, LeafrefSpecification, EffectiveStatement<String, LeafrefSpecification>> {
+abstract class AbstractLeafrefSpecificationSupport extends AbstractStatementSupport<String, LeafrefSpecification,
+            EffectiveStatement<String, LeafrefSpecification>> {
     AbstractLeafrefSpecificationSupport() {
-        super(YangStmtMapping.TYPE);
+        super(YangStmtMapping.TYPE, StatementPolicy.legacyDeclaredCopy());
     }
 
     @Override
@@ -34,7 +36,7 @@ abstract class AbstractLeafrefSpecificationSupport
     @Override
     protected final LeafrefSpecification createDeclared(final StmtContext<String, LeafrefSpecification, ?> ctx,
             final ImmutableList<? extends DeclaredStatement<?>> substatements) {
-        return new LeafrefSpecificationImpl(ctx, substatements);
+        return new LeafrefSpecificationImpl(ctx.getRawArgument(), substatements);
     }
 
     @Override
@@ -43,37 +45,33 @@ abstract class AbstractLeafrefSpecificationSupport
     }
 
     @Override
-    protected final EffectiveStatement<String, LeafrefSpecification> createEffective(
-            final StmtContext<String, LeafrefSpecification, EffectiveStatement<String, LeafrefSpecification>> ctx,
-            final LeafrefSpecification declared,
+    protected EffectiveStatement<String, LeafrefSpecification> createEffective(
+            final Current<String, LeafrefSpecification> stmt,
             final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
-        final LeafrefTypeBuilder builder = BaseTypes.leafrefTypeBuilder(ctx.getSchemaPath().get());
+        if (substatements.isEmpty()) {
+            throw noPath(stmt);
+        }
+
+        final LeafrefTypeBuilder builder = BaseTypes.leafrefTypeBuilder(stmt.argumentAsTypeQName());
 
-        for (final EffectiveStatement<?, ?> stmt : substatements) {
-            if (stmt instanceof PathEffectiveStatement) {
-                builder.setPathStatement(((PathEffectiveStatement) stmt).argument());
-            } else if (stmt instanceof RequireInstanceEffectiveStatement) {
-                builder.setRequireInstance(((RequireInstanceEffectiveStatement)stmt).argument());
+        for (final EffectiveStatement<?, ?> subStmt : substatements) {
+            if (subStmt instanceof PathEffectiveStatement) {
+                builder.setPathStatement(((PathEffectiveStatement) subStmt).argument());
+            } else if (subStmt instanceof RequireInstanceEffectiveStatement) {
+                builder.setRequireInstance(((RequireInstanceEffectiveStatement)subStmt).argument());
             }
         }
 
-        return new TypeEffectiveStatementImpl<>(declared, substatements, builder);
-    }
-
-    @Override
-    protected final EffectiveStatement<String, LeafrefSpecification> createEmptyEffective(
-            final StmtContext<String, LeafrefSpecification, EffectiveStatement<String, LeafrefSpecification>> ctx,
-            final LeafrefSpecification declared) {
-        throw noPath(ctx);
+        return new TypeEffectiveStatementImpl<>(stmt.declared(), substatements, builder);
     }
 
-    private static SourceException noPath(final StmtContext<?, ?, ?> ctx) {
+    private static SourceException noPath(final CommonStmtCtx stmt) {
         /*
          *  https://tools.ietf.org/html/rfc7950#section-9.12
          *
          *     When the type is "union", the "type" statement (Section 7.4) MUST be
          *     present.
          */
-        return new SourceException("A path statement has to be present", ctx.getStatementSourceReference());
+        return new SourceException("A path statement has to be present", stmt);
     }
 }
\ No newline at end of file