Integrate {Inference,Source}Exception with CommonStmtCtx
[yangtools.git] / yang / yang-parser-rfc7950 / src / main / java / org / opendaylight / yangtools / yang / parser / rfc7950 / stmt / import_ / AbstractImportStatementSupport.java
index 56b122722493f40ce81701343dc6b01222c696d8..2ad26bad3b2a0ba3b5386a151852338c444f6d8f 100644 (file)
@@ -58,7 +58,7 @@ abstract class AbstractImportStatementSupport
          */
         stmt.addRequiredSource(RevisionImport.getImportedSourceIdentifier(stmt));
 
-        final String moduleName = stmt.coerceStatementArgument();
+        final String moduleName = stmt.getArgument();
         final ModelActionBuilder importAction = stmt.newInferenceAction(SOURCE_PRE_LINKAGE);
         final Prerequisite<StmtContext<?, ?, ?>> imported = importAction.requiresCtx(stmt,
                 PreLinkageModuleNamespace.class, moduleName, SOURCE_PRE_LINKAGE);
@@ -68,21 +68,21 @@ abstract class AbstractImportStatementSupport
             @Override
             public void apply(final InferenceContext ctx) {
                 final StmtContext<?, ?, ?> importedModuleContext = imported.resolve(ctx);
-                Verify.verify(moduleName.equals(importedModuleContext.coerceRawStatementArgument()));
+                Verify.verify(moduleName.equals(importedModuleContext.getRawArgument()));
                 final URI importedModuleNamespace = importedModuleContext.getFromNamespace(ModuleNameToNamespace.class,
                         moduleName);
                 Verify.verifyNotNull(importedModuleNamespace);
                 final String impPrefix = SourceException.throwIfNull(
-                    firstAttributeOf(stmt.declaredSubstatements(), PrefixStatement.class),
-                    stmt.getStatementSourceReference(), "Missing prefix statement");
+                    firstAttributeOf(stmt.declaredSubstatements(), PrefixStatement.class), stmt,
+                    "Missing prefix statement");
 
                 stmt.addToNs(ImpPrefixToNamespace.class, impPrefix, importedModuleNamespace);
             }
 
             @Override
             public void prerequisiteFailed(final Collection<? extends Prerequisite<?>> failed) {
-                InferenceException.throwIf(failed.contains(imported), stmt.getStatementSourceReference(),
-                        "Imported module [%s] was not found.", moduleName);
+                InferenceException.throwIf(failed.contains(imported), stmt, "Imported module [%s] was not found.",
+                    moduleName);
             }
         });
     }
@@ -99,7 +99,7 @@ abstract class AbstractImportStatementSupport
     @Override
     protected final ImportStatement createDeclared(final StmtContext<String, ImportStatement, ?> ctx,
             final ImmutableList<? extends DeclaredStatement<?>> substatements) {
-        return new ImportStatementImpl(ctx.coerceRawStatementArgument(), substatements);
+        return new ImportStatementImpl(ctx.getRawArgument(), substatements);
     }
 
     @Override
@@ -138,9 +138,9 @@ abstract class AbstractImportStatementSupport
             final String moduleName, final String prefix) {
         // When 'revision-date' of an import is not specified in yang source, we need to find revision of imported
         // module.
-        final QNameModule importedModule = StmtContextUtils.getModuleQNameByPrefix(ctx, prefix);
-        SourceException.throwIfNull(importedModule, ctx.sourceReference(),
-                "Unable to find import of module %s with prefix %s.", moduleName, prefix);
+        final QNameModule importedModule = SourceException.throwIfNull(
+            StmtContextUtils.getModuleQNameByPrefix(ctx, prefix), ctx,
+            "Unable to find import of module %s with prefix %s.", moduleName, prefix);
         return importedModule.getRevision().orElse(null);
     }
 }