BUG-2646: downgrade warnings to debug
[yangtools.git] / yang / yang-parser-impl / src / main / java / org / opendaylight / yangtools / yang / parser / stmt / rfc6020 / GroupingUtils.java
index e28a1c6bb90d65c0fe337d665cc5b83bd1fdb250..19d5be006ab0988fc3f3b8ebcbfbe8794dc123ea 100644 (file)
@@ -28,9 +28,13 @@ import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
 import org.opendaylight.yangtools.yang.parser.spi.validation.ValidationBundlesNamespace;
 import org.opendaylight.yangtools.yang.parser.spi.validation.ValidationBundlesNamespace.ValidationBundleType;
 import org.opendaylight.yangtools.yang.parser.stmt.reactor.StatementContextBase;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 public final class GroupingUtils {
 
+    private static final Logger LOG = LoggerFactory.getLogger(GroupingUtils.class);
+
     private GroupingUtils() {
         throw new UnsupportedOperationException();
     }
@@ -113,14 +117,14 @@ public final class GroupingUtils {
         return true;
     }
 
-    private static final Set<Rfc6020Mapping> NOCOPY_DEF_SET = ImmutableSet.of(
-        Rfc6020Mapping.USES, Rfc6020Mapping.TYPEDEF, Rfc6020Mapping.TYPE);
-    private static final Set<Rfc6020Mapping> NOCOPY_FROM_GROUPING_SET = ImmutableSet.of(
-        Rfc6020Mapping.DESCRIPTION, Rfc6020Mapping.REFERENCE);
-    private static final Set<Rfc6020Mapping> REUSED_DEF_SET = ImmutableSet.of(
-        Rfc6020Mapping.TYPEDEF, Rfc6020Mapping.TYPE, Rfc6020Mapping.USES);
-    private static final Set<Rfc6020Mapping> TOP_REUSED_DEF_SET = ImmutableSet.of(
-        Rfc6020Mapping.TYPEDEF, Rfc6020Mapping.TYPE);
+    private static final Set<Rfc6020Mapping> NOCOPY_DEF_SET = ImmutableSet.of(Rfc6020Mapping.USES,
+            Rfc6020Mapping.TYPEDEF, Rfc6020Mapping.TYPE);
+    private static final Set<Rfc6020Mapping> NOCOPY_FROM_GROUPING_SET = ImmutableSet.of(Rfc6020Mapping.DESCRIPTION,
+            Rfc6020Mapping.REFERENCE, Rfc6020Mapping.STATUS);
+    private static final Set<Rfc6020Mapping> REUSED_DEF_SET = ImmutableSet.of(Rfc6020Mapping.TYPEDEF,
+            Rfc6020Mapping.TYPE, Rfc6020Mapping.USES);
+    private static final Set<Rfc6020Mapping> TOP_REUSED_DEF_SET = ImmutableSet.of(Rfc6020Mapping.TYPEDEF,
+            Rfc6020Mapping.TYPE);
 
     public static boolean needToCopyByUses(final StmtContext<?, ?, ?> stmtContext) {
         final StatementDefinition def = stmtContext.getPublicDefinition();
@@ -159,6 +163,13 @@ public final class GroupingUtils {
         StatementContextBase<?, ?, ?> refineTargetNodeCtx = Utils.findNode(usesParentCtx, refineTargetNodeIdentifier);
         Preconditions.checkArgument(refineTargetNodeCtx != null, "Refine target node %s not found. At %s",
                 refineTargetNodeIdentifier, refineCtx.getStatementSourceReference());
+        if (StmtContextUtils.isUnknownStatement(refineTargetNodeCtx)) {
+            LOG.debug("Refine node '{}' in uses '{}' has target node unknown statement '{}'. Refine has been skipped. At line: {}",
+                    refineCtx.getStatementArgument(), refineCtx.getParentContext().getStatementArgument(), refineTargetNodeCtx.getStatementArgument(),
+                    refineCtx.getStatementSourceReference());
+            refineCtx.addAsEffectOfStatement(refineTargetNodeCtx);
+            return;
+        }
 
         addOrReplaceNodes(refineCtx, refineTargetNodeCtx);
         refineCtx.addAsEffectOfStatement(refineTargetNodeCtx);
@@ -177,17 +188,13 @@ public final class GroupingUtils {
             final StatementContextBase<?, ?, ?> refineTargetNodeCtx) {
 
         StatementDefinition refineSubstatementDef = refineSubstatementCtx.getPublicDefinition();
-        StatementDefinition refineTargetNodeDef = refineTargetNodeCtx.getPublicDefinition();
-
-        if (!isSupportedRefineTarget(refineSubstatementCtx, refineTargetNodeCtx)) {
-            throw new SourceException("Error in module '"
-                    + refineSubstatementCtx.getRoot().getStatementArgument()
-                    + "' in the refine of uses '"
-                    + refineSubstatementCtx.getParentContext().getStatementArgument()
-                    + "': can not perform refine of '" + refineSubstatementCtx.getPublicDefinition()
-                    + "' for the target '" + refineTargetNodeCtx.getPublicDefinition() + "'.",
-                    refineSubstatementCtx.getStatementSourceReference());
-        }
+
+        SourceException.throwIf(!isSupportedRefineTarget(refineSubstatementCtx, refineTargetNodeCtx),
+            refineSubstatementCtx.getStatementSourceReference(),
+            "Error in module '%s' in the refine of uses '%s': can not perform refine of '%s' for the target '%s'.",
+                    refineSubstatementCtx.getRoot().getStatementArgument(),
+                    refineSubstatementCtx.getParentContext().getStatementArgument(),
+                    refineSubstatementCtx.getPublicDefinition(), refineTargetNodeCtx.getPublicDefinition());
 
         if (isAllowedToAddByRefine(refineSubstatementDef)) {
             refineTargetNodeCtx.addEffectiveSubstatement(refineSubstatementCtx);