import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Optional;
private final SubstatementValidator validator;
ListStatementSupport(final SubstatementValidator validator) {
- super(YangStmtMapping.LIST, StatementPolicy.legacyDeclaredCopy());
+ super(YangStmtMapping.LIST, instantiatedPolicy());
this.validator = requireNonNull(validator);
}
return new EmptyListStatement(ctx.getArgument());
}
+ @Override
+ public ListEffectiveStatement copyEffective(final Current<QName, ListStatement> stmt,
+ final ListEffectiveStatement original) {
+ final int flags = computeFlags(stmt, original.effectiveSubstatements());
+ if (original instanceof EmptyListEffectiveStatement) {
+ return new EmptyListEffectiveStatement((EmptyListEffectiveStatement) original, stmt.wrapSchemaPath(),
+ flags);
+ } else if (original instanceof RegularListEffectiveStatement) {
+ return new RegularListEffectiveStatement((RegularListEffectiveStatement) original, stmt.wrapSchemaPath(),
+ flags);
+ } else {
+ // Safe fallback
+ return super.copyEffective(stmt, original);
+ }
+ }
+
@Override
protected ListEffectiveStatement createEffective(final Current<QName, ListStatement> stmt,
final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
keyDefinition = ImmutableList.of();
}
- final EffectiveConfig configuration = stmt.effectiveConfig();
- final int flags = new FlagsBuilder()
- .setHistory(stmt.history())
- .setStatus(findFirstArgument(substatements, StatusEffectiveStatement.class, Status.CURRENT))
- .setConfiguration(configuration.asNullable())
- .setUserOrdered(findFirstArgument(substatements, OrderedByEffectiveStatement.class, Ordering.SYSTEM)
- .equals(Ordering.USER))
- .toFlags();
- if (configuration == EffectiveConfig.TRUE && keyDefinition.isEmpty() && isInstantied(stmt)) {
+ final int flags = computeFlags(stmt, substatements);
+ if (stmt.effectiveConfig() == EffectiveConfig.TRUE && keyDefinition.isEmpty() && isInstantied(stmt)) {
warnConfigList(stmt);
}
}
}
+ private static int computeFlags(final Current<?, ?> stmt,
+ final Collection<? extends EffectiveStatement<?, ?>> substatements) {
+ return new FlagsBuilder()
+ .setHistory(stmt.history())
+ .setStatus(findFirstArgument(substatements, StatusEffectiveStatement.class, Status.CURRENT))
+ .setConfiguration(stmt.effectiveConfig().asNullable())
+ .setUserOrdered(findFirstArgument(substatements, OrderedByEffectiveStatement.class, Ordering.SYSTEM)
+ .equals(Ordering.USER))
+ .toFlags();
+ }
+
private static void warnConfigList(final @NonNull Current<QName, ListStatement> stmt) {
final StatementSourceReference ref = stmt.sourceReference();
final Boolean warned = stmt.getFromNamespace(ConfigListWarningNamespace.class, ref);
import org.opendaylight.yangtools.yang.model.api.stmt.GroupingEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.LeafEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.LeafListEffectiveStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.ListEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.NotificationEffectiveStatement;
assertSame(contBar, grpBar);
}
+
+ @Test
+ public void testListStatementReuse() throws Exception {
+ final ModuleEffectiveStatement module = StmtTestUtils.parseYangSource("/bugs/YT1208/list.yang")
+ .getModuleStatements()
+ .get(QNameModule.create(URI.create("foo")));
+ assertNotNull(module);
+
+ final NotificationEffectiveStatement notif = module
+ .findFirstEffectiveSubstatement(NotificationEffectiveStatement.class).orElseThrow();
+
+ final ListEffectiveStatement grpBar = notif
+ .findFirstEffectiveSubstatement(GroupingEffectiveStatement.class).orElseThrow()
+ .findFirstEffectiveSubstatement(ListEffectiveStatement.class).orElseThrow();
+ final ListEffectiveStatement contBar = notif
+ .findFirstEffectiveSubstatement(ContainerEffectiveStatement.class).orElseThrow()
+ .findFirstEffectiveSubstatement(ListEffectiveStatement.class).orElseThrow();
+
+ assertSame(contBar, grpBar);
+ }
+
}