import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceKeyCriterion;
import org.opendaylight.yangtools.yang.parser.spi.meta.ParserNamespace;
import org.opendaylight.yangtools.yang.parser.spi.meta.StatementFactory;
-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.StatementSupport.CopyPolicy;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
/**
* Invoked whenever a new item is added to a namespace.
*/
- void namespaceItemAdded(StatementContextBase<?, ?, ?> context, Class<?> namespace, Object key, Object value);
+ void namespaceItemAdded(StatementContextBase<?, ?, ?> context, ParserNamespace<?, ?> namespace, Object key,
+ Object value);
}
/**
}
@Override
- public final <K, V, T extends K, U extends V, N extends ParserNamespace<K, V>> void addToNs(
- final Class<@NonNull N> type, final T key, final U value) {
+ public final <K, V, T extends K, U extends V> void addToNs(final ParserNamespace<K, V> type, final T key,
+ final U value) {
addToNamespace(type, key, value);
}
static final void afterAddEffectiveSubstatement(final Mutable<?, ?, ?> substatement) {
// Undeclared statements still need to have 'onDeclarationFinished()' triggered
- if (substatement instanceof UndeclaredStmtCtx) {
- finishDeclaration((UndeclaredStmtCtx<?, ?, ?>) substatement);
+ if (substatement instanceof UndeclaredStmtCtx<?, ?, ?> undeclared) {
+ finishDeclaration(undeclared);
}
}
@Override
final E createEffective() {
final E result = createEffective(definition.getFactory());
- if (result instanceof MutableStatement) {
- getRoot().addMutableStmtToSeal((MutableStatement) result);
+ if (result instanceof MutableStatement mutable) {
+ getRoot().addMutableStmtToSeal(mutable);
}
return result;
}
* @return Stream of supported declared statements.
*/
// FIXME: we really want to unify this with streamEffective(), under its name
- abstract Stream<? extends @NonNull StmtContext<?, ?, ?>> streamDeclared();
+ abstract Stream<? extends @NonNull ReactorStmtCtx<?, ?, ?>> streamDeclared();
/**
* Return a stream of inferred statements which can be built into an {@link EffectiveStatement}, as per
* @return Stream of supported effective statements.
*/
// FIXME: this method is currently a misnomer, but unifying with streamDeclared() would make this accurate again
- abstract Stream<? extends @NonNull StmtContext<?, ?, ?>> streamEffective();
+ abstract Stream<? extends @NonNull ReactorStmtCtx<?, ?, ?>> streamEffective();
@Override
final boolean doTryToCompletePhase(final byte targetOrder) {
return definition;
}
- final <K, V, N extends ParserNamespace<K, V>> void onNamespaceItemAddedAction(final Class<N> type, final K key,
+ final <K, V> void onNamespaceItemAddedAction(final ParserNamespace<K, V> type, final K key,
final OnNamespaceItemAdded listener) {
- final Object potential = getFromNamespace(type, key);
+ final Object potential = namespaceItem(type, key);
if (potential != null) {
LOG.trace("Listener on {} key {} satisfied immediately", type, key);
listener.namespaceItemAdded(this, type, key, potential);
});
}
- final <K, V, N extends ParserNamespace<K, V>> void onNamespaceItemAddedAction(final Class<N> type,
+ final <K, V> void onNamespaceItemAddedAction(final ParserNamespace<K, V> type,
final ModelProcessingPhase phase, final NamespaceKeyCriterion<K> criterion,
final OnNamespaceItemAdded listener) {
final Optional<Entry<K, V>> existing = getFromNamespace(type, criterion);
return;
}
- final NamespaceBehaviourWithListeners<K, V, N> behaviour = getBehaviour(type);
+ final NamespaceBehaviourWithListeners<K, V> behaviour = getBehaviour(type);
behaviour.addListener(new PredicateValueAddedListener<K, V>(this) {
@Override
boolean onValueAdded(final K key, final V value) {
});
}
- final <K, V, N extends ParserNamespace<K, V>> void selectMatch(final Class<N> type,
- final NamespaceKeyCriterion<K> criterion, final OnNamespaceItemAdded listener) {
+ final <K, V> void selectMatch(final ParserNamespace<K, V> type, final NamespaceKeyCriterion<K> criterion,
+ final OnNamespaceItemAdded listener) {
final Optional<Entry<K, V>> optMatch = getFromNamespace(type, criterion);
checkState(optMatch.isPresent(), "Failed to find a match for criterion %s in namespace %s node %s", criterion,
type, this);
listener.namespaceItemAdded(StatementContextBase.this, type, match.getKey(), match.getValue());
}
- final <K, V, N extends ParserNamespace<K, V>> void waitForPhase(final Object value, final Class<N> type,
+ final <K, V> void waitForPhase(final Object value, final ParserNamespace<K, V> type,
final ModelProcessingPhase phase, final NamespaceKeyCriterion<K> criterion,
final OnNamespaceItemAdded listener) {
((StatementContextBase<?, ? ,?>) value).addPhaseCompletedListener(phase,
});
}
- private <K, V, N extends ParserNamespace<K, V>> NamespaceBehaviourWithListeners<K, V, N> getBehaviour(
- final Class<N> type) {
- final NamespaceBehaviour<K, V, N> behaviour = getBehaviourRegistry().getNamespaceBehaviour(type);
+ private <K, V> NamespaceBehaviourWithListeners<K, V> getBehaviour(final ParserNamespace<K, V> type) {
+ final NamespaceBehaviour<K, V> behaviour = getBehaviourRegistry().getNamespaceBehaviour(type);
checkArgument(behaviour instanceof NamespaceBehaviourWithListeners, "Namespace %s does not support listeners",
type);
- return (NamespaceBehaviourWithListeners<K, V, N>) behaviour;
+ return (NamespaceBehaviourWithListeners<K, V>) behaviour;
}
private static <T> Multimap<ModelProcessingPhase, T> newMultimap() {
}
@Override
- public final <K, KT extends K, N extends StatementNamespace<K, ?, ?>> void addContext(
- final Class<@NonNull N> namespace, final KT key,final StmtContext<?, ?, ?> stmt) {
+ public final <K, KT extends K, C extends StmtContext<?, ?, ?>> void addContext(
+ final ParserNamespace<K, ? super C> namespace, final KT key, final C stmt) {
addContextToNamespace(namespace, key, stmt);
}
@Override
- public final Optional<? extends Mutable<?, ?, ?>> copyAsChildOf(final Mutable<?, ?, ?> parent, final CopyType type,
+ public final Optional<Mutable<A, D, E>> copyAsChildOf(final Mutable<?, ?, ?> parent, final CopyType type,
final QNameModule targetModule) {
checkEffectiveModelCompleted(this);
return Optional.ofNullable(copyAsChildOfImpl(parent, type, targetModule));
public final Mutable<?, ?, ?> childCopyOf(final StmtContext<?, ?, ?> stmt, final CopyType type,
final QNameModule targetModule) {
checkEffectiveModelCompleted(stmt);
- if (stmt instanceof StatementContextBase) {
- return childCopyOf((StatementContextBase<?, ?, ?>) stmt, type, targetModule);
- } else if (stmt instanceof ReplicaStatementContext) {
- return ((ReplicaStatementContext<?, ?, ?>) stmt).replicaAsChildOf(this);
+ if (stmt instanceof StatementContextBase<?, ?, ?> base) {
+ return childCopyOf(base, type, targetModule);
+ } else if (stmt instanceof ReplicaStatementContext<?, ?, ?> replica) {
+ return replica.replicaAsChildOf(this);
} else {
throw new IllegalArgumentException("Unsupported statement " + stmt);
}
if (optImplicit.isEmpty()) {
return original;
}
-
- checkArgument(original instanceof StatementContextBase, "Unsupported original %s", original);
- final var origBase = (StatementContextBase<?, ?, ?>)original;
-
- @SuppressWarnings({ "rawtypes", "unchecked" })
- final UndeclaredStmtCtx<?, ?, ?> result = new UndeclaredStmtCtx(origBase, optImplicit.orElseThrow());
- result.addEffectiveSubstatement(origBase.reparent(result));
- result.setCompletedPhase(original.getCompletedPhase());
- return result;
+ if (original instanceof StatementContextBase<?, ?, ?> origBase) {
+ final var result = new UndeclaredStmtCtx<>(origBase, optImplicit.orElseThrow());
+ result.addEffectiveSubstatement(origBase.reparent(result));
+ result.setCompletedPhase(original.getCompletedPhase());
+ return result;
+ }
+ throw new IllegalArgumentException("Unsupported original " + original);
}
abstract StatementContextBase<A, D, E> reparent(StatementContextBase<?, ?, ?> newParent);