Bug 4540: Yang parser exceptions should follow consistent path
[yangtools.git] / yang / yang-parser-impl / src / main / java / org / opendaylight / yangtools / yang / parser / stmt / reactor / StatementContextBase.java
index 59a22343e13743e8d9531faf92dea4059bc94adb..92b2d0bd37c8461dbf6c3ec1412688fe2ed2e9be 100644 (file)
@@ -167,12 +167,13 @@ public abstract class StatementContextBase<A, D extends DeclaredStatement<A>, E
     }
 
     StatementContextBase(final StatementContextBase<A, D, E> original) {
-        this.definition = Preconditions
-                .checkNotNull(original.definition, "Statement context definition cannot be null");
-        this.identifier = Preconditions
-                .checkNotNull(original.identifier, "Statement context identifier cannot be null");
+        this.definition = Preconditions.checkNotNull(original.definition,
+                "Statement context definition cannot be null copying from: %s", original.getStatementSourceReference());
+        this.identifier = Preconditions.checkNotNull(original.identifier,
+                "Statement context identifier cannot be null copying from: %s", original.getStatementSourceReference());
         this.statementDeclSource = Preconditions.checkNotNull(original.statementDeclSource,
-                "Statement context statementDeclSource cannot be null");
+                "Statement context statementDeclSource cannot be null copying from: %s",
+                original.getStatementSourceReference());
         this.completedPhase = null;
         this.copyHistory.add(TypeOfCopy.ORIGINAL);
     }
@@ -274,10 +275,10 @@ public abstract class StatementContextBase<A, D extends DeclaredStatement<A>, E
         final ModelProcessingPhase inProgressPhase = getRoot().getSourceContext().getInProgressPhase();
         Preconditions.checkState(inProgressPhase == ModelProcessingPhase.FULL_DECLARATION
                 || inProgressPhase == ModelProcessingPhase.EFFECTIVE_MODEL,
-                "Effective statement cannot be added in declared phase");
+                "Effective statement cannot be added in declared phase at: %s", getStatementSourceReference());
 
         effective.add(Preconditions.checkNotNull(substatement,
-                "StatementContextBase effective substatement cannot be null"));
+                "StatementContextBase effective substatement cannot be null at: %s", getStatementSourceReference()));
     }
 
     /**
@@ -294,10 +295,10 @@ public abstract class StatementContextBase<A, D extends DeclaredStatement<A>, E
 
         final ModelProcessingPhase inProgressPhase = getRoot().getSourceContext().getInProgressPhase();
         Preconditions.checkState(inProgressPhase != ModelProcessingPhase.EFFECTIVE_MODEL,
-                "Declared statement cannot be added in effective phase");
+                "Declared statement cannot be added in effective phase at: %s", getStatementSourceReference());
 
         declared.add(Preconditions.checkNotNull(substatement,
-                "StatementContextBase declared substatement cannot be null"));
+                "StatementContextBase declared substatement cannot be null at: %s", getStatementSourceReference()));
     }
 
     /**
@@ -382,7 +383,7 @@ public abstract class StatementContextBase<A, D extends DeclaredStatement<A>, E
 
         final SourceSpecificContext sourceContext = getRoot().getSourceContext();
         Preconditions.checkState(sourceContext.getInProgressPhase() != ModelProcessingPhase.EFFECTIVE_MODEL,
-                "Declared statements list cannot be cleared in effective phase");
+                "Declared statements list cannot be cleared in effective phase at: %s", getStatementSourceReference());
 
         declared.clear();
     }
@@ -518,8 +519,10 @@ public abstract class StatementContextBase<A, D extends DeclaredStatement<A>, E
      */
     void addPhaseCompletedListener(final ModelProcessingPhase phase, final OnPhaseFinished listener) throws SourceException {
 
-        Preconditions.checkNotNull(phase, "Statement context processing phase cannot be null");
-        Preconditions.checkNotNull(listener, "Statement context phase listener cannot be null");
+        Preconditions.checkNotNull(phase, "Statement context processing phase cannot be null at: %s",
+                getStatementSourceReference());
+        Preconditions.checkNotNull(listener, "Statement context phase listener cannot be null at: %s",
+                getStatementSourceReference());
 
         ModelProcessingPhase finishedPhase = completedPhase;
         while (finishedPhase != null) {
@@ -542,7 +545,8 @@ public abstract class StatementContextBase<A, D extends DeclaredStatement<A>, E
         ModelProcessingPhase finishedPhase = completedPhase;
         while (finishedPhase != null) {
             if (phase.equals(finishedPhase)) {
-                throw new IllegalStateException("Mutation registered after phase was completed.");
+                throw new IllegalStateException("Mutation registered after phase was completed at: "  +
+                        getStatementSourceReference());
             }
             finishedPhase = finishedPhase.getPreviousPhase();
         }