import org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition;
import org.opendaylight.yangtools.yang.model.api.stmt.IdentityEffectiveStatement;
import org.opendaylight.yangtools.yang.parser.api.YangParserConfiguration;
-import org.opendaylight.yangtools.yang.parser.spi.IdentityNamespace;
+import org.opendaylight.yangtools.yang.parser.spi.ParserNamespaces;
import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractStatementSupport;
import org.opendaylight.yangtools.yang.parser.spi.meta.EffectiveStmtCtx.Current;
import org.opendaylight.yangtools.yang.parser.spi.meta.InferenceException;
@Override
public void onStatementDefinitionDeclared(final Mutable<QName, D, E> stmt) {
final ModelActionBuilder action = stmt.newInferenceAction(ModelProcessingPhase.EFFECTIVE_MODEL);
- action.requiresCtx(stmt, IdentityNamespace.class, stmt.getArgument(), ModelProcessingPhase.EFFECTIVE_MODEL);
+ action.requiresCtx(stmt, ParserNamespaces.IDENTITY, stmt.getArgument(), ModelProcessingPhase.EFFECTIVE_MODEL);
action.apply(new InferenceAction() {
@Override
final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
final QName qname = stmt.getArgument();
final StmtContext<?, ?, IdentityEffectiveStatement> identityCtx =
- verifyNotNull(stmt.getFromNamespace(IdentityNamespace.class, qname), "Failed to find identity %s", qname);
+ verifyNotNull(stmt.getFromNamespace(ParserNamespaces.IDENTITY, qname), "Failed to find identity %s", qname);
return createEffective(stmt.declared(), identityCtx.buildEffective(), substatements);
}
import org.opendaylight.yangtools.yang.model.api.stmt.RpcStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.TypeEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.type.TypeDefinitions;
-import org.opendaylight.yangtools.yang.parser.spi.ModuleNamespace;
+import org.opendaylight.yangtools.yang.parser.spi.ParserNamespaces;
import org.opendaylight.yangtools.yang.parser.spi.meta.ModelActionBuilder.InferenceAction;
import org.opendaylight.yangtools.yang.parser.spi.meta.ModelActionBuilder.InferenceContext;
import org.opendaylight.yangtools.yang.parser.spi.meta.ModelActionBuilder.Prerequisite;
import org.opendaylight.yangtools.yang.parser.spi.meta.ModelProcessingPhase;
import org.opendaylight.yangtools.yang.parser.spi.meta.StatementSupport;
-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;
final var prereqs = new ArrayList<Prerequisite<? extends StmtContext<?, ?, ?>>>();
// FIXME: this not accurate: we need all sources, not just modules
- for (var module : ietfRestconfModule.getAllFromNamespace(ModuleNamespace.class).values()) {
+ for (var module : ietfRestconfModule.getAllFromNamespace(ParserNamespaces.MODULE).values()) {
if (!ietfRestconfModule.equals(module)) {
prereqs.add(action.requiresCtx((StmtContext<?, ?, ?>)module, ModelProcessingPhase.EFFECTIVE_MODEL));
}
private <X, Y extends DeclaredStatement<X>, Z extends EffectiveStatement<X, Y>>
StatementSupport<X, Y, Z> getSupport(final StatementDefinition def, final Class<Z> effectiveClass) {
- final var tmp = verifyNotNull(operations.getFromNamespace(StatementSupportNamespace.class,
+ final var tmp = verifyNotNull(operations.getFromNamespace(StatementSupport.NAMESPACE,
def.getStatementName()));
final var repr = tmp.definition().getEffectiveRepresentationClass();
verify(effectiveClass.equals(repr), "Unexpected support %s representation %s", tmp, repr);
import org.opendaylight.yangtools.yang.parser.spi.meta.ModelActionBuilder.Prerequisite;
import org.opendaylight.yangtools.yang.parser.spi.meta.ModelProcessingPhase;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.Mutable;
-import org.opendaylight.yangtools.yang.parser.spi.source.ModuleCtxToModuleQName;
+import org.opendaylight.yangtools.yang.parser.spi.source.SourceParserNamespaces;
/**
* An {@link InferenceAction} tasked with identifying when we are dealing with {@link YangDataConstants#RFC8040_SOURCE}.
final Mutable<?, ?, ?> moduleCtx = prereq.resolve(ctx);
// Check namespace and revision first
- final QNameModule moduleQName = moduleCtx.getFromNamespace(ModuleCtxToModuleQName.class, moduleCtx);
+ final QNameModule moduleQName =
+ moduleCtx.getFromNamespace(SourceParserNamespaces.MODULECTX_TO_QNAME, moduleCtx);
if (!YangDataConstants.RFC8040_MODULE.equals(moduleQName)) {
return;
}
@Beta
// FIXME: We should not be needing this namespace, as yang-data's argument is not documented anywhere to be compatible
// with 'identifier', hence we cannot safely form a QName.
-public final class YangDataArgumentNamespace extends ParserNamespace<Empty, QName> {
- public static final @NonNull NamespaceBehaviour<?, ? ,?> BEHAVIOUR =
- NamespaceBehaviour.statementLocal(YangDataArgumentNamespace.class);
+public final class YangDataArgumentNamespace {
+ public static final @NonNull ParserNamespace<Empty, QName> INSTANCE = new ParserNamespace<>("yangDataArgument");
+ public static final @NonNull NamespaceBehaviour<?, ? ,?> BEHAVIOUR = NamespaceBehaviour.statementLocal(INSTANCE);
private YangDataArgumentNamespace() {
// Hidden on purpose
// Parse and populate our argument to be picked up when we build the effective statement
final String argument = SourceException.throwIfNull(ctx.argument(), ctx, "yang-data requires an argument");
final QName qname = StmtContextUtils.parseIdentifier(ctx, argument);
- ctx.addToNs(YangDataArgumentNamespace.class, Empty.value(), qname);
+ ctx.addToNs(YangDataArgumentNamespace.INSTANCE, Empty.value(), qname);
// Support for 'operations' container semantics. For this we need to recognize when the model at hand matches
// RFC8040 ietf-restconf module. In ordered to do that we hook onto this particular definition:
}
return new YangDataEffectiveStatementImpl(stmt, substatements,
- verifyNotNull(stmt.namespaceItem(YangDataArgumentNamespace.class, Empty.value())));
+ verifyNotNull(stmt.namespaceItem(YangDataArgumentNamespace.INSTANCE, Empty.value())));
}
}
import org.opendaylight.yangtools.yang.parser.spi.meta.StatementSupportBundle;
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.ModuleCtxToModuleQName;
-import org.opendaylight.yangtools.yang.parser.spi.source.ModulesDeviatedByModules;
import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
+import org.opendaylight.yangtools.yang.parser.spi.source.SourceParserNamespaces;
import org.opendaylight.yangtools.yang.parser.spi.source.StatementStreamSource;
-import org.opendaylight.yangtools.yang.parser.spi.source.SupportedFeaturesNamespace;
-import org.opendaylight.yangtools.yang.parser.spi.validation.ValidationBundlesNamespace;
-import org.opendaylight.yangtools.yang.parser.spi.validation.ValidationBundlesNamespace.ValidationBundleType;
+import org.opendaylight.yangtools.yang.parser.spi.validation.ValidationBundles;
+import org.opendaylight.yangtools.yang.parser.spi.validation.ValidationBundles.ValidationBundleType;
import org.opendaylight.yangtools.yang.parser.stmt.reactor.SourceSpecificContext.PhaseCompletionProgress;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
private final Table<YangVersion, QName, StatementDefinitionContext<?, ?, ?>> definitions = HashBasedTable.create();
private final Map<QName, StatementDefinitionContext<?, ?, ?>> modelDefinedStmtDefs = new HashMap<>();
- private final Map<Class<?>, NamespaceBehaviourWithListeners<?, ?, ?>> supportedNamespaces = new HashMap<>();
+ private final Map<ParserNamespace<?, ?>, NamespaceBehaviourWithListeners<?, ?, ?>> supportedNamespaces =
+ new HashMap<>();
private final List<MutableStatement> mutableStatementsToSeal = new ArrayList<>();
private final ImmutableMap<ModelProcessingPhase, StatementSupportBundle> supports;
private final Set<SourceSpecificContext> sources = new HashSet<>();
final ImmutableMap<ValidationBundleType, Collection<?>> supportedValidation) {
this.supports = requireNonNull(supports, "BuildGlobalContext#supports cannot be null");
- addToNamespace(ValidationBundlesNamespace.class, supportedValidation);
+ addToNamespace(ValidationBundles.NAMESPACE, supportedValidation);
supportedVersions = ImmutableSet.copyOf(
verifyNotNull(supports.get(ModelProcessingPhase.INIT)).getSupportedVersions());
}
void setSupportedFeatures(final Set<QName> supportedFeatures) {
- addToNamespace(SupportedFeaturesNamespace.class, Empty.value(), ImmutableSet.copyOf(supportedFeatures));
+ addToNamespace(SourceParserNamespaces.SUPPORTED_FEATURES, Empty.value(),
+ ImmutableSet.copyOf(supportedFeatures));
}
void setModulesDeviatedByModules(final SetMultimap<QNameModule, QNameModule> modulesDeviatedByModules) {
- addToNamespace(ModulesDeviatedByModules.class, Empty.value(),
- ImmutableSetMultimap.copyOf(modulesDeviatedByModules));
+ addToNamespace(SourceParserNamespaces.MODULES_DEVIATED_BY, Empty.value(),
+ ImmutableSetMultimap.copyOf(modulesDeviatedByModules));
}
@Override
@Override
public <K, V, N extends ParserNamespace<K, V>> NamespaceBehaviourWithListeners<K, V, N> getNamespaceBehaviour(
- final Class<N> type) {
+ final N type) {
NamespaceBehaviourWithListeners<?, ?, ?> potential = supportedNamespaces.get(type);
if (potential == null) {
final var potentialRaw = verifyNotNull(supports.get(currentPhase)).getNamespaceBehaviour(type);
}
private static SourceIdentifier createSourceIdentifier(final StmtContext<?, ?, ?> root) {
- final QNameModule qNameModule = root.getFromNamespace(ModuleCtxToModuleQName.class, root);
+ final QNameModule qNameModule = root.getFromNamespace(SourceParserNamespaces.MODULECTX_TO_QNAME, root);
final Object arg = root.getArgument();
verify(arg instanceof Unqualified, "Unexpected argument %s", arg);
import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
import org.opendaylight.yangtools.yang.parser.spi.meta.StatementSupportBundle;
import org.opendaylight.yangtools.yang.parser.spi.source.StatementStreamSource;
-import org.opendaylight.yangtools.yang.parser.spi.validation.ValidationBundlesNamespace.ValidationBundleType;
+import org.opendaylight.yangtools.yang.parser.spi.validation.ValidationBundles.ValidationBundleType;
public final class CrossSourceStatementReactor {
private final ImmutableMap<ModelProcessingPhase, StatementSupportBundle> supportedTerminology;
}
@Override
- public <K, V, N extends ParserNamespace<K, V>> Map<K, V> namespace(final Class<@NonNull N> nsType) {
+ public <K, V, N extends ParserNamespace<K, V>> Map<K, V> namespace(final @NonNull N nsType) {
return delegate.namespace(nsType);
}
@Override
- public <K, V, T extends K, N extends ParserNamespace<K, V>> V namespaceItem(final Class<@NonNull N> nsType,
- final T key) {
+ public <K, V, T extends K, N extends ParserNamespace<K, V>> V namespaceItem(final @NonNull N nsType, final T key) {
return delegate.namespaceItem(nsType, key);
}
@Override
- public <K, V, N extends ParserNamespace<K, V>> Map<K, V> localNamespacePortion(final Class<@NonNull N> nsType) {
+ public <K, V, N extends ParserNamespace<K, V>> Map<K, V> localNamespacePortion(final @NonNull N nsType) {
return delegate.localNamespacePortion(nsType);
}
if (prototype instanceof InferredStatementContext) {
// Note: we need to access namespace here, as the target statement may have already been populated, in which
// case we want to obtain the statement in local namespace storage.
- template = (StmtContext) ((InferredStatementContext<?, ?, ?>) prototype).getFromNamespace(
- SchemaTreeNamespace.class, templateQName);
+ template = ((InferredStatementContext<?, ?, ?>) prototype).getFromNamespace(SchemaTreeNamespace.instance(),
+ templateQName);
} else {
template = prototype.allSubstatementsStream()
.filter(stmt -> stmt.producesEffective(SchemaTreeEffectiveStatement.class)
}
private <K, C extends StmtContext<?, ?, ?>, N extends StatementNamespace<K, ?, ?>> @NonNull AbstractPrerequisite<C>
- requiresCtxImpl(final StmtContext<?, ?, ?> context, final Class<N> namespace, final K key,
+ requiresCtxImpl(final StmtContext<?, ?, ?> context, final N namespace, final K key,
final ModelProcessingPhase phase) {
checkNotRegistered();
}
private <K, C extends StmtContext<?, ?, ?>, N extends StatementNamespace<K, ?, ?>> @NonNull AbstractPrerequisite<C>
- requiresCtxImpl(final StmtContext<?, ?, ?> context, final Class<N> namespace,
+ requiresCtxImpl(final StmtContext<?, ?, ?> context, final N namespace,
final NamespaceKeyCriterion<K> criterion, final ModelProcessingPhase phase) {
checkNotRegistered();
}
@SuppressWarnings({ "rawtypes", "unchecked" })
- private <K, C extends Mutable<?, ?, ?>, N extends ParserNamespace<K, ? extends StmtContext<?, ?, ?>>>
- AbstractPrerequisite<C> mutatesCtxImpl(final StmtContext<?, ?, ?> context, final Class<N> namespace,
- final K key, final ModelProcessingPhase phase) {
+ private <K, C extends Mutable<?, ?, ?>> AbstractPrerequisite<C> mutatesCtxImpl(final StmtContext<?, ?, ?> context,
+ final ParserNamespace<K, ? extends StmtContext<?, ?, ?>> namespace, final K key,
+ final ModelProcessingPhase phase) {
checkNotRegistered();
final PhaseModificationInNamespace<C> mod = new PhaseModificationInNamespace<>(EFFECTIVE_MODEL);
addReq(mod);
addMutation(mod);
- contextImpl(context).onNamespaceItemAddedAction((Class) namespace, key, mod);
+ contextImpl(context).onNamespaceItemAddedAction((ParserNamespace) namespace, key, mod);
return mod;
}
@Override
public <K, N extends StatementNamespace<K, ?, ?>> Prerequisite<StmtContext<?, ?, ?>> requiresCtx(
- final StmtContext<?, ?, ?> context, final Class<@NonNull N> namespace, final K key,
- final ModelProcessingPhase phase) {
+ final StmtContext<?, ?, ?> context, final N namespace, final K key, final ModelProcessingPhase phase) {
return requiresCtxImpl(context, namespace, key, phase);
}
@Override
public <K, N extends StatementNamespace<K, ?, ?>> Prerequisite<StmtContext<?, ?, ?>> requiresCtx(
- final StmtContext<?, ?, ?> context, final Class<@NonNull N> namespace,
- final NamespaceKeyCriterion<K> criterion, final ModelProcessingPhase phase) {
+ final StmtContext<?, ?, ?> context, final N namespace, final NamespaceKeyCriterion<K> criterion,
+ final ModelProcessingPhase phase) {
return requiresCtxImpl(context, namespace, criterion, phase);
}
@Override
public <K, E extends EffectiveStatement<?, ?>, N extends ParserNamespace<K, ? extends StmtContext<?, ?, ?>>>
Prerequisite<StmtContext<?, ?, E>> requiresCtxPath(final StmtContext<?, ?, ?> context,
- final Class<N> namespace, final Iterable<K> keys, final ModelProcessingPhase phase) {
+ final N namespace, final Iterable<K> keys, final ModelProcessingPhase phase) {
checkNotRegistered();
final var ret = new PhaseRequirementInNamespacePath<StmtContext<?, ?, E>, K, N>(EFFECTIVE_MODEL, keys);
@Override
@Deprecated
public <K, D extends DeclaredStatement<?>, N extends StatementNamespace<K, ? extends D, ?>> Prerequisite<D>
- requiresDeclared(final StmtContext<?, ?, ?> context, final Class<N> namespace, final K key) {
+ requiresDeclared(final StmtContext<?, ?, ?> context, final N namespace, final K key) {
final AbstractPrerequisite<StmtContext<?, D, ?>> rawContext = requiresCtxImpl(context, namespace, key,
FULL_DECLARATION);
return rawContext.transform(StmtContext::declared);
@Deprecated
public <K, D extends DeclaredStatement<?>, N extends StatementNamespace<K, ? extends D, ?>>
AbstractPrerequisite<StmtContext<?, D, ?>> requiresDeclaredCtx(final StmtContext<?, ?, ?> context,
- final Class<N> namespace, final K key) {
+ final N namespace, final K key) {
return requiresCtxImpl(context, namespace, key, FULL_DECLARATION);
}
@Override
@Deprecated
public <K, E extends EffectiveStatement<?, ?>, N extends StatementNamespace<K, ?, ? extends E>> Prerequisite<E>
- requiresEffective(final StmtContext<?, ?, ?> context, final Class<N> namespace, final K key) {
+ requiresEffective(final StmtContext<?, ?, ?> context, final N namespace, final K key) {
final AbstractPrerequisite<StmtContext<?, ?, E>> rawContext = requiresCtxImpl(context, namespace, key,
EFFECTIVE_MODEL);
return rawContext.transform(StmtContext::buildEffective);
@Deprecated
public <K, E extends EffectiveStatement<?, ?>, N extends StatementNamespace<K, ?, ? extends E>>
AbstractPrerequisite<StmtContext<?, ?, E>> requiresEffectiveCtx(final StmtContext<?, ?, ?> context,
- final Class<N> namespace, final K key) {
+ final N namespace, final K key) {
return requiresCtxImpl(contextImpl(context), namespace, key, EFFECTIVE_MODEL);
}
@Override
@Deprecated
public <N extends ParserNamespace<?, ?>> Prerequisite<Mutable<?, ?, ?>> mutatesNs(final Mutable<?, ?, ?> context,
- final Class<N> namespace) {
+ final N namespace) {
return addMutation(new NamespaceMutation<>(contextImpl(context), namespace));
}
@Override
public <K, E extends EffectiveStatement<?, ?>, N extends ParserNamespace<K, ? extends StmtContext<?, ?, ?>>>
AbstractPrerequisite<Mutable<?, ?, E>> mutatesEffectiveCtx(final StmtContext<?, ?, ?> context,
- final Class<N> namespace, final K key) {
+ final N namespace, final K key) {
return mutatesCtxImpl(context, namespace, key, EFFECTIVE_MODEL);
}
@Override
public <K, E extends EffectiveStatement<?, ?>, N extends ParserNamespace<K, ? extends StmtContext<?, ?, ?>>>
AbstractPrerequisite<Mutable<?, ?, E>> mutatesEffectiveCtxPath(final StmtContext<?, ?, ?> context,
- final Class<N> namespace, final Iterable<K> keys) {
+ final N namespace, final Iterable<K> keys) {
checkNotRegistered();
final var ret = new PhaseModificationInNamespacePath<Mutable<?, ?, E>, K, N>(EFFECTIVE_MODEL, keys);
}
@Override
- public final void namespaceItemAdded(final StatementContextBase<?, ?, ?> context, final Class<?> namespace,
- final Object key, final Object value) {
+ public final void namespaceItemAdded(final StatementContextBase<?, ?, ?> context,
+ final ParserNamespace<?, ?> namespace, final Object key, final Object value) {
LOG.debug("Action for {} got key {}", keys, key);
final StatementContextBase<?, ?, ?> target = contextImpl(value);
return super.addToStringAttributes(toStringHelper).add("phase", modPhase).add("keys", keys);
}
- final void hookOnto(final StmtContext<?, ?, ?> context, final Class<?> namespace) {
+ final void hookOnto(final StmtContext<?, ?, ?> context, final ParserNamespace<?, ?> namespace) {
checkArgument(it.hasNext(), "Namespace %s keys may not be empty", namespace);
hookOnto(contextImpl(context), namespace, it.next());
}
@SuppressWarnings("unchecked")
- private void hookOnto(final StatementContextBase<?, ?, ?> context, final Class<?> namespace, final K key) {
- context.onNamespaceItemAddedAction((Class) namespace, requireNonNull(key), this);
+ private void hookOnto(final StatementContextBase<?, ?, ?> context, final ParserNamespace<?, ?> namespace,
+ final K key) {
+ context.onNamespaceItemAddedAction((ParserNamespace) namespace, requireNonNull(key), this);
}
}
private final class NamespaceMutation<N extends ParserNamespace<?, ?>>
extends AbstractPrerequisite<Mutable<?, ?, ?>> {
- NamespaceMutation(final StatementContextBase<?, ?, ?> ctx, final Class<N> namespace) {
+ NamespaceMutation(final StatementContextBase<?, ?, ?> ctx, final N namespace) {
resolvePrereq(ctx);
}
}
}
@Override
- public void namespaceItemAdded(final StatementContextBase<?, ?, ?> context, final Class<?> namespace,
- final Object key, final Object value) {
+ public void namespaceItemAdded(final StatementContextBase<?, ?, ?> context,
+ final ParserNamespace<?, ?> namespace, final Object key, final Object value) {
((StatementContextBase<?, ?, ?>) value).addPhaseCompletedListener(phase, this);
}
@SuppressWarnings("unchecked")
@Override
- public void namespaceItemAdded(final StatementContextBase<?, ?, ?> context, final Class<?> namespace,
- final Object key, final Object value) {
+ public void namespaceItemAdded(final StatementContextBase<?, ?, ?> context,
+ final ParserNamespace<?, ?> namespace, final Object key, final Object value) {
StatementContextBase<?, ?, ?> targetCtx = contextImpl(value);
targetCtx.addMutation(modPhase, this);
resolvePrereq((C) targetCtx);
abstract class NamespaceStorageSupport implements NamespaceStorageNode {
private static final Logger LOG = LoggerFactory.getLogger(NamespaceStorageSupport.class);
- private Map<Class<?>, Map<?, ?>> namespaces = ImmutableMap.of();
+ private Map<ParserNamespace<?, ?>, Map<?, ?>> namespaces = ImmutableMap.of();
/**
* {@inheritDoc}
public abstract @NonNull Registry getBehaviourRegistry();
// FIXME: 8.0.0: do we really need this method?
- final void checkLocalNamespaceAllowed(final Class<? extends ParserNamespace<?, ?>> type) {
+ final void checkLocalNamespaceAllowed(final ParserNamespace<?, ?> type) {
// Always no-op. We used to route this towards StatementDefinitionContext, but this method remained
// unimplemented even there.
}
*
* @throws SourceException instance of SourceException
*/
- protected <K, V, N extends ParserNamespace<K, V>> void onNamespaceElementAdded(final Class<N> type, final K key,
+ protected <K, V, N extends ParserNamespace<K, V>> void onNamespaceElementAdded(final N type, final K key,
final V value) {
// NOOP
}
- public final <K, V, N extends ParserNamespace<K, V>> Optional<Entry<K, V>> getFromNamespace(
- final Class<N> type, final NamespaceKeyCriterion<K> criterion) {
+ public final <K, V, N extends ParserNamespace<K, V>> Optional<Entry<K, V>> getFromNamespace(final N type,
+ final NamespaceKeyCriterion<K> criterion) {
return getBehaviourRegistry().getNamespaceBehaviour(type).getFrom(this, criterion);
}
- public final <K, V, N extends ParserNamespace<K, V>> Map<K, V> getNamespace(final Class<N> type) {
+ public final <K, V, N extends ParserNamespace<K, V>> Map<K, V> getNamespace(final N type) {
return getBehaviourRegistry().getNamespaceBehaviour(type).getAllFrom(this);
}
@SuppressWarnings("unchecked")
- final <K, V, N extends ParserNamespace<K, V>> Map<K, V> getLocalNamespace(final Class<N> type) {
+ final <K, V, N extends ParserNamespace<K, V>> Map<K, V> getLocalNamespace(final N type) {
return (Map<K, V>) accessNamespaces().get(type);
}
- final <K, V, T extends K, U extends V, N extends ParserNamespace<K, V>> void addToNamespace(
- final Class<N> type, final T key, final U value) {
+ final <K, V, T extends K, U extends V> void addToNamespace(final ParserNamespace<K, V> type, final T key,
+ final U value) {
getBehaviourRegistry().getNamespaceBehaviour(type).addTo(this, key, value);
}
- final <K, V, T extends K, U extends V, N extends ParserNamespace<K, V>> void addToNamespace(
- final Class<N> type, final Map<T, U> map) {
+ final <K, V, T extends K, U extends V, N extends ParserNamespace<K, V>> void addToNamespace(final N type,
+ final Map<T, U> map) {
final NamespaceBehaviour<K, V, N> behavior = getBehaviourRegistry().getNamespaceBehaviour(type);
for (final Entry<T, U> validationBundle : map.entrySet()) {
behavior.addTo(this, validationBundle.getKey(), validationBundle.getValue());
* @throws NamespaceNotAvailableException when the namespace is not available.
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
- public final <K, N extends StatementNamespace<K, ?,?>> void addContextToNamespace(final Class<N> type, final K key,
+ public final <K, N extends StatementNamespace<K, ?,?>> void addContextToNamespace(final N type, final K key,
final StmtContext<?, ?, ?> value) {
- getBehaviourRegistry().getNamespaceBehaviour((Class)type).addTo(this, key, value);
+ getBehaviourRegistry().getNamespaceBehaviour(type).addTo(this, key, value);
}
@SuppressWarnings("unchecked")
@Override
- public <K, V, N extends ParserNamespace<K, V>> V getFromLocalStorage(final Class<N> type, final K key) {
+ public <K, V, N extends ParserNamespace<K, V>> V getFromLocalStorage(final N type, final K key) {
final Map<K, V> localNamespace = (Map<K, V>) accessNamespaces().get(type);
return localNamespace == null ? null : localNamespace.get(key);
}
@Override
- public <K, V, N extends ParserNamespace<K, V>> Map<K, V> getAllFromLocalStorage(final Class<N> type) {
+ public <K, V, N extends ParserNamespace<K, V>> Map<K, V> getAllFromLocalStorage(final N type) {
@SuppressWarnings("unchecked")
final Map<K, V> localNamespace = (Map<K, V>) accessNamespaces().get(type);
return localNamespace;
}
@Override
- public <K, V, N extends ParserNamespace<K, V>> V putToLocalStorage(final Class<N> type, final K key,
- final V value) {
+ public <K, V, N extends ParserNamespace<K, V>> V putToLocalStorage(final N type, final K key, final V value) {
final V ret = ensureLocalNamespace(type).put(key, value);
onNamespaceElementAdded(type, key, value);
return ret;
}
@Override
- public <K, V, N extends ParserNamespace<K, V>> V putToLocalStorageIfAbsent(final Class<N> type, final K key,
+ public <K, V, N extends ParserNamespace<K, V>> V putToLocalStorageIfAbsent(final N type, final K key,
final V value) {
final V ret = ensureLocalNamespace(type).putIfAbsent(key, value);
if (ret == null) {
LOG.trace("Swept namespace storages of {}", this);
}
- void sweepNamespaces(final Map<Class<?>, SweptNamespace> toWipe) {
+ void sweepNamespaces(final Map<ParserNamespace<?, ?>, SweptNamespace> toWipe) {
switch (namespaces.size()) {
case 0:
namespaces = ImmutableMap.copyOf(toWipe);
LOG.trace("Trimmed namespace storages of {} to {}", this, namespaces.keySet());
}
- private Map<Class<?>, Map<?, ?>> accessNamespaces() {
+ private Map<ParserNamespace<?, ?>, Map<?, ?>> accessNamespaces() {
return verifyNotNull(namespaces, "Attempted to access swept namespaces of %s", this);
}
- private <K, V, N extends ParserNamespace<K, V>> Map<K, V> ensureLocalNamespace(final Class<N> type) {
+ private <K, V, N extends ParserNamespace<K, V>> Map<K, V> ensureLocalNamespace(final N type) {
@SuppressWarnings("unchecked")
Map<K, V> ret = (Map<K,V>) accessNamespaces().get(type);
if (ret == null) {
break;
case 1:
// Alright, time to grow to a full HashMap
- final Map<Class<?>, Map<?,?>> newNamespaces = new HashMap<>(4);
- final Entry<Class<?>, Map<?, ?>> entry = namespaces.entrySet().iterator().next();
+ final Map<ParserNamespace<?, ?>, Map<?,?>> newNamespaces = new HashMap<>(4);
+ final Entry<ParserNamespace<?, ?>, Map<?, ?>> entry = namespaces.entrySet().iterator().next();
newNamespaces.put(entry.getKey(), entry.getValue());
namespaces = newNamespaces;
// fall through
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.Mutable;
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.SupportedFeaturesNamespace;
+import org.opendaylight.yangtools.yang.parser.spi.source.SourceParserNamespaces;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
//
@Override
- public final <K, V, T extends K, N extends ParserNamespace<K, V>> V namespaceItem(final Class<@NonNull N> type,
+ public final <K, V, T extends K, N extends ParserNamespace<K, V>> V namespaceItem(final @NonNull N type,
final T key) {
return getBehaviourRegistry().getNamespaceBehaviour(type).getFrom(this, key);
}
@Override
- public final <K, V, N extends ParserNamespace<K, V>> Map<K, V> namespace(final Class<@NonNull N> type) {
+ public final <K, V, N extends ParserNamespace<K, V>> Map<K, V> namespace(final @NonNull N type) {
return getNamespace(type);
}
@Override
- public final <K, V, N extends ParserNamespace<K, V>>
- Map<K, V> localNamespacePortion(final Class<@NonNull N> type) {
+ public final <K, V, N extends ParserNamespace<K, V>> Map<K, V> localNamespacePortion(final @NonNull N type) {
return getLocalNamespace(type);
}
@Override
- protected <K, V, N extends ParserNamespace<K, V>> void onNamespaceElementAdded(final Class<N> type, final K key,
+ protected <K, V, N extends ParserNamespace<K, V>> void onNamespaceElementAdded(final N type, final K key,
final V value) {
// definition().onNamespaceElementAdded(this, type, key, value);
}
*/
if (isParentSupportedByFeatures()) {
// If the set of supported features has not been provided, all features are supported by default.
- final Set<QName> supportedFeatures = getFromNamespace(SupportedFeaturesNamespace.class, Empty.value());
+ final Set<QName> supportedFeatures = getFromNamespace(SourceParserNamespaces.SUPPORTED_FEATURES,
+ Empty.value());
if (supportedFeatures == null || StmtContextUtils.checkFeatureSupport(this, supportedFeatures)) {
flags |= SET_SUPPORTED_BY_FEATURES;
return true;
@Override
@Deprecated
- public <K, V, T extends K, U extends V, N extends ParserNamespace<K, V>> void addToNs(final Class<@NonNull N> type,
+ public <K, V, T extends K, U extends V, N extends ParserNamespace<K, V>> void addToNs(final @NonNull N type,
final T key, final U value) {
throw new UnsupportedOperationException();
}
@Override
@Deprecated
- public <K, KT extends K, N extends StatementNamespace<K, ?, ?>> void addContext(final Class<@NonNull N> namespace,
+ public <K, KT extends K, N extends StatementNamespace<K, ?, ?>> void addContext(final @NonNull N namespace,
final KT key, final StmtContext<?, ?, ?> stmt) {
throw new UnsupportedOperationException();
}
import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
-import org.opendaylight.yangtools.yang.parser.spi.GroupingNamespace;
+import org.opendaylight.yangtools.yang.parser.spi.ParserNamespaces;
import org.opendaylight.yangtools.yang.parser.spi.SchemaTreeNamespace;
-import org.opendaylight.yangtools.yang.parser.spi.TypeNamespace;
import org.opendaylight.yangtools.yang.parser.spi.meta.ModelProcessingPhase;
import org.opendaylight.yangtools.yang.parser.spi.meta.MutableStatement;
import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour.NamespaceStorageNode;
import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour.StorageNodeType;
import org.opendaylight.yangtools.yang.parser.spi.meta.ParserNamespace;
import org.opendaylight.yangtools.yang.parser.spi.meta.RootStmtContext;
-import org.opendaylight.yangtools.yang.parser.spi.source.IncludedModuleContext;
+import org.opendaylight.yangtools.yang.parser.spi.source.SourceParserNamespaces;
import org.opendaylight.yangtools.yang.parser.spi.source.StatementSourceReference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
private static final Logger LOG = LoggerFactory.getLogger(RootStatementContext.class);
// These namespaces are well-known and not needed after the root is cleaned up
- private static final Map<Class<?>, SweptNamespace> SWEPT_NAMESPACES = ImmutableMap.of(
- GroupingNamespace.class, new SweptNamespace(GroupingNamespace.class),
- SchemaTreeNamespace.class, new SweptNamespace(SchemaTreeNamespace.class),
- TypeNamespace.class, new SweptNamespace(TypeNamespace.class));
+ private static final Map<ParserNamespace<?, ?>, SweptNamespace> SWEPT_NAMESPACES = ImmutableMap.of(
+ ParserNamespaces.GROUPING, new SweptNamespace(ParserNamespaces.GROUPING),
+ SchemaTreeNamespace.instance(), new SweptNamespace(SchemaTreeNamespace.instance()),
+ ParserNamespaces.TYPE, new SweptNamespace(ParserNamespaces.TYPE));
private final @NonNull SourceSpecificContext sourceContext;
private final A argument;
final StatementSourceReference ref, final String rawArgument, final YangVersion version,
final SourceIdentifier identifier) {
this(sourceContext, def, ref, rawArgument);
- this.setRootVersion(version);
- this.setRootIdentifier(identifier);
+ setRootVersion(version);
+ setRootIdentifier(identifier);
}
@Override
}
@Override
- public <K, V, N extends ParserNamespace<K, V>> V putToLocalStorage(final Class<N> type, final K key,
- final V value) {
- if (IncludedModuleContext.class.isAssignableFrom(type)) {
+ public <K, V, N extends ParserNamespace<K, V>> V putToLocalStorage(final N type, final K key, final V value) {
+ if (SourceParserNamespaces.INCLUDED_MODULE.equals(type)) {
if (includedContexts.isEmpty()) {
includedContexts = new ArrayList<>(1);
}
}
@Override
- public <K, V, N extends ParserNamespace<K, V>> V getFromLocalStorage(final Class<N> type, final K key) {
+ public <K, V, N extends ParserNamespace<K, V>> V getFromLocalStorage(final N type, final K key) {
return getFromLocalStorage(type, key, new HashSet<>());
}
* We need to track already checked RootStatementContexts due to possible
* circular chains of includes between submodules
*/
- private <K, V, N extends ParserNamespace<K, V>> @Nullable V getFromLocalStorage(final Class<N> type,
+ private <K, V, N extends ParserNamespace<K, V>> @Nullable V getFromLocalStorage(final N type,
final K key, final HashSet<RootStatementContext<?, ?, ?>> alreadyChecked) {
final V potentialLocal = super.getFromLocalStorage(type, key);
if (potentialLocal != null) {
}
@Override
- public <K, V, N extends ParserNamespace<K, V>> Map<K, V> getAllFromLocalStorage(final Class<N> type) {
+ public <K, V, N extends ParserNamespace<K, V>> Map<K, V> getAllFromLocalStorage(final N type) {
return getAllFromLocalStorage(type, new HashSet<>());
}
* We need to track already checked RootStatementContexts due to possible
* circular chains of includes between submodules
*/
- private <K, V, N extends ParserNamespace<K, V>> @Nullable Map<K, V> getAllFromLocalStorage(final Class<N> type,
+ private <K, V, N extends ParserNamespace<K, V>> @Nullable Map<K, V> getAllFromLocalStorage(final N type,
final HashSet<RootStatementContext<?, ?, ?>> alreadyChecked) {
final Map<K, V> potentialLocal = super.getAllFromLocalStorage(type);
if (potentialLocal != null) {
import org.opendaylight.yangtools.concepts.Mutable;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.QNameModule;
-import org.opendaylight.yangtools.yang.common.XMLNamespace;
import org.opendaylight.yangtools.yang.common.YangVersion;
import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
import org.opendaylight.yangtools.yang.parser.spi.meta.InferenceException;
import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour.NamespaceStorageNode;
import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour.StorageNodeType;
import org.opendaylight.yangtools.yang.parser.spi.meta.ParserNamespace;
-import org.opendaylight.yangtools.yang.parser.spi.meta.StatementDefinitionNamespace;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StatementDefinitions;
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.BelongsToPrefixToModuleCtx;
-import org.opendaylight.yangtools.yang.parser.spi.source.ImpPrefixToNamespace;
-import org.opendaylight.yangtools.yang.parser.spi.source.ImportPrefixToModuleCtx;
-import org.opendaylight.yangtools.yang.parser.spi.source.ImportedModuleContext;
-import org.opendaylight.yangtools.yang.parser.spi.source.ModuleCtxToModuleQName;
import org.opendaylight.yangtools.yang.parser.spi.source.PrefixResolver;
import org.opendaylight.yangtools.yang.parser.spi.source.QNameToStatementDefinition;
import org.opendaylight.yangtools.yang.parser.spi.source.QNameToStatementDefinitionMap;
import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
+import org.opendaylight.yangtools.yang.parser.spi.source.SourceParserNamespaces;
import org.opendaylight.yangtools.yang.parser.spi.source.StatementSourceReference;
import org.opendaylight.yangtools.yang.parser.spi.source.StatementStreamSource;
import org.slf4j.Logger;
FINISHED
}
- private static final class SupportedStatements
- extends NamespaceBehaviour<QName, StatementSupport<?, ?, ?>, StatementSupportNamespace> {
+ private static final class SupportedStatements extends NamespaceBehaviour<QName, StatementSupport<?, ?, ?>,
+ ParserNamespace<QName, StatementSupport<?, ?, ?>>> {
private final QNameToStatementDefinitionMap statementDefinitions;
SupportedStatements(final QNameToStatementDefinitionMap statementDefinitions) {
- super(StatementSupportNamespace.class);
+ super(StatementSupport.NAMESPACE);
this.statementDefinitions = requireNonNull(statementDefinitions);
}
LOG.debug("Source {} started phase {}", source, phase);
}
- private void updateImportedNamespaces(final Class<?> type, final Object value) {
- if (BelongsToPrefixToModuleCtx.class.isAssignableFrom(type)
- || ImportedModuleContext.class.isAssignableFrom(type)) {
+ private void updateImportedNamespaces(final ParserNamespace<?, ?> type, final Object value) {
+ if (SourceParserNamespaces.BELONGSTO_PREFIX_TO_MODULECTX.equals(type)
+ || SourceParserNamespaces.IMPORTED_MODULE.equals(type)) {
verify(value instanceof RootStatementContext, "Unexpected imported value %s", value);
if (importedNamespaces.isEmpty()) {
}
@Override
- public <K, V, N extends ParserNamespace<K, V>> V putToLocalStorage(final Class<N> type, final K key,
- final V value) {
+ public <K, V, N extends ParserNamespace<K, V>> V putToLocalStorage(final N type, final K key, final V value) {
// RootStatementContext takes care of IncludedModuleContext and the rest...
final V ret = getRoot().putToLocalStorage(type, key, value);
// FIXME: what about duplicates?
}
@Override
- public <K, V, N extends ParserNamespace<K, V>> V putToLocalStorageIfAbsent(final Class<N> type, final K key,
+ public <K, V, N extends ParserNamespace<K, V>> V putToLocalStorageIfAbsent(final N type, final K key,
final V value) {
// RootStatementContext takes care of IncludedModuleContext and the rest...
final V ret = getRoot().putToLocalStorageIfAbsent(type, key, value);
}
@Override
- public <K, V, N extends ParserNamespace<K, V>> V getFromLocalStorage(final Class<N> type, final K key) {
+ public <K, V, N extends ParserNamespace<K, V>> V getFromLocalStorage(final N type, final K key) {
final V potentialLocal = getRoot().getFromLocalStorage(type, key);
if (potentialLocal != null) {
return potentialLocal;
}
@Override
- public <K, V, N extends ParserNamespace<K, V>> Map<K, V> getAllFromLocalStorage(final Class<N> type) {
+ public <K, V, N extends ParserNamespace<K, V>> Map<K, V> getAllFromLocalStorage(final N type) {
final Map<K, V> potentialLocal = getRoot().getAllFromLocalStorage(type);
if (potentialLocal != null) {
return potentialLocal;
@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)) {
+ public <K, V, N extends ParserNamespace<K, V>> NamespaceBehaviour<K, V, N> getNamespaceBehaviour(final N type) {
+ if (StatementSupport.NAMESPACE.equals(type)) {
return (NamespaceBehaviour<K, V, N>) statementSupports;
}
return globalContext.getNamespaceBehaviour(type);
private PrefixResolver preLinkagePrefixes() {
final HashMapPrefixResolver preLinkagePrefixes = new HashMapPrefixResolver();
- final Map<String, XMLNamespace> prefixToNamespaceMap = getAllFromLocalStorage(ImpPrefixToNamespace.class);
+ final var prefixToNamespaceMap = getAllFromLocalStorage(SourceParserNamespaces.IMP_PREFIX_TO_NAMESPACE);
if (prefixToNamespaceMap == null) {
//:FIXME if it is a submodule without any import, the map is null. Handle also submodules and includes...
return null;
}
private PrefixResolver prefixes() {
- final Map<String, StmtContext<?, ?, ?>> allImports = getRoot().getAllFromNamespace(
- ImportPrefixToModuleCtx.class);
+ final var allImports = root.getAllFromNamespace(SourceParserNamespaces.IMPORT_PREFIX_TO_MODULECTX);
if (allImports != null) {
allImports.forEach((key, value) ->
- prefixToModuleMap.put(key, getRoot().getFromNamespace(ModuleCtxToModuleQName.class, value)));
+ prefixToModuleMap.put(key, root.getFromNamespace(SourceParserNamespaces.MODULECTX_TO_QNAME, value)));
}
- final Map<String, StmtContext<?, ?, ?>> allBelongsTo = getRoot().getAllFromNamespace(
- BelongsToPrefixToModuleCtx.class);
+ final var allBelongsTo = root.getAllFromNamespace(SourceParserNamespaces.BELONGSTO_PREFIX_TO_MODULECTX);
if (allBelongsTo != null) {
allBelongsTo.forEach((key, value) ->
- prefixToModuleMap.put(key, getRoot().getFromNamespace(ModuleCtxToModuleQName.class, value)));
+ prefixToModuleMap.put(key, root.getFromNamespace(SourceParserNamespaces.MODULECTX_TO_QNAME, value)));
}
return prefixToModuleMap;
// We need to any and all extension statements which have been declared in the context
final Map<QName, StatementSupport<?, ?, ?>> extensions = globalContext.getNamespace(
- StatementDefinitionNamespace.class);
+ StatementDefinitions.NAMESPACE);
if (extensions != null) {
extensions.forEach((qname, support) -> {
final StatementSupport<?, ?, ?> existing = qnameToStmtDefMap.putIfAbsent(qname, support);
/**
* 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, N extends ParserNamespace<K, V>> void addToNs(final @NonNull N type,
+ final T key, final U value) {
addToNamespace(type, key, value);
}
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);
if (potential != null) {
});
}
- final <K, V, N extends ParserNamespace<K, V>> void onNamespaceItemAddedAction(final Class<N> type,
+ final <K, V, N extends ParserNamespace<K, V>> void onNamespaceItemAddedAction(final N type,
final ModelProcessingPhase phase, final NamespaceKeyCriterion<K> criterion,
final OnNamespaceItemAdded listener) {
final Optional<Entry<K, V>> existing = getFromNamespace(type, criterion);
});
}
- final <K, V, N extends ParserNamespace<K, V>> void selectMatch(final Class<N> type,
+ final <K, V, N extends ParserNamespace<K, V>> void selectMatch(final N 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,
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, N extends ParserNamespace<K, V>> void waitForPhase(final Object value, final N 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 N type) {
final NamespaceBehaviour<K, V, N> behaviour = getBehaviourRegistry().getNamespaceBehaviour(type);
checkArgument(behaviour instanceof NamespaceBehaviourWithListeners, "Namespace %s does not support listeners",
type);
}
@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, N extends StatementNamespace<K, ?, ?>> void addContext(final @NonNull N namespace,
+ final KT key, final StmtContext<?, ?, ?> stmt) {
addContextToNamespace(namespace, key, stmt);
}
import com.google.common.base.VerifyException;
import java.util.AbstractMap;
import java.util.Set;
+import org.opendaylight.yangtools.yang.parser.spi.meta.ParserNamespace;
/**
* Placeholder namespace map which does not allow access and acts as a sentinel for namespaces which have been
* explicitly removed from {@link NamespaceStorageSupport}.
*/
final class SweptNamespace extends AbstractMap<Object, Object> {
- private final Class<?> name;
+ private final ParserNamespace<?, ?> name;
- SweptNamespace(final Class<?> name) {
+ SweptNamespace(final ParserNamespace<?, ?> name) {
this.name = requireNonNull(name);
}
* some quality parsing time.
*/
@Beta
-public final class ModuleQNameToPrefix extends ParserNamespace<QNameModule, String> {
+public final class ModuleQNameToPrefix {
+ public static final @NonNull ParserNamespace<QNameModule, String> INSTANCE =
+ new ParserNamespace<>("module-qname-to-prefix");
public static final @NonNull NamespaceBehaviour<?, ?, ?> BEHAVIOUR =
- NamespaceBehaviour.rootStatementLocal(ModuleQNameToPrefix.class);
+ NamespaceBehaviour.rootStatementLocal(INSTANCE);
private ModuleQNameToPrefix() {
// Hidden on purpose
*/
package org.opendaylight.yangtools.yang.parser.rfc7950.namespace;
+import static org.opendaylight.yangtools.yang.parser.spi.source.SourceParserNamespaces.BELONGSTO_PREFIX_TO_MODULE_NAME;
+import static org.opendaylight.yangtools.yang.parser.spi.source.SourceParserNamespaces.IMPORT_PREFIX_TO_MODULECTX;
+import static org.opendaylight.yangtools.yang.parser.spi.source.SourceParserNamespaces.MODULECTX_TO_QNAME;
+import static org.opendaylight.yangtools.yang.parser.spi.source.SourceParserNamespaces.MODULE_NAME_TO_QNAME;
+
import com.google.common.collect.ImmutableBiMap;
import com.google.common.collect.ImmutableMap;
import java.util.HashMap;
import org.opendaylight.yangtools.yang.common.YangNamespaceContext;
import org.opendaylight.yangtools.yang.model.api.stmt.SubmoduleStatement;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
-import org.opendaylight.yangtools.yang.parser.spi.source.BelongsToPrefixToModuleName;
-import org.opendaylight.yangtools.yang.parser.spi.source.ImportPrefixToModuleCtx;
-import org.opendaylight.yangtools.yang.parser.spi.source.ModuleCtxToModuleQName;
-import org.opendaylight.yangtools.yang.parser.spi.source.ModuleNameToModuleQName;
/**
* A {@link NamespaceContext} implementation based on the set of imports and local module namespace.
StmtNamespaceContext(final StmtContext<?, ?, ?> ctx) {
// QNameModule -> prefix mappings
- final Map<QNameModule, String> qnameToPrefix = ctx.getAllFromNamespace(ModuleQNameToPrefix.class);
+ final Map<QNameModule, String> qnameToPrefix = ctx.getAllFromNamespace(ModuleQNameToPrefix.INSTANCE);
moduleToPrefix = qnameToPrefix == null ? ImmutableBiMap.of() : ImmutableBiMap.copyOf(qnameToPrefix);
// Additional mappings
final Map<String, QNameModule> additional = new HashMap<>();
- final Map<String, StmtContext<?, ?, ?>> imports = ctx.getAllFromNamespace(ImportPrefixToModuleCtx.class);
+ final Map<String, StmtContext<?, ?, ?>> imports = ctx.getAllFromNamespace(IMPORT_PREFIX_TO_MODULECTX);
if (imports != null) {
for (Entry<String, StmtContext<?, ?, ?>> entry : imports.entrySet()) {
if (!moduleToPrefix.containsValue(entry.getKey())) {
- QNameModule qnameModule = ctx.getFromNamespace(ModuleCtxToModuleQName.class, entry.getValue());
+ QNameModule qnameModule = ctx.getFromNamespace(MODULECTX_TO_QNAME, entry.getValue());
if (qnameModule == null && ctx.producesDeclared(SubmoduleStatement.class)) {
- final Unqualified moduleName = ctx.getFromNamespace(BelongsToPrefixToModuleName.class,
- entry.getKey());
- qnameModule = ctx.getFromNamespace(ModuleNameToModuleQName.class, moduleName);
+ qnameModule = ctx.getFromNamespace(MODULE_NAME_TO_QNAME,
+ ctx.getFromNamespace(BELONGSTO_PREFIX_TO_MODULE_NAME, entry.getKey()));
}
if (qnameModule != null) {
}
}
if (ctx.producesDeclared(SubmoduleStatement.class)) {
- final Map<String, Unqualified> belongsTo = ctx.getAllFromNamespace(BelongsToPrefixToModuleName.class);
+ final Map<String, Unqualified> belongsTo = ctx.getAllFromNamespace(BELONGSTO_PREFIX_TO_MODULE_NAME);
if (belongsTo != null) {
for (Entry<String, Unqualified> entry : belongsTo.entrySet()) {
- final QNameModule module = ctx.getFromNamespace(ModuleNameToModuleQName.class, entry.getValue());
+ final QNameModule module = ctx.getFromNamespace(MODULE_NAME_TO_QNAME, entry.getValue());
if (module != null && !additional.containsKey(entry.getKey())) {
additional.put(entry.getKey(), module);
}
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.Mutable;
@Beta
-public final class YangNamespaceContextNamespace extends ParserNamespace<StmtContext<?, ?, ?>, YangNamespaceContext> {
- public static final @NonNull NamespaceBehaviour<?, ?, ?> BEHAVIOUR =
- NamespaceBehaviour.global(YangNamespaceContextNamespace.class);
+public final class YangNamespaceContextNamespace {
+ public static final @NonNull ParserNamespace<StmtContext<?, ?, ?>, YangNamespaceContext> INSTANCE =
+ new ParserNamespace<>("yangNamespaceContext");
+ public static final @NonNull NamespaceBehaviour<?, ?, ?> BEHAVIOUR = NamespaceBehaviour.global(INSTANCE);
private YangNamespaceContextNamespace() {
// Hidden on purpose
public static @NonNull YangNamespaceContext computeIfAbsent(final StmtContext<?, ?, ?> ctx) {
final RootStmtContext<?, ?, ?> root = ctx.getRoot();
- YangNamespaceContext ret = ctx.getFromNamespace(YangNamespaceContextNamespace.class, root);
+ YangNamespaceContext ret = ctx.getFromNamespace(INSTANCE, root);
if (ret == null) {
verify(ctx instanceof Mutable, "Cannot populate namespace context to %s", ctx);
ret = new StmtNamespaceContext(root);
- ((Mutable<?, ?, ?>)ctx).addToNs(YangNamespaceContextNamespace.class, root, ret);
+ ((Mutable<?, ?, ?>)ctx).addToNs(INSTANCE, root, ret);
}
return ret;
}
import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour;
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.validation.ValidationBundlesNamespace.ValidationBundleType;
+import org.opendaylight.yangtools.yang.parser.spi.validation.ValidationBundles.ValidationBundleType;
import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor;
@Beta
import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.type.TypeStatementRFC7950Support;
import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.uses.SourceGroupingNamespace;
import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.uses.UsesStatementSupport;
-import org.opendaylight.yangtools.yang.parser.spi.ExtensionNamespace;
-import org.opendaylight.yangtools.yang.parser.spi.FeatureNamespace;
-import org.opendaylight.yangtools.yang.parser.spi.GroupingNamespace;
-import org.opendaylight.yangtools.yang.parser.spi.IdentityNamespace;
-import org.opendaylight.yangtools.yang.parser.spi.ModuleNamespace;
-import org.opendaylight.yangtools.yang.parser.spi.NamespaceToModule;
-import org.opendaylight.yangtools.yang.parser.spi.PreLinkageModuleNamespace;
-import org.opendaylight.yangtools.yang.parser.spi.SchemaTreeNamespace;
-import org.opendaylight.yangtools.yang.parser.spi.SubmoduleNamespace;
-import org.opendaylight.yangtools.yang.parser.spi.TypeNamespace;
+import org.opendaylight.yangtools.yang.parser.spi.NamespaceBehaviours;
+import org.opendaylight.yangtools.yang.parser.spi.SchemaTreeNamespaceBehaviour;
import org.opendaylight.yangtools.yang.parser.spi.meta.ModelProcessingPhase;
-import org.opendaylight.yangtools.yang.parser.spi.meta.StatementDefinitionNamespace;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StatementDefinitions;
import org.opendaylight.yangtools.yang.parser.spi.meta.StatementSupportBundle;
-import org.opendaylight.yangtools.yang.parser.spi.source.BelongsToPrefixToModuleCtx;
-import org.opendaylight.yangtools.yang.parser.spi.source.BelongsToPrefixToModuleName;
-import org.opendaylight.yangtools.yang.parser.spi.source.ImpPrefixToNamespace;
-import org.opendaylight.yangtools.yang.parser.spi.source.ImportPrefixToModuleCtx;
-import org.opendaylight.yangtools.yang.parser.spi.source.ImportedModuleContext;
-import org.opendaylight.yangtools.yang.parser.spi.source.IncludedModuleContext;
-import org.opendaylight.yangtools.yang.parser.spi.source.IncludedSubmoduleNameToModuleCtx;
-import org.opendaylight.yangtools.yang.parser.spi.source.ModuleCtxToModuleQName;
-import org.opendaylight.yangtools.yang.parser.spi.source.ModuleCtxToSourceIdentifier;
-import org.opendaylight.yangtools.yang.parser.spi.source.ModuleNameToModuleQName;
-import org.opendaylight.yangtools.yang.parser.spi.source.ModuleNameToNamespace;
-import org.opendaylight.yangtools.yang.parser.spi.source.ModuleNamespaceForBelongsTo;
-import org.opendaylight.yangtools.yang.parser.spi.source.ModuleQNameToModuleName;
-import org.opendaylight.yangtools.yang.parser.spi.source.ModulesDeviatedByModules;
-import org.opendaylight.yangtools.yang.parser.spi.source.PrefixToModule;
-import org.opendaylight.yangtools.yang.parser.spi.source.SupportedFeaturesNamespace;
-import org.opendaylight.yangtools.yang.parser.spi.validation.ValidationBundlesNamespace;
-import org.opendaylight.yangtools.yang.parser.spi.validation.ValidationBundlesNamespace.ValidationBundleType;
+import org.opendaylight.yangtools.yang.parser.spi.source.SourceNamespaceBehaviours;
+import org.opendaylight.yangtools.yang.parser.spi.validation.ValidationBundles;
+import org.opendaylight.yangtools.yang.parser.spi.validation.ValidationBundles.ValidationBundleType;
import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor;
import org.opendaylight.yangtools.yang.xpath.api.YangXPathParserFactory;
private static final ImmutableSet<YangVersion> SUPPORTED_VERSIONS = Sets.immutableEnumSet(VERSION_1, VERSION_1_1);
private static final StatementSupportBundle INIT_BUNDLE = StatementSupportBundle.builder(SUPPORTED_VERSIONS)
- .addSupport(ValidationBundlesNamespace.BEHAVIOUR)
- .addSupport(SupportedFeaturesNamespace.BEHAVIOUR)
- .addSupport(ModulesDeviatedByModules.BEHAVIOUR)
+ .addSupport(ValidationBundles.BEHAVIOUR)
+ .addSupport(SourceNamespaceBehaviours.SUPPORTED_FEATURES)
+ .addSupport(SourceNamespaceBehaviours.MODULES_DEVIATED_BY)
.build();
private RFC7950Reactors() {
.addSupport(new YangVersionStatementSupport(config))
.addSupport(new RevisionStatementSupport(config))
.addSupport(new RevisionDateStatementSupport(config))
- .addSupport(ModuleNameToNamespace.BEHAVIOUR)
- .addSupport(PreLinkageModuleNamespace.BEHAVIOUR)
- .addSupport(ImpPrefixToNamespace.BEHAVIOUR)
- .addSupport(ModuleCtxToModuleQName.BEHAVIOUR)
+ .addSupport(SourceNamespaceBehaviours.MODULE_NAME_TO_NAMESPACE)
+ .addSupport(NamespaceBehaviours.PRELINKAGE_MODULE)
+ .addSupport(SourceNamespaceBehaviours.IMP_PREFIX_TO_NAMESPACE)
+ .addSupport(SourceNamespaceBehaviours.MODULECTX_TO_QNAME)
.addSupport(QNameModuleNamespace.BEHAVIOUR)
.addSupport(ImportedVersionNamespace.BEHAVIOUR)
.build();
.addSupport(new ReferenceStatementSupport(config))
.addSupport(new ContactStatementSupport(config))
.addSupport(new OrganizationStatementSupport(config))
- .addSupport(ModuleNamespace.BEHAVIOUR)
- .addSupport(ModuleNamespaceForBelongsTo.BEHAVIOUR)
- .addSupport(SubmoduleNamespace.BEHAVIOUR)
- .addSupport(NamespaceToModule.BEHAVIOUR)
- .addSupport(ModuleNameToModuleQName.BEHAVIOUR)
- .addSupport(ModuleCtxToSourceIdentifier.BEHAVIOUR)
- .addSupport(ModuleQNameToModuleName.BEHAVIOUR)
- .addSupport(PrefixToModule.BEHAVIOUR)
- .addSupport(ImportedModuleContext.BEHAVIOUR)
- .addSupport(IncludedModuleContext.BEHAVIOUR)
- .addSupport(IncludedSubmoduleNameToModuleCtx.BEHAVIOUR)
- .addSupport(ImportPrefixToModuleCtx.BEHAVIOUR)
- .addSupport(BelongsToPrefixToModuleCtx.BEHAVIOUR)
+ .addSupport(NamespaceBehaviours.MODULE)
+ .addSupport(SourceNamespaceBehaviours.MODULE_FOR_BELONGSTO)
+ .addSupport(NamespaceBehaviours.SUBMODULE)
+ .addSupport(NamespaceBehaviours.NAMESPACE_TO_MODULE)
+ .addSupport(SourceNamespaceBehaviours.MODULE_NAME_TO_QNAME)
+ .addSupport(SourceNamespaceBehaviours.MODULECTX_TO_SOURCE)
+ .addSupport(SourceNamespaceBehaviours.MODULE_NAMESPACE_TO_NAME)
+ .addSupport(SourceNamespaceBehaviours.PREFIX_TO_MODULE)
+ .addSupport(SourceNamespaceBehaviours.IMPORTED_MODULE)
+ .addSupport(SourceNamespaceBehaviours.INCLUDED_MODULE)
+ .addSupport(SourceNamespaceBehaviours.INCLUDED_SUBMODULE_NAME_TO_MODULECTX)
+ .addSupport(SourceNamespaceBehaviours.IMPORT_PREFIX_TO_MODULECTX)
+ .addSupport(SourceNamespaceBehaviours.BELONGSTO_PREFIX_TO_MODULECTX)
.addSupport(ModuleQNameToPrefix.BEHAVIOUR)
- .addSupport(BelongsToPrefixToModuleName.BEHAVIOUR)
+ .addSupport(SourceNamespaceBehaviours.BELONGSTO_PREFIX_TO_MODULE_NAME)
.build();
}
.addSupport(new YinElementStatementSupport(config))
.addSupport(new ArgumentStatementSupport(config))
.addSupport(new ExtensionStatementSupport(config))
- .addSupport(SchemaTreeNamespace.BEHAVIOUR)
- .addSupport(ExtensionNamespace.BEHAVIOUR)
+ .addSupport(SchemaTreeNamespaceBehaviour.INSTANCE)
+ .addSupport(NamespaceBehaviours.EXTENSION)
.addSupport(new TypedefStatementSupport(config))
- .addSupport(TypeNamespace.BEHAVIOUR)
+ .addSupport(NamespaceBehaviours.TYPE)
.addVersionSpecificSupport(VERSION_1, IdentityStatementSupport.rfc6020Instance(config))
.addVersionSpecificSupport(VERSION_1_1, IdentityStatementSupport.rfc7950Instance(config))
- .addSupport(IdentityNamespace.BEHAVIOUR)
+ .addSupport(NamespaceBehaviours.IDENTITY)
.addSupport(new DefaultStatementSupport(config))
.addSupport(new StatusStatementSupport(config))
.addSupport(BaseTypeNamespace.BEHAVIOUR)
.addVersionSpecificSupport(VERSION_1_1, new NotificationStatementRFC7950Support(config))
.addSupport(new FractionDigitsStatementSupport(config))
.addSupport(new BaseStatementSupport(config))
- .addSupport(StatementDefinitionNamespace.BEHAVIOUR)
+ .addSupport(StatementDefinitions.BEHAVIOUR)
.build();
}
.addSupport(new MandatoryStatementSupport(config))
.addSupport(new AnyxmlStatementSupport(config))
.addVersionSpecificSupport(VERSION_1_1, new AnydataStatementSupport(config))
- .addSupport(FeatureNamespace.BEHAVIOUR)
+ .addSupport(NamespaceBehaviours.FEATURE)
.addVersionSpecificSupport(VERSION_1, new IfFeatureStatementRFC6020Support(config))
.addVersionSpecificSupport(VERSION_1_1, new IfFeatureStatementRFC7950Support(config))
- .addSupport(GroupingNamespace.BEHAVIOUR)
+ .addSupport(NamespaceBehaviours.GROUPING)
.addSupport(SourceGroupingNamespace.BEHAVIOUR)
.addSupport(new UsesStatementSupport(config))
.addSupport(new ErrorMessageStatementSupport(config))
import org.opendaylight.yangtools.yang.parser.spi.meta.CommonStmtCtx;
import org.opendaylight.yangtools.yang.parser.spi.meta.EffectiveStmtCtx.Current;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
-import org.opendaylight.yangtools.yang.parser.spi.source.ImportPrefixToModuleCtx;
import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
+import org.opendaylight.yangtools.yang.parser.spi.source.SourceParserNamespaces;
@Beta
public abstract class AbstractEffectiveModule<D extends DeclaredStatement<Unqualified>,
.map(imp -> imp.findFirstEffectiveSubstatementArgument(PrefixEffectiveStatement.class).get())
.forEach(pfx -> {
final StmtContext<?, ?, ?> importedCtx =
- verifyNotNull(stmt.getFromNamespace(ImportPrefixToModuleCtx.class, pfx),
+ verifyNotNull(stmt.getFromNamespace(SourceParserNamespaces.IMPORT_PREFIX_TO_MODULECTX, pfx),
"Failed to resolve prefix %s", pfx);
builder.put(pfx, (ModuleEffectiveStatement) importedCtx.buildEffective());
});
final ModelActionBuilder augmentAction = augmentNode.newInferenceAction(ModelProcessingPhase.EFFECTIVE_MODEL);
augmentAction.requiresCtx(augmentNode, ModelProcessingPhase.EFFECTIVE_MODEL);
final Prerequisite<Mutable<?, ?, EffectiveStatement<?, ?>>> target = augmentAction.mutatesEffectiveCtxPath(
- getSearchRoot(augmentNode), SchemaTreeNamespace.class, augmentNode.getArgument().getNodeIdentifiers());
+ getSearchRoot(augmentNode), SchemaTreeNamespace.instance(), augmentNode.getArgument().getNodeIdentifiers());
augmentAction.apply(new AugmentInferenceAction(this, augmentNode, target));
}
final List<? extends StmtContext<?, ?, ?>> substatements) {
// Pick up the marker left by onFullDefinitionDeclared() inference action. If it is present we need to pass our
// children through target's implicit wrapping.
- final var implicitDef = stmt.getFromNamespace(AugmentImplicitHandlingNamespace.class, Empty.value());
+ final var implicitDef = stmt.getFromNamespace(AugmentImplicitHandlingNamespace.INSTANCE, Empty.value());
return implicitDef == null ? substatements
: Lists.transform(substatements, subCtx -> implicitDef.wrapWithImplicit(subCtx));
}
* the effective augment has correct implicit statements created.
*/
@Beta
-public final class AugmentImplicitHandlingNamespace extends ParserNamespace<Empty, Mutable<?, ?, ?>> {
- public static final @NonNull NamespaceBehaviour<?, ?, ?> BEHAVIOUR =
- NamespaceBehaviour.statementLocal(AugmentImplicitHandlingNamespace.class);
+public final class AugmentImplicitHandlingNamespace {
+ public static final @NonNull ParserNamespace<Empty, Mutable<?, ?, ?>> INSTANCE =
+ new ParserNamespace<>("augment-implicit-handling");
+ public static final @NonNull NamespaceBehaviour<?, ?, ?> BEHAVIOUR = NamespaceBehaviour.statementLocal(INSTANCE);
private AugmentImplicitHandlingNamespace() {
// Hidden on purpose
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;
-import org.opendaylight.yangtools.yang.parser.spi.validation.ValidationBundlesNamespace;
-import org.opendaylight.yangtools.yang.parser.spi.validation.ValidationBundlesNamespace.ValidationBundleType;
+import org.opendaylight.yangtools.yang.parser.spi.validation.ValidationBundles;
+import org.opendaylight.yangtools.yang.parser.spi.validation.ValidationBundles.ValidationBundleType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
// We are targeting a context which is creating implicit nodes. In order to keep things consistent,
// we will need to circle back when creating effective statements.
if (augmentTargetCtx.hasImplicitParentSupport()) {
- augmentNode.addToNs(AugmentImplicitHandlingNamespace.class, Empty.value(), augmentTargetCtx);
+ augmentNode.addToNs(AugmentImplicitHandlingNamespace.INSTANCE, Empty.value(), augmentTargetCtx);
}
copyFromSourceToTarget(augmentNode, augmentTargetCtx);
* statement, therefore return false and skip mandatory nodes validation
*/
final Object arg = sourceCtx.argument();
- if (!(arg instanceof QName)) {
+ if (!(arg instanceof QName sourceStmtQName)) {
return false;
}
- final QName sourceStmtQName = (QName) arg;
-
// RootStatementContext, for example
final Mutable<?, ?, ?> root = targetCtx.getRoot();
do {
* ignored as disallowed augment target.
*/
final Collection<?> allowedAugmentTargets = substatementCtx.getFromNamespace(
- ValidationBundlesNamespace.class, ValidationBundleType.SUPPORTED_AUGMENT_TARGETS);
+ ValidationBundles.NAMESPACE, ValidationBundleType.SUPPORTED_AUGMENT_TARGETS);
// if no allowed target is returned we consider all targets allowed
return allowedAugmentTargets == null || allowedAugmentTargets.isEmpty()
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.Mutable;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils;
import org.opendaylight.yangtools.yang.parser.spi.meta.SubstatementValidator;
-import org.opendaylight.yangtools.yang.parser.spi.source.ModuleCtxToModuleQName;
-import org.opendaylight.yangtools.yang.parser.spi.source.ModulesDeviatedByModules;
import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
+import org.opendaylight.yangtools.yang.parser.spi.source.SourceParserNamespaces;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
final Prerequisite<Mutable<?, ?, EffectiveStatement<?, ?>>> targetCtxPrerequisite =
deviateAction.mutatesEffectiveCtxPath(deviateStmtCtx.getRoot(),
- SchemaTreeNamespace.class, deviationTarget.getNodeIdentifiers());
+ SchemaTreeNamespace.instance(), deviationTarget.getNodeIdentifiers());
deviateAction.apply(new InferenceAction() {
@Override
final Mutable<DeviateKind, DeviateStatement, DeviateEffectiveStatement> deviateStmtCtx,
final SchemaNodeIdentifier deviationTarget) {
final SetMultimap<QNameModule, QNameModule> modulesDeviatedByModules = deviateStmtCtx.getFromNamespace(
- ModulesDeviatedByModules.class, Empty.value());
+ SourceParserNamespaces.MODULES_DEVIATED_BY, Empty.value());
if (modulesDeviatedByModules == null) {
return true;
}
- final QNameModule currentModule = deviateStmtCtx.getFromNamespace(ModuleCtxToModuleQName.class,
+ final QNameModule currentModule = deviateStmtCtx.getFromNamespace(SourceParserNamespaces.MODULECTX_TO_QNAME,
deviateStmtCtx.getRoot());
final QNameModule targetModule = Iterables.getLast(deviationTarget.getNodeIdentifiers()).getModule();
import org.opendaylight.yangtools.yang.model.ri.stmt.DeclaredStatements;
import org.opendaylight.yangtools.yang.model.ri.stmt.EffectiveStatements;
import org.opendaylight.yangtools.yang.parser.api.YangParserConfiguration;
-import org.opendaylight.yangtools.yang.parser.spi.ExtensionNamespace;
+import org.opendaylight.yangtools.yang.parser.spi.ParserNamespaces;
import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractQNameStatementSupport;
import org.opendaylight.yangtools.yang.parser.spi.meta.BoundStmtCtx;
import org.opendaylight.yangtools.yang.parser.spi.meta.EffectiveStmtCtx.Current;
-import org.opendaylight.yangtools.yang.parser.spi.meta.StatementDefinitionNamespace;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StatementDefinitions;
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;
final Mutable<QName, ExtensionStatement, ExtensionEffectiveStatement> stmt) {
super.onStatementDefinitionDeclared(stmt);
- stmt.addContext(ExtensionNamespace.class, stmt.getArgument(), stmt);
+ stmt.addContext(ParserNamespaces.EXTENSION, stmt.getArgument(), stmt);
final StmtContext<QName, ?, ?> argument = StmtContextUtils.findFirstDeclaredSubstatement(stmt,
ArgumentStatement.class);
final StmtContext<Boolean, ?, ?> yinElement = StmtContextUtils.findFirstDeclaredSubstatement(stmt,
YinElementStatement.class);
- stmt.addToNs(StatementDefinitionNamespace.class, stmt.argument(),
+ stmt.addToNs(StatementDefinitions.NAMESPACE, stmt.argument(),
new UnrecognizedStatementSupport(new ModelDefinedStatementDefinition(stmt.getArgument(),
argument != null ? argument.argument() : null, yinElement != null && yinElement.getArgument()),
config));
import org.opendaylight.yangtools.yang.model.ri.stmt.DeclaredStatements;
import org.opendaylight.yangtools.yang.model.ri.stmt.EffectiveStatements;
import org.opendaylight.yangtools.yang.parser.api.YangParserConfiguration;
-import org.opendaylight.yangtools.yang.parser.spi.FeatureNamespace;
+import org.opendaylight.yangtools.yang.parser.spi.ParserNamespaces;
import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractStatementSupport;
import org.opendaylight.yangtools.yang.parser.spi.meta.BoundStmtCtx;
import org.opendaylight.yangtools.yang.parser.spi.meta.EffectiveStmtCtx.Current;
final ModelActionBuilder verifyFeatures = stmt.newInferenceAction(ModelProcessingPhase.EFFECTIVE_MODEL);
final Map<Prerequisite<?>, QName> backRef = new HashMap<>();
for (QName feature : stmt.getArgument().getReferencedFeatures()) {
- backRef.put(verifyFeatures.requiresCtx(stmt, FeatureNamespace.class, feature,
+ backRef.put(verifyFeatures.requiresCtx(stmt, ParserNamespaces.FEATURE, feature,
ModelProcessingPhase.EFFECTIVE_MODEL), feature);
}
import org.opendaylight.yangtools.yang.model.ri.stmt.DeclaredStatements;
import org.opendaylight.yangtools.yang.model.ri.stmt.EffectiveStatements;
import org.opendaylight.yangtools.yang.parser.api.YangParserConfiguration;
-import org.opendaylight.yangtools.yang.parser.spi.PreLinkageModuleNamespace;
+import org.opendaylight.yangtools.yang.parser.spi.ParserNamespaces;
import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractUnqualifiedStatementSupport;
import org.opendaylight.yangtools.yang.parser.spi.meta.BoundStmtCtx;
import org.opendaylight.yangtools.yang.parser.spi.meta.EffectiveStmtCtx.Current;
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.SubstatementValidator;
-import org.opendaylight.yangtools.yang.parser.spi.source.ImpPrefixToNamespace;
-import org.opendaylight.yangtools.yang.parser.spi.source.ModuleNameToNamespace;
import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
+import org.opendaylight.yangtools.yang.parser.spi.source.SourceParserNamespaces;
import org.opendaylight.yangtools.yang.parser.spi.source.YangVersionLinkageException;
@Beta
final Unqualified moduleName = stmt.getArgument();
final ModelActionBuilder importAction = stmt.newInferenceAction(SOURCE_PRE_LINKAGE);
final Prerequisite<StmtContext<?, ?, ?>> imported = importAction.requiresCtx(stmt,
- PreLinkageModuleNamespace.class, moduleName, SOURCE_PRE_LINKAGE);
+ ParserNamespaces.PRELINKAGE_MODULE, moduleName, SOURCE_PRE_LINKAGE);
final Prerequisite<Mutable<?, ?, ?>> rootPrereq = importAction.mutatesCtx(stmt.getRoot(), SOURCE_PRE_LINKAGE);
importAction.apply(new InferenceAction() {
public void apply(final InferenceContext ctx) {
final StmtContext<?, ?, ?> importedModuleContext = imported.resolve(ctx);
verify(moduleName.equals(importedModuleContext.getArgument()));
- final XMLNamespace importedModuleNamespace = verifyNotNull(
- importedModuleContext.getFromNamespace(ModuleNameToNamespace.class, moduleName));
+ final XMLNamespace importedModuleNamespace = verifyNotNull(importedModuleContext.getFromNamespace(
+ SourceParserNamespaces.MODULE_NAME_TO_NAMESPACE, moduleName));
final String impPrefix = SourceException.throwIfNull(
firstAttributeOf(stmt.declaredSubstatements(), PrefixStatement.class), stmt,
"Missing prefix statement");
}
}
- stmt.addToNs(ImpPrefixToNamespace.class, impPrefix, importedModuleNamespace);
+ stmt.addToNs(SourceParserNamespaces.IMP_PREFIX_TO_NAMESPACE, impPrefix, importedModuleNamespace);
}
@Override
final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
InferenceException.throwIf(substatements.isEmpty(), stmt, "Unexpected empty effective import statement");
return EffectiveStatements.createImport(stmt.declared(), substatements,
- verifyNotNull(stmt.getFromNamespace(ImportedVersionNamespace.class, Empty.value())));
+ verifyNotNull(stmt.getFromNamespace(ImportedVersionNamespace.INSTANCE, Empty.value())));
}
}
* Statement-local namespace carrying the versioning information about how the import was satisfied.
*/
@Beta
-public final class ImportedVersionNamespace extends ParserNamespace<Empty, SourceIdentifier> {
- public static final @NonNull NamespaceBehaviour<?, ?, ?> BEHAVIOUR =
- NamespaceBehaviour.statementLocal(ImportedVersionNamespace.class);
+public final class ImportedVersionNamespace {
+ public static final @NonNull ParserNamespace<Empty, SourceIdentifier> INSTANCE =
+ new ParserNamespace<>("imported-version");
+ public static final @NonNull NamespaceBehaviour<?, ?, ?> BEHAVIOUR = NamespaceBehaviour.statementLocal(INSTANCE);
private ImportedVersionNamespace() {
// Hidden on purpose
import org.opendaylight.yangtools.yang.model.api.stmt.RevisionDateStatement;
import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
import org.opendaylight.yangtools.yang.parser.rfc7950.namespace.ModuleQNameToPrefix;
-import org.opendaylight.yangtools.yang.parser.spi.ModuleNamespace;
+import org.opendaylight.yangtools.yang.parser.spi.ParserNamespaces;
import org.opendaylight.yangtools.yang.parser.spi.meta.InferenceException;
import org.opendaylight.yangtools.yang.parser.spi.meta.ModelActionBuilder;
import org.opendaylight.yangtools.yang.parser.spi.meta.ModelActionBuilder.InferenceAction;
import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceKeyCriterion;
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.ImportPrefixToModuleCtx;
-import org.opendaylight.yangtools.yang.parser.spi.source.ImportedModuleContext;
-import org.opendaylight.yangtools.yang.parser.spi.source.ModuleCtxToModuleQName;
-import org.opendaylight.yangtools.yang.parser.spi.source.ModuleCtxToSourceIdentifier;
+import org.opendaylight.yangtools.yang.parser.spi.source.SourceParserNamespaces;
final class RevisionImport {
private RevisionImport() {
final Unqualified moduleName = stmt.getArgument();
final Revision revision = firstAttributeOf(stmt.declaredSubstatements(), RevisionDateStatement.class);
if (revision == null) {
- imported = importAction.requiresCtx(stmt, ModuleNamespace.class,
+ imported = importAction.requiresCtx(stmt, ParserNamespaces.MODULE,
NamespaceKeyCriterion.latestRevisionModule(moduleName), SOURCE_LINKAGE);
} else {
- imported = importAction.requiresCtx(stmt, ModuleNamespace.class, new SourceIdentifier(moduleName, revision),
- SOURCE_LINKAGE);
+ imported = importAction.requiresCtx(stmt, ParserNamespaces.MODULE,
+ new SourceIdentifier(moduleName, revision), SOURCE_LINKAGE);
}
final Prerequisite<Mutable<?, ?, ?>> linkageTarget = importAction.mutatesCtx(stmt.getRoot(), SOURCE_LINKAGE);
public void apply(final InferenceContext ctx) {
final StmtContext<?, ?, ?> importedModule = imported.resolve(ctx);
- final SourceIdentifier importedModuleIdentifier =
- stmt.getFromNamespace(ModuleCtxToSourceIdentifier.class, importedModule);
- stmt.addToNs(ImportedVersionNamespace.class, Empty.value(), importedModuleIdentifier);
+ final SourceIdentifier importedModuleIdentifier = stmt.getFromNamespace(
+ SourceParserNamespaces.MODULECTX_TO_SOURCE, importedModule);
+ stmt.addToNs(ImportedVersionNamespace.INSTANCE, Empty.value(), importedModuleIdentifier);
- final QNameModule mod = InferenceException.throwIfNull(stmt.getFromNamespace(
- ModuleCtxToModuleQName.class, importedModule), stmt, "Failed to find module of %s", importedModule);
+ final QNameModule mod = InferenceException.throwIfNull(
+ stmt.getFromNamespace(SourceParserNamespaces.MODULECTX_TO_QNAME, importedModule), stmt,
+ "Failed to find module of %s", importedModule);
- linkageTarget.resolve(ctx).addToNs(ImportedModuleContext.class,
- importedModuleIdentifier, importedModule);
+ linkageTarget.resolve(ctx).addToNs(SourceParserNamespaces.IMPORTED_MODULE, importedModuleIdentifier,
+ importedModule);
final String impPrefix = firstAttributeOf(stmt.declaredSubstatements(), PrefixStatement.class);
- stmt.addToNs(ImportPrefixToModuleCtx.class, impPrefix, importedModule);
- stmt.addToNs(ModuleQNameToPrefix.class, mod, impPrefix);
+ stmt.addToNs(SourceParserNamespaces.IMPORT_PREFIX_TO_MODULECTX, impPrefix, importedModule);
+ stmt.addToNs(ModuleQNameToPrefix.INSTANCE, mod, impPrefix);
}
@Override
import org.opendaylight.yangtools.yang.parser.spi.source.StatementSourceReference;
@Beta
-public final class ConfigListWarningNamespace extends ParserNamespace<StatementSourceReference, Boolean> {
- public static final @NonNull NamespaceBehaviour<?, ?, ?> BEHAVIOUR =
- NamespaceBehaviour.global(ConfigListWarningNamespace.class);
+public final class ConfigListWarningNamespace {
+ public static final @NonNull ParserNamespace<StatementSourceReference, Boolean> INSTANCE =
+ new ParserNamespace<>("configListWarning");
+ public static final @NonNull NamespaceBehaviour<?, ?, ?> BEHAVIOUR = NamespaceBehaviour.global(INSTANCE);
private ConfigListWarningNamespace() {
// Hidden on purpose
ListStatementSupport(final YangParserConfiguration config, final SubstatementValidator validator) {
super(YangStmtMapping.LIST, instantiatedPolicy(), config, validator);
- this.warnForUnkeyedLists = config.warnForUnkeyedLists();
+ warnForUnkeyedLists = config.warnForUnkeyedLists();
}
public static @NonNull ListStatementSupport rfc6020Instance(final YangParserConfiguration config) {
private static void warnConfigList(final @NonNull Current<QName, ListStatement> stmt) {
final StatementSourceReference ref = stmt.sourceReference();
- final Boolean warned = stmt.getFromNamespace(ConfigListWarningNamespace.class, ref);
+ final Boolean warned = stmt.getFromNamespace(ConfigListWarningNamespace.INSTANCE, ref);
// Hacky check if we have issued a warning for the original statement
if (warned == null) {
final StmtContext<?, ?, ?> ctx = stmt.caerbannog();
verify(ctx instanceof Mutable, "Unexpected context %s", ctx);
- ((Mutable<?, ?, ?>) ctx).addToNs(ConfigListWarningNamespace.class, ref, Boolean.TRUE);
+ ((Mutable<?, ?, ?>) ctx).addToNs(ConfigListWarningNamespace.INSTANCE, ref, Boolean.TRUE);
LOG.info("Configuration list {} does not define any keys in violation of RFC7950 section 7.8.2. While "
+ "this is fine with OpenDaylight, it can cause interoperability issues with other systems "
+ "[defined at {}]", stmt.argument(), ref);
import org.opendaylight.yangtools.yang.parser.spi.meta.EffectiveStatementState;
import org.opendaylight.yangtools.yang.parser.spi.meta.EffectiveStmtCtx.Current;
import org.opendaylight.yangtools.yang.parser.spi.meta.QNameWithFlagsEffectiveStatementState;
-import org.opendaylight.yangtools.yang.parser.spi.meta.StatementSupportNamespace;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StatementSupport;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.Mutable;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils;
import org.opendaylight.yangtools.yang.parser.spi.meta.SubstatementValidator;
private static void appendImplicitSubstatement(final Mutable<QName, ActionStatement, ActionEffectiveStatement> stmt,
final QName substatementName) {
stmt.addEffectiveSubstatement(stmt.createUndeclaredSubstatement(
- verifyNotNull(stmt.getFromNamespace(StatementSupportNamespace.class, substatementName)), null));
+ verifyNotNull(stmt.getFromNamespace(StatementSupport.NAMESPACE, substatementName)), null));
}
}
import org.opendaylight.yangtools.yang.model.ri.stmt.DeclaredStatements;
import org.opendaylight.yangtools.yang.model.ri.stmt.EffectiveStatements;
import org.opendaylight.yangtools.yang.parser.api.YangParserConfiguration;
-import org.opendaylight.yangtools.yang.parser.spi.IdentityNamespace;
+import org.opendaylight.yangtools.yang.parser.spi.ParserNamespaces;
import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractQNameStatementSupport;
import org.opendaylight.yangtools.yang.parser.spi.meta.BoundStmtCtx;
import org.opendaylight.yangtools.yang.parser.spi.meta.EffectiveStmtCtx.Current;
final QName baseIdentityQName = baseStmtCtx.getArgument();
final ModelActionBuilder baseIdentityAction = baseStmtCtx.newInferenceAction(
ModelProcessingPhase.STATEMENT_DEFINITION);
- baseIdentityAction.requiresCtx(baseStmtCtx, IdentityNamespace.class, baseIdentityQName,
+ baseIdentityAction.requiresCtx(baseStmtCtx, ParserNamespaces.IDENTITY, baseIdentityQName,
ModelProcessingPhase.STATEMENT_DEFINITION);
baseIdentityAction.mutatesCtx(baseParentCtx, ModelProcessingPhase.STATEMENT_DEFINITION);
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.SubstatementValidator;
-import org.opendaylight.yangtools.yang.parser.spi.source.BelongsToPrefixToModuleCtx;
-import org.opendaylight.yangtools.yang.parser.spi.source.ModuleNamespaceForBelongsTo;
+import org.opendaylight.yangtools.yang.parser.spi.source.SourceParserNamespaces;
public final class BelongsToStatementSupport
extends AbstractUnqualifiedStatementSupport<BelongsToStatement, BelongsToEffectiveStatement> {
ModelActionBuilder belongsToAction = belongsToCtx.newInferenceAction(ModelProcessingPhase.SOURCE_LINKAGE);
final Prerequisite<StmtContext<?, ?, ?>> belongsToPrereq = belongsToAction.requiresCtx(belongsToCtx,
- ModuleNamespaceForBelongsTo.class, belongsToCtx.getArgument(), ModelProcessingPhase.SOURCE_LINKAGE);
+ SourceParserNamespaces.MODULE_FOR_BELONGSTO, belongsToCtx.getArgument(),
+ ModelProcessingPhase.SOURCE_LINKAGE);
belongsToAction.apply(new InferenceAction() {
@Override
public void apply(final InferenceContext ctx) {
- belongsToCtx.addToNs(BelongsToPrefixToModuleCtx.class,
+ belongsToCtx.addToNs(SourceParserNamespaces.BELONGSTO_PREFIX_TO_MODULECTX,
findFirstDeclaredSubstatement(belongsToCtx, PrefixStatement.class).getArgument(),
belongsToPrereq.resolve(ctx));
}
import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceStmtCtx;
import org.opendaylight.yangtools.yang.parser.spi.meta.QNameWithFlagsEffectiveStatementState;
import org.opendaylight.yangtools.yang.parser.spi.meta.StatementSupport;
-import org.opendaylight.yangtools.yang.parser.spi.meta.StatementSupportNamespace;
import org.opendaylight.yangtools.yang.parser.spi.meta.SubstatementValidator;
import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
if (!caseShorthands.contains(stmtDef)) {
return Optional.empty();
}
- return Optional.of(verifyNotNull(parent.getFromNamespace(StatementSupportNamespace.class,
+ return Optional.of(verifyNotNull(parent.getFromNamespace(StatementSupport.NAMESPACE,
YangStmtMapping.CASE.getStatementName())));
}
private static CaseSchemaNode findCase(final QName qname,
final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
for (final EffectiveStatement<?, ?> effectiveStatement : substatements) {
- if (effectiveStatement instanceof CaseSchemaNode) {
- final CaseSchemaNode choiceCaseNode = (CaseSchemaNode) effectiveStatement;
+ if (effectiveStatement instanceof CaseSchemaNode choiceCaseNode) {
if (qname.equals(choiceCaseNode.getQName())) {
return choiceCaseNode;
}
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.SubstatementValidator;
-import org.opendaylight.yangtools.yang.parser.spi.source.ModuleCtxToModuleQName;
+import org.opendaylight.yangtools.yang.parser.spi.source.SourceParserNamespaces;
public final class DeviationStatementSupport
extends AbstractStatementSupport<Absolute, DeviationStatement, DeviationEffectiveStatement> {
@Override
public void onFullDefinitionDeclared(
final Mutable<Absolute, DeviationStatement, DeviationEffectiveStatement> ctx) {
- final QNameModule currentModule = ctx.getFromNamespace(ModuleCtxToModuleQName.class, ctx.getRoot());
+ final QNameModule currentModule = ctx.getFromNamespace(SourceParserNamespaces.MODULECTX_TO_QNAME,
+ ctx.getRoot());
final QNameModule targetModule = Iterables.getLast(ctx.getArgument().getNodeIdentifiers()).getModule();
if (currentModule.equals(targetModule)) {
import org.opendaylight.yangtools.yang.model.ri.stmt.EffectiveStatements;
import org.opendaylight.yangtools.yang.model.spi.meta.EffectiveStatementMixins.EffectiveStatementWithFlags.FlagsBuilder;
import org.opendaylight.yangtools.yang.parser.api.YangParserConfiguration;
-import org.opendaylight.yangtools.yang.parser.spi.FeatureNamespace;
+import org.opendaylight.yangtools.yang.parser.spi.ParserNamespaces;
import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractQNameStatementSupport;
import org.opendaylight.yangtools.yang.parser.spi.meta.BoundStmtCtx;
import org.opendaylight.yangtools.yang.parser.spi.meta.EffectiveStmtCtx.Current;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.Mutable;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils;
import org.opendaylight.yangtools.yang.parser.spi.meta.SubstatementValidator;
-import org.opendaylight.yangtools.yang.parser.spi.source.SupportedFeaturesNamespace;
+import org.opendaylight.yangtools.yang.parser.spi.source.SourceParserNamespaces;
public final class FeatureStatementSupport
extends AbstractQNameStatementSupport<FeatureStatement, FeatureEffectiveStatement> {
@Override
public void onFullDefinitionDeclared(final Mutable<QName, FeatureStatement, FeatureEffectiveStatement> stmt) {
super.onFullDefinitionDeclared(stmt);
- stmt.addContext(FeatureNamespace.class, stmt.getArgument(), stmt);
+ stmt.addContext(ParserNamespaces.FEATURE, stmt.getArgument(), stmt);
// Do not build effective statement if supported features does not include this feature
- final var supportedFeatures = stmt.getFromNamespace(SupportedFeaturesNamespace.class, Empty.value());
+ final var supportedFeatures = stmt.getFromNamespace(SourceParserNamespaces.SUPPORTED_FEATURES, Empty.value());
if (supportedFeatures != null && !supportedFeatures.contains(stmt.getArgument())) {
stmt.setUnsupported();
}
import org.opendaylight.yangtools.yang.model.spi.meta.SubstatementIndexingException;
import org.opendaylight.yangtools.yang.parser.api.YangParserConfiguration;
import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.EffectiveStmtUtils;
-import org.opendaylight.yangtools.yang.parser.spi.GroupingNamespace;
+import org.opendaylight.yangtools.yang.parser.spi.ParserNamespaces;
import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractQNameStatementSupport;
import org.opendaylight.yangtools.yang.parser.spi.meta.BoundStmtCtx;
import org.opendaylight.yangtools.yang.parser.spi.meta.EffectiveStmtCtx.Current;
// Shadowing check: make sure we do not trample on pre-existing definitions. This catches sibling
// declarations and parent declarations which have already been declared.
checkConflict(parent, stmt);
- parent.addContext(GroupingNamespace.class, stmt.getArgument(), stmt);
+ parent.addContext(ParserNamespaces.GROUPING, stmt.getArgument(), stmt);
final StmtContext<?, ?, ?> grandParent = parent.getParentContext();
if (grandParent != null) {
private static void checkConflict(final StmtContext<?, ?, ?> parent, final StmtContext<QName, ?, ?> stmt) {
final QName arg = stmt.getArgument();
- final StmtContext<?, ?, ?> existing = parent.getFromNamespace(GroupingNamespace.class, arg);
+ final StmtContext<?, ?, ?> existing = parent.getFromNamespace(ParserNamespaces.GROUPING, arg);
SourceException.throwIf(existing != null, stmt, "Duplicate name for grouping %s", arg);
}
}
import org.opendaylight.yangtools.yang.model.ri.stmt.EffectiveStatements;
import org.opendaylight.yangtools.yang.model.spi.meta.EffectiveStatementMixins.EffectiveStatementWithFlags.FlagsBuilder;
import org.opendaylight.yangtools.yang.parser.api.YangParserConfiguration;
-import org.opendaylight.yangtools.yang.parser.spi.IdentityNamespace;
+import org.opendaylight.yangtools.yang.parser.spi.ParserNamespaces;
import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractQNameStatementSupport;
import org.opendaylight.yangtools.yang.parser.spi.meta.BoundStmtCtx;
import org.opendaylight.yangtools.yang.parser.spi.meta.EffectiveStmtCtx.Current;
public void onStatementDefinitionDeclared(
final Mutable<QName, IdentityStatement, IdentityEffectiveStatement> stmt) {
final QName qname = stmt.getArgument();
- final StmtContext<?, ?, ?> prev = stmt.getFromNamespace(IdentityNamespace.class, qname);
+ final StmtContext<?, ?, ?> prev = stmt.getFromNamespace(ParserNamespaces.IDENTITY, qname);
SourceException.throwIf(prev != null, stmt, "Duplicate identity definition %s", qname);
- stmt.addToNs(IdentityNamespace.class, qname, stmt);
+ stmt.addToNs(ParserNamespaces.IDENTITY, qname, stmt);
}
@Override
if (substatement instanceof BaseEffectiveStatement) {
final QName qname = ((BaseEffectiveStatement) substatement).argument();
final IdentityEffectiveStatement identity =
- verifyNotNull(stmt.getFromNamespace(IdentityNamespace.class, qname),
+ verifyNotNull(stmt.getFromNamespace(ParserNamespaces.IDENTITY, qname),
"Failed to find identity %s", qname)
.buildEffective();
verify(identity instanceof IdentitySchemaNode, "%s is not a IdentitySchemaNode", identity);
import org.opendaylight.yangtools.yang.model.ri.stmt.DeclaredStatements;
import org.opendaylight.yangtools.yang.model.ri.stmt.EffectiveStatements;
import org.opendaylight.yangtools.yang.parser.api.YangParserConfiguration;
-import org.opendaylight.yangtools.yang.parser.spi.SubmoduleNamespace;
+import org.opendaylight.yangtools.yang.parser.spi.ParserNamespaces;
import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractUnqualifiedStatementSupport;
import org.opendaylight.yangtools.yang.parser.spi.meta.BoundStmtCtx;
import org.opendaylight.yangtools.yang.parser.spi.meta.EffectiveStmtCtx.Current;
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.SubstatementValidator;
-import org.opendaylight.yangtools.yang.parser.spi.source.IncludedModuleContext;
-import org.opendaylight.yangtools.yang.parser.spi.source.IncludedSubmoduleNameToModuleCtx;
+import org.opendaylight.yangtools.yang.parser.spi.source.SourceParserNamespaces;
import org.opendaylight.yangtools.yang.parser.spi.source.YangVersionLinkageException;
@Beta
final ModelActionBuilder includeAction = stmt.newInferenceAction(SOURCE_LINKAGE);
final Prerequisite<StmtContext<?, ?, ?>> requiresCtxPrerequisite;
if (revision == null) {
- requiresCtxPrerequisite = includeAction.requiresCtx(stmt, SubmoduleNamespace.class,
+ requiresCtxPrerequisite = includeAction.requiresCtx(stmt, ParserNamespaces.SUBMODULE,
NamespaceKeyCriterion.latestRevisionModule(submoduleName), SOURCE_LINKAGE);
} else {
- requiresCtxPrerequisite = includeAction.requiresCtx(stmt, SubmoduleNamespace.class,
+ requiresCtxPrerequisite = includeAction.requiresCtx(stmt, ParserNamespaces.SUBMODULE,
new SourceIdentifier(submoduleName, revision.argument()), SOURCE_LINKAGE);
}
"Cannot include a version %s submodule in a version %s module", subVersion, modVersion);
}
- stmt.addToNs(IncludedModuleContext.class,
+ stmt.addToNs(SourceParserNamespaces.INCLUDED_MODULE,
new SourceIdentifier(submoduleName, revision != null ? revision.getArgument() : null),
includedSubModuleContext);
- stmt.addToNs(IncludedSubmoduleNameToModuleCtx.class, stmt.argument(), includedSubModuleContext);
+ stmt.addToNs(SourceParserNamespaces.INCLUDED_SUBMODULE_NAME_TO_MODULECTX, stmt.argument(),
+ includedSubModuleContext);
}
@Override
import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractSchemaTreeStatementSupport;
import org.opendaylight.yangtools.yang.parser.spi.meta.BoundStmtCtx;
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.StatementSupport;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.Mutable;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils;
import org.opendaylight.yangtools.yang.parser.spi.meta.SubstatementValidator;
private static void appendImplicitSubstatement(final Mutable<QName, RpcStatement, RpcEffectiveStatement> stmt,
final QName substatementName) {
stmt.addEffectiveSubstatement(stmt.createUndeclaredSubstatement(
- verifyNotNull(stmt.getFromNamespace(StatementSupportNamespace.class, substatementName)), null));
+ verifyNotNull(stmt.getFromNamespace(StatementSupport.NAMESPACE, substatementName)), null));
}
}
import org.opendaylight.yangtools.yang.model.spi.meta.EffectiveStatementMixins.EffectiveStatementWithFlags.FlagsBuilder;
import org.opendaylight.yangtools.yang.parser.api.YangParserConfiguration;
import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.EffectiveStmtUtils;
-import org.opendaylight.yangtools.yang.parser.spi.TypeNamespace;
+import org.opendaylight.yangtools.yang.parser.spi.ParserNamespaces;
import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractQNameStatementSupport;
import org.opendaylight.yangtools.yang.parser.spi.meta.BoundStmtCtx;
import org.opendaylight.yangtools.yang.parser.spi.meta.EffectiveStmtCtx.Current;
// Shadowing check: make sure we do not trample on pre-existing definitions. This catches sibling
// declarations and parent declarations which have already been declared.
checkConflict(parent, stmt);
- parent.addContext(TypeNamespace.class, stmt.getArgument(), stmt);
+ parent.addContext(ParserNamespaces.TYPE, stmt.getArgument(), stmt);
final StmtContext<?, ?, ?> grandParent = parent.getParentContext();
if (grandParent != null) {
private static void checkConflict(final StmtContext<?, ?, ?> parent, final StmtContext<QName, ?, ?> stmt) {
final QName arg = stmt.getArgument();
- final StmtContext<?, ?, ?> existing = parent.getFromNamespace(TypeNamespace.class, arg);
+ final StmtContext<?, ?, ?> existing = parent.getFromNamespace(ParserNamespaces.TYPE, arg);
// RFC7950 sections 5.5 and 6.2.1: identifiers must not be shadowed
SourceException.throwIf(existing != null, stmt, "Duplicate name for typedef %s", arg);
}
// ... and before going further ...
action.apply(new RequireLeafDescendants(unique,
// ... require that each schema node identifier resolves against the schema tree
- Maps.uniqueIndex(unique.getArgument(), desc -> action.requiresCtxPath(list,
- SchemaTreeNamespace.class, desc.getNodeIdentifiers(), ModelProcessingPhase.EFFECTIVE_MODEL))));
+ Maps.uniqueIndex(unique.getArgument(),
+ desc -> action.requiresCtxPath(list,
+ (SchemaTreeNamespace) SchemaTreeNamespace.instance(), desc.getNodeIdentifiers(),
+ ModelProcessingPhase.EFFECTIVE_MODEL))));
}
}
import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.AbstractEffectiveModule;
import org.opendaylight.yangtools.yang.parser.spi.meta.EffectiveStmtCtx.Current;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
-import org.opendaylight.yangtools.yang.parser.spi.source.IncludedSubmoduleNameToModuleCtx;
+import org.opendaylight.yangtools.yang.parser.spi.source.SourceParserNamespaces;
final class ModuleEffectiveStatementImpl extends AbstractEffectiveModule<ModuleStatement, ModuleEffectiveStatement>
implements Module, ModuleEffectiveStatement {
namespaceToPrefix = ImmutableMap.copyOf(tmp);
final Map<Unqualified, StmtContext<?, ?, ?>> includedSubmodules =
- stmt.localNamespacePortion(IncludedSubmoduleNameToModuleCtx.class);
+ stmt.localNamespacePortion(SourceParserNamespaces.INCLUDED_SUBMODULE_NAME_TO_MODULECTX);
nameToSubmodule = includedSubmodules == null ? ImmutableMap.of()
: ImmutableMap.copyOf(Maps.transformValues(includedSubmodules,
submodule -> (SubmoduleEffectiveStatement) submodule.buildEffective()));
import org.opendaylight.yangtools.yang.model.ri.stmt.DeclaredStatements;
import org.opendaylight.yangtools.yang.model.spi.meta.SubstatementIndexingException;
import org.opendaylight.yangtools.yang.parser.api.YangParserConfiguration;
-import org.opendaylight.yangtools.yang.parser.spi.ModuleNamespace;
-import org.opendaylight.yangtools.yang.parser.spi.NamespaceToModule;
-import org.opendaylight.yangtools.yang.parser.spi.PreLinkageModuleNamespace;
+import org.opendaylight.yangtools.yang.parser.spi.ParserNamespaces;
import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractUnqualifiedStatementSupport;
import org.opendaylight.yangtools.yang.parser.spi.meta.BoundStmtCtx;
import org.opendaylight.yangtools.yang.parser.spi.meta.CommonStmtCtx;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.Mutable;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils;
import org.opendaylight.yangtools.yang.parser.spi.meta.SubstatementValidator;
-import org.opendaylight.yangtools.yang.parser.spi.source.ImpPrefixToNamespace;
-import org.opendaylight.yangtools.yang.parser.spi.source.ImportPrefixToModuleCtx;
-import org.opendaylight.yangtools.yang.parser.spi.source.IncludedSubmoduleNameToModuleCtx;
-import org.opendaylight.yangtools.yang.parser.spi.source.ModuleCtxToModuleQName;
-import org.opendaylight.yangtools.yang.parser.spi.source.ModuleCtxToSourceIdentifier;
-import org.opendaylight.yangtools.yang.parser.spi.source.ModuleNameToModuleQName;
-import org.opendaylight.yangtools.yang.parser.spi.source.ModuleNameToNamespace;
-import org.opendaylight.yangtools.yang.parser.spi.source.ModuleNamespaceForBelongsTo;
-import org.opendaylight.yangtools.yang.parser.spi.source.ModuleQNameToModuleName;
-import org.opendaylight.yangtools.yang.parser.spi.source.PrefixToModule;
import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
+import org.opendaylight.yangtools.yang.parser.spi.source.SourceParserNamespaces;
@Beta
public final class ModuleStatementSupport
final XMLNamespace moduleNs = SourceException.throwIfNull(
firstAttributeOf(stmt.declaredSubstatements(), NamespaceStatement.class), stmt,
"Namespace of the module [%s] is missing", moduleName);
- stmt.addToNs(ModuleNameToNamespace.class, moduleName, moduleNs);
+ stmt.addToNs(SourceParserNamespaces.MODULE_NAME_TO_NAMESPACE, moduleName, moduleNs);
final String modulePrefix = SourceException.throwIfNull(
firstAttributeOf(stmt.declaredSubstatements(), PrefixStatement.class), stmt,
"Prefix of the module [%s] is missing", moduleName);
- stmt.addToNs(ImpPrefixToNamespace.class, modulePrefix, moduleNs);
+ stmt.addToNs(SourceParserNamespaces.IMP_PREFIX_TO_NAMESPACE, modulePrefix, moduleNs);
- stmt.addContext(PreLinkageModuleNamespace.class, moduleName, stmt);
+ stmt.addContext(ParserNamespaces.PRELINKAGE_MODULE, moduleName, stmt);
final Revision revisionDate = StmtContextUtils.getLatestRevision(stmt.declaredSubstatements()).orElse(null);
final QNameModule qNameModule = QNameModule.create(moduleNs, revisionDate).intern();
- stmt.addToNs(ModuleCtxToModuleQName.class, stmt, qNameModule);
+ stmt.addToNs(SourceParserNamespaces.MODULECTX_TO_QNAME, stmt, qNameModule);
stmt.setRootIdentifier(new SourceIdentifier(stmt.getArgument(), revisionDate));
}
final Revision revisionDate = StmtContextUtils.getLatestRevision(stmt.declaredSubstatements()).orElse(null);
final QNameModule qNameModule = QNameModule.create(moduleNs, revisionDate).intern();
final StmtContext<?, ModuleStatement, ModuleEffectiveStatement> possibleDuplicateModule =
- stmt.getFromNamespace(NamespaceToModule.class, qNameModule);
+ stmt.getFromNamespace(ParserNamespaces.NAMESPACE_TO_MODULE, qNameModule);
if (possibleDuplicateModule != null && possibleDuplicateModule != stmt) {
throw new SourceException(stmt, "Module namespace collision: %s. At %s", qNameModule.getNamespace(),
possibleDuplicateModule.sourceReference());
final Unqualified moduleName = stmt.getArgument();
final SourceIdentifier moduleIdentifier = new SourceIdentifier(moduleName, revisionDate);
- stmt.addContext(ModuleNamespace.class, moduleIdentifier, stmt);
- stmt.addContext(ModuleNamespaceForBelongsTo.class, moduleName, stmt);
- stmt.addContext(NamespaceToModule.class, qNameModule, stmt);
+ stmt.addContext(ParserNamespaces.MODULE, moduleIdentifier, stmt);
+ stmt.addContext(SourceParserNamespaces.MODULE_FOR_BELONGSTO, moduleName, stmt);
+ stmt.addContext(ParserNamespaces.NAMESPACE_TO_MODULE, qNameModule, stmt);
final String modulePrefix = SourceException.throwIfNull(
firstAttributeOf(stmt.declaredSubstatements(), PrefixStatement.class), stmt,
"Prefix of the module [%s] is missing", stmt.argument());
- stmt.addToNs(QNameModuleNamespace.class, Empty.value(), qNameModule);
- stmt.addToNs(PrefixToModule.class, modulePrefix, qNameModule);
- stmt.addToNs(ModuleNameToModuleQName.class, moduleName, qNameModule);
- stmt.addToNs(ModuleCtxToModuleQName.class, stmt, qNameModule);
- stmt.addToNs(ModuleCtxToSourceIdentifier.class, stmt, moduleIdentifier);
- stmt.addToNs(ModuleQNameToModuleName.class, qNameModule, moduleName);
- stmt.addToNs(ImportPrefixToModuleCtx.class, modulePrefix, stmt);
+ stmt.addToNs(QNameModuleNamespace.INSTANCE, Empty.value(), qNameModule);
+ stmt.addToNs(SourceParserNamespaces.PREFIX_TO_MODULE, modulePrefix, qNameModule);
+ stmt.addToNs(SourceParserNamespaces.MODULE_NAME_TO_QNAME, moduleName, qNameModule);
+ stmt.addToNs(SourceParserNamespaces.MODULECTX_TO_QNAME, stmt, qNameModule);
+ stmt.addToNs(SourceParserNamespaces.MODULECTX_TO_SOURCE, stmt, moduleIdentifier);
+ stmt.addToNs(SourceParserNamespaces.MODULE_NAMESPACE_TO_NAME, qNameModule, moduleName);
+ stmt.addToNs(SourceParserNamespaces.IMPORT_PREFIX_TO_MODULECTX, modulePrefix, stmt);
}
@Override
submodules.add((Submodule) submodule);
}
- final QNameModule qnameModule = verifyNotNull(stmt.namespaceItem(QNameModuleNamespace.class, Empty.value()));
+ final QNameModule qnameModule = verifyNotNull(stmt.namespaceItem(QNameModuleNamespace.INSTANCE, Empty.value()));
try {
return new ModuleEffectiveStatementImpl(stmt, substatements, submodules, qnameModule);
} catch (SubstatementIndexingException e) {
private static Collection<StmtContext<?, ?, ?>> submoduleContexts(final Current<?, ?> stmt) {
final Map<Unqualified, StmtContext<?, ?, ?>> submodules = stmt.localNamespacePortion(
- IncludedSubmoduleNameToModuleCtx.class);
+ SourceParserNamespaces.INCLUDED_SUBMODULE_NAME_TO_MODULECTX);
return submodules == null ? List.of() : submodules.values();
}
* Module-local namespace holding the module's QName.
*/
@Beta
-public final class QNameModuleNamespace extends ParserNamespace<Empty, QNameModule> {
- public static final @NonNull NamespaceBehaviour<?, ?, ?> BEHAVIOUR =
- NamespaceBehaviour.statementLocal(QNameModuleNamespace.class);
+public final class QNameModuleNamespace {
+ public static final @NonNull ParserNamespace<Empty, QNameModule> INSTANCE = new ParserNamespace<>("QNameModule");
+ public static final @NonNull NamespaceBehaviour<?, ?, ?> BEHAVIOUR = NamespaceBehaviour.statementLocal(INSTANCE);
private QNameModuleNamespace() {
// Hidden on purpose
final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
// Empty refine is exceedingly unlikely: let's be lazy and reuse the implementation
return new RefineEffectiveStatementImpl(stmt.declared(), substatements,
- (SchemaNode) verifyNotNull(stmt.namespaceItem(RefineTargetNamespace.class, Empty.value()))
+ (SchemaNode) verifyNotNull(stmt.namespaceItem(RefineTargetNamespace.INSTANCE, Empty.value()))
.buildEffective());
}
}
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
@Beta
-public final class RefineTargetNamespace extends ParserNamespace<Empty, StmtContext<?, ?, ?>> {
- public static final @NonNull NamespaceBehaviour<?, ?, ?> BEHAVIOUR =
- NamespaceBehaviour.statementLocal(RefineTargetNamespace.class);
+public final class RefineTargetNamespace {
+ public static final @NonNull ParserNamespace<Empty, StmtContext<?, ?, ?>> INSTANCE =
+ new ParserNamespace<>("refineTarget");
+ public static final @NonNull NamespaceBehaviour<?, ?, ?> BEHAVIOUR = NamespaceBehaviour.statementLocal(INSTANCE);
private RefineTargetNamespace() {
// Hidden on purpose
import org.opendaylight.yangtools.yang.parser.spi.meta.EffectiveStmtCtx.Current;
import org.opendaylight.yangtools.yang.parser.spi.meta.MutableStatement;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
-import org.opendaylight.yangtools.yang.parser.spi.source.IncludedSubmoduleNameToModuleCtx;
-import org.opendaylight.yangtools.yang.parser.spi.source.ModuleNameToModuleQName;
import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
+import org.opendaylight.yangtools.yang.parser.spi.source.SourceParserNamespaces;
final class SubmoduleEffectiveStatementImpl
extends AbstractEffectiveModule<SubmoduleStatement, SubmoduleEffectiveStatement>
final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
super(stmt, substatements, findSubmodulePrefix(stmt, substatements));
- final QNameModule belongsToModuleQName = stmt.getFromNamespace(ModuleNameToModuleQName.class,
+ final QNameModule belongsToModuleQName = stmt.getFromNamespace(SourceParserNamespaces.MODULE_NAME_TO_QNAME,
findBelongsTo(stmt, substatements).argument());
final Builder<String, ModuleEffectiveStatement> prefixToModuleBuilder = ImmutableMap.builder();
* sealing of this statement.
*/
final Map<Unqualified, StmtContext<?, ?, ?>> includedSubmodulesMap = stmt.localNamespacePortion(
- IncludedSubmoduleNameToModuleCtx.class);
+ SourceParserNamespaces.INCLUDED_SUBMODULE_NAME_TO_MODULECTX);
if (includedSubmodulesMap != null) {
final Set<StmtContext<?, SubmoduleStatement, SubmoduleEffectiveStatement>> submoduleContextsInit =
new HashSet<>();
import org.opendaylight.yangtools.yang.model.ri.stmt.DeclaredStatements;
import org.opendaylight.yangtools.yang.model.spi.meta.SubstatementIndexingException;
import org.opendaylight.yangtools.yang.parser.api.YangParserConfiguration;
-import org.opendaylight.yangtools.yang.parser.spi.SubmoduleNamespace;
+import org.opendaylight.yangtools.yang.parser.spi.ParserNamespaces;
import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractUnqualifiedStatementSupport;
import org.opendaylight.yangtools.yang.parser.spi.meta.BoundStmtCtx;
import org.opendaylight.yangtools.yang.parser.spi.meta.CommonStmtCtx;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.Mutable;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils;
import org.opendaylight.yangtools.yang.parser.spi.meta.SubstatementValidator;
-import org.opendaylight.yangtools.yang.parser.spi.source.BelongsToPrefixToModuleName;
import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
+import org.opendaylight.yangtools.yang.parser.spi.source.SourceParserNamespaces;
@Beta
public final class SubmoduleStatementSupport
StmtContextUtils.getLatestRevision(stmt.declaredSubstatements()).orElse(null));
final StmtContext<?, SubmoduleStatement, SubmoduleEffectiveStatement>
- possibleDuplicateSubmodule = stmt.getFromNamespace(SubmoduleNamespace.class, submoduleIdentifier);
+ possibleDuplicateSubmodule = stmt.getFromNamespace(ParserNamespaces.SUBMODULE, submoduleIdentifier);
if (possibleDuplicateSubmodule != null && possibleDuplicateSubmodule != stmt) {
throw new SourceException(stmt, "Submodule name collision: %s. At %s", stmt.rawArgument(),
possibleDuplicateSubmodule.sourceReference());
}
- stmt.addContext(SubmoduleNamespace.class, submoduleIdentifier, stmt);
+ stmt.addContext(ParserNamespaces.SUBMODULE, submoduleIdentifier, stmt);
final Unqualified belongsToModuleName = firstAttributeOf(stmt.declaredSubstatements(),
BelongsToStatement.class);
"Prefix of belongsTo statement is missing in submodule [%s]", stmt.rawArgument());
final String prefix = prefixSubStmtCtx.rawArgument();
- stmt.addToNs(BelongsToPrefixToModuleName.class, prefix, belongsToModuleName);
+ stmt.addToNs(SourceParserNamespaces.BELONGSTO_PREFIX_TO_MODULE_NAME, prefix, belongsToModuleName);
}
@Override
import org.opendaylight.yangtools.yang.model.ri.type.RestrictedTypes;
import org.opendaylight.yangtools.yang.model.ri.type.StringTypeBuilder;
import org.opendaylight.yangtools.yang.parser.api.YangParserConfiguration;
-import org.opendaylight.yangtools.yang.parser.spi.TypeNamespace;
+import org.opendaylight.yangtools.yang.parser.spi.ParserNamespaces;
import org.opendaylight.yangtools.yang.parser.spi.meta.BoundStmtCtx;
import org.opendaylight.yangtools.yang.parser.spi.meta.EffectiveStmtCtx;
import org.opendaylight.yangtools.yang.parser.spi.meta.EffectiveStmtCtx.Current;
final QName typeQName = stmt.getArgument();
final BuiltinEffectiveStatement builtin = STATIC_BUILT_IN_TYPES.get(typeQName);
if (builtin != null) {
- stmt.addToNs(BaseTypeNamespace.class, Empty.value(), builtin);
+ stmt.addToNs(BaseTypeNamespace.INSTANCE, Empty.value(), builtin);
return;
}
final ModelActionBuilder typeAction = stmt.newInferenceAction(ModelProcessingPhase.EFFECTIVE_MODEL);
- final Prerequisite<StmtContext<?, ?, ?>> typePrereq = typeAction.requiresCtx(stmt, TypeNamespace.class,
+ final Prerequisite<StmtContext<?, ?, ?>> typePrereq = typeAction.requiresCtx(stmt, ParserNamespaces.TYPE,
typeQName, ModelProcessingPhase.EFFECTIVE_MODEL);
typeAction.mutatesEffectiveCtx(stmt.getParentContext());
@Override
public void apply(final InferenceContext ctx) {
// Note: do not attempt to call buildEffective() here
- stmt.addToNs(BaseTypeNamespace.class, Empty.value(), typePrereq.resolve(ctx));
+ stmt.addToNs(BaseTypeNamespace.INSTANCE, Empty.value(), typePrereq.resolve(ctx));
}
@Override
* @throws SourceException if the target type cannot be found
*/
private static @NonNull TypeEffectiveStatement<TypeStatement> resolveType(final NamespaceStmtCtx ctx) {
- final Object obj = verifyNotNull(ctx.namespaceItem(BaseTypeNamespace.class, Empty.value()));
+ final Object obj = verifyNotNull(ctx.namespaceItem(BaseTypeNamespace.INSTANCE, Empty.value()));
if (obj instanceof BuiltinEffectiveStatement) {
return (BuiltinEffectiveStatement) obj;
} else if (obj instanceof StmtContext) {
RestrictedTypes.newBinaryBuilder(baseType, typeEffectiveQName(ctx));
for (EffectiveStatement<?, ?> stmt : substatements) {
- if (stmt instanceof LengthEffectiveStatement) {
- final LengthEffectiveStatement length = (LengthEffectiveStatement)stmt;
-
+ if (stmt instanceof LengthEffectiveStatement length) {
try {
builder.setLengthConstraint(length, length.argument());
} catch (IllegalStateException e) {
RestrictedTypes.newDecima64Builder(baseType, typeEffectiveQName(ctx));
for (EffectiveStatement<?, ?> stmt : substatements) {
- if (stmt instanceof RangeEffectiveStatement) {
- final RangeEffectiveStatement range = (RangeEffectiveStatement) stmt;
+ if (stmt instanceof RangeEffectiveStatement range) {
builder.setRangeConstraint(range, range.argument());
}
if (stmt instanceof FractionDigitsEffectiveStatement) {
final TypeStatement declared, final ImmutableList<? extends EffectiveStatement<?, ?>> substatements,
final RangeRestrictedTypeBuilder<T, N> builder) {
for (EffectiveStatement<?, ?> stmt : substatements) {
- if (stmt instanceof RangeEffectiveStatement) {
- final RangeEffectiveStatement rangeStmt = (RangeEffectiveStatement)stmt;
+ if (stmt instanceof RangeEffectiveStatement rangeStmt) {
builder.setRangeConstraint(rangeStmt, rangeStmt.argument());
}
}
AbstractTypeStatementSupport.typeEffectiveQName(ctx));
for (EffectiveStatement<?, ?> stmt : substatements) {
- if (stmt instanceof LengthEffectiveStatement) {
- final LengthEffectiveStatement length = (LengthEffectiveStatement)stmt;
-
+ if (stmt instanceof LengthEffectiveStatement length) {
try {
builder.setLengthConstraint(length, length.argument());
} catch (IllegalStateException e) {
import org.opendaylight.yangtools.yang.parser.spi.meta.ParserNamespace;
@Beta
-public final class BaseTypeNamespace extends ParserNamespace<Empty, Object> {
- public static final @NonNull NamespaceBehaviour<?, ?, ?> BEHAVIOUR =
- NamespaceBehaviour.statementLocal(BaseTypeNamespace.class);
+public final class BaseTypeNamespace {
+ public static final @NonNull ParserNamespace<Empty, Object> INSTANCE = new ParserNamespace<>("baseType");
+ public static final @NonNull NamespaceBehaviour<?, ?, ?> BEHAVIOUR = NamespaceBehaviour.statementLocal(INSTANCE);
private BaseTypeNamespace() {
// Hidden on purpose
import org.opendaylight.yangtools.yang.model.ri.type.BaseTypes;
import org.opendaylight.yangtools.yang.model.ri.type.IdentityrefTypeBuilder;
import org.opendaylight.yangtools.yang.parser.api.YangParserConfiguration;
-import org.opendaylight.yangtools.yang.parser.spi.IdentityNamespace;
+import org.opendaylight.yangtools.yang.parser.spi.ParserNamespaces;
import org.opendaylight.yangtools.yang.parser.spi.meta.BoundStmtCtx;
import org.opendaylight.yangtools.yang.parser.spi.meta.CommonStmtCtx;
import org.opendaylight.yangtools.yang.parser.spi.meta.EffectiveStmtCtx.Current;
StmtContextUtils.findAllDeclaredSubstatements(stmt, BaseStatement.class);
for (StmtContext<QName, BaseStatement, ?> baseStmt : baseStatements) {
final QName baseIdentity = baseStmt.getArgument();
- final StmtContext<?, ?, ?> stmtCtx = stmt.getFromNamespace(IdentityNamespace.class, baseIdentity);
+ final StmtContext<?, ?, ?> stmtCtx = stmt.getFromNamespace(ParserNamespaces.IDENTITY, baseIdentity);
InferenceException.throwIfNull(stmtCtx, stmt,
"Referenced base identity '%s' doesn't exist in given scope (module, imported modules, submodules)",
baseIdentity.getLocalName());
if (subStmt instanceof BaseEffectiveStatement) {
final QName identityQName = ((BaseEffectiveStatement) subStmt).argument();
final IdentityEffectiveStatement baseIdentity =
- verifyNotNull(stmt.getFromNamespace(IdentityNamespace.class, identityQName)).buildEffective();
+ verifyNotNull(stmt.getFromNamespace(ParserNamespaces.IDENTITY, identityQName)).buildEffective();
verify(baseIdentity instanceof IdentitySchemaNode, "Statement %s is not an IdentitySchemaNode",
baseIdentity);
builder.addIdentity((IdentitySchemaNode) baseIdentity);
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
@Beta
-public final class SourceGroupingNamespace extends ParserNamespace<Empty, StmtContext<?, ?, ?>> {
- public static final @NonNull NamespaceBehaviour<?, ?, ?> BEHAVIOUR =
- NamespaceBehaviour.statementLocal(SourceGroupingNamespace.class);
+public final class SourceGroupingNamespace {
+ public static final @NonNull ParserNamespace<Empty, StmtContext<?, ?, ?>> INSTANCE =
+ new ParserNamespace<>("sourceGrouping");
+ public static final @NonNull NamespaceBehaviour<?, ?, ?> BEHAVIOUR = NamespaceBehaviour.statementLocal(INSTANCE);
private SourceGroupingNamespace() {
// Hidden on purpose
import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.EffectiveStmtUtils;
import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.refine.RefineEffectiveStatementImpl;
import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.refine.RefineTargetNamespace;
-import org.opendaylight.yangtools.yang.parser.spi.GroupingNamespace;
+import org.opendaylight.yangtools.yang.parser.spi.ParserNamespaces;
import org.opendaylight.yangtools.yang.parser.spi.SchemaTreeNamespace;
import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractQNameStatementSupport;
import org.opendaylight.yangtools.yang.parser.spi.meta.BoundStmtCtx;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.Mutable;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils;
import org.opendaylight.yangtools.yang.parser.spi.meta.SubstatementValidator;
-import org.opendaylight.yangtools.yang.parser.spi.source.ModuleCtxToModuleQName;
import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
-import org.opendaylight.yangtools.yang.parser.spi.validation.ValidationBundlesNamespace;
-import org.opendaylight.yangtools.yang.parser.spi.validation.ValidationBundlesNamespace.ValidationBundleType;
+import org.opendaylight.yangtools.yang.parser.spi.source.SourceParserNamespaces;
+import org.opendaylight.yangtools.yang.parser.spi.validation.ValidationBundles;
+import org.opendaylight.yangtools.yang.parser.spi.validation.ValidationBundles.ValidationBundleType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
final QName groupingName = usesNode.argument();
final Prerequisite<StmtContext<?, ?, ?>> sourceGroupingPre = usesAction.requiresCtx(usesNode,
- GroupingNamespace.class, groupingName, ModelProcessingPhase.EFFECTIVE_MODEL);
+ ParserNamespaces.GROUPING, groupingName, ModelProcessingPhase.EFFECTIVE_MODEL);
final Prerequisite<? extends Mutable<?, ?, ?>> targetNodePre = usesAction.mutatesEffectiveCtx(
- usesNode.getParentContext());
+ usesNode.getParentContext());
usesAction.apply(new InferenceAction() {
copyFromSourceToTarget(sourceGrpStmtCtx, targetNodeStmtCtx, usesNode);
resolveUsesNode(usesNode, targetNodeStmtCtx);
StmtContextUtils.validateIfFeatureAndWhenOnListKeys(usesNode);
- usesNode.addToNs(SourceGroupingNamespace.class, Empty.value(), sourceGrpStmtCtx);
+ usesNode.addToNs(SourceGroupingNamespace.INSTANCE, Empty.value(), sourceGrpStmtCtx);
}
@Override
protected UsesEffectiveStatement createEffective(final Current<QName, UsesStatement> stmt,
final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
final EffectiveStatement<?, ?> source =
- verifyNotNull(stmt.getFromNamespace(SourceGroupingNamespace.class, Empty.value())).buildEffective();
+ verifyNotNull(stmt.getFromNamespace(SourceGroupingNamespace.INSTANCE, Empty.value())).buildEffective();
verify(source instanceof GroupingDefinition, "Unexpected source %s", source);
final GroupingDefinition sourceGrouping = (GroupingDefinition) source;
final Map<Descendant, SchemaNode> refines = new LinkedHashMap<>();
for (EffectiveStatement<?, ?> effectiveStatement : substatements) {
- if (effectiveStatement instanceof RefineEffectiveStatementImpl) {
- final RefineEffectiveStatementImpl refineStmt = (RefineEffectiveStatementImpl) effectiveStatement;
+ if (effectiveStatement instanceof RefineEffectiveStatementImpl refineStmt) {
refines.put(refineStmt.argument(), refineStmt.getRefineTargetNode());
}
}
private static QNameModule getNewQNameModule(final StmtContext<?, ?, ?> targetCtx,
final StmtContext<?, ?, ?> stmtContext) {
if (targetCtx.getParentContext() == null) {
- return targetCtx.getFromNamespace(ModuleCtxToModuleQName.class, targetCtx);
+ return targetCtx.getFromNamespace(SourceParserNamespaces.MODULECTX_TO_QNAME, targetCtx);
}
if (targetCtx.publicDefinition() == YangStmtMapping.AUGMENT) {
return StmtContextUtils.getRootModuleQName(targetCtx);
// Target is a prerequisite for the 'refine', hence if the target is not supported, the refine is not supported
// as well. Otherwise add a pointer to the target into refine's local namespace.
if (refineTargetNodeCtx.isSupportedToBuildEffective()) {
- subStmtCtx.addToNs(RefineTargetNamespace.class, Empty.value(), refineTargetNodeCtx);
+ subStmtCtx.addToNs(RefineTargetNamespace.INSTANCE, Empty.value(), refineTargetNodeCtx);
} else {
subStmtCtx.setUnsupported();
}
private static boolean isSupportedRefineSubstatement(final StmtContext<?, ?, ?> refineSubstatementCtx) {
final Collection<?> supportedRefineSubstatements = refineSubstatementCtx.getFromNamespace(
- ValidationBundlesNamespace.class, ValidationBundleType.SUPPORTED_REFINE_SUBSTATEMENTS);
+ ValidationBundles.NAMESPACE, ValidationBundleType.SUPPORTED_REFINE_SUBSTATEMENTS);
return supportedRefineSubstatements == null || supportedRefineSubstatements.isEmpty()
|| supportedRefineSubstatements.contains(refineSubstatementCtx.publicDefinition())
ThirdPartyExtensionEffectiveStatementImpl(final Current<String, ThirdPartyExtensionStatement> stmt,
final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
super(stmt.declared(), stmt.argument(), stmt.history(), substatements);
- valueFromNamespace = stmt.getFromNamespace(ThirdPartyNamespace.class, Empty.value());
+ valueFromNamespace = stmt.getFromNamespace(ThirdPartyNamespace.INSTANCE, Empty.value());
}
@Override
public void onFullDefinitionDeclared(
final Mutable<String, ThirdPartyExtensionStatement, ThirdPartyExtensionEffectiveStatement> stmt) {
super.onFullDefinitionDeclared(stmt);
- stmt.addToNs(ThirdPartyNamespace.class, Empty.value(), "Third-party namespace test.");
+ stmt.addToNs(ThirdPartyNamespace.INSTANCE, Empty.value(), "Third-party namespace test.");
}
@Override
/**
* ThirdPartyNamespace.
*/
-public final class ThirdPartyNamespace extends ParserNamespace<Empty, String> {
- public static final @NonNull NamespaceBehaviour<?, ?, ?> BEHAVIOUR =
- NamespaceBehaviour.statementLocal(ThirdPartyNamespace.class);
+public final class ThirdPartyNamespace {
+ public static final @NonNull ParserNamespace<Empty, String> INSTANCE = new ParserNamespace<>("third-party");
+ public static final @NonNull NamespaceBehaviour<?, ?, ?> BEHAVIOUR = NamespaceBehaviour.statementLocal(INSTANCE);
private ThirdPartyNamespace() {
// Hidden on purpose
+++ /dev/null
-/*
- * Copyright (c) 2015 Cisco Systems, Inc. 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;
-
-import org.eclipse.jdt.annotation.NonNull;
-import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.model.api.stmt.ExtensionEffectiveStatement;
-import org.opendaylight.yangtools.yang.model.api.stmt.ExtensionStatement;
-import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour;
-import org.opendaylight.yangtools.yang.parser.spi.meta.StatementNamespace;
-
-/**
- * Extension namespace. All extension names defined in a module and its submodules share the same extension identifier
- * namespace, where each extension is identified by a QName formed from the defining module's QNameModule and the
- * identifier specified in extension statement's argument.
- */
-public final class ExtensionNamespace
- extends StatementNamespace<QName, ExtensionStatement, ExtensionEffectiveStatement> {
- public static final @NonNull NamespaceBehaviour<?, ?, ?> BEHAVIOUR =
- NamespaceBehaviour.global(ExtensionNamespace.class);
-
- private ExtensionNamespace() {
- // Hidden on purpose
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2015 Cisco Systems, Inc. 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;
-
-import org.eclipse.jdt.annotation.NonNull;
-import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.model.api.stmt.FeatureEffectiveStatement;
-import org.opendaylight.yangtools.yang.model.api.stmt.FeatureStatement;
-import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour;
-import org.opendaylight.yangtools.yang.parser.spi.meta.StatementNamespace;
-
-/**
- * Feature namespace. All feature names defined in a module and its submodules share the same feature identifier
- * namespace. Each feature is identified by a QName formed from the defining module's QNameModule and the feature name.
- */
-public final class FeatureNamespace extends StatementNamespace<QName, FeatureStatement, FeatureEffectiveStatement> {
- public static final @NonNull NamespaceBehaviour<?, ?, ?> BEHAVIOUR =
- NamespaceBehaviour.global(FeatureNamespace.class);
-
- private FeatureNamespace() {
- // Hidden on purpose
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2015 Cisco Systems, Inc. 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;
-
-import org.eclipse.jdt.annotation.NonNull;
-import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.model.api.stmt.GroupingEffectiveStatement;
-import org.opendaylight.yangtools.yang.model.api.stmt.GroupingStatement;
-import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour;
-import org.opendaylight.yangtools.yang.parser.spi.meta.StatementNamespace.TreeScoped;
-
-/**
- * Grouping namespace. * All grouping names defined within a parent node or at the top level of the module
- * or its submodules share the same grouping identifier namespace. This namespace is scoped to all
- * descendant nodes of the parent node or module.
- *
- * <p>
- * This means that any descendant node may use that grouping, and it MUST NOT define a grouping with the same name.
- */
-public final class GroupingNamespace extends TreeScoped<QName, GroupingStatement, GroupingEffectiveStatement> {
- public static final @NonNull NamespaceBehaviour<?, ?, ?> BEHAVIOUR =
- NamespaceBehaviour.treeScoped(GroupingNamespace.class);
-
- private GroupingNamespace() {
- // Hidden on purpose
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2015 Cisco Systems, Inc. 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;
-
-import org.eclipse.jdt.annotation.NonNull;
-import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.model.api.stmt.IdentityEffectiveStatement;
-import org.opendaylight.yangtools.yang.model.api.stmt.IdentityStatement;
-import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour;
-import org.opendaylight.yangtools.yang.parser.spi.meta.StatementNamespace;
-
-/**
- * Identity namespace. All identity names defined in a module and its submodules share the same identity identifier
- * namespace.
- */
-public final class IdentityNamespace extends StatementNamespace<QName, IdentityStatement, IdentityEffectiveStatement> {
- public static final @NonNull NamespaceBehaviour<?, ?, ?> BEHAVIOUR =
- NamespaceBehaviour.global(IdentityNamespace.class);
-
- private IdentityNamespace() {
- // Hidden on purpose
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2015 Cisco Systems, Inc. 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;
-
-import org.eclipse.jdt.annotation.NonNull;
-import org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement;
-import org.opendaylight.yangtools.yang.model.api.stmt.ModuleStatement;
-import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
-import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour;
-import org.opendaylight.yangtools.yang.parser.spi.meta.StatementNamespace;
-
-/**
- * Module namespace. All modules known to the reactor are populated to this namespace. Each module is identified
- * by a {@link SourceIdentifier}.
- */
-public final class ModuleNamespace
- extends StatementNamespace<SourceIdentifier, ModuleStatement, ModuleEffectiveStatement> {
- public static final @NonNull NamespaceBehaviour<?, ?, ?> BEHAVIOUR =
- NamespaceBehaviour.global(ModuleNamespace.class);
-
- private ModuleNamespace() {
- // Hidden on purpose
- }
-}
--- /dev/null
+/*
+ * Copyright (c) 2022 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;
+
+import org.eclipse.jdt.annotation.NonNull;
+import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour;
+
+/**
+ * {@link NamespaceBehaviour}s corresponding to {@link ParserNamespaces}.
+ */
+public final class NamespaceBehaviours {
+ public static final @NonNull NamespaceBehaviour<?, ?, ?> EXTENSION =
+ NamespaceBehaviour.global(ParserNamespaces.EXTENSION);
+
+ public static final @NonNull NamespaceBehaviour<?, ?, ?> FEATURE =
+ NamespaceBehaviour.global(ParserNamespaces.FEATURE);
+
+ public static final @NonNull NamespaceBehaviour<?, ?, ?> GROUPING =
+ NamespaceBehaviour.treeScoped(ParserNamespaces.GROUPING);
+
+ public static final @NonNull NamespaceBehaviour<?, ?, ?> IDENTITY =
+ NamespaceBehaviour.global(ParserNamespaces.IDENTITY);
+
+ public static final @NonNull NamespaceBehaviour<?, ?, ?> MODULE =
+ NamespaceBehaviour.global(ParserNamespaces.MODULE);
+
+ public static final @NonNull NamespaceBehaviour<?, ?, ?> SUBMODULE =
+ NamespaceBehaviour.global(ParserNamespaces.SUBMODULE);
+
+ public static final @NonNull NamespaceBehaviour<?, ?, ?> TYPE =
+ NamespaceBehaviour.treeScoped(ParserNamespaces.TYPE);
+
+ public static final @NonNull NamespaceBehaviour<?, ?, ?> NAMESPACE_TO_MODULE =
+ NamespaceBehaviour.global(ParserNamespaces.NAMESPACE_TO_MODULE);
+
+ public static final @NonNull NamespaceBehaviour<?, ?, ?> PRELINKAGE_MODULE =
+ NamespaceBehaviour.global(ParserNamespaces.PRELINKAGE_MODULE);
+
+ private NamespaceBehaviours() {
+ // Hidden on purpose
+ }
+}
+++ /dev/null
-/*
- * Copyright (c) 2015 Cisco Systems, Inc. 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;
-
-import org.eclipse.jdt.annotation.NonNull;
-import org.opendaylight.yangtools.yang.common.QNameModule;
-import org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement;
-import org.opendaylight.yangtools.yang.model.api.stmt.ModuleStatement;
-import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour;
-import org.opendaylight.yangtools.yang.parser.spi.meta.StatementNamespace;
-
-/**
- * A derived namespace allowing lookup of modules based on their {@link QNameModule}.
- */
-public final class NamespaceToModule
- extends StatementNamespace<QNameModule, ModuleStatement, ModuleEffectiveStatement> {
- public static final @NonNull NamespaceBehaviour<?, ?, ?> BEHAVIOUR =
- NamespaceBehaviour.global(NamespaceToModule.class);
-
- private NamespaceToModule() {
- // Hidden on purpose
- }
-}
--- /dev/null
+/*
+ * Copyright (c) 2022 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;
+
+import org.eclipse.jdt.annotation.NonNull;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.common.QNameModule;
+import org.opendaylight.yangtools.yang.common.UnresolvedQName.Unqualified;
+import org.opendaylight.yangtools.yang.model.api.stmt.ExtensionEffectiveStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.ExtensionStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.FeatureEffectiveStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.FeatureStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.GroupingEffectiveStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.GroupingStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.IdentityEffectiveStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.IdentityStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.ModuleStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.SubmoduleEffectiveStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.SubmoduleStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.TypedefEffectiveStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.TypedefStatement;
+import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
+import org.opendaylight.yangtools.yang.parser.spi.meta.ParserNamespace;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StatementNamespace;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StatementNamespace.TreeScoped;
+
+/**
+ * Baseline {@link ParserNamespace}s mostly derived from YANG specification.
+ */
+public final class ParserNamespaces {
+ /**
+ * Extension namespace. All extension names defined in a module and its submodules share the same extension
+ * identifier namespace, where each extension is identified by a QName formed from the defining module's QNameModule
+ * and the identifier specified in extension statement's argument.
+ */
+ public static final @NonNull StatementNamespace<QName, ExtensionStatement, ExtensionEffectiveStatement> EXTENSION =
+ new StatementNamespace<>("extension");
+
+ /**
+ * Feature namespace. All feature names defined in a module and its submodules share the same feature identifier
+ * namespace. Each feature is identified by a QName formed from the defining module's QNameModule and the feature
+ * name.
+ */
+ public static final @NonNull StatementNamespace<QName, FeatureStatement, FeatureEffectiveStatement> FEATURE =
+ new StatementNamespace<>("feature");
+
+ /**
+ * Grouping namespace. * All grouping names defined within a parent node or at the top level of the module
+ * or its submodules share the same grouping identifier namespace. This namespace is scoped to all
+ * descendant nodes of the parent node or module.
+ *
+ * <p>
+ * This means that any descendant node may use that grouping, and it MUST NOT define a grouping with the same name.
+ */
+ public static final @NonNull TreeScoped<QName, GroupingStatement, GroupingEffectiveStatement> GROUPING =
+ new TreeScoped<>("grouping");
+
+ /**
+ * Identity namespace. All identity names defined in a module and its submodules share the same identity identifier
+ * namespace.
+ */
+ public static final @NonNull StatementNamespace<QName, IdentityStatement, IdentityEffectiveStatement> IDENTITY =
+ new StatementNamespace<>("identity");
+
+ /**
+ * Module namespace. All modules known to the reactor are populated to this namespace. Each module is identified
+ * by a {@link SourceIdentifier}.
+ */
+ public static final @NonNull StatementNamespace<SourceIdentifier, ModuleStatement, ModuleEffectiveStatement> MODULE
+ = new StatementNamespace<>("module");
+
+ /**
+ * Submodule equivalent of {@link #MODULE}.
+ */
+ public static final @NonNull StatementNamespace<SourceIdentifier, SubmoduleStatement, SubmoduleEffectiveStatement>
+ SUBMODULE = new StatementNamespace<>("submodule");
+
+ /**
+ * Derived types namespace. All derived type names defined within a parent node or at the top level of the module
+ * (or its submodules) share the same type identifier namespace.
+ *
+ * <p>
+ * This namespace is scoped to all descendant nodes of the parent node or module. This means that any descendant
+ * node may use that typedef, and it MUST NOT define a typedef with the same name.
+ *
+ * <p>
+ * This namespace includes all type definitions implied by the language in which the current statement resides
+ * (e.g. RFC6020/RFC7950 for YANG 1.0/1.1).
+ */
+ public static final @NonNull TreeScoped<QName, TypedefStatement, TypedefEffectiveStatement> TYPE =
+ new TreeScoped<>("typedef");
+
+ /**
+ * A derived namespace allowing lookup of modules based on their {@link QNameModule}.
+ */
+ public static final @NonNull StatementNamespace<QNameModule, ModuleStatement, ModuleEffectiveStatement>
+ NAMESPACE_TO_MODULE = new StatementNamespace<>("namespace-to-module");
+
+ /**
+ * Intermediate-stage namespace equivalent to {@link #MODULE} except it is keyed by module names. This namespace is
+ * used to resolve inter-module references before actual linkage occurs.
+ */
+ public static final @NonNull StatementNamespace<Unqualified, ModuleStatement, ModuleEffectiveStatement>
+ PRELINKAGE_MODULE = new StatementNamespace<>("prelinkage-module");
+
+ private ParserNamespaces() {
+ // Hidden on purpose
+ }
+}
+++ /dev/null
-/*
- * Copyright (c) 2016 Cisco Systems, Inc. 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;
-
-import org.eclipse.jdt.annotation.NonNull;
-import org.opendaylight.yangtools.yang.common.UnresolvedQName.Unqualified;
-import org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement;
-import org.opendaylight.yangtools.yang.model.api.stmt.ModuleStatement;
-import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour;
-import org.opendaylight.yangtools.yang.parser.spi.meta.StatementNamespace;
-
-/**
- * Intermediate-stage namespace equivalent to ModuleNamespace except it is keyed by module names. This namespace is
- * used to resolve inter-module references before actual linkage occurs.
- */
-public final class PreLinkageModuleNamespace
- extends StatementNamespace<Unqualified, ModuleStatement, ModuleEffectiveStatement> {
- public static final @NonNull NamespaceBehaviour<?, ?, ?> BEHAVIOUR =
- NamespaceBehaviour.global(PreLinkageModuleNamespace.class);
-
- private PreLinkageModuleNamespace() {
- // Hidden on purpose
- }
-}
*/
package org.opendaylight.yangtools.yang.parser.spi;
-import static com.google.common.base.Verify.verifyNotNull;
-import static java.util.Objects.requireNonNull;
-
import com.google.common.annotations.Beta;
+import java.io.Serial;
import java.util.Collection;
import java.util.Iterator;
-import java.util.Map;
import java.util.Optional;
import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.stmt.SchemaTreeAwareEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.SchemaTreeEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.UnknownStatement;
-import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour;
import org.opendaylight.yangtools.yang.parser.spi.meta.StatementNamespace;
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;
/**
* Statement local namespace, which holds direct schema node descendants. This corresponds to the contents of the schema
@Beta
public final class SchemaTreeNamespace<D extends DeclaredStatement<QName>, E extends SchemaTreeEffectiveStatement<D>>
extends StatementNamespace<QName, D, E> {
- public static final class Behaviour<D extends DeclaredStatement<QName>, E extends SchemaTreeEffectiveStatement<D>>
- extends NamespaceBehaviour<QName, StmtContext<?, D, E>, SchemaTreeNamespace<D, E>> {
- @SuppressWarnings({ "rawtypes", "unchecked" })
- Behaviour() {
- super((Class) SchemaTreeNamespace.class);
- }
-
- /**
- * {@inheritDoc}
- *
- * <p>
- * This method is analogous to {@link SchemaTreeAwareEffectiveStatement#findSchemaTreeNode(QName)}.
- */
- @Override
- public StmtContext<?, D, E> getFrom(final NamespaceStorageNode storage, final QName key) {
- // Get the backing storage node for the requested storage
- final NamespaceStorageNode storageNode = globalOrStatementSpecific(storage);
- // Check try to look up existing node
- final StmtContext<?, D, E> existing = storageNode.getFromLocalStorage(getIdentifier(), key);
-
- // An existing node takes precedence, if it does not exist try to request it
- return existing != null ? existing : requestFrom(storageNode, key);
- }
-
- @Override
- public Map<QName, StmtContext<?, D, E>> getAllFrom(final NamespaceStorageNode storage) {
- // FIXME: 7.0.0: this method needs to be well-defined
- return null;
- }
-
- @Override
- @SuppressWarnings("unchecked")
- public void addTo(final NamespaceStorageNode storage, final QName key, final StmtContext<?, D, E> value) {
- final StmtContext<?, D, E> prev = globalOrStatementSpecific(storage).putToLocalStorageIfAbsent(
- SchemaTreeNamespace.class, key, value);
-
- if (prev != null) {
- throw new SourceException(value,
- "Error in module '%s': cannot add '%s'. Node name collision: '%s' already declared at %s",
- value.getRoot().rawArgument(), key, prev.argument(), prev.sourceReference());
- }
- }
+ @Serial
+ private static final long serialVersionUID = 1L;
+ private static final @NonNull SchemaTreeNamespace<?, ?> INSTANCE = new SchemaTreeNamespace<>();
- private static <D extends DeclaredStatement<QName>, E extends SchemaTreeEffectiveStatement<D>>
- StmtContext<?, D, E> requestFrom(final NamespaceStorageNode storageNode, final QName key) {
- return storageNode instanceof OnDemandSchemaTreeStorageNode ondemand ? ondemand.requestSchemaTreeChild(key)
- : null;
- }
-
- private static NamespaceStorageNode globalOrStatementSpecific(final NamespaceStorageNode storage) {
- NamespaceStorageNode current = requireNonNull(storage);
- while (!isLocalOrGlobal(current.getStorageNodeType())) {
- current = verifyNotNull(current.getParentNamespaceStorage());
- }
- return current;
- }
-
- private static boolean isLocalOrGlobal(final StorageNodeType type) {
- return type == StorageNodeType.STATEMENT_LOCAL || type == StorageNodeType.GLOBAL;
- }
+ private SchemaTreeNamespace() {
+ super("schemaTree");
}
- public static final @NonNull NamespaceBehaviour<?, ?, ?> BEHAVIOUR = new Behaviour<>();
-
- private SchemaTreeNamespace() {
- // Hidden on purpose
+ @SuppressWarnings("unchecked")
+ public static <D extends DeclaredStatement<QName>, E extends SchemaTreeEffectiveStatement<D>>
+ @NonNull SchemaTreeNamespace<D, E> instance() {
+ return (SchemaTreeNamespace<D, E>) INSTANCE;
}
/**
}
QName nextPath = iterator.next();
- @SuppressWarnings("unchecked")
- StmtContext<?, ?, ?> current = (StmtContext<?, ?, ?>) root.getFromNamespace(SchemaTreeNamespace.class,
- nextPath);
+ StmtContext<?, ?, ?> current = root.getFromNamespace(SchemaTreeNamespace.INSTANCE, nextPath);
if (current == null) {
return Optional.ofNullable(tryToFindUnknownStatement(nextPath.getLocalName(), root));
}
while (current != null && iterator.hasNext()) {
nextPath = iterator.next();
- @SuppressWarnings("unchecked")
- final StmtContext<?, ?, ?> nextNodeCtx = (StmtContext<?, ?, ?>) current.getFromNamespace(
- SchemaTreeNamespace.class, nextPath);
+ final StmtContext<?, ?, ?> nextNodeCtx = current.getFromNamespace(SchemaTreeNamespace.INSTANCE, nextPath);
if (nextNodeCtx == null) {
return Optional.ofNullable(tryToFindUnknownStatement(nextPath.getLocalName(), current));
}
--- /dev/null
+/*
+ * Copyright (c) 2022 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;
+
+import static com.google.common.base.Verify.verifyNotNull;
+import static java.util.Objects.requireNonNull;
+
+import java.util.Map;
+import org.eclipse.jdt.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.stmt.SchemaTreeAwareEffectiveStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.SchemaTreeEffectiveStatement;
+import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
+import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
+
+/**
+ * {@link NamespaceBehaviour} handling {@link SchemaTreeNamespace}.
+ */
+public final class SchemaTreeNamespaceBehaviour<D extends DeclaredStatement<QName>,
+ E extends SchemaTreeEffectiveStatement<D>>
+ extends NamespaceBehaviour<QName, StmtContext<?, D, E>, SchemaTreeNamespace<D, E>> {
+ public static final @NonNull SchemaTreeNamespaceBehaviour<?, ?> INSTANCE = new SchemaTreeNamespaceBehaviour<>();
+
+ private SchemaTreeNamespaceBehaviour() {
+ super(SchemaTreeNamespace.instance());
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * <p>
+ * This method is analogous to {@link SchemaTreeAwareEffectiveStatement#findSchemaTreeNode(QName)}.
+ */
+ @Override
+ public StmtContext<?, D, E> getFrom(final NamespaceStorageNode storage, final QName key) {
+ // Get the backing storage node for the requested storage
+ final NamespaceStorageNode storageNode = globalOrStatementSpecific(storage);
+ // Check try to look up existing node
+ final StmtContext<?, D, E> existing = storageNode.getFromLocalStorage(getIdentifier(), key);
+
+ // An existing node takes precedence, if it does not exist try to request it
+ return existing != null ? existing : requestFrom(storageNode, key);
+ }
+
+ @Override
+ public Map<QName, StmtContext<?, D, E>> getAllFrom(final NamespaceStorageNode storage) {
+ // FIXME: 7.0.0: this method needs to be well-defined
+ return null;
+ }
+
+ @Override
+ public void addTo(final NamespaceStorageNode storage, final QName key, final StmtContext<?, D, E> value) {
+ final StmtContext<?, D, E> prev = globalOrStatementSpecific(storage).putToLocalStorageIfAbsent(
+ SchemaTreeNamespace.instance(), key, value);
+
+ if (prev != null) {
+ throw new SourceException(value,
+ "Error in module '%s': cannot add '%s'. Node name collision: '%s' already declared at %s",
+ value.getRoot().rawArgument(), key, prev.argument(), prev.sourceReference());
+ }
+ }
+
+ private static <D extends DeclaredStatement<QName>, E extends SchemaTreeEffectiveStatement<D>>
+ StmtContext<?, D, E> requestFrom(final NamespaceStorageNode storageNode, final QName key) {
+ return storageNode instanceof OnDemandSchemaTreeStorageNode ondemand ? ondemand.requestSchemaTreeChild(key)
+ : null;
+ }
+
+ private static NamespaceStorageNode globalOrStatementSpecific(final NamespaceStorageNode storage) {
+ NamespaceStorageNode current = requireNonNull(storage);
+ while (!isLocalOrGlobal(current.getStorageNodeType())) {
+ current = verifyNotNull(current.getParentNamespaceStorage());
+ }
+ return current;
+ }
+
+ private static boolean isLocalOrGlobal(final StorageNodeType type) {
+ return type == StorageNodeType.STATEMENT_LOCAL || type == StorageNodeType.GLOBAL;
+ }
+}
\ No newline at end of file
+++ /dev/null
-/*
- * Copyright (c) 2015 Cisco Systems, Inc. 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;
-
-import org.eclipse.jdt.annotation.NonNull;
-import org.opendaylight.yangtools.yang.model.api.stmt.SubmoduleEffectiveStatement;
-import org.opendaylight.yangtools.yang.model.api.stmt.SubmoduleStatement;
-import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
-import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour;
-import org.opendaylight.yangtools.yang.parser.spi.meta.StatementNamespace;
-
-/**
- * Submodule equivalent of ModuleNamespace.
- */
-// FIXME: describe scoping of this namespace
-public final class SubmoduleNamespace
- extends StatementNamespace<SourceIdentifier, SubmoduleStatement, SubmoduleEffectiveStatement> {
- public static final @NonNull NamespaceBehaviour<?, ?, ?> BEHAVIOUR =
- NamespaceBehaviour.global(SubmoduleNamespace.class);
-
- private SubmoduleNamespace() {
- // Hidden on purpose
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2015 Cisco Systems, Inc. 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;
-
-import org.eclipse.jdt.annotation.NonNull;
-import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.model.api.stmt.TypedefEffectiveStatement;
-import org.opendaylight.yangtools.yang.model.api.stmt.TypedefStatement;
-import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour;
-import org.opendaylight.yangtools.yang.parser.spi.meta.StatementNamespace.TreeScoped;
-
-/**
- * Derived types namespace. All derived type names defined within a parent node or at the top level of the module
- * (or its submodules) share the same type identifier namespace.
- *
- * <p>
- * This namespace is scoped to all descendant nodes of the parent node or module. This means that any descendant node
- * may use that typedef, and it MUST NOT define a typedef with the same name.
- *
- * <p>
- * This namespace includes all type definitions implied by the language in which the current statement resides
- * (e.g. RFC6020/RFC7950 for YANG 1.0/1.1).
- */
-public final class TypeNamespace extends TreeScoped<QName, TypedefStatement, TypedefEffectiveStatement> {
- public static final @NonNull NamespaceBehaviour<?, ?, ?> BEHAVIOUR =
- NamespaceBehaviour.treeScoped(TypeNamespace.class);
-
- private TypeNamespace() {
- // Hidden on purpose
- }
-}
*/
@Override
public void onStatementAdded(final Mutable<QName, D, E> stmt) {
- stmt.coerceParentContext().addToNs(SchemaTreeNamespace.class, stmt.getArgument(), stmt);
+ stmt.coerceParentContext().addToNs(SchemaTreeNamespace.instance(), stmt.getArgument(), stmt);
}
// Non-final because {@code input} and {@code output} are doing their own thing.
import com.google.common.base.MoreObjects.ToStringHelper;
import java.util.Map;
+import org.eclipse.jdt.annotation.NonNull;
/**
* An {@link NamespaceBehaviour} which derives keys from a different namespace.
public abstract class DerivedNamespaceBehaviour<K, V, L, N extends ParserNamespace<K, V>,
O extends ParserNamespace<L, ?>> extends NamespaceBehaviour<K, V, N> {
- private final Class<O> derivedFrom;
+ private final @NonNull O derivedFrom;
- protected DerivedNamespaceBehaviour(final Class<N> identifier, final Class<O> derivedFrom) {
+ protected DerivedNamespaceBehaviour(final N identifier, final O derivedFrom) {
super(identifier);
this.derivedFrom = requireNonNull(derivedFrom);
}
- public Class<O> getDerivedFrom() {
+ public final @NonNull O getDerivedFrom() {
return derivedFrom;
}
@Override
protected ToStringHelper addToStringAttributes(final ToStringHelper helper) {
- return helper.add("derivedFrom", derivedFrom.getName());
+ return helper.add("derivedFrom", derivedFrom);
}
}
*/
package org.opendaylight.yangtools.yang.parser.spi.meta;
+import java.io.Serial;
+import org.eclipse.jdt.annotation.NonNull;
+
/**
* Special namespace which allows import of namespaces from other sources.
*
*
* @param <K> Imported context identifier
*/
-public abstract class ImportedNamespaceContext<K> extends ParserNamespace<K, StmtContext<?, ?, ?>> {
+public final class ImportedNamespaceContext<K> extends ParserNamespace<K, StmtContext<?, ?, ?>> {
+ @Serial
+ private static final long serialVersionUID = 1L;
+ public ImportedNamespaceContext(final @NonNull String name) {
+ super(name);
+ }
}
*/
@Deprecated
<K, D extends DeclaredStatement<?>, N extends StatementNamespace<K, ? extends D, ?>>
- @NonNull Prerequisite<D> requiresDeclared(StmtContext<?, ?, ?> context, Class<N> namespace, K key);
+ @NonNull Prerequisite<D> requiresDeclared(StmtContext<?, ?, ?> context, N namespace, K key);
/**
* Action requires that the specified context completes specified phase before {@link #apply(InferenceAction)}
requiresCtx(StmtContext<A, D, E> context, ModelProcessingPhase phase);
<K, N extends StatementNamespace<K, ?, ?>> @NonNull Prerequisite<StmtContext<?, ?, ?>> requiresCtx(
- StmtContext<?, ?, ?> context, Class<@NonNull N> namespace, K key, ModelProcessingPhase phase);
+ StmtContext<?, ?, ?> context, @NonNull N namespace, K key, ModelProcessingPhase phase);
<K, N extends StatementNamespace<K, ?, ?>> @NonNull Prerequisite<StmtContext<?, ?, ?>> requiresCtx(
- StmtContext<?, ?, ?> context, Class<@NonNull N> namespace, NamespaceKeyCriterion<K> criterion,
+ StmtContext<?, ?, ?> context, @NonNull N namespace, NamespaceKeyCriterion<K> criterion,
ModelProcessingPhase phase);
<K, E extends EffectiveStatement<?, ?>, N extends ParserNamespace<K, ? extends StmtContext<?, ?, ?>>>
- @NonNull Prerequisite<StmtContext<?, ?, E>> requiresCtxPath(StmtContext<?, ?, ?> context, Class<N> namespace,
+ @NonNull Prerequisite<StmtContext<?, ?, E>> requiresCtxPath(StmtContext<?, ?, ?> context, N namespace,
Iterable<K> keys, ModelProcessingPhase phase);
/**
}
<K, E extends EffectiveStatement<?, ?>, N extends ParserNamespace<K, ? extends StmtContext<?, ?, ?>>>
- @NonNull Prerequisite<Mutable<?, ?, E>> mutatesEffectiveCtx(StmtContext<?, ?, ?> context, Class<N> namespace,
- K key);
+ @NonNull Prerequisite<Mutable<?, ?, E>> mutatesEffectiveCtx(StmtContext<?, ?, ?> context, N namespace, K key);
<K, E extends EffectiveStatement<?, ?>, N extends ParserNamespace<K, ? extends StmtContext<?, ?, ?>>>
@NonNull Prerequisite<Mutable<?, ?, E>> mutatesEffectiveCtxPath(StmtContext<?, ?, ?> context,
- Class<N> namespace, Iterable<K> keys);
+ N namespace, Iterable<K> keys);
/**
* Action mutates the specified statement in the specified phase. Target statement cannot complete specified
@Deprecated
<K, D extends DeclaredStatement<?>, N extends StatementNamespace<K, ? extends D, ?>>
@NonNull Prerequisite<StmtContext<?, D, ?>> requiresDeclaredCtx(StmtContext<?, ?, ?> context,
- Class<N> namespace, K key);
+ N namespace, K key);
/**
* Create a requirement on specified statement to become effective.
*/
@Deprecated
<K, E extends EffectiveStatement<?, ?>, N extends StatementNamespace<K, ?, ? extends E>>
- @NonNull Prerequisite<E> requiresEffective(StmtContext<?, ?, ?> context, Class<N> namespace, K key);
+ @NonNull Prerequisite<E> requiresEffective(StmtContext<?, ?, ?> context, N namespace, K key);
/**
* Create a requirement on specified statement context to become effective.
*/
@Deprecated
<K, E extends EffectiveStatement<?, ?>, N extends StatementNamespace<K, ?, ? extends E>>
- @NonNull Prerequisite<StmtContext<?, ?, E>> requiresEffectiveCtx(StmtContext<?, ?, ?> context,
- Class<N> namespace, K key);
+ @NonNull Prerequisite<StmtContext<?, ?, E>> requiresEffectiveCtx(StmtContext<?, ?, ?> context, N namespace,
+ K key);
/**
* Mark the fact that this action is mutating a namespace.
* @deprecated Undocumented method. Use at your own risk.
*/
@Deprecated
- <N extends ParserNamespace<?, ?>> @NonNull Prerequisite<Mutable<?,?,?>> mutatesNs(Mutable<?,?, ?> ctx,
- Class<N> namespace);
+ <N extends ParserNamespace<?, ?>> @NonNull Prerequisite<Mutable<?,?,?>> mutatesNs(Mutable<?,?, ?> ctx, N namespace);
}
import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.SchemaTreeAwareEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.SchemaTreeEffectiveStatement;
-import org.opendaylight.yangtools.yang.parser.spi.SchemaTreeNamespace;
+import org.opendaylight.yangtools.yang.parser.spi.SchemaTreeNamespaceBehaviour;
/**
* Definition / implementation of specific Identifier Namespace behaviour. A namespace behaviour is built on top
* n {@link StorageNodeType}.
*
* <p>
- * For common behaviour models please use static factories {@link #global(Class)}, {@link #sourceLocal(Class)} and
- * {@link #treeScoped(Class)}.
+ * For common behaviour models please use static factories {@link #global(ParserNamespace)},
+ * {@link #sourceLocal(ParserNamespace)} and {@link #treeScoped(ParserNamespace)}.
*
* @param <K> Key type
* @param <V> Value type
* @param <N> Namespace Type
*/
-public abstract class NamespaceBehaviour<K, V, N extends ParserNamespace<K, V>>
- extends AbstractSimpleIdentifiable<Class<N>> {
+// FIXME: remove the 'N' parameter?
+public abstract class NamespaceBehaviour<K, V, N extends ParserNamespace<K, V>> extends AbstractSimpleIdentifiable<N> {
public enum StorageNodeType {
/**
* @return Namespace behaviour
* @throws NamespaceNotAvailableException when the namespace is not available
*/
- <K, V, N extends ParserNamespace<K, V>> NamespaceBehaviour<K, V, N> getNamespaceBehaviour(Class<N> type);
+ <K, V, N extends ParserNamespace<K, V>> NamespaceBehaviour<K, V, N> getNamespaceBehaviour(N type);
}
public interface NamespaceStorageNode {
@Nullable NamespaceStorageNode getParentNamespaceStorage();
- <K, V, N extends ParserNamespace<K, V>> @Nullable V getFromLocalStorage(Class<N> type, K key);
+ <K, V, N extends ParserNamespace<K, V>> @Nullable V getFromLocalStorage(N type, K key);
- <K, V, N extends ParserNamespace<K, V>> @Nullable Map<K, V> getAllFromLocalStorage(Class<N> type);
+ <K, V, N extends ParserNamespace<K, V>> @Nullable Map<K, V> getAllFromLocalStorage(N type);
/**
* Populate specified namespace with a key/value pair, overwriting previous contents. Similar to
* @param value Value
* @return Previously-stored value, or null if the key was not present
*/
- <K, V, N extends ParserNamespace<K, V>> @Nullable V putToLocalStorage(Class<N> type, K key, V value);
+ <K, V, N extends ParserNamespace<K, V>> @Nullable V putToLocalStorage(N type, K key, V value);
/**
* Populate specified namespace with a key/value pair unless the key is already associated with a value. Similar
* @param value Value
* @return Preexisting value or null if there was no previous mapping
*/
- <K, V, N extends ParserNamespace<K, V>> @Nullable V putToLocalStorageIfAbsent(Class<N> type, K key, V value);
+ <K, V, N extends ParserNamespace<K, V>> @Nullable V putToLocalStorageIfAbsent(N type, K key, V value);
}
/**
* Request that a new member of this node's schema tree statement be added. Implementations are required to
* perform lookup in their internal structure and create a child if tractable. Resulting node is expected to
* have been registered with local storage, so that it is accessible through
- * {@link #getFromLocalStorage(Class, Object)}.
+ * {@link #getFromLocalStorage(ParserNamespace, Object)}.
*
* <p>
* This method must not change its mind about a child's presence -- once it returns non-present, it has to be
* <p>
* The results produced by this method are expected to be consistent with
* {@link SchemaTreeAwareEffectiveStatement#findSchemaTreeNode(QName)} and
- * {@link SchemaTreeNamespace.Behaviour#getFrom(NamespaceStorageNode, QName)}.
+ * {@link SchemaTreeNamespaceBehaviour#getFrom(NamespaceStorageNode, QName)}.
*
* @param qname node identifier of the child being requested
* @return Requested child, if it is present.
@Nullable StmtContext<QName, D, E> requestSchemaTreeChild(QName qname);
}
- protected NamespaceBehaviour(final Class<N> identifier) {
+ protected NamespaceBehaviour(final N identifier) {
super(identifier);
}
* @return global namespace behaviour for supplied namespace type.
*/
public static <K, V, N extends ParserNamespace<K, V>> @NonNull NamespaceBehaviour<K, V, N> global(
- final Class<N> identifier) {
+ final N identifier) {
return new StorageSpecific<>(identifier, StorageNodeType.GLOBAL);
}
* @return source-local namespace behaviour for supplied namespace type.
*/
public static <K, V, N extends ParserNamespace<K, V>> @NonNull NamespaceBehaviour<K, V, N> sourceLocal(
- final Class<N> identifier) {
+ final N identifier) {
return new StorageSpecific<>(identifier, StorageNodeType.SOURCE_LOCAL_SPECIAL);
}
public static <K, V, N extends ParserNamespace<K, V>> @NonNull NamespaceBehaviour<K, V, N> statementLocal(
- final Class<N> identifier) {
+ final N identifier) {
return new StatementLocal<>(identifier);
}
* @return root-statement-local namespace behaviour for supplied namespace type.
*/
public static <K, V, N extends ParserNamespace<K, V>> @NonNull NamespaceBehaviour<K, V, N> rootStatementLocal(
- final Class<N> identifier) {
+ final N identifier) {
return new StorageSpecific<>(identifier, StorageNodeType.ROOT_STATEMENT_LOCAL);
}
* @return tree-scoped namespace behaviour for supplied namespace type.
*/
public static <K, V, N extends ParserNamespace<K, V>> @NonNull NamespaceBehaviour<K, V, N> treeScoped(
- final Class<N> identifier) {
+ final N identifier) {
return new TreeScoped<>(identifier);
}
storage.putToLocalStorage(getIdentifier(), key, value);
}
- abstract static class AbstractSpecific<K, V, N extends ParserNamespace<K, V>>
- extends NamespaceBehaviour<K, V, N> {
- AbstractSpecific(final Class<N> identifier) {
+ abstract static class AbstractSpecific<K, V, N extends ParserNamespace<K, V>> extends NamespaceBehaviour<K, V, N> {
+ AbstractSpecific(final N identifier) {
super(identifier);
}
}
static final class StatementLocal<K, V, N extends ParserNamespace<K, V>> extends AbstractSpecific<K, V, N> {
- StatementLocal(final Class<N> identifier) {
+ StatementLocal(final N identifier) {
super(identifier);
}
static final class StorageSpecific<K, V, N extends ParserNamespace<K, V>> extends AbstractSpecific<K, V, N> {
private final StorageNodeType storageType;
- StorageSpecific(final Class<N> identifier, final StorageNodeType type) {
+ StorageSpecific(final N identifier, final StorageNodeType type) {
super(identifier);
storageType = requireNonNull(type);
}
}
static final class TreeScoped<K, V, N extends ParserNamespace<K, V>> extends NamespaceBehaviour<K, V, N> {
- TreeScoped(final Class<N> identifier) {
+ TreeScoped(final N identifier) {
super(identifier);
}
@Override
protected ToStringHelper addToStringAttributes(final ToStringHelper helper) {
- return helper.add("identifier", getIdentifier().getName());
+ return helper.add("identifier", getIdentifier());
}
}
/**
* Support work with namespace content.
*/
+// FIXME: ditch <N> parameters
@Beta
public interface NamespaceStmtCtx extends CommonStmtCtx {
/**
* @param nsType namespace type class
* @return Namespace contents, if available
*/
- <K, V, N extends ParserNamespace<K, V>> @Nullable Map<K, V> namespace(Class<@NonNull N> nsType);
+ <K, V, N extends ParserNamespace<K, V>> @Nullable Map<K, V> namespace(@NonNull N nsType);
/**
* Return a value associated with specified key within a namespace.
* @return Value, or null if there is no element
* @throws NamespaceNotAvailableException when the namespace is not available.
*/
- <K, V, T extends K, N extends ParserNamespace<K, V>> @Nullable V namespaceItem(Class<@NonNull N> nsType, T key);
+ <K, V, T extends K, N extends ParserNamespace<K, V>> @Nullable V namespaceItem(@NonNull N nsType, T key);
/**
* Return the portion of specified namespace stored in this node. Depending on namespace behaviour this may or may
- * not represent the complete contents of the namespace as available via {@link #namespace(Class)}.
+ * not represent the complete contents of the namespace as available via {@link #namespace(ParserNamespace)}.
*
* <p>
* This partial view is useful when the need is not to perform a proper namespace lookup, but rather act on current
* @param nsType namespace type class
* @return Namespace portion stored in this node, if available
*/
- <K, V, N extends ParserNamespace<K, V>> @Nullable Map<K, V> localNamespacePortion(Class<@NonNull N> nsType);
+ <K, V, N extends ParserNamespace<K, V>> @Nullable Map<K, V> localNamespacePortion(@NonNull N nsType);
/**
* Return the selected namespace.
* @return Namespace contents, if available
*/
// TODO: migrate users away
- default <K, V, N extends ParserNamespace<K, V>> Map<K, V> getAllFromNamespace(final Class<N> nsType) {
+ default <K, V, N extends ParserNamespace<K, V>> Map<K, V> getAllFromNamespace(final @NonNull N nsType) {
return namespace(nsType);
}
* @throws NamespaceNotAvailableException when the namespace is not available.
*/
// TODO: migrate users away
- default <K, V, T extends K, N extends ParserNamespace<K, V>>
- @Nullable V getFromNamespace(final Class<@NonNull N> type, final T key) {
+ default <K, V, T extends K, N extends ParserNamespace<K, V>> @Nullable V getFromNamespace(
+ final @NonNull N type, final T key) {
return namespaceItem(type, key);
}
}
*/
package org.opendaylight.yangtools.yang.parser.spi.meta;
+import static java.util.Objects.requireNonNull;
+
import com.google.common.base.MoreObjects;
+import java.io.Serial;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
+import org.opendaylight.yangtools.concepts.Identifier;
/**
* {@link ParserNamespace} serves as common superclass for namespaces used during parser operation. Each such namespace,
* is a type-captured subclass. This type capture of namespace allows for handy type-safe reading methods such as
- * {@link NamespaceStmtCtx#getFromNamespace(Class, Object)} and still allows introduction of new namespaces without need
- * to change APIs.
+ * {@link NamespaceStmtCtx#getFromNamespace(ParserNamespace, Object)} and still allows introduction of new namespaces
+ * without need to change APIs.
*
* @param <K> Identifier type
* @param <V> Value type
*/
@NonNullByDefault
-public abstract class ParserNamespace<K, V> {
+public class ParserNamespace<K, V> implements Identifier {
+ @Serial
+ private static final long serialVersionUID = 1L;
+
+ private final String name;
+
+ // FIXME: hide this constructor once we collapse the type hierarchy
+ public ParserNamespace(final String name) {
+ this.name = requireNonNull(name);
+ }
+
@Override
public final int hashCode() {
return super.hashCode();
@Override
public final String toString() {
- return MoreObjects.toStringHelper(this).toString();
+ return MoreObjects.toStringHelper(this).add("name", name).toString();
}
}
// 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 final class StatementDefinitionNamespace extends ParserNamespace<QName, StatementSupport<?, ?, ?>> {
- public static final @NonNull NamespaceBehaviour<?, ?, ?> BEHAVIOUR =
- NamespaceBehaviour.global(StatementDefinitionNamespace.class);
+public final class StatementDefinitions {
- private StatementDefinitionNamespace() {
+ public static final @NonNull ParserNamespace<QName, StatementSupport<?, ?, ?>> NAMESPACE =
+ new ParserNamespace<>("statementDefinitions");
+
+ public static final @NonNull NamespaceBehaviour<?, ?, ?> BEHAVIOUR = NamespaceBehaviour.global(NAMESPACE);
+
+ private StatementDefinitions() {
// Hidden on purpose
}
}
*/
package org.opendaylight.yangtools.yang.parser.spi.meta;
+import java.io.Serial;
+import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
-public abstract class StatementNamespace<K, D extends DeclaredStatement<?>, E extends EffectiveStatement<?, D>>
+// FIXME: is this subclass useful at all?
+public class StatementNamespace<K, D extends DeclaredStatement<?>, E extends EffectiveStatement<?, D>>
extends ParserNamespace<K, StmtContext<?, D, E>> {
- public abstract static class TreeScoped<K, D extends DeclaredStatement<?>, E extends EffectiveStatement<?, D>>
+ @Serial
+ private static final long serialVersionUID = 1L;
+
+ public StatementNamespace(final @NonNull String name) {
+ super(name);
+ }
+
+ // FIXME: is this subclass useful at all?
+ public static class TreeScoped<K, D extends DeclaredStatement<?>, E extends EffectiveStatement<?, D>>
extends StatementNamespace<K, D, E> {
+ @Serial
+ private static final long serialVersionUID = 1L;
+ public TreeScoped(final @NonNull String name) {
+ super(name);
+ }
}
}
@NonNull Collection<? extends EffectiveStatement<?, ?>> substatements);
}
+ /**
+ * Projection of {@link StatementSupport}s available within a particular source. This namespace is purely virtual
+ * and its behaviour corresponds to {@link NamespaceBehaviour#rootStatementLocal(ParserNamespace)} and is always
+ * available.
+ * Its contents are derived from {@link StatementSupportBundle}s active in the current {@link ModelProcessingPhase}
+ * as well as {@link StatementDefinitions} and {@link StmtContext#yangVersion()} of the source root statement.
+ */
+ @Beta
+ public static final @NonNull ParserNamespace<QName, StatementSupport<?, ?, ?>> NAMESPACE =
+ new ParserNamespace<>("statementSupports");
+
private final @NonNull StatementPolicy<A, D> policy;
private final @NonNull StatementDefinition publicDefinition;
private final @NonNull CopyPolicy copyPolicy;
private final StatementSupportBundle parent;
private final ImmutableMap<QName, StatementSupport<?, ?, ?>> commonDefinitions;
private final ImmutableTable<YangVersion, QName, StatementSupport<?, ?, ?>> versionSpecificDefinitions;
- private final ImmutableMap<Class<?>, NamespaceBehaviour<?, ?, ?>> namespaceDefinitions;
+ private final ImmutableMap<ParserNamespace<?, ?>, NamespaceBehaviour<?, ?, ?>> namespaceDefinitions;
private final ImmutableSet<YangVersion> supportedVersions;
private StatementSupportBundle(final StatementSupportBundle parent,
final ImmutableSet<YangVersion> supportedVersions,
final ImmutableMap<QName, StatementSupport<?, ?, ?>> commonStatements,
- final ImmutableMap<Class<?>, NamespaceBehaviour<?, ?, ?>> namespaces,
+ final ImmutableMap<ParserNamespace<?, ?>, NamespaceBehaviour<?, ?, ?>> namespaces,
final ImmutableTable<YangVersion, QName, StatementSupport<?, ?, ?>> versionSpecificStatements) {
this.parent = parent;
this.supportedVersions = supportedVersions;
return versionSpecificDefinitions;
}
- public ImmutableMap<Class<?>, NamespaceBehaviour<?, ?, ?>> getNamespaceDefinitions() {
+ public ImmutableMap<ParserNamespace<?, ?>, NamespaceBehaviour<?, ?, ?>> getNamespaceDefinitions() {
return namespaceDefinitions;
}
@Override
@SuppressWarnings("unchecked")
public <K, V, N extends ParserNamespace<K, V>> NamespaceBehaviour<K, V, N> getNamespaceBehaviour(
- final Class<N> namespace) {
+ final N namespace) {
final NamespaceBehaviour<?, ?, ?> potential = namespaceDefinitions.get(namespace);
if (potential != null) {
checkState(namespace.equals(potential.getIdentifier()));
return null;
}
- public boolean hasNamespaceBehaviour(final Class<? extends ParserNamespace<?, ?>> namespace) {
+ public boolean hasNamespaceBehaviour(final ParserNamespace<?, ?> namespace) {
if (namespaceDefinitions.containsKey(namespace)) {
return true;
}
private final Map<QName, StatementSupport<?, ?, ?>> commonStatements = new HashMap<>();
private final Table<YangVersion, QName, StatementSupport<?, ?, ?>> versionSpecificStatements =
HashBasedTable.create();
- private final Map<Class<?>, NamespaceBehaviour<?, ?, ?>> namespaces = new HashMap<>();
+ private final Map<ParserNamespace<?, ?>, NamespaceBehaviour<?, ?, ?>> namespaces = new HashMap<>();
private final ImmutableSet<YangVersion> supportedVersions;
private StatementSupportBundle parent;
+++ /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 final class StatementSupportNamespace extends ParserNamespace<QName, StatementSupport<?, ?, ?>> {
- StatementSupportNamespace() {
- // FIXME: is this really used?!
- }
-}
* @param <U> value type
* @throws NamespaceNotAvailableException when the namespace is not available.
*/
- <K, V, T extends K, U extends V, N extends ParserNamespace<K, V>> void addToNs(Class<@NonNull N> type,
- T key, U value);
+ <K, V, T extends K, U extends V, N extends ParserNamespace<K, V>> void addToNs(@NonNull N type, T key, U value);
@Override
RootStmtContext.Mutable<?, ?, ?> getRoot();
* @param stmt
* to be added to namespace map
*/
- <K, KT extends K, N extends StatementNamespace<K, ?, ?>> void addContext(Class<@NonNull N> namespace, KT key,
+ <K, KT extends K, N extends StatementNamespace<K, ?, ?>> void addContext(@NonNull N namespace, KT key,
StmtContext<?, ?, ?> stmt);
/**
import org.opendaylight.yangtools.yang.parser.spi.meta.ModelActionBuilder.InferenceContext;
import org.opendaylight.yangtools.yang.parser.spi.meta.ModelActionBuilder.Prerequisite;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.Mutable;
-import org.opendaylight.yangtools.yang.parser.spi.source.BelongsToPrefixToModuleCtx;
-import org.opendaylight.yangtools.yang.parser.spi.source.BelongsToPrefixToModuleName;
-import org.opendaylight.yangtools.yang.parser.spi.source.ImportPrefixToModuleCtx;
-import org.opendaylight.yangtools.yang.parser.spi.source.ModuleCtxToModuleQName;
-import org.opendaylight.yangtools.yang.parser.spi.source.ModuleNameToModuleQName;
import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
+import org.opendaylight.yangtools.yang.parser.spi.source.SourceParserNamespaces;
public final class StmtContextUtils {
private StmtContextUtils() {
if (ctx.producesDeclared(ModuleStatement.class)) {
return lookupModuleQName(ctx, ctx);
} else if (ctx.producesDeclared(SubmoduleStatement.class)) {
- final var belongsTo = ctx.getAllFromNamespace(BelongsToPrefixToModuleCtx.class);
+ final var belongsTo = ctx.getAllFromNamespace(SourceParserNamespaces.BELONGSTO_PREFIX_TO_MODULECTX);
if (belongsTo == null || belongsTo.isEmpty()) {
throw new IllegalArgumentException(ctx + " does not have belongs-to linkage resolved");
}
private static @NonNull QNameModule lookupModuleQName(final NamespaceStmtCtx storage,
final StmtContext<?, ?, ?> module) {
- final var ret = storage.getFromNamespace(ModuleCtxToModuleQName.class, module);
+ final var ret = storage.getFromNamespace(SourceParserNamespaces.MODULECTX_TO_QNAME, module);
if (ret == null) {
throw new IllegalArgumentException("Failed to look up QNameModule for " + module + " in " + storage);
}
public static QNameModule getModuleQNameByPrefix(final StmtContext<?, ?, ?> ctx, final String prefix) {
final StmtContext<?, ?, ?> root = ctx.getRoot();
- final StmtContext<?, ?, ?> importedModule = root.getFromNamespace(ImportPrefixToModuleCtx.class, prefix);
- final QNameModule qnameModule = ctx.getFromNamespace(ModuleCtxToModuleQName.class, importedModule);
+ final StmtContext<?, ?, ?> importedModule = root.getFromNamespace(
+ SourceParserNamespaces.IMPORT_PREFIX_TO_MODULECTX, prefix);
+ final QNameModule qnameModule = ctx.getFromNamespace(SourceParserNamespaces.MODULECTX_TO_QNAME, importedModule);
if (qnameModule != null) {
return qnameModule;
}
if (root.producesDeclared(SubmoduleStatement.class)) {
- final var moduleName = root.getFromNamespace(BelongsToPrefixToModuleName.class, prefix);
- return ctx.getFromNamespace(ModuleNameToModuleQName.class, moduleName);
+ return ctx.getFromNamespace(SourceParserNamespaces.MODULE_NAME_TO_QNAME,
+ root.getFromNamespace(SourceParserNamespaces.BELONGSTO_PREFIX_TO_MODULE_NAME, prefix));
}
return null;
import java.util.Map;
import java.util.Map.Entry;
import org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition;
-import org.opendaylight.yangtools.yang.parser.spi.ExtensionNamespace;
-import org.opendaylight.yangtools.yang.parser.spi.source.ModuleCtxToModuleQName;
+import org.opendaylight.yangtools.yang.parser.spi.ParserNamespaces;
+import org.opendaylight.yangtools.yang.parser.spi.source.SourceParserNamespaces;
public final class SubstatementValidator {
private final ImmutableMap<StatementDefinition, Cardinality> cardinalityMap;
private final StatementDefinition currentStatement;
private SubstatementValidator(final Builder builder) {
- this.cardinalityMap = builder.cardinalityMap.build();
- this.currentStatement = builder.currentStatement;
- this.mandatoryStatements = ImmutableMap.copyOf(Maps.filterValues(cardinalityMap, c -> c.getMin() > 0));
+ cardinalityMap = builder.cardinalityMap.build();
+ currentStatement = builder.currentStatement;
+ mandatoryStatements = ImmutableMap.copyOf(Maps.filterValues(cardinalityMap, c -> c.getMin() > 0));
}
public static Builder builder(final StatementDefinition currentStatement) {
final int value = entry.getValue().getValue();
if (cardinality == null) {
- if (ctx.getFromNamespace(ExtensionNamespace.class, key.getStatementName()) == null) {
+ if (ctx.getFromNamespace(ParserNamespaces.EXTENSION, key.getStatementName()) == null) {
final StmtContext<?, ?, ?> root = ctx.getRoot();
throw new InvalidSubstatementException(ctx, "%s is not valid for %s. Error in module %s (%s)", key,
- currentStatement, root.rawArgument(), ctx.getFromNamespace(ModuleCtxToModuleQName.class, root));
+ currentStatement, root.rawArgument(),
+ ctx.getFromNamespace(SourceParserNamespaces.MODULECTX_TO_QNAME, root));
}
continue;
throw new InvalidSubstatementException(ctx,
"Minimal count of %s for %s is %s, detected %s. Error in module %s (%s)", key, currentStatement,
cardinality.getMin(), value, root.rawArgument(),
- ctx.getFromNamespace(ModuleCtxToModuleQName.class, root));
+ ctx.getFromNamespace(SourceParserNamespaces.MODULECTX_TO_QNAME, root));
}
// Encountered a mandatory statement, hence we are not missing it
throw new InvalidSubstatementException(ctx,
"Maximal count of %s for %s is %s, detected %s. Error in module %s (%s)", key, currentStatement,
cardinality.getMax(), value, root.rawArgument(),
- ctx.getFromNamespace(ModuleCtxToModuleQName.class, root));
+ ctx.getFromNamespace(SourceParserNamespaces.MODULECTX_TO_QNAME, root));
}
}
throw new MissingSubstatementException(ctx,
"%s is missing %s. Minimal count is %s. Error in module %s (%s)", currentStatement, e.getKey(),
- e.getValue().getMin(), root.rawArgument(), ctx.getFromNamespace(ModuleCtxToModuleQName.class, root));
+ e.getValue().getMin(), root.rawArgument(),
+ ctx.getFromNamespace(SourceParserNamespaces.MODULECTX_TO_QNAME, root));
}
}
+++ /dev/null
-/*
- * Copyright (c) 2015 Cisco Systems, Inc. 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.source;
-
-import org.eclipse.jdt.annotation.NonNull;
-import org.opendaylight.yangtools.yang.parser.spi.meta.ImportedNamespaceContext;
-import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour;
-
-/**
- * Source-specific mapping of belongsTo prefixes to module identifiers. This mapping allows source-specific context
- * to correctly populate prefixes map for actual parsing phase and eventually, resolve QName for any valid declared
- * statement.
- */
-public final class BelongsToPrefixToModuleCtx extends ImportedNamespaceContext<String> {
- public static final @NonNull NamespaceBehaviour<?, ?, ?> BEHAVIOUR =
- NamespaceBehaviour.sourceLocal(BelongsToPrefixToModuleCtx.class);
-
- private BelongsToPrefixToModuleCtx() {
- // Hidden on purpose
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2015 Cisco Systems, Inc. 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.source;
-
-import org.eclipse.jdt.annotation.NonNull;
-import org.opendaylight.yangtools.yang.common.UnresolvedQName.Unqualified;
-import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour;
-import org.opendaylight.yangtools.yang.parser.spi.meta.ParserNamespace;
-
-/**
- * Source-specific mapping of prefixes to namespaces.
- */
-public final class BelongsToPrefixToModuleName extends ParserNamespace<String, Unqualified> {
- public static final @NonNull NamespaceBehaviour<?, ?, ?> BEHAVIOUR =
- NamespaceBehaviour.sourceLocal(BelongsToPrefixToModuleName.class);
-
- private BelongsToPrefixToModuleName() {
- // Hidden on purpose
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2016 Cisco Systems, Inc. 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.source;
-
-import org.eclipse.jdt.annotation.NonNull;
-import org.opendaylight.yangtools.yang.common.XMLNamespace;
-import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour;
-import org.opendaylight.yangtools.yang.parser.spi.meta.ParserNamespace;
-
-/**
- * Pre-linkage source-specific mapping of prefixes to module namespaces.
- */
-public final class ImpPrefixToNamespace extends ParserNamespace<String, XMLNamespace> {
- public static final @NonNull NamespaceBehaviour<?, ?, ?> BEHAVIOUR =
- NamespaceBehaviour.rootStatementLocal(ImpPrefixToNamespace.class);
-
- private ImpPrefixToNamespace() {
- // Hidden on purpose
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2015 Cisco Systems, Inc. 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.source;
-
-import org.eclipse.jdt.annotation.NonNull;
-import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour;
-import org.opendaylight.yangtools.yang.parser.spi.meta.ParserNamespace;
-import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
-
-/**
- * Source-specific mapping of prefix strings to module context.
- */
-public final class ImportPrefixToModuleCtx extends ParserNamespace<String, StmtContext<?, ?, ?>> {
- public static final @NonNull NamespaceBehaviour<?, ?, ?> BEHAVIOUR =
- NamespaceBehaviour.rootStatementLocal(ImportPrefixToModuleCtx.class);
-
- private ImportPrefixToModuleCtx() {
- // Hidden on purpose
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2015 Cisco Systems, Inc. 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.source;
-
-import org.eclipse.jdt.annotation.NonNull;
-import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
-import org.opendaylight.yangtools.yang.parser.spi.meta.ImportedNamespaceContext;
-import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour;
-
-public final class ImportedModuleContext extends ImportedNamespaceContext<SourceIdentifier> {
- public static final @NonNull NamespaceBehaviour<?, ?, ?> BEHAVIOUR =
- NamespaceBehaviour.sourceLocal(ImportedModuleContext.class);
-
- private ImportedModuleContext() {
- // Hidden on purpose
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2015 Cisco Systems, Inc. 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.source;
-
-import org.eclipse.jdt.annotation.NonNull;
-import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
-import org.opendaylight.yangtools.yang.parser.spi.meta.ImportedNamespaceContext;
-import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour;
-
-public final class IncludedModuleContext extends ImportedNamespaceContext<SourceIdentifier> {
- public static final @NonNull NamespaceBehaviour<?, ?, ?> BEHAVIOUR =
- NamespaceBehaviour.sourceLocal(IncludedModuleContext.class);
-
- private IncludedModuleContext() {
- // Hidden on purpose
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2015 Cisco Systems, Inc. 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.source;
-
-import org.eclipse.jdt.annotation.NonNull;
-import org.opendaylight.yangtools.yang.common.UnresolvedQName.Unqualified;
-import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour;
-import org.opendaylight.yangtools.yang.parser.spi.meta.ParserNamespace;
-import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
-
-/**
- * Source-specific mapping of prefixes to namespaces.
- */
-public final class IncludedSubmoduleNameToModuleCtx extends ParserNamespace<Unqualified, StmtContext<?, ?, ?>> {
- public static final @NonNull NamespaceBehaviour<?, ?, ?> BEHAVIOUR =
- NamespaceBehaviour.sourceLocal(IncludedSubmoduleNameToModuleCtx.class);
-
- private IncludedSubmoduleNameToModuleCtx() {
- // Hidden on purpose
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2015 Cisco Systems, Inc. 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.source;
-
-import org.eclipse.jdt.annotation.NonNull;
-import org.opendaylight.yangtools.yang.common.QNameModule;
-import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour;
-import org.opendaylight.yangtools.yang.parser.spi.meta.ParserNamespace;
-import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
-
-/**
- * Global mapping of modules to QNameModules.
- */
-public final class ModuleCtxToModuleQName extends ParserNamespace<StmtContext<?,?,?>, QNameModule> {
- public static final @NonNull NamespaceBehaviour<?, ?, ?> BEHAVIOUR =
- NamespaceBehaviour.global(ModuleCtxToModuleQName.class);
-
- private ModuleCtxToModuleQName() {
- // Hidden on purpose
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2015 Cisco Systems, Inc. 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.source;
-
-import org.eclipse.jdt.annotation.NonNull;
-import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
-import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour;
-import org.opendaylight.yangtools.yang.parser.spi.meta.ParserNamespace;
-import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
-
-/**
- * Global mapping of modules to source identifier.
- */
-public final class ModuleCtxToSourceIdentifier extends ParserNamespace<StmtContext<?, ?, ?>, SourceIdentifier> {
- public static final @NonNull NamespaceBehaviour<?, ?, ?> BEHAVIOUR =
- NamespaceBehaviour.global(ModuleCtxToSourceIdentifier.class);
-
- private ModuleCtxToSourceIdentifier() {
- // Hidden on purpose
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2015 Cisco Systems, Inc. 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.source;
-
-import org.eclipse.jdt.annotation.NonNull;
-import org.opendaylight.yangtools.yang.common.QNameModule;
-import org.opendaylight.yangtools.yang.common.UnresolvedQName.Unqualified;
-import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour;
-import org.opendaylight.yangtools.yang.parser.spi.meta.ParserNamespace;
-
-/**
- * Source-specific mapping of prefixes to namespaces.
- */
-public final class ModuleNameToModuleQName extends ParserNamespace<Unqualified, QNameModule> {
- public static final @NonNull NamespaceBehaviour<?, ?, ?> BEHAVIOUR =
- NamespaceBehaviour.sourceLocal(ModuleNameToModuleQName.class);
-
- private ModuleNameToModuleQName() {
- // Hidden on purpose
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2016 Cisco Systems, Inc. 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.source;
-
-import org.eclipse.jdt.annotation.NonNull;
-import org.opendaylight.yangtools.yang.common.UnresolvedQName.Unqualified;
-import org.opendaylight.yangtools.yang.common.XMLNamespace;
-import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour;
-import org.opendaylight.yangtools.yang.parser.spi.meta.ParserNamespace;
-
-/**
- * Pre-linkage global mapping of module names to namespaces.
- */
-public final class ModuleNameToNamespace extends ParserNamespace<Unqualified, XMLNamespace> {
- public static final @NonNull NamespaceBehaviour<?, ?, ?> BEHAVIOUR =
- NamespaceBehaviour.global(ModuleNameToNamespace.class);
-
- private ModuleNameToNamespace() {
- // Hidden on purpose
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2015 Cisco Systems, Inc. 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.source;
-
-import org.eclipse.jdt.annotation.NonNull;
-import org.opendaylight.yangtools.yang.common.UnresolvedQName.Unqualified;
-import org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement;
-import org.opendaylight.yangtools.yang.model.api.stmt.ModuleStatement;
-import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour;
-import org.opendaylight.yangtools.yang.parser.spi.meta.StatementNamespace;
-
-/**
- * Namespace class similar to {@link org.opendaylight.yangtools.yang.parser.spi.ModuleNamespace} for storing modules
- * into Yang model storage but keyed by plain name.
- */
-public final class ModuleNamespaceForBelongsTo
- extends StatementNamespace<Unqualified, ModuleStatement, ModuleEffectiveStatement> {
- public static final @NonNull NamespaceBehaviour<?, ?, ?> BEHAVIOUR =
- NamespaceBehaviour.global(ModuleNamespaceForBelongsTo.class);
-
- private ModuleNamespaceForBelongsTo() {
- // Hidden on purpose
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2015 Cisco Systems, Inc. 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.source;
-
-import org.eclipse.jdt.annotation.NonNull;
-import org.opendaylight.yangtools.yang.common.QNameModule;
-import org.opendaylight.yangtools.yang.common.UnresolvedQName.Unqualified;
-import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour;
-import org.opendaylight.yangtools.yang.parser.spi.meta.ParserNamespace;
-
-/**
- * Source-specific mapping of prefixes to namespaces.
- */
-public final class ModuleQNameToModuleName extends ParserNamespace<QNameModule, Unqualified> {
- public static final @NonNull NamespaceBehaviour<?, ?, ?> BEHAVIOUR =
- NamespaceBehaviour.global(ModuleQNameToModuleName.class);
-
- private ModuleQNameToModuleName() {
- // Hidden on purpose
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2017 Pantheon Technologies 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.source;
-
-import com.google.common.annotations.Beta;
-import com.google.common.collect.SetMultimap;
-import org.eclipse.jdt.annotation.NonNull;
-import org.opendaylight.yangtools.yang.common.Empty;
-import org.opendaylight.yangtools.yang.common.QNameModule;
-import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour;
-import org.opendaylight.yangtools.yang.parser.spi.meta.ParserNamespace;
-
-/**
- * Namespace used for storing information about modules that support deviation resolution.
- * Map key (QNameModule) denotes a module which can be deviated by the modules specified in the Map value.
- */
-@Beta
-public final class ModulesDeviatedByModules extends ParserNamespace<Empty, SetMultimap<QNameModule, QNameModule>> {
- public static final @NonNull NamespaceBehaviour<?, ?, ?> BEHAVIOUR =
- NamespaceBehaviour.global(ModulesDeviatedByModules.class);
-
- private ModulesDeviatedByModules() {
- // Hidden on purpose
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2015 Cisco Systems, Inc. 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.source;
-
-import org.eclipse.jdt.annotation.NonNull;
-import org.opendaylight.yangtools.yang.common.QNameModule;
-import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour;
-import org.opendaylight.yangtools.yang.parser.spi.meta.ParserNamespace;
-
-/**
- * Source-specific mapping of prefixes to namespaces. This namespace is populated by all statements which have impact
- * on the XML namespace, for example {@code import}, {@code belongs-to} and really anywhere a {@code prefix} statement
- * is present.
- *
- * @see PrefixResolver
- */
-public final class PrefixToModule extends ParserNamespace<String, QNameModule> {
- public static final @NonNull NamespaceBehaviour<?, ?, ?> BEHAVIOUR =
- NamespaceBehaviour.global(PrefixToModule.class);
-
- private PrefixToModule() {
- // Hidden on purpose
- }
-}
--- /dev/null
+/*
+ * Copyright (c) 2022 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.source;
+
+import org.eclipse.jdt.annotation.NonNull;
+import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour;
+
+/**
+ * {@link NamespaceBehaviour}s corresponding to {@link SourceParserNamespaces}.
+ */
+public final class SourceNamespaceBehaviours {
+ public static final @NonNull NamespaceBehaviour<?, ?, ?> BELONGSTO_PREFIX_TO_MODULECTX =
+ NamespaceBehaviour.sourceLocal(SourceParserNamespaces.BELONGSTO_PREFIX_TO_MODULECTX);
+
+ public static final @NonNull NamespaceBehaviour<?, ?, ?> BELONGSTO_PREFIX_TO_MODULE_NAME =
+ NamespaceBehaviour.sourceLocal(SourceParserNamespaces.BELONGSTO_PREFIX_TO_MODULE_NAME);
+
+ public static final @NonNull NamespaceBehaviour<?, ?, ?> MODULE_NAME_TO_QNAME =
+ NamespaceBehaviour.sourceLocal(SourceParserNamespaces.MODULE_NAME_TO_QNAME);
+
+ public static final @NonNull NamespaceBehaviour<?, ?, ?> IMPORTED_MODULE =
+ NamespaceBehaviour.sourceLocal(SourceParserNamespaces.IMPORTED_MODULE);
+
+ public static final @NonNull NamespaceBehaviour<?, ?, ?> INCLUDED_MODULE =
+ NamespaceBehaviour.sourceLocal(SourceParserNamespaces.INCLUDED_MODULE);
+
+ public static final @NonNull NamespaceBehaviour<?, ?, ?> MODULECTX_TO_QNAME =
+ NamespaceBehaviour.global(SourceParserNamespaces.MODULECTX_TO_QNAME);
+
+ public static final @NonNull NamespaceBehaviour<?, ?, ?> INCLUDED_SUBMODULE_NAME_TO_MODULECTX =
+ NamespaceBehaviour.sourceLocal(SourceParserNamespaces.INCLUDED_SUBMODULE_NAME_TO_MODULECTX);
+
+ public static final @NonNull NamespaceBehaviour<?, ?, ?> IMP_PREFIX_TO_NAMESPACE =
+ NamespaceBehaviour.rootStatementLocal(SourceParserNamespaces.IMP_PREFIX_TO_NAMESPACE);
+
+ public static final @NonNull NamespaceBehaviour<?, ?, ?> IMPORT_PREFIX_TO_MODULECTX =
+ NamespaceBehaviour.rootStatementLocal(SourceParserNamespaces.IMPORT_PREFIX_TO_MODULECTX);
+
+ public static final @NonNull NamespaceBehaviour<?, ?, ?> MODULE_FOR_BELONGSTO =
+ NamespaceBehaviour.global(SourceParserNamespaces.MODULE_FOR_BELONGSTO);
+
+ public static final @NonNull NamespaceBehaviour<?, ?, ?> SUPPORTED_FEATURES =
+ NamespaceBehaviour.global(SourceParserNamespaces.SUPPORTED_FEATURES);
+
+ public static final @NonNull NamespaceBehaviour<?, ?, ?> PREFIX_TO_MODULE =
+ NamespaceBehaviour.global(SourceParserNamespaces.PREFIX_TO_MODULE);
+
+ public static final @NonNull NamespaceBehaviour<?, ?, ?> MODULES_DEVIATED_BY =
+ NamespaceBehaviour.global(SourceParserNamespaces.MODULES_DEVIATED_BY);
+
+ public static final @NonNull NamespaceBehaviour<?, ?, ?> MODULE_NAMESPACE_TO_NAME =
+ NamespaceBehaviour.global(SourceParserNamespaces.MODULE_NAMESPACE_TO_NAME);
+
+ public static final @NonNull NamespaceBehaviour<?, ?, ?> MODULE_NAME_TO_NAMESPACE =
+ NamespaceBehaviour.global(SourceParserNamespaces.MODULE_NAME_TO_NAMESPACE);
+
+ public static final @NonNull NamespaceBehaviour<?, ?, ?> MODULECTX_TO_SOURCE =
+ NamespaceBehaviour.global(SourceParserNamespaces.MODULECTX_TO_SOURCE);
+
+ private SourceNamespaceBehaviours() {
+ // Hidden on purpose
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2022 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.source;
+
+import com.google.common.collect.SetMultimap;
+import java.util.Set;
+import org.eclipse.jdt.annotation.NonNull;
+import org.opendaylight.yangtools.yang.common.Empty;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.common.QNameModule;
+import org.opendaylight.yangtools.yang.common.UnresolvedQName.Unqualified;
+import org.opendaylight.yangtools.yang.common.XMLNamespace;
+import org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.ModuleStatement;
+import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
+import org.opendaylight.yangtools.yang.parser.spi.ParserNamespaces;
+import org.opendaylight.yangtools.yang.parser.spi.meta.ImportedNamespaceContext;
+import org.opendaylight.yangtools.yang.parser.spi.meta.ParserNamespace;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StatementNamespace;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
+
+/**
+ * Namespaces related to YANG/YIN source processing.
+ */
+public final class SourceParserNamespaces {
+ /**
+ * Source-specific mapping of belongsTo prefixes to module identifiers. This mapping allows source-specific context
+ * to correctly populate prefixes map for actual parsing phase and eventually, resolve QName for any valid declared
+ * statement.
+ */
+ public static final @NonNull ImportedNamespaceContext<String> BELONGSTO_PREFIX_TO_MODULECTX =
+ new ImportedNamespaceContext<>("belongsto-prefix-to-module");
+
+ /**
+ * Source-specific mapping of prefixes to namespaces.
+ */
+ // FIXME: bad javadoc
+ public static final @NonNull ParserNamespace<String, Unqualified> BELONGSTO_PREFIX_TO_MODULE_NAME =
+ new ParserNamespace<>("belongsto-prefix-to-name");
+
+ /**
+ * Namespace similar to {@link ParserNamespaces#MODULE} for storing modules into Yang model storage but keyed by
+ * plain name.
+ */
+ // FIXME: Better name?
+ public static final @NonNull StatementNamespace<Unqualified, ModuleStatement, ModuleEffectiveStatement>
+ MODULE_FOR_BELONGSTO = new StatementNamespace<>("module-belongsto");
+
+ /**
+ * Pre-linkage source-specific mapping of prefixes to module namespaces.
+ */
+ // FIXME: a better name?
+ public static final @NonNull ParserNamespace<String, XMLNamespace> IMP_PREFIX_TO_NAMESPACE =
+ new ParserNamespace<>("prefix-to-xmlnamespace");
+
+ /**
+ * Source-specific mapping of prefix strings to module context.
+ */
+ public static final @NonNull ParserNamespace<String, StmtContext<?, ?, ?>> IMPORT_PREFIX_TO_MODULECTX =
+ new ParserNamespace<>("import-prefix-to-modulectx");
+
+ // FIXME: document this
+ public static final @NonNull ImportedNamespaceContext<SourceIdentifier> IMPORTED_MODULE =
+ new ImportedNamespaceContext<>("imported-module");
+
+ // FIXME: document this
+ // FIXME: is this 'included submodule' instead?
+ public static final @NonNull ImportedNamespaceContext<SourceIdentifier> INCLUDED_MODULE =
+ new ImportedNamespaceContext<>("included-module");
+
+ /**
+ * Source-specific mapping of prefixes to namespaces.
+ */
+ // FIXME: bad javadoc
+ public static final @NonNull ParserNamespace<Unqualified, StmtContext<?, ?, ?>> INCLUDED_SUBMODULE_NAME_TO_MODULECTX
+ = new ParserNamespace<>("included-submodule-to-modulectx");
+
+ /**
+ * Source-specific mapping of prefixes to namespaces.
+ */
+ // FIXME: bad javadoc
+ public static final @NonNull ParserNamespace<Unqualified, QNameModule> MODULE_NAME_TO_QNAME =
+ new ParserNamespace<>("module-name-to-qnamemodule");
+
+ /**
+ * Global mapping of modules to QNameModules.
+ */
+ public static final @NonNull ParserNamespace<StmtContext<?,?,?>, QNameModule> MODULECTX_TO_QNAME =
+ new ParserNamespace<>("modulectx-to-qnamemodule");
+
+ public static final @NonNull ParserNamespace<Empty, Set<QName>> SUPPORTED_FEATURES =
+ new ParserNamespace<>("supportedFeatures");
+
+ /**
+ * Source-specific mapping of prefixes to namespaces. This namespace is populated by all statements which have
+ * impact on the XML namespace, for example {@code import}, {@code belongs-to} and really anywhere a {@code prefix}
+ * statement is present.
+ *
+ * @see PrefixResolver
+ */
+ public static final @NonNull ParserNamespace<String, QNameModule> PREFIX_TO_MODULE =
+ new ParserNamespace<>("prefix-to-qnamemodule");
+
+ /**
+ * Namespace used for storing information about modules that support deviation resolution.
+ * Map key (QNameModule) denotes a module which can be deviated by the modules specified in the Map value.
+ */
+ public static final @NonNull ParserNamespace<Empty, SetMultimap<QNameModule, QNameModule>> MODULES_DEVIATED_BY =
+ new ParserNamespace<>("moduleDeviations");
+
+ /**
+ * Source-specific mapping of prefixes to namespaces.
+ */
+ // FIXME: bad javadoc
+ public static final @NonNull ParserNamespace<QNameModule, Unqualified> MODULE_NAMESPACE_TO_NAME =
+ new ParserNamespace<>("qnamemodule-to-name");
+
+ /**
+ * Pre-linkage global mapping of module names to namespaces.
+ */
+ public static final @NonNull ParserNamespace<Unqualified, XMLNamespace> MODULE_NAME_TO_NAMESPACE =
+ new ParserNamespace<>("module-name-to-xmlnamespace");
+
+ /**
+ * Global mapping of modules to source identifier.
+ */
+ public static final @NonNull ParserNamespace<StmtContext<?, ?, ?>, SourceIdentifier> MODULECTX_TO_SOURCE =
+ new ParserNamespace<>("modulectx-to-source");
+
+ private SourceParserNamespaces() {
+ // Hidden on purpose
+ }
+}
+++ /dev/null
-/*
- * Copyright (c) 2016 Cisco Systems, Inc. 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.source;
-
-import java.util.Set;
-import org.eclipse.jdt.annotation.NonNull;
-import org.opendaylight.yangtools.yang.common.Empty;
-import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour;
-import org.opendaylight.yangtools.yang.parser.spi.meta.ParserNamespace;
-
-public final class SupportedFeaturesNamespace extends ParserNamespace<Empty, Set<QName>> {
- public static final @NonNull NamespaceBehaviour<?, ?, ?> BEHAVIOUR =
- NamespaceBehaviour.global(SupportedFeaturesNamespace.class);
-
- private SupportedFeaturesNamespace() {
- // Hidden on purpose
- }
-}
* Namespace used for validating whether a node is of some type, e.g. usable target for some operation or has other
* significant properties.
*/
-public final class ValidationBundlesNamespace
- extends ParserNamespace<ValidationBundlesNamespace.ValidationBundleType, Collection<?>> {
- public static final @NonNull NamespaceBehaviour<?, ?, ?> BEHAVIOUR =
- NamespaceBehaviour.global(ValidationBundlesNamespace.class);
-
- private ValidationBundlesNamespace() {
- // Hidden on purpose
- }
-
+public final class ValidationBundles {
public enum ValidationBundleType {
/**
* Whether a node is suitable refine substatement.
*/
SUPPORTED_DATA_NODES
}
+
+ public static final @NonNull ParserNamespace<ValidationBundleType, Collection<?>> NAMESPACE =
+ new ParserNamespace<>("validationBundles");
+
+ public static final @NonNull NamespaceBehaviour<?, ?, ?> BEHAVIOUR = NamespaceBehaviour.global(NAMESPACE);
+
+ private ValidationBundles() {
+ // Hidden on purpose
+ }
}
* Currently, this package contains an interface which represents a namespace used
* by the validation process. This namespace contains different types of validation
* bundles or collections. Allowed types of validation bundles are defined by the
- * enumeration {@link ValidationBundlesNamespace.ValidationBundleType} which is
+ * enumeration {@link ValidationBundles.ValidationBundleType} which is
* provided by this package.
*/
package org.opendaylight.yangtools.yang.parser.spi.validation;
\ No newline at end of file
+++ /dev/null
-/*
- * Copyright (c) 2017 Pantheon Technologies 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;
-
-import static org.junit.Assert.assertNotNull;
-
-import org.junit.Test;
-
-public class NamespaceTest {
- @Test
- public void testNamespaces() {
- // Touch behaviors
- // FIXME: add more checks/split this up when behaviours are testable
- assertNotNull(ExtensionNamespace.BEHAVIOUR);
- assertNotNull(GroupingNamespace.BEHAVIOUR);
- assertNotNull(IdentityNamespace.BEHAVIOUR);
- assertNotNull(ModuleNamespace.BEHAVIOUR);
- assertNotNull(PreLinkageModuleNamespace.BEHAVIOUR);
- assertNotNull(SubmoduleNamespace.BEHAVIOUR);
- assertNotNull(TypeNamespace.BEHAVIOUR);
-
- assertNotNull(NamespaceToModule.BEHAVIOUR);
- }
-}
public void testNamespaces() {
// Touch behaviors
// FIXME: add more checks/split this up when behaviours are testable
- assertNotNull(StatementDefinitionNamespace.BEHAVIOUR);
+ assertNotNull(StatementDefinitions.BEHAVIOUR);
}
}
+++ /dev/null
-/*
- * Copyright (c) 2017 Pantheon Technologies 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.source;
-
-import static org.junit.Assert.assertNotNull;
-
-import org.junit.Test;
-
-public class NamespaceTest {
- @Test
- public void testNamespaces() {
- // Touch behaviors
- // FIXME: add more checks/split this up when behaviours are testable
- assertNotNull(BelongsToPrefixToModuleCtx.BEHAVIOUR);
- assertNotNull(BelongsToPrefixToModuleName.BEHAVIOUR);
- assertNotNull(ImpPrefixToNamespace.BEHAVIOUR);
- assertNotNull(ImportedModuleContext.BEHAVIOUR);
- assertNotNull(ImportPrefixToModuleCtx.BEHAVIOUR);
- assertNotNull(IncludedSubmoduleNameToModuleCtx.BEHAVIOUR);
- assertNotNull(IncludedModuleContext.BEHAVIOUR);
- assertNotNull(ModuleCtxToModuleQName.BEHAVIOUR);
- assertNotNull(ModuleNameToNamespace.BEHAVIOUR);
- assertNotNull(ModuleQNameToModuleName.BEHAVIOUR);
- assertNotNull(ModuleCtxToSourceIdentifier.BEHAVIOUR);
- assertNotNull(ModuleNamespaceForBelongsTo.BEHAVIOUR);
- assertNotNull(ModuleNameToModuleQName.BEHAVIOUR);
- assertNotNull(ModulesDeviatedByModules.BEHAVIOUR);
- assertNotNull(PrefixToModule.BEHAVIOUR);
- assertNotNull(SupportedFeaturesNamespace.BEHAVIOUR);
- }
-}