Move findSubstatementArgument()/hasSubstatement() to BoundStmtCtx
[yangtools.git] / yang / yang-parser-spi / src / main / java / org / opendaylight / yangtools / yang / parser / spi / meta / StmtContextUtils.java
index e47b0052ecfe786424c43e219ba8c66cfdf18167..8aaad4478c78a9ba81d70d04fb717b69ed4c9b8b 100644 (file)
@@ -151,7 +151,7 @@ public final class StmtContextUtils {
      * @param <A> statement argument type
      * @param <D> declared statement type
      * @return statement context that was searched for or null if was not found
-     * @deprecated Use {@link StmtContext#findSubstatementArgument(Class)} instead.
+     * @deprecated Use {@link BoundStmtCtx#findSubstatementArgument(Class)} instead.
      */
     @Deprecated(forRemoval = true)
     public static <A, D extends DeclaredStatement<A>> StmtContext<A, ?, ?> findFirstSubstatement(
@@ -440,7 +440,7 @@ public final class StmtContextUtils {
     }
 
     private static boolean isRelevantForIfFeatureAndWhenOnListKeysCheck(final StmtContext<?, ?, ?> ctx) {
-        return YangVersion.VERSION_1_1.equals(ctx.getRootVersion()) && hasParentOfType(ctx, YangStmtMapping.LIST)
+        return YangVersion.VERSION_1_1.equals(ctx.yangVersion()) && hasParentOfType(ctx, YangStmtMapping.LIST)
                 && findFirstDeclaredSubstatement(ctx.coerceParentContext(), KeyStatement.class) != null;
     }
 
@@ -453,7 +453,7 @@ public final class StmtContextUtils {
         leafStmtCtx.allSubstatements().forEach(leafSubstmtCtx -> {
             final StatementDefinition statementDef = leafSubstmtCtx.publicDefinition();
             SourceException.throwIf(YangStmtMapping.IF_FEATURE.equals(statementDef)
-                    || YangStmtMapping.WHEN.equals(statementDef), leafStmtCtx.sourceReference(),
+                    || YangStmtMapping.WHEN.equals(statementDef), leafStmtCtx,
                     "%s statement is not allowed in %s leaf statement which is specified as a list key.",
                     statementDef.getStatementName(), leafStmtCtx.argument());
         });
@@ -483,13 +483,13 @@ public final class StmtContextUtils {
                     localName = value;
                     qnameModule = getRootModuleQName(ctx);
                 }
-                if (qnameModule == null && ctx.getCopyHistory().getLastOperation() == CopyType.ADDED_BY_AUGMENTATION) {
+                if (qnameModule == null && ctx.history().getLastOperation() == CopyType.ADDED_BY_AUGMENTATION) {
                     ctx = ctx.getOriginalCtx().orElse(null);
                     qnameModule = getModuleQNameByPrefix(ctx, prefix);
                 }
         }
 
-        return internedQName(ctx, InferenceException.throwIfNull(qnameModule, ctx.sourceReference(),
+        return internedQName(ctx, InferenceException.throwIfNull(qnameModule, ctx,
             "Cannot resolve QNameModule for '%s'", value), localName);
     }
 
@@ -503,14 +503,14 @@ public final class StmtContextUtils {
      * @throws SourceException if the string is not a valid YANG identifier
      */
     public static QName parseIdentifier(final StmtContext<?, ?, ?> ctx, final String str) {
-        SourceException.throwIf(str.isEmpty(), ctx.sourceReference(), "Identifier may not be an empty string");
+        SourceException.throwIf(str.isEmpty(), ctx, "Identifier may not be an empty string");
         return internedQName(ctx, str);
     }
 
     public static QName parseNodeIdentifier(final StmtContext<?, ?, ?> ctx, final String prefix,
             final String localName) {
         return internedQName(ctx,
-            InferenceException.throwIfNull(getModuleQNameByPrefix(ctx, prefix), ctx.sourceReference(),
+            InferenceException.throwIfNull(getModuleQNameByPrefix(ctx, prefix), ctx,
                 "Cannot resolve QNameModule for '%s'", prefix),
             localName);
     }
@@ -525,7 +525,7 @@ public final class StmtContextUtils {
      * @throws SourceException if the string is not a valid YANG node identifier
      */
     public static QName parseNodeIdentifier(final StmtContext<?, ?, ?> ctx, final String str) {
-        SourceException.throwIf(str.isEmpty(), ctx.sourceReference(), "Node identifier may not be an empty string");
+        SourceException.throwIf(str.isEmpty(), ctx, "Node identifier may not be an empty string");
 
         final int colon = str.indexOf(':');
         if (colon == -1) {
@@ -533,9 +533,9 @@ public final class StmtContextUtils {
         }
 
         final String prefix = str.substring(0, colon);
-        SourceException.throwIf(prefix.isEmpty(), ctx.sourceReference(), "String '%s' has an empty prefix", str);
+        SourceException.throwIf(prefix.isEmpty(), ctx, "String '%s' has an empty prefix", str);
         final String localName = str.substring(colon + 1);
-        SourceException.throwIf(localName.isEmpty(), ctx.sourceReference(), "String '%s' has an empty identifier", str);
+        SourceException.throwIf(localName.isEmpty(), ctx, "String '%s' has an empty identifier", str);
 
         return parseNodeIdentifier(ctx, prefix, localName);
     }
@@ -544,13 +544,13 @@ public final class StmtContextUtils {
         return internedQName(ctx, getRootModuleQName(ctx), localName);
     }
 
-    private static QName internedQName(final StmtContext<?, ?, ?> ctx, final QNameModule module,
+    private static QName internedQName(final CommonStmtCtx ctx, final QNameModule module,
             final String localName) {
         final QName template;
         try {
             template = QName.create(module, localName);
         } catch (IllegalArgumentException e) {
-            throw new SourceException(ctx.sourceReference(), e, "Invalid identifier '%s'", localName);
+            throw new SourceException(ctx, e, "Invalid identifier '%s'", localName);
         }
         return template.intern();
     }