2 * Copyright (c) 2020 PANTHEON.tech, s.r.o. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.yangtools.yang.parser.rfc7950.stmt.meta;
10 import static java.util.Objects.requireNonNull;
12 import com.google.common.collect.ImmutableList;
13 import java.util.stream.Collectors;
14 import java.util.stream.Stream;
15 import org.eclipse.jdt.annotation.NonNull;
16 import org.opendaylight.yangtools.yang.common.QName;
17 import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
18 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
19 import org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition;
20 import org.opendaylight.yangtools.yang.model.api.stmt.SchemaTreeEffectiveStatement;
21 import org.opendaylight.yangtools.yang.parser.api.YangParserConfiguration;
22 import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractSchemaTreeStatementSupport;
23 import org.opendaylight.yangtools.yang.parser.spi.meta.EffectiveStmtCtx.UndeclaredCurrent;
24 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
25 import org.opendaylight.yangtools.yang.parser.spi.meta.SubstatementValidator;
26 import org.opendaylight.yangtools.yang.parser.spi.meta.UndeclaredStatementFactory;
29 * A massively-misnamed superclass for statements which are both schema tree participants and can be created as implicit
30 * nodes. This covers {@code case}, {@code input} and {@code output} statements.
32 * @param <D> Declared Statement representation
33 * @param <E> Effective Statement representation
35 abstract class AbstractImplicitStatementSupport<D extends DeclaredStatement<QName>,
36 E extends SchemaTreeEffectiveStatement<D>> extends AbstractSchemaTreeStatementSupport<D, E>
37 implements UndeclaredStatementFactory<QName, D, E> {
38 AbstractImplicitStatementSupport(final StatementDefinition publicDefinition, final StatementPolicy<QName, D> policy,
39 final YangParserConfiguration config, final SubstatementValidator validator) {
40 super(publicDefinition, policy, config, requireNonNull(validator));
44 public final E createUndeclaredEffective(final UndeclaredCurrent<QName, D> stmt,
45 final @NonNull Stream<? extends StmtContext<?, ?, ?>> effectiveSubstatements) {
46 return createUndeclaredEffective(stmt, buildEffectiveSubstatements(stmt,
47 statementsToBuild(stmt, effectiveSubstatements
48 .filter(StmtContext::isSupportedToBuildEffective)
49 .collect(Collectors.toUnmodifiableList()))));
52 abstract @NonNull E createUndeclaredEffective(@NonNull UndeclaredCurrent<QName, D> stmt,
53 @NonNull ImmutableList<? extends EffectiveStatement<?, ?>> substatements);