Migrate rawStatementArgument()/getStatementSourceReference() callers
[yangtools.git] / yang / yang-parser-rfc7950 / src / main / java / org / opendaylight / yangtools / yang / parser / rfc7950 / stmt / unique / UniqueStatementSupport.java
index 8f0cd2476bfef31eec071161c830c8b4be239c8a..5e6763204af26b2004f6c15d12ab15573839789e 100644 (file)
@@ -24,6 +24,7 @@ import org.opendaylight.yangtools.yang.model.api.stmt.UniqueEffectiveStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.UniqueStatement;
 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.ArgumentUtils;
 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.SubstatementValidator;
 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
@@ -54,9 +55,9 @@ public final class UniqueStatementSupport
     @Override
     public ImmutableSet<Descendant> parseArgumentValue(final StmtContext<?, ?, ?> ctx, final String value) {
         final ImmutableSet<Descendant> uniqueConstraints = parseUniqueConstraintArgument(ctx, value);
-        SourceException.throwIf(uniqueConstraints.isEmpty(), ctx.getStatementSourceReference(),
-                "Invalid argument value '%s' of unique statement. The value must contains at least "
-                        + "one descendant schema node identifier.", value);
+        SourceException.throwIf(uniqueConstraints.isEmpty(), ctx.sourceReference(),
+            "Invalid argument value '%s' of unique statement. The value must contains at least one descendant schema "
+                + "node identifier.", value);
         return uniqueConstraints;
     }
 
@@ -78,17 +79,11 @@ public final class UniqueStatementSupport
     }
 
     @Override
-    protected UniqueEffectiveStatement createEffective(
-            final StmtContext<Set<Descendant>, UniqueStatement, UniqueEffectiveStatement> ctx,
-            final UniqueStatement declared, final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
-        return new RegularUniqueEffectiveStatement(declared, substatements);
-    }
+    protected UniqueEffectiveStatement createEffective(final Current<Set<Descendant>, UniqueStatement> stmt,
+            final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
+        return substatements.isEmpty() ? new EmptyUniqueEffectiveStatement(stmt.declared())
+            : new RegularUniqueEffectiveStatement(stmt.declared(), substatements);
 
-    @Override
-    protected UniqueEffectiveStatement createEmptyEffective(
-            final StmtContext<Set<Descendant>, UniqueStatement, UniqueEffectiveStatement> ctx,
-            final UniqueStatement declared) {
-        return new EmptyUniqueEffectiveStatement(declared);
     }
 
     private static ImmutableSet<Descendant> parseUniqueConstraintArgument(final StmtContext<?, ?, ?> ctx,
@@ -99,9 +94,9 @@ public final class UniqueStatementSupport
         final Set<Descendant> uniqueConstraintNodes = new HashSet<>();
         for (final String uniqueArgToken : SEP_SPLITTER.split(nocrlf)) {
             final SchemaNodeIdentifier nodeIdentifier = ArgumentUtils.nodeIdentifierFromPath(ctx, uniqueArgToken);
-            SourceException.throwIf(nodeIdentifier instanceof Absolute, ctx.getStatementSourceReference(),
-                    "Unique statement argument '%s' contains schema node identifier '%s' "
-                            + "which is not in the descendant node identifier form.", argumentValue, uniqueArgToken);
+            SourceException.throwIf(nodeIdentifier instanceof Absolute, ctx.sourceReference(),
+                "Unique statement argument '%s' contains schema node identifier '%s' which is not in the descendant "
+                    + "node identifier form.", argumentValue, uniqueArgToken);
             uniqueConstraintNodes.add((Descendant) nodeIdentifier);
         }
         return ImmutableSet.copyOf(uniqueConstraintNodes);