import org.opendaylight.yangtools.yang.parser.spi.meta.MissingSubstatementException;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
import org.opendaylight.yangtools.yang.parser.spi.source.ModuleCtxToModuleQName;
-import org.opendaylight.yangtools.yang.parser.stmt.reactor.StatementContextBase;
public final class SubstatementValidator {
/**
MissingSubstatementException {
final Map<StatementDefinition, Counter> stmtCounts = new HashMap<>();
- for (StatementContextBase<?, ?, ?> stmtCtx : Iterables.concat(ctx.declaredSubstatements(), ctx.effectiveSubstatements())) {
+ for (StmtContext<?, ?, ?> stmtCtx : Iterables.concat(ctx.declaredSubstatements(), ctx.effectiveSubstatements())) {
stmtCounts.computeIfAbsent(stmtCtx.getPublicDefinition(), key -> new Counter()).increment();
}
import org.opendaylight.yangtools.yang.model.api.meta.IdentifierNamespace;
import org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition;
import org.opendaylight.yangtools.yang.model.api.meta.StatementSource;
-import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
import org.opendaylight.yangtools.yang.parser.spi.source.StatementSourceReference;
import org.opendaylight.yangtools.yang.parser.stmt.reactor.StatementContextBase;
* @return Collection of declared substatements
*/
@Nonnull
- Collection<StatementContextBase<?, ?, ?>> declaredSubstatements();
+ Collection<? extends StmtContext<?, ?, ?>> declaredSubstatements();
/**
* Return effective substatements. These are the statements which are added as this statement's substatements
* @return Collection of declared substatements
*/
@Nonnull
- Collection<StatementContextBase<?, ?, ?>> effectiveSubstatements();
+ Collection<? extends StmtContext<?, ?, ?>> effectiveSubstatements();
/**
* Builds {@link DeclaredStatement} for statement context.
boolean isSupportedToBuildEffective();
- void setIsSupportedToBuildEffective(boolean isSupportedToBuild);
+ Collection<? extends StmtContext<?, ?, ?>> getEffectOfStatement();
- Collection<StatementContextBase<?, ?, ?>> getEffectOfStatement();
+ StatementContextBase<A, D, E> createCopy(StatementContextBase<?, ?, ?> newParent, CopyType typeOfCopy);
- void addAsEffectOfStatement(StatementContextBase<?, ?, ?> ctx);
-
- void addAsEffectOfStatement(Collection<StatementContextBase<?, ?, ?>> ctxs);
-
- StatementContextBase<?, ?, ?> createCopy(
- StatementContextBase<?, ?, ?> newParent, CopyType typeOfCopy)
- throws SourceException;
-
- StatementContextBase<?, ?, ?> createCopy(QNameModule newQNameModule,
- StatementContextBase<?, ?, ?> newParent, CopyType typeOfCopy)
- throws SourceException;
+ StatementContextBase<A, D, E> createCopy(QNameModule newQNameModule, StatementContextBase<?, ?, ?> newParent,
+ CopyType typeOfCopy);
CopyHistory getCopyHistory();
- enum SupportedByFeatures {
- UNDEFINED, SUPPORTED, NOT_SUPPORTED
- }
-
- SupportedByFeatures getSupportedByFeatures();
-
- void appendCopyHistory(CopyType typeOfCopy, CopyHistory toAppend);
+ boolean isSupportedByFeatures();
- StatementContextBase<?, ?, ?> getOriginalCtx();
-
- void setOriginalCtx(StatementContextBase<?, ?, ?> originalCtx);
+ StmtContext<?, ?, ?> getOriginalCtx();
boolean isRootContext();
- void setOrder(int order);
-
int getOrder();
- void setCompletedPhase(ModelProcessingPhase completedPhase);
-
ModelProcessingPhase getCompletedPhase();
/**
@Override
StmtContext.Mutable<?, ?, ?> getRoot();
+ @Override
+ @Nonnull
+ Collection<StatementContextBase<?, ?, ?>> declaredSubstatements();
+
+ @Override
+ @Nonnull
+ Collection<StatementContextBase<?, ?, ?>> effectiveSubstatements();
+
/**
* Create a new inference action to be executed during specified phase. The action cannot be cancelled
* and will be executed even if its definition remains incomplete.
<K, KT extends K, N extends StatementNamespace<K, ?, ?>> void addContext(
Class<N> namespace, KT key, StmtContext<?, ?, ?> stmt);
- void setSupportedByFeatures(boolean isSupported);
-
/**
* Set version of root statement context.
*
*/
void addRequiredModule(ModuleIdentifier dependency);
+ void addAsEffectOfStatement(StmtContext<?, ?, ?> ctx);
+
+ void addAsEffectOfStatement(Collection<? extends StmtContext<?, ?, ?>> ctxs);
+
/**
* Set identifier of current root context.
*
* of current root context
*/
void setRootIdentifier(ModuleIdentifier identifier);
+
+ void setIsSupportedToBuildEffective(boolean isSupportedToBuild);
+
+ void appendCopyHistory(CopyType typeOfCopy, CopyHistory toAppend);
+
+ void setOriginalCtx(StmtContext<?, ?, ?> originalCtx);
+
+ void setOrder(int order);
+
+ // FIXME: this seems to be unused, but looks useful.
+ void setCompletedPhase(ModelProcessingPhase completedPhase);
}
}
import org.opendaylight.yangtools.yang.model.api.stmt.PresenceStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier;
import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
-import org.opendaylight.yangtools.yang.parser.spi.source.SupportedFeaturesNamespace;
-import org.opendaylight.yangtools.yang.parser.spi.source.SupportedFeaturesNamespace.SupportedFeatures;
import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.UnknownStatementImpl;
import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangDataStatementImpl;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
public final class StmtContextUtils {
+ private static final Logger LOG = LoggerFactory.getLogger(StmtContextUtils.class);
+
public static final Splitter LIST_KEY_SPLITTER = Splitter.on(' ').omitEmptyStrings().trimResults();
private StmtContextUtils() {
return replaced ? builder.build() : keyStmtCtx.getStatementArgument();
}
- public static boolean areFeaturesSupported(final StmtContext.Mutable<?, ?, ?> stmtContext) {
- switch (stmtContext.getSupportedByFeatures()) {
- case SUPPORTED:
- return true;
- case NOT_SUPPORTED:
- return false;
- default:
- break;
- }
-
- final Set<QName> supportedFeatures = stmtContext.getFromNamespace(SupportedFeaturesNamespace.class,
- SupportedFeatures.SUPPORTED_FEATURES);
- /*
- * If set of supported features has not been provided, all features are
- * supported by default.
- */
- if (supportedFeatures == null) {
- stmtContext.setSupportedByFeatures(true);
- return true;
- }
-
- final boolean result = checkFeatureSupport(stmtContext, supportedFeatures);
- stmtContext.setSupportedByFeatures(result);
- return result;
- }
-
- private static boolean checkFeatureSupport(final StmtContext.Mutable<?, ?, ?> stmtContext,
+ public static boolean checkFeatureSupport(final StmtContext<?, ?, ?> stmtContext,
final Set<QName> supportedFeatures) {
boolean isSupported = false;
boolean containsIfFeature = false;
import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour.Registry;
import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour.StorageNodeType;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
-import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils;
import org.opendaylight.yangtools.yang.parser.spi.source.IncludedModuleContext;
import org.opendaylight.yangtools.yang.parser.spi.source.StatementSourceReference;
final Collection<StatementContextBase<?, ?, ?>> buffer = new ArrayList<>(declared.size() + effective.size());
for (final StatementContextBase<?, ?, ?> stmtContext : declared) {
- if (StmtContextUtils.areFeaturesSupported(stmtContext)) {
+ if (stmtContext.isSupportedByFeatures()) {
buffer.add(stmtContext.createCopy(newQNameModule, this, typeOfCopy));
}
}
* @throws org.opendaylight.yangtools.yang.parser.spi.source.SourceException instance of SourceException
*/
@Override
- public StatementContextBase<?, ?, ?> createCopy(final StatementContextBase<?, ?, ?> newParent,
+ public StatementContextBase<A, D, E> createCopy(final StatementContextBase<?, ?, ?> newParent,
final CopyType typeOfCopy) {
return createCopy(null, newParent, typeOfCopy);
}
import java.util.EventListener;
import java.util.Iterator;
import java.util.Optional;
+import java.util.Set;
import javax.annotation.Nonnull;
+import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.meta.IdentifierNamespace;
import org.opendaylight.yangtools.yang.parser.spi.meta.StatementNamespace;
import org.opendaylight.yangtools.yang.parser.spi.meta.StatementSupport;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils;
import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
import org.opendaylight.yangtools.yang.parser.spi.source.StatementSourceReference;
+import org.opendaylight.yangtools.yang.parser.spi.source.SupportedFeaturesNamespace;
+import org.opendaylight.yangtools.yang.parser.spi.source.SupportedFeaturesNamespace.SupportedFeatures;
import org.opendaylight.yangtools.yang.parser.stmt.reactor.NamespaceBehaviourWithListeners.ValueAddedListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public abstract class StatementContextBase<A, D extends DeclaredStatement<A>, E extends EffectiveStatement<A, D>>
extends NamespaceStorageSupport implements StmtContext.Mutable<A, D, E> {
-
/**
* event listener when an item is added to model namespace.
*/
private Multimap<ModelProcessingPhase, OnPhaseFinished> phaseListeners = ImmutableMultimap.of();
private Multimap<ModelProcessingPhase, ContextMutation> phaseMutation = ImmutableMultimap.of();
private Collection<StatementContextBase<?, ?, ?>> effective = ImmutableList.of();
- private Collection<StatementContextBase<?, ?, ?>> effectOfStatement = ImmutableList.of();
+ private Collection<StmtContext<?, ?, ?>> effectOfStatement = ImmutableList.of();
private StatementMap substatements = StatementMap.empty();
- private SupportedByFeatures supportedByFeatures = SupportedByFeatures.UNDEFINED;
+ private Boolean supportedByFeatures = null;
private CopyHistory copyHistory = CopyHistory.original();
private boolean isSupportedToBuildEffective = true;
private ModelProcessingPhase completedPhase = null;
- private StatementContextBase<?, ?, ?> originalCtx;
+ private StmtContext<?, ?, ?> originalCtx;
private D declaredInstance;
private E effectiveInstance;
private int order = 0;
}
@Override
- public Collection<StatementContextBase<?, ?, ?>> getEffectOfStatement() {
+ public Collection<? extends StmtContext<?, ?, ?>> getEffectOfStatement() {
return effectOfStatement;
}
@Override
- public void addAsEffectOfStatement(final StatementContextBase<?, ?, ?> ctx) {
+ public void addAsEffectOfStatement(final StmtContext<?, ?, ?> ctx) {
if (effectOfStatement.isEmpty()) {
effectOfStatement = new ArrayList<>(1);
}
}
@Override
- public void addAsEffectOfStatement(final Collection<StatementContextBase<?, ?, ?>> ctxs) {
+ public void addAsEffectOfStatement(final Collection<? extends StmtContext<?, ?, ?>> ctxs) {
if (ctxs.isEmpty()) {
return;
}
}
@Override
- public SupportedByFeatures getSupportedByFeatures() {
- return supportedByFeatures;
- }
+ public boolean isSupportedByFeatures() {
+ if (supportedByFeatures == null) {
+ final Set<QName> supportedFeatures = getFromNamespace(SupportedFeaturesNamespace.class,
+ SupportedFeatures.SUPPORTED_FEATURES);
+ // If the set of supported features has not been provided, all features are supported by default.
+ supportedByFeatures = supportedFeatures == null ? Boolean.TRUE
+ : StmtContextUtils.checkFeatureSupport(this, supportedFeatures);
+ }
- @Override
- public void setSupportedByFeatures(final boolean isSupported) {
- this.supportedByFeatures = isSupported ? SupportedByFeatures.SUPPORTED : SupportedByFeatures.NOT_SUPPORTED;
+ return supportedByFeatures.booleanValue();
}
@Override
}
@Override
- public StatementContextBase<?, ?, ?> getOriginalCtx() {
+ public StmtContext<?, ?, ?> getOriginalCtx() {
return originalCtx;
}
@Override
- public void setOriginalCtx(final StatementContextBase<?, ?, ?> originalCtx) {
+ public void setOriginalCtx(final StmtContext<?, ?, ?> originalCtx) {
this.originalCtx = originalCtx;
}
return Collections.unmodifiableCollection(effective);
}
- public void removeStatementsFromEffectiveSubstatements(final Collection<StatementContextBase<?, ?, ?>> substatements) {
+ public void removeStatementsFromEffectiveSubstatements(final Collection<? extends StmtContext<?, ?, ?>> substatements) {
if (!effective.isEmpty()) {
effective.removeAll(substatements);
shrinkEffective();
}
@Override
- public StatementContextBase<?, ?, ?> createCopy(final StatementContextBase<?, ?, ?> newParent,
+ public StatementContextBase<A, D, E> createCopy(final StatementContextBase<?, ?, ?> newParent,
final CopyType typeOfCopy) {
return createCopy(null, newParent, typeOfCopy);
}
final Collection<StatementContextBase<?, ?, ?>> buffer = new ArrayList<>(declared.size() + effective.size());
for (final StatementContextBase<?, ?, ?> stmtContext : declared) {
- if (StmtContextUtils.areFeaturesSupported(stmtContext)) {
+ if (stmtContext.isSupportedByFeatures()) {
copySubstatement(stmtContext, newQNameModule, typeOfCopy, buffer);
}
}
}
if (argument instanceof String) {
// FIXME: This may yield illegal argument exceptions
- final StatementContextBase<?, ?, ?> originalCtx = getOriginalCtx();
+ final StmtContext<?, ?, ?> originalCtx = getOriginalCtx();
final QName qname = originalCtx != null ? Utils.qNameFromArgument(originalCtx, (String) argument) : Utils
.qNameFromArgument(this, (String) argument);
return parentPath.createChild(qname);
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.source.AnyxmlSchemaLocationNamespace;
-import org.opendaylight.yangtools.yang.parser.stmt.reactor.StatementContextBase;
import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.AnyXmlEffectiveStatementImpl;
import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.YangModeledAnyXmlEffectiveStatementImpl;
private static Optional<ContainerSchemaNode> getAnyXmlSchema(
final StmtContext<QName, AnyxmlStatement, EffectiveStatement<QName, AnyxmlStatement>> ctx,
final SchemaNodeIdentifier contentSchemaPath) {
- final StatementContextBase<?, ?, ?> findNode = Utils.findNode(ctx.getRoot(), contentSchemaPath);
+ final StmtContext<?, ?, ?> findNode = Utils.findNode(ctx.getRoot(), contentSchemaPath);
if (findNode != null) {
final EffectiveStatement<?, ?> anyXmlSchemaNode = findNode.buildEffective();
if (anyXmlSchemaNode instanceof ContainerSchemaNode) {
@Override
public void onFullDefinitionDeclared(
final StmtContext.Mutable<SchemaNodeIdentifier, AugmentStatement, EffectiveStatement<SchemaNodeIdentifier, AugmentStatement>> augmentNode) {
- if (!StmtContextUtils.areFeaturesSupported(augmentNode)) {
+ if (!augmentNode.isSupportedByFeatures()) {
return;
}
final Collection<StatementContextBase<?, ?, ?>> buffer = new ArrayList<>(declared.size() + effective.size());
for (final StatementContextBase<?, ?, ?> originalStmtCtx : declared) {
- if (StmtContextUtils.areFeaturesSupported(originalStmtCtx)) {
+ if (originalStmtCtx.isSupportedByFeatures()) {
copyStatement(originalStmtCtx, targetCtx, typeOfCopy, buffer, skipCheckOfMandatoryNodes);
}
}
@Override
public void onFullDefinitionDeclared(
final StmtContext.Mutable<QName, UsesStatement, EffectiveStatement<QName, UsesStatement>> usesNode) {
- if (!StmtContextUtils.areFeaturesSupported(usesNode)) {
+ if (!usesNode.isSupportedByFeatures()) {
return;
}
super.onFullDefinitionDeclared(usesNode);
* @throws SourceException
* instance of SourceException
*/
- private static void copyFromSourceToTarget(final StmtContext<?, ?, ?> sourceGrpStmtCtx,
+ private static void copyFromSourceToTarget(final Mutable<?, ?, ?> sourceGrpStmtCtx,
final StatementContextBase<?, ?, ?> targetCtx,
final StmtContext.Mutable<QName, UsesStatement, EffectiveStatement<QName, UsesStatement>> usesNode) {
final Collection<StatementContextBase<?, ?, ?>> declared = sourceGrpStmtCtx.declaredSubstatements();
final QNameModule newQNameModule = getNewQNameModule(targetCtx, sourceGrpStmtCtx);
for (final StatementContextBase<?, ?, ?> original : declared) {
- if (StmtContextUtils.areFeaturesSupported(original)) {
+ if (original.isSupportedByFeatures()) {
copyStatement(original, targetCtx, newQNameModule, buffer);
}
}
/*
* In case of Yang 1.1, checks whether features are supported.
*/
- return !YangVersion.VERSION_1_1.equals(subStmtCtx.getRootVersion()) || StmtContextUtils
- .areFeaturesSupported(subStmtCtx);
+ return !YangVersion.VERSION_1_1.equals(subStmtCtx.getRootVersion()) || subStmtCtx.isSupportedByFeatures();
}
private static void performRefine(final StatementContextBase<?, ?, ?> refineCtx,
import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.CaseStatement;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
-import org.opendaylight.yangtools.yang.parser.stmt.reactor.StatementContextBase;
public final class CaseEffectiveStatementImpl extends AbstractEffectiveSimpleDataNodeContainer<CaseStatement> implements
ChoiceCaseNode, DerivableSchemaNode {
this.original = ctx.getOriginalCtx() == null ? null : (ChoiceCaseNode) ctx.getOriginalCtx().buildEffective();
if (ctx.isConfiguration()) {
- configuration = isAtLeastOneChildConfiguration(ctx.declaredSubstatements()) ||
- isAtLeastOneChildConfiguration(ctx.effectiveSubstatements());
+ configuration = isAtLeastOneChildConfiguration(ctx.declaredSubstatements())
+ || isAtLeastOneChildConfiguration(ctx.effectiveSubstatements());
} else {
configuration = false;
}
}
- private static boolean isAtLeastOneChildConfiguration(final Collection<StatementContextBase<?, ?, ?>> substatements) {
- for (StatementContextBase<?, ?, ?> substatement : substatements) {
- if (substatement.isConfiguration()) {
- return true;
- }
- }
- return false;
+ private static boolean isAtLeastOneChildConfiguration(final Collection<? extends StmtContext<?, ?, ?>> children) {
+ return children.stream().anyMatch(StmtContext::isConfiguration);
}
@Override
import java.util.List;
import java.util.Map;
import javax.annotation.Nonnull;
-import org.opendaylight.yangtools.yang.model.api.YangStmtMapping;
import org.opendaylight.yangtools.yang.model.api.SchemaNode;
+import org.opendaylight.yangtools.yang.model.api.YangStmtMapping;
import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.meta.IdentifierNamespace;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
-import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils;
import org.opendaylight.yangtools.yang.parser.stmt.reactor.StatementContextBase;
public abstract class EffectiveStatementBase<A, D extends DeclaredStatement<A>> implements EffectiveStatement<A, D> {
* context of statement.
*/
protected EffectiveStatementBase(final StmtContext<A, D, ?> ctx) {
- final Collection<StatementContextBase<?, ?, ?>> effectiveSubstatements = ctx.effectiveSubstatements();
- final Collection<StatementContextBase<?, ?, ?>> substatementsInit = new ArrayList<>();
+ final Collection<? extends StmtContext<?, ?, ?>> effectiveSubstatements = ctx.effectiveSubstatements();
+ final Collection<StmtContext<?, ?, ?>> substatementsInit = new ArrayList<>();
- final Collection<StatementContextBase<?, ?, ?>> supportedDeclaredSubStmts = Collections2.filter(
- ctx.declaredSubstatements(), StmtContextUtils::areFeaturesSupported);
- for (final StatementContextBase<?, ?, ?> declaredSubstatement : supportedDeclaredSubStmts) {
+ final Collection<? extends StmtContext<?, ?, ?>> supportedDeclaredSubStmts = Collections2.filter(
+ ctx.declaredSubstatements(), StmtContext::isSupportedByFeatures);
+ for (final StmtContext<?, ?, ?> declaredSubstatement : supportedDeclaredSubStmts) {
if (declaredSubstatement.getPublicDefinition().equals(YangStmtMapping.USES)) {
substatementsInit.add(declaredSubstatement);
substatementsInit.addAll(declaredSubstatement.getEffectOfStatement());
* @return Filtered substatements
*/
Collection<? extends EffectiveStatement<?, ?>> initSubstatements(
- final Collection<StatementContextBase<?, ?, ?>> substatementsInit) {
+ final Collection<? extends StmtContext<?, ?, ?>> substatementsInit) {
return Collections2.transform(Collections2.filter(substatementsInit,
- StmtContext::isSupportedToBuildEffective), StatementContextBase::buildEffective);
+ StmtContext::isSupportedToBuildEffective), StmtContext::buildEffective);
}
@Override
import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.ExtensionStatement;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
-import org.opendaylight.yangtools.yang.parser.stmt.reactor.StatementContextBase;
import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.RecursiveObjectLeaker;
public class ExtensionEffectiveStatementImpl extends AbstractEffectiveDocumentedNode<QName, ExtensionStatement>
final ExtensionEffectiveStatementImpl existing = RecursiveObjectLeaker.lookup(ctx,
ExtensionEffectiveStatementImpl.class);
if (existing != null) {
- // Careful! this not fully initialized!
+ // Careful! this object is not fully initialized!
return existing;
}
@Override
Collection<? extends EffectiveStatement<?, ?>> initSubstatements(
- final Collection<StatementContextBase<?, ?, ?>> substatementsInit) {
+ final Collection<? extends StmtContext<?, ?, ?>> substatementsInit) {
// WARNING: this leaks an incompletely-initialized object
RecursiveObjectLeaker.inConstructor(this);