*/
package org.opendaylight.yangtools.yang.parser.spi.meta;
+import com.google.common.collect.Iterables;
+import com.google.common.collect.Streams;
import java.util.Collection;
import java.util.Map;
import java.util.Optional;
+import java.util.stream.Stream;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import org.opendaylight.yangtools.yang.common.QNameModule;
@Nonnull
Collection<? extends StmtContext<?, ?, ?>> effectiveSubstatements();
+ default Iterable<? extends StmtContext<?, ?, ?>> allSubstatements() {
+ return Iterables.concat(declaredSubstatements(), effectiveSubstatements());
+ }
+
+ default Stream<? extends StmtContext<?, ?, ?>> allSubstatementsStream() {
+ return Streams.concat(declaredSubstatements().stream(), effectiveSubstatements().stream());
+ }
+
/**
* Builds {@link DeclaredStatement} for statement context.
*/
import com.google.common.base.Splitter;
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableList;
-import com.google.common.collect.Iterables;
import java.util.Collection;
import java.util.Date;
import java.util.Optional;
public static <A, D extends DeclaredStatement<A>> A firstSubstatementAttributeOf(
final StmtContext<?, ?, ?> ctx, final Class<D> declaredType) {
- final A firstAttribute = firstAttributeOf(ctx.effectiveSubstatements(), declaredType);
- return firstAttribute != null ? firstAttribute : firstAttributeOf(ctx.declaredSubstatements(), declaredType);
+ return firstAttributeOf(ctx.allSubstatements(), declaredType);
}
@SuppressWarnings("unchecked")
}
private static void disallowIfFeatureAndWhenOnListKeys(final StmtContext<?, ?, ?> leafStmtCtx) {
- Iterables.concat(leafStmtCtx.declaredSubstatements(), leafStmtCtx.effectiveSubstatements()).forEach(
- leafSubstmtCtx -> {
+ leafStmtCtx.allSubstatements().forEach(leafSubstmtCtx -> {
final StatementDefinition statementDef = leafSubstmtCtx.getPublicDefinition();
SourceException.throwIf(YangStmtMapping.IF_FEATURE.equals(statementDef)
|| YangStmtMapping.WHEN.equals(statementDef), leafStmtCtx.getStatementSourceReference(),
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.Iterables;
import com.google.common.collect.Maps;
import java.util.HashMap;
import java.util.Map;
MissingSubstatementException {
final Map<StatementDefinition, Counter> stmtCounts = new HashMap<>();
- for (StmtContext<?, ?, ?> stmtCtx : Iterables.concat(ctx.declaredSubstatements(), ctx.effectiveSubstatements())) {
+ for (StmtContext<?, ?, ?> stmtCtx : ctx.allSubstatements()) {
stmtCounts.computeIfAbsent(stmtCtx.getPublicDefinition(), key -> new Counter()).increment();
}
package org.opendaylight.yangtools.yang.parser.stmt.rfc6020;
import com.google.common.base.Verify;
-import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import java.util.ArrayList;
import java.util.Collection;
-import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.regex.Pattern;
checkForMandatoryNodes(sourceCtx);
}
- final List<Mutable<?, ?, ?>> targetSubStatements = ImmutableList.<Mutable<?, ?, ?>>builder()
- .addAll(targetCtx.mutableDeclaredSubstatements()).addAll(targetCtx.mutableEffectiveSubstatements())
- .build();
-
- for (final Mutable<?, ?, ?> subStatement : targetSubStatements) {
+ for (final StmtContext<?, ?, ?> subStatement : targetCtx.allSubstatements()) {
final boolean sourceIsDataNode = DataDefinitionStatement.class.isAssignableFrom(sourceCtx
.getPublicDefinition().getDeclaredRepresentationClass());
final boolean targetIsDataNode = DataDefinitionStatement.class.isAssignableFrom(subStatement
* b) added to augment body also via uses of a grouping and
* such sub-statements are stored in effective sub-statements collection.
*/
- sourceCtx.declaredSubstatements().forEach(Definition::checkForMandatoryNodes);
- sourceCtx.effectiveSubstatements().forEach(Definition::checkForMandatoryNodes);
+ sourceCtx.allSubstatementsStream().forEach(Definition::checkForMandatoryNodes);
}
InferenceException.throwIf(StmtContextUtils.isMandatoryNode(sourceCtx),
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableMap.Builder;
import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.Iterables;
import java.util.Collection;
import java.util.Map;
import java.util.Objects;
final StatementDefinition stmtToBeAdded = stmtCtxToBeAdded.getPublicDefinition();
if (SINGLETON_STATEMENTS.contains(stmtToBeAdded) || YangStmtMapping.DEFAULT.equals(stmtToBeAdded)
&& YangStmtMapping.LEAF.equals(targetCtx.getPublicDefinition())) {
- final Iterable<StmtContext<?, ?, ?>> targetCtxSubstatements = Iterables.concat(
- targetCtx.declaredSubstatements(), targetCtx.effectiveSubstatements());
-
- for (final StmtContext<?, ?, ?> targetCtxSubstatement : targetCtxSubstatements) {
+ for (final StmtContext<?, ?, ?> targetCtxSubstatement : targetCtx.allSubstatements()) {
InferenceException.throwIf(stmtToBeAdded.equals(targetCtxSubstatement.getPublicDefinition()),
stmtCtxToBeAdded.getStatementSourceReference(), "Deviation cannot add substatement %s "
+ "to target node %s because it is already defined in target and can appear only once.",
public static void resolveUsesNode(
final Mutable<QName, UsesStatement, EffectiveStatement<QName, UsesStatement>> usesNode,
- final StatementContextBase<?, ?, ?> targetNodeStmtCtx) {
+ final StmtContext<?, ?, ?> targetNodeStmtCtx) {
for (final Mutable<?, ?, ?> subStmtCtx : usesNode.mutableDeclaredSubstatements()) {
if (StmtContextUtils.producesDeclared(subStmtCtx, RefineStatement.class)
&& areFeaturesSupported(subStmtCtx)) {
}
}
- private static boolean areFeaturesSupported(final Mutable<?, ?, ?> subStmtCtx) {
+ private static boolean areFeaturesSupported(final StmtContext<?, ?, ?> subStmtCtx) {
/*
* In case of Yang 1.1, checks whether features are supported.
*/
return !YangVersion.VERSION_1_1.equals(subStmtCtx.getRootVersion()) || subStmtCtx.isSupportedByFeatures();
}
- private static void performRefine(final Mutable<?, ?, ?> subStmtCtx,
- final StatementContextBase<?, ?, ?> usesParentCtx) {
+ private static void performRefine(final Mutable<?, ?, ?> subStmtCtx, final StmtContext<?, ?, ?> usesParentCtx) {
final Object refineArgument = subStmtCtx.getStatementArgument();
InferenceException.throwIf(!(refineArgument instanceof SchemaNodeIdentifier),
"Refine target node %s not found.", refineTargetNodeIdentifier);
if (StmtContextUtils.isUnknownStatement(refineTargetNodeCtx)) {
- LOG.debug(
- "Refine node '{}' in uses '{}' has target node unknown statement '{}'. Refine has been skipped. At line: {}",
- subStmtCtx.getStatementArgument(), subStmtCtx.getParentContext().getStatementArgument(),
- refineTargetNodeCtx.getStatementArgument(), subStmtCtx.getStatementSourceReference());
+ LOG.debug("Refine node '{}' in uses '{}' has target node unknown statement '{}'. "
+ + "Refine has been skipped. At line: {}", subStmtCtx.getStatementArgument(),
+ subStmtCtx.getParentContext().getStatementArgument(),
+ refineTargetNodeCtx.getStatementArgument(), subStmtCtx.getStatementSourceReference());
subStmtCtx.addAsEffectOfStatement(refineTargetNodeCtx);
return;
}
package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective;
import com.google.common.base.Optional;
-import java.util.Collection;
import java.util.Objects;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.ChoiceCaseNode;
this.original = (ChoiceCaseNode) ctx.getOriginalCtx().map(StmtContext::buildEffective).orElse(null);
if (ctx.isConfiguration()) {
- configuration = isAtLeastOneChildConfiguration(ctx.declaredSubstatements())
- || isAtLeastOneChildConfiguration(ctx.effectiveSubstatements());
+ configuration = ctx.allSubstatementsStream().anyMatch(StmtContext::isConfiguration);
} else {
configuration = false;
}
}
- private static boolean isAtLeastOneChildConfiguration(final Collection<? extends StmtContext<?, ?, ?>> children) {
- return children.stream().anyMatch(StmtContext::isConfiguration);
- }
-
@Override
public Optional<ChoiceCaseNode> getOriginal() {
return Optional.fromNullable(original);