import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.min_elements.MinElementsStatementSupport;
import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.modifier.ModifierStatementSupport;
import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.module.ModuleStatementSupport;
+import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.module.QNameModuleNamespace;
import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.must.MustStatementSupport;
import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.namespace.NamespaceStatementSupport;
import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.notification.NotificationStatementRFC6020Support;
.addSupport(PreLinkageModuleNamespace.BEHAVIOUR)
.addSupport(ImpPrefixToNamespace.BEHAVIOUR)
.addSupport(ModuleCtxToModuleQName.BEHAVIOUR)
+ .addSupport(QNameModuleNamespace.BEHAVIOUR)
.build();
private static final StatementSupportBundle LINKAGE_BUNDLE = StatementSupportBundle
*/
package org.opendaylight.yangtools.yang.parser.rfc7950.stmt.module;
-import static com.google.common.base.Verify.verifyNotNull;
+import static java.util.Objects.requireNonNull;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
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.ModuleCtxToModuleQName;
final class ModuleEffectiveStatementImpl extends AbstractEffectiveModule<ModuleStatement, ModuleEffectiveStatement>
implements Module, ModuleEffectiveStatement {
ModuleEffectiveStatementImpl(final Current<UnqualifiedQName, ModuleStatement> stmt,
final ImmutableList<? extends EffectiveStatement<?, ?>> substatements,
- final Collection<? extends Submodule> submodules) {
+ final Collection<? extends Submodule> submodules, final QNameModule qnameModule) {
super(stmt, substatements, findPrefix(stmt, substatements, "module", stmt.getRawArgument()));
-
- qnameModule = verifyNotNull(stmt.getFromNamespace(ModuleCtxToModuleQName.class, stmt.caerbannog()));
+ this.qnameModule = requireNonNull(qnameModule);
this.submodules = ImmutableList.copyOf(submodules);
final String localPrefix = findFirstEffectiveSubstatementArgument(PrefixEffectiveStatement.class).get();
package org.opendaylight.yangtools.yang.parser.rfc7950.stmt.module;
import static com.google.common.base.Verify.verify;
+import static com.google.common.base.Verify.verifyNotNull;
import static java.util.Objects.requireNonNull;
import static org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils.firstAttributeOf;
import java.util.Optional;
import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.yangtools.openconfig.model.api.OpenConfigStatements;
+import org.opendaylight.yangtools.yang.common.Empty;
import org.opendaylight.yangtools.yang.common.QNameModule;
import org.opendaylight.yangtools.yang.common.Revision;
import org.opendaylight.yangtools.yang.common.UnqualifiedQName;
firstAttributeOf(stmt.declaredSubstatements(), PrefixStatement.class), stmt,
"Prefix of the module [%s] is missing", stmt.argument());
+ stmt.addToNs(QNameModuleNamespace.class, Empty.getInstance(), qNameModule);
stmt.addToNs(PrefixToModule.class, modulePrefix, qNameModule);
stmt.addToNs(ModuleNameToModuleQName.class, moduleName, qNameModule);
stmt.addToNs(ModuleCtxToModuleQName.class, stmt, qNameModule);
submodules.add((Submodule) submodule);
}
+ final QNameModule qnameModule = verifyNotNull(stmt.namespaceItem(QNameModuleNamespace.class,
+ Empty.getInstance()));
try {
- return new ModuleEffectiveStatementImpl(stmt, substatements, submodules);
+ return new ModuleEffectiveStatementImpl(stmt, substatements, submodules, qnameModule);
} catch (SubstatementIndexingException e) {
throw new SourceException(e.getMessage(), stmt, e);
}
--- /dev/null
+/*
+ * Copyright (c) 2020 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.rfc7950.stmt.module;
+
+import com.google.common.annotations.Beta;
+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.model.api.meta.IdentifierNamespace;
+import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour;
+
+/**
+ * Module-local namespace holding the module's QName.
+ */
+@Beta
+public interface QNameModuleNamespace extends IdentifierNamespace<Empty, QNameModule> {
+ NamespaceBehaviour<Empty, QNameModule, @NonNull QNameModuleNamespace> BEHAVIOUR =
+ NamespaceBehaviour.statementLocal(QNameModuleNamespace.class);
+
+}
public static <K, V, N extends IdentifierNamespace<K, V>> @NonNull NamespaceBehaviour<K, V, N> statementLocal(
final Class<N> identifier) {
- return new StorageSpecific<>(identifier, StorageNodeType.STATEMENT_LOCAL);
+ return new StatementLocal<>(identifier);
}
/**
storage.putToLocalStorage(getIdentifier(), key, value);
}
- static final class StorageSpecific<K, V, N extends IdentifierNamespace<K, V>> extends NamespaceBehaviour<K, V, N> {
- private final StorageNodeType storageType;
-
- StorageSpecific(final Class<N> identifier, final StorageNodeType type) {
+ abstract static class AbstractSpecific<K, V, N extends IdentifierNamespace<K, V>>
+ extends NamespaceBehaviour<K, V, N> {
+ AbstractSpecific(final Class<N> identifier) {
super(identifier);
- storageType = requireNonNull(type);
}
@Override
- public V getFrom(final NamespaceStorageNode storage, final K key) {
- NamespaceStorageNode current = findClosestTowardsRoot(storage, storageType);
- return getFromLocalStorage(current, key);
+ public final V getFrom(final NamespaceStorageNode storage, final K key) {
+ return getFromLocalStorage(findStorageNode(storage), key);
}
@Override
- public Map<K, V> getAllFrom(final NamespaceStorageNode storage) {
- NamespaceStorageNode current = storage;
- while (current.getStorageNodeType() != storageType) {
- current = current.getParentNamespaceStorage();
- }
+ public final Map<K, V> getAllFrom(final NamespaceStorageNode storage) {
+ return getAllFromLocalStorage(findStorageNode(storage));
+ }
+
+ @Override
+ public final void addTo(final NamespaceStorageNode storage, final K key, final V value) {
+ addToStorage(findStorageNode(storage), key, value);
+ }
+
+ abstract NamespaceStorageNode findStorageNode(NamespaceStorageNode storage);
+ }
+
+ static final class StatementLocal<K, V, N extends IdentifierNamespace<K, V>> extends AbstractSpecific<K, V, N> {
+ StatementLocal(final Class<N> identifier) {
+ super(identifier);
+ }
+
+ @Override
+ NamespaceStorageNode findStorageNode(final NamespaceStorageNode storage) {
+ return storage;
+ }
+ }
+
+ static final class StorageSpecific<K, V, N extends IdentifierNamespace<K, V>> extends AbstractSpecific<K, V, N> {
+ private final StorageNodeType storageType;
- return getAllFromLocalStorage(current);
+ StorageSpecific(final Class<N> identifier, final StorageNodeType type) {
+ super(identifier);
+ storageType = requireNonNull(type);
}
@Override
- public void addTo(final NamespaceBehaviour.NamespaceStorageNode storage, final K key, final V value) {
- NamespaceStorageNode current = findClosestTowardsRoot(storage, storageType);
- addToStorage(current, key, value);
+ NamespaceStorageNode findStorageNode(final NamespaceStorageNode storage) {
+ return findClosestTowardsRoot(storage, storageType);
}
@Override
}
static final class TreeScoped<K, V, N extends IdentifierNamespace<K, V>> extends NamespaceBehaviour<K, V, N> {
-
TreeScoped(final Class<N> identifier) {
super(identifier);
}