+ protected ListEffectiveStatement createEffective(final Current<QName, ListStatement> stmt,
+ final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
+ final SchemaPath path = stmt.getSchemaPath();
+ final ListSchemaNode original = (ListSchemaNode) stmt.original();
+
+ final ImmutableList<QName> keyDefinition;
+ final KeyEffectiveStatement keyStmt = findFirstStatement(substatements, KeyEffectiveStatement.class);
+ if (keyStmt != null) {
+ final List<QName> keyDefinitionInit = new ArrayList<>(keyStmt.argument().size());
+ final Set<QName> possibleLeafQNamesForKey = new HashSet<>();
+ for (final EffectiveStatement<?, ?> effectiveStatement : substatements) {
+ if (effectiveStatement instanceof LeafSchemaNode) {
+ possibleLeafQNamesForKey.add(((LeafSchemaNode) effectiveStatement).getQName());
+ }
+ }
+ for (final QName keyQName : keyStmt.argument()) {
+ if (!possibleLeafQNamesForKey.contains(keyQName)) {
+ throw new InferenceException(stmt.sourceReference(),
+ "Key '%s' misses node '%s' in list '%s'", keyStmt.getDeclared().rawArgument(),
+ keyQName.getLocalName(), stmt.argument());
+ }
+ keyDefinitionInit.add(keyQName);
+ }
+
+ keyDefinition = ImmutableList.copyOf(keyDefinitionInit);
+ } else {
+ keyDefinition = ImmutableList.of();
+ }
+
+ final boolean configuration = stmt.effectiveConfig();
+ final int flags = new FlagsBuilder()
+ .setHistory(stmt.history())
+ .setStatus(findFirstArgument(substatements, StatusEffectiveStatement.class, Status.CURRENT))
+ .setConfiguration(configuration)
+ .setUserOrdered(findFirstArgument(substatements, OrderedByEffectiveStatement.class, Ordering.SYSTEM)
+ .equals(Ordering.USER))
+ .toFlags();
+ if (configuration && keyDefinition.isEmpty() && isInstantied(stmt)) {
+ warnConfigList(stmt);
+ }
+
+ final Optional<ElementCountConstraint> elementCountConstraint =
+ EffectiveStmtUtils.createElementCountConstraint(substatements);
+ return original == null && !elementCountConstraint.isPresent()
+ ? new EmptyListEffectiveStatement(stmt, path, flags, substatements, keyDefinition)
+ : new RegularListEffectiveStatement(stmt, path, flags, substatements, keyDefinition,
+ elementCountConstraint.orElse(null), original);