import org.opendaylight.yangtools.yang.parser.spi.meta.StatementDefinitionNamespace;
import org.opendaylight.yangtools.yang.parser.spi.meta.StatementSupport;
import org.opendaylight.yangtools.yang.parser.spi.meta.StatementSupportBundle;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StatementSupportNamespace;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
import org.opendaylight.yangtools.yang.parser.spi.source.BelongsToModuleContext;
import org.opendaylight.yangtools.yang.parser.spi.source.BelongsToPrefixToModuleCtx;
FINISHED
}
+ private static final class SupportedStatements
+ extends NamespaceBehaviour<QName, StatementSupport<?, ?, ?>, StatementSupportNamespace> {
+ private final QNameToStatementDefinitionMap statementDefinitions;
+
+ SupportedStatements(final QNameToStatementDefinitionMap statementDefinitions) {
+ super(StatementSupportNamespace.class);
+ this.statementDefinitions = requireNonNull(statementDefinitions);
+ }
+
+ @Override
+ public StatementSupport<?, ?, ?> getFrom(final NamespaceStorageNode storage, final QName key) {
+ return statementDefinitions.get(key);
+ }
+
+ @Override
+ public Map<QName, StatementSupport<?, ?, ?>> getAllFrom(final NamespaceStorageNode storage) {
+ throw new UnsupportedOperationException("StatementSupportNamespace is immutable");
+ }
+
+ @Override
+ public void addTo(final NamespaceStorageNode storage, final QName key, final StatementSupport<?, ?, ?> value) {
+ throw new UnsupportedOperationException("StatementSupportNamespace is immutable");
+ }
+ }
+
private static final Logger LOG = LoggerFactory.getLogger(SourceSpecificContext.class);
// TODO: consider keying by Byte equivalent of ExecutionOrder
private final Multimap<ModelProcessingPhase, ModifierImpl> modifiers = HashMultimap.create();
private final QNameToStatementDefinitionMap qnameToStmtDefMap = new QNameToStatementDefinitionMap();
+ private final SupportedStatements statementSupports = new SupportedStatements(qnameToStmtDefMap);
private final PrefixToModuleMap prefixToModuleMap = new PrefixToModuleMap();
private final @NonNull BuildGlobalContext globalContext;
}
@Override
+ @SuppressWarnings("unchecked")
public <K, V, N extends ParserNamespace<K, V>> NamespaceBehaviour<K, V, N> getNamespaceBehaviour(
final Class<N> type) {
+ if (StatementSupportNamespace.class.equals(type)) {
+ return (NamespaceBehaviour<K, V, N>) statementSupports;
+ }
return globalContext.getNamespaceBehaviour(type);
}
private static StatementSupportBundle stmtDefBundle(final StatementSupportBundle linkageBundle,
final YangParserConfiguration config) {
- final InputStatementSupport rfc6020input = InputStatementSupport.rfc6020Instance(config);
- final InputStatementSupport rfc7950input = InputStatementSupport.rfc7950Instance(config);
- final OutputStatementSupport rfc6020output = OutputStatementSupport.rfc6020Instance(config);
- final OutputStatementSupport rfc7950output = OutputStatementSupport.rfc7950Instance(config);
-
return StatementSupportBundle.derivedFrom(linkageBundle)
.addSupport(new YinElementStatementSupport(config))
.addSupport(new ArgumentStatementSupport(config))
.addVersionSpecificSupport(VERSION_1_1, ListStatementSupport.rfc7950Instance(config))
.addSupport(ConfigListWarningNamespace.BEHAVIOUR)
.addSupport(new UniqueStatementSupport(config))
- .addVersionSpecificSupport(VERSION_1_1, new ActionStatementSupport(config, rfc7950input, rfc7950output))
- .addVersionSpecificSupport(VERSION_1, new RpcStatementSupport(config, rfc6020input, rfc6020output))
- .addVersionSpecificSupport(VERSION_1_1, new RpcStatementSupport(config, rfc7950input, rfc7950output))
- .addVersionSpecificSupport(VERSION_1, rfc6020input)
- .addVersionSpecificSupport(VERSION_1_1, rfc7950input)
- .addVersionSpecificSupport(VERSION_1, rfc6020output)
- .addVersionSpecificSupport(VERSION_1_1, rfc7950output)
+ .addVersionSpecificSupport(VERSION_1_1, new ActionStatementSupport(config))
+ .addVersionSpecificSupport(VERSION_1, new RpcStatementSupport(config))
+ .addVersionSpecificSupport(VERSION_1_1, new RpcStatementSupport(config))
+ .addVersionSpecificSupport(VERSION_1, InputStatementSupport.rfc6020Instance(config))
+ .addVersionSpecificSupport(VERSION_1_1, InputStatementSupport.rfc7950Instance(config))
+ .addVersionSpecificSupport(VERSION_1, OutputStatementSupport.rfc6020Instance(config))
+ .addVersionSpecificSupport(VERSION_1_1, OutputStatementSupport.rfc7950Instance(config))
.addVersionSpecificSupport(VERSION_1, new NotificationStatementRFC6020Support(config))
.addVersionSpecificSupport(VERSION_1_1, new NotificationStatementRFC7950Support(config))
.addSupport(new FractionDigitsStatementSupport(config))
package org.opendaylight.yangtools.yang.parser.rfc7950.stmt.meta;
import static com.google.common.base.Verify.verify;
-import static java.util.Objects.requireNonNull;
+import static com.google.common.base.Verify.verifyNotNull;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import org.opendaylight.yangtools.yang.parser.api.YangParserConfiguration;
import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractSchemaTreeStatementSupport;
import org.opendaylight.yangtools.yang.parser.spi.meta.EffectiveStmtCtx.Current;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StatementSupportNamespace;
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.meta.StmtContextUtils;
.addAny(YangStmtMapping.TYPEDEF)
.build();
- private final InputStatementSupport implicitInput;
- private final OutputStatementSupport implicitOutput;
-
- public ActionStatementSupport(final YangParserConfiguration config, final InputStatementSupport implicitInput,
- final OutputStatementSupport implicitOutput) {
+ public ActionStatementSupport(final YangParserConfiguration config) {
super(YangStmtMapping.ACTION, uninstantiatedPolicy(), config, SUBSTATEMENT_VALIDATOR);
- this.implicitInput = requireNonNull(implicitInput);
- this.implicitOutput = requireNonNull(implicitOutput);
}
@Override
verify(stmt instanceof StatementContextBase);
if (StmtContextUtils.findFirstDeclaredSubstatement(stmt, InputStatement.class) == null) {
- ((StatementContextBase<?, ?, ?>) stmt).appendImplicitSubstatement(implicitInput, null);
+ appendImplicitSubstatement(stmt, YangStmtMapping.INPUT.getStatementName());
}
if (StmtContextUtils.findFirstDeclaredSubstatement(stmt, OutputStatement.class) == null) {
- ((StatementContextBase<?, ?, ?>) stmt).appendImplicitSubstatement(implicitOutput, null);
+ appendImplicitSubstatement(stmt, YangStmtMapping.OUTPUT.getStatementName());
}
}
return EffectiveStatements.copyAction(original, stmt.getArgument(),
EffectiveStatementMixins.historyAndStatusFlags(stmt.history(), original.effectiveSubstatements()));
}
+
+ private static void appendImplicitSubstatement(final Mutable<QName, ActionStatement, ActionEffectiveStatement> stmt,
+ final QName substatementName) {
+ ((StatementContextBase<?, ?, ?>) stmt).appendImplicitSubstatement(
+ verifyNotNull(stmt.getFromNamespace(StatementSupportNamespace.class, substatementName)), null);
+ }
}
import static com.google.common.base.Preconditions.checkState;
import static com.google.common.base.Verify.verify;
-import static java.util.Objects.requireNonNull;
+import static com.google.common.base.Verify.verifyNotNull;
import com.google.common.annotations.Beta;
import com.google.common.collect.ImmutableList;
import org.opendaylight.yangtools.yang.parser.api.YangParserConfiguration;
import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractSchemaTreeStatementSupport;
import org.opendaylight.yangtools.yang.parser.spi.meta.EffectiveStmtCtx.Current;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StatementSupportNamespace;
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.meta.StmtContextUtils;
.addAny(YangStmtMapping.TYPEDEF)
.build();
- private final InputStatementSupport implicitInput;
- private final OutputStatementSupport implicitOutput;
-
- public RpcStatementSupport(final YangParserConfiguration config, final InputStatementSupport implicitInput,
- final OutputStatementSupport implicitOutput) {
+ public RpcStatementSupport(final YangParserConfiguration config) {
super(YangStmtMapping.RPC, StatementPolicy.reject(), config, SUBSTATEMENT_VALIDATOR);
- this.implicitInput = requireNonNull(implicitInput);
- this.implicitOutput = requireNonNull(implicitOutput);
}
@Override
verify(stmt instanceof StatementContextBase);
if (StmtContextUtils.findFirstDeclaredSubstatement(stmt, InputStatement.class) == null) {
- ((StatementContextBase<?, ?, ?>) stmt).appendImplicitSubstatement(implicitInput, null);
+ appendImplicitSubstatement(stmt, YangStmtMapping.INPUT.getStatementName());
}
if (StmtContextUtils.findFirstDeclaredSubstatement(stmt, OutputStatement.class) == null) {
- ((StatementContextBase<?, ?, ?>) stmt).appendImplicitSubstatement(implicitOutput, null);
+ appendImplicitSubstatement(stmt, YangStmtMapping.OUTPUT.getStatementName());
}
}
.setStatus(findFirstArgument(substatements, StatusEffectiveStatement.class, Status.CURRENT))
.toFlags();
}
+
+ private static void appendImplicitSubstatement(final Mutable<QName, RpcStatement, RpcEffectiveStatement> stmt,
+ final QName substatementName) {
+ ((StatementContextBase<?, ?, ?>) stmt).appendImplicitSubstatement(
+ verifyNotNull(stmt.getFromNamespace(StatementSupportNamespace.class, substatementName)), null);
+ }
}
* @param stmtDef statement definition of substatement
* @return optional of implicit parent statement support
*/
+ // FIXME: YANGTOOLS-1371: pass a NamespaceStmtCtx here, so choice/case can be decoupled
Optional<StatementSupport<?, ?, ?>> getImplicitParentFor(StatementDefinition stmtDef);
}
*
* @author Robert Varga
*/
+// FIXME: 8.0.0: Fix naming and javadoc of this namespace.
+//
+// We have three competing namespaces dealing with various things and the interaction is no entirely clear:
+// - ExtensionNamespace, which is populated by ExtensionStatementSupport for all extensions with the corresponding
+// effective statement and used by SubstatementValidator
+// - StatementDefinitionNamespace (this), which is again populated by ExtensionStatementSupport to point to unrecognized
+// statement support, i.e. preventing instantiation, and is used only by
+// reactor's SourceSpecificContext
+// - StatementSupportNamespace, which is a virtual namespace providing access to StatementSupport instances for all
+// statements available in current processing phase of the source. It works as a union of
+// this namespace (StatementDefinitionNamespace) and the contents of
+// StatementSupportBundles.
+//
+// At the end of the day this feels like an under-utilized namespace: provided the contents of ExtensionNamespace and
+// StatementSupportBundles, SourceSpecificSpecificContext should be able to work its magic even without this namespace.
@Beta
public interface StatementDefinitionNamespace extends ParserNamespace<QName, StatementSupport<?, ?, ?>> {
NamespaceBehaviour<QName, StatementSupport<?, ?, ?>, @NonNull StatementDefinitionNamespace> BEHAVIOUR =
--- /dev/null
+/*
+ * Copyright (c) 2021 PANTHEON.tech, s.r.o. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.yang.parser.spi.meta;
+
+import com.google.common.annotations.Beta;
+import org.opendaylight.yangtools.yang.common.QName;
+
+/**
+ * Projection of {@link StatementSupport}s available within a particular source. This namespace is purely virtual and
+ * its behaviour corresponds to {@link NamespaceBehaviour#rootStatementLocal(Class)} and is always available. Its
+ * contents are derived from {@link StatementSupportBundle}s active in the current {@link ModelProcessingPhase} as well
+ * as {@link StatementDefinitionNamespace} and {@link StmtContext#yangVersion()} of the source root statement.
+ */
+@Beta
+public interface StatementSupportNamespace extends ParserNamespace<QName, StatementSupport<?, ?, ?>> {
+
+}