import com.google.common.base.Verify;
import com.google.common.collect.HashBasedTable;
-import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableSetMultimap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
-import java.util.Map.Entry;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.meta.IdentifierNamespace;
+import org.opendaylight.yangtools.yang.model.repo.api.RevisionSourceIdentifier;
import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
import org.opendaylight.yangtools.yang.model.repo.api.StatementParserMode;
import org.opendaylight.yangtools.yang.parser.spi.meta.DerivedNamespaceBehaviour;
import org.opendaylight.yangtools.yang.parser.spi.meta.SomeModifiersUnresolvedException;
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.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.ModulesDeviatedByModules.SupportedModules;
import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-class BuildGlobalContext extends NamespaceStorageSupport implements Registry {
+final class BuildGlobalContext extends NamespaceStorageSupport implements Registry {
private static final Logger LOG = LoggerFactory.getLogger(BuildGlobalContext.class);
- private static final List<ModelProcessingPhase> PHASE_EXECUTION_ORDER =
- ImmutableList.<ModelProcessingPhase>builder().add(ModelProcessingPhase.SOURCE_PRE_LINKAGE)
- .add(ModelProcessingPhase.SOURCE_LINKAGE).add(ModelProcessingPhase.STATEMENT_DEFINITION)
- .add(ModelProcessingPhase.FULL_DECLARATION).add(ModelProcessingPhase.EFFECTIVE_MODEL).build();
+ private static final ModelProcessingPhase[] PHASE_EXECUTION_ORDER = {
+ ModelProcessingPhase.SOURCE_PRE_LINKAGE,
+ ModelProcessingPhase.SOURCE_LINKAGE,
+ ModelProcessingPhase.STATEMENT_DEFINITION,
+ ModelProcessingPhase.FULL_DECLARATION,
+ ModelProcessingPhase.EFFECTIVE_MODEL
+ };
private final Table<YangVersion, QName, StatementDefinitionContext<?, ?, ?>> definitions = HashBasedTable.create();
private final Map<QName, StatementDefinitionContext<?, ?, ?>> modelDefinedStmtDefs = new HashMap<>();
throw new IllegalArgumentException("Unhandled parser mode " + statementParserMode);
}
- for (final Entry<ValidationBundleType, Collection<?>> validationBundle : supportedValidation.entrySet()) {
- addToNs(ValidationBundlesNamespace.class, validationBundle.getKey(), validationBundle.getValue());
- }
+ addToNamespace(ValidationBundlesNamespace.class, supportedValidation);
this.supportedVersions = ImmutableSet.copyOf(supports.get(ModelProcessingPhase.INIT).getSupportedVersions());
}
}
void setSupportedFeatures(final Set<QName> supportedFeatures) {
- addToNs(SupportedFeaturesNamespace.class, SupportedFeatures.SUPPORTED_FEATURES,
+ addToNamespace(SupportedFeaturesNamespace.class, SupportedFeatures.SUPPORTED_FEATURES,
ImmutableSet.copyOf(supportedFeatures));
}
void setModulesDeviatedByModules(final SetMultimap<QNameModule, QNameModule> modulesDeviatedByModules) {
- addToNs(ModulesDeviatedByModules.class, SupportedModules.SUPPORTED_MODULES,
+ addToNamespace(ModulesDeviatedByModules.class, SupportedModules.SUPPORTED_MODULES,
ImmutableSetMultimap.copyOf(modulesDeviatedByModules));
}
private SomeModifiersUnresolvedException propagateException(final SourceSpecificContext source,
final RuntimeException cause) throws SomeModifiersUnresolvedException {
- final SourceIdentifier sourceId = StmtContextUtils.createSourceIdentifier(source.getRoot());
+ final SourceIdentifier sourceId = createSourceIdentifier(source.getRoot());
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.getFromNamespace(ModuleCtxToModuleQName.class, root);
+ final String arg = root.coerceRawStatementArgument();
+ if (qNameModule != null) {
+ // creates SourceIdentifier for a module
+ return RevisionSourceIdentifier.create(arg, qNameModule.getRevision());
+ }
+
+ // creates SourceIdentifier for a submodule
+ return RevisionSourceIdentifier.create(arg, StmtContextUtils.getLatestRevision(root.declaredSubstatements()));
+ }
+
@SuppressWarnings("checkstyle:illegalCatch")
private EffectiveSchemaContext transformEffective() throws ReactorException {
checkState(finishedPhase == ModelProcessingPhase.EFFECTIVE_MODEL);
SomeModifiersUnresolvedException buildFailure = null;
for (final SourceSpecificContext failedSource : sourcesToProgress) {
final Optional<SourceException> optSourceEx = failedSource.failModifiers(currentPhase);
- if (!optSourceEx.isPresent()) {
+ if (optSourceEx.isEmpty()) {
continue;
}
if (!addedCause) {
addedCause = true;
- final SourceIdentifier sourceId = StmtContextUtils.createSourceIdentifier(failedSource.getRoot());
+ final SourceIdentifier sourceId = createSourceIdentifier(failedSource.getRoot());
buildFailure = new SomeModifiersUnresolvedException(currentPhase, sourceId, sourceEx);
} else {
buildFailure.addSuppressed(sourceEx);