import static com.google.common.base.Verify.verifyNotNull;
import static java.util.Objects.requireNonNull;
-import com.google.common.base.Verify;
import com.google.common.collect.HashBasedTable;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
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;
-import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour.NamespaceStorageNode;
-import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour.Registry;
-import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour.StorageNodeType;
import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceNotAvailableException;
+import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceStorage;
import org.opendaylight.yangtools.yang.parser.spi.meta.ParserNamespace;
import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
import org.opendaylight.yangtools.yang.parser.spi.meta.SomeModifiersUnresolvedException;
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.SourceException;
import org.opendaylight.yangtools.yang.parser.spi.source.StatementStreamSource;
import org.opendaylight.yangtools.yang.parser.spi.validation.ValidationBundles;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-final class BuildGlobalContext extends NamespaceStorageSupport implements Registry {
+final class BuildGlobalContext extends AbstractNamespaceStorage {
private static final Logger LOG = LoggerFactory.getLogger(BuildGlobalContext.class);
private static final ModelProcessingPhase[] PHASE_EXECUTION_ORDER = {
}
@Override
- public StorageNodeType getStorageNodeType() {
- return StorageNodeType.GLOBAL;
+ public StorageType getStorageType() {
+ return StorageType.GLOBAL;
}
@Override
- public NamespaceStorageNode getParentNamespaceStorage() {
+ public NamespaceStorage getParentStorage() {
return null;
}
@Override
- Registry getBehaviourRegistry() {
- return this;
- }
-
- @Override
- public <K, V> NamespaceBehaviourWithListeners<K, V> getNamespaceBehaviour(final ParserNamespace<K, V> type) {
+ <K, V> NamespaceBehaviourWithListeners<K, V> getNamespaceBehaviour(final ParserNamespace<K, V> type) {
NamespaceBehaviourWithListeners<?, ?> potential = supportedNamespaces.get(type);
if (potential == null) {
- final var potentialRaw = verifyNotNull(supports.get(currentPhase)).getNamespaceBehaviour(type);
+ final var potentialRaw = verifyNotNull(supports.get(currentPhase)).namespaceBehaviourOf(type);
if (potentialRaw != null) {
potential = createNamespaceContext(potentialRaw);
supportedNamespaces.put(type, potential);
}
}
- Verify.verify(type.equals(potential.getIdentifier()));
+ verify(type.equals(potential.namespace()));
/*
* Safe cast, previous checkState checks equivalence of key from which
* type argument are derived
private ReactorDeclaredModel transform() {
checkState(finishedPhase == ModelProcessingPhase.EFFECTIVE_MODEL);
- final List<DeclaredStatement<?>> rootStatements = new ArrayList<>(sources.size());
- for (final SourceSpecificContext source : sources) {
- rootStatements.add(source.getRoot().declared());
+ final var rootStatements = new ArrayList<DeclaredStatement<?>>(sources.size());
+ for (var source : sources) {
+ rootStatements.add(source.declaredRoot());
}
return new ReactorDeclaredModel(rootStatements);
}
private SomeModifiersUnresolvedException propagateException(final SourceSpecificContext source,
final RuntimeException cause) throws SomeModifiersUnresolvedException {
- final SourceIdentifier sourceId = createSourceIdentifier(source.getRoot());
+ final SourceIdentifier sourceId = source.identifySource();
if (!(cause instanceof SourceException)) {
/*
* This should not be happening as all our processing should provide SourceExceptions.
throw new SomeModifiersUnresolvedException(currentPhase, sourceId, cause);
}
- private static SourceIdentifier createSourceIdentifier(final StmtContext<?, ?, ?> root) {
- final QNameModule qNameModule = root.namespaceItem(ParserNamespaces.MODULECTX_TO_QNAME, root);
- final Object arg = root.getArgument();
- verify(arg instanceof Unqualified, "Unexpected argument %s", arg);
-
- if (qNameModule != null) {
- // creates SourceIdentifier for a module
- return new SourceIdentifier((Unqualified) arg, qNameModule.getRevision().orElse(null));
- }
-
- // creates SourceIdentifier for a submodule
- return new SourceIdentifier((Unqualified) arg,
- StmtContextUtils.getLatestRevision(root.declaredSubstatements()).orElse(null));
- }
-
@SuppressWarnings("checkstyle:illegalCatch")
private EffectiveSchemaContext transformEffective() throws ReactorException {
checkState(finishedPhase == ModelProcessingPhase.EFFECTIVE_MODEL);
- final List<DeclaredStatement<?>> rootStatements = new ArrayList<>(sources.size());
- final List<EffectiveStatement<?, ?>> rootEffectiveStatements = new ArrayList<>(sources.size());
+ final var rootStatements = new ArrayList<DeclaredStatement<?>>(sources.size());
+ final var rootEffectiveStatements = new ArrayList<EffectiveStatement<?, ?>>(sources.size());
- for (final SourceSpecificContext source : sources) {
- final RootStatementContext<?, ?, ?> root = source.getRoot();
+ for (var source : sources) {
try {
- rootStatements.add(root.declared());
- rootEffectiveStatements.add(root.buildEffective());
+ rootStatements.add(source.declaredRoot());
+ rootEffectiveStatements.add(source.effectiveRoot());
} catch (final RuntimeException ex) {
throw propagateException(source, ex);
}
if (!addedCause) {
addedCause = true;
- final SourceIdentifier sourceId = createSourceIdentifier(failedSource.getRoot());
+ final SourceIdentifier sourceId = failedSource.identifySource();
buildFailure = new SomeModifiersUnresolvedException(currentPhase, sourceId, sourceEx);
} else {
buildFailure.addSuppressed(sourceEx);