*/
package org.opendaylight.yangtools.yang.parser.rfc7950.stmt.list;
+import static com.google.common.base.Verify.verify;
+
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.Set;
+import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.ElementCountConstraint;
import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.Mutable;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils;
-import org.opendaylight.yangtools.yang.parser.spi.source.StatementSourceReference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
protected final ListEffectiveStatement createEffective(
final StmtContext<QName, ListStatement, ListEffectiveStatement> ctx,
final ListStatement declared, final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
- final StatementSourceReference ref = ctx.getStatementSourceReference();
final SchemaPath path = ctx.getSchemaPath().get();
final ListSchemaNode original = (ListSchemaNode) ctx.getOriginalCtx().map(StmtContext::buildEffective)
.orElse(null);
final QName keyQName = key.getLastComponent();
if (!possibleLeafQNamesForKey.contains(keyQName)) {
- throw new InferenceException(ref, "Key '%s' misses node '%s' in list '%s'",
- keyStmt.getDeclared().rawArgument(), keyQName.getLocalName(), ctx.getStatementArgument());
+ throw new InferenceException(ctx.getStatementSourceReference(),
+ "Key '%s' misses node '%s' in list '%s'", keyStmt.getDeclared().rawArgument(),
+ keyQName.getLocalName(), ctx.getStatementArgument());
}
keyDefinitionInit.add(keyQName);
}
.equals("user"))
.toFlags();
if (configuration && keyDefinition.isEmpty() && isInstantied(ctx)) {
- LOG.info("Configuration list {} does not define any keys in violation of RFC7950 section 7.8.2. While "
- + " this is fine with OpenDaylight, it can cause interoperability issues with other systems "
- + "[at {}]", ctx.getStatementArgument(), ref);
+ warnConfigList(ctx);
}
final Optional<ElementCountConstraint> elementCountConstraint =
elementCountConstraint.orElse(null), original);
}
+ private static void warnConfigList(final @NonNull StmtContext<QName, ListStatement, ListEffectiveStatement> ctx) {
+ final StmtContext<?, ?, ?> warnCtx = ctx.getOriginalCtx().orElse(ctx);
+ final Boolean warned = warnCtx.getFromNamespace(ConfigListWarningNamespace.class, Boolean.TRUE);
+ // Hacky check if we have issued a warning for the original statement
+ if (warned == null) {
+ verify(warnCtx instanceof Mutable, "Unexpected context %s", warnCtx);
+ ((Mutable<?, ?, ?>) warnCtx).addToNs(ConfigListWarningNamespace.class, Boolean.TRUE, Boolean.TRUE);
+ LOG.info("Configuration list {} does not define any keys in violation of RFC7950 section 7.8.2. While "
+ + "this is fine with OpenDaylight, it can cause interoperability issues with other systems "
+ + "[defined at {}]", ctx.getStatementArgument(), warnCtx.getStatementSourceReference());
+ }
+ }
+
private static boolean isInstantied(final StmtContext<?, ?, ?> ctx) {
for (StmtContext<?, ?, ?> parent = ctx.getParentContext(); parent != null; parent = parent.getParentContext()) {
if (UNINSTANTIATED_DATATREE_STATEMENTS.contains(parent.getPublicDefinition())) {