import com.google.common.base.Preconditions;
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.Lists;
+import com.google.common.collect.Table;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.function.Predicate;
import javax.annotation.Nonnull;
import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.common.YangVersion;
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;
.add(ModelProcessingPhase.SOURCE_LINKAGE).add(ModelProcessingPhase.STATEMENT_DEFINITION)
.add(ModelProcessingPhase.FULL_DECLARATION).add(ModelProcessingPhase.EFFECTIVE_MODEL).build();
- private final Map<QName, StatementDefinitionContext<?, ?, ?>> definitions = new HashMap<>();
+ private final Table<YangVersion, QName, StatementDefinitionContext<?, ?, ?>> definitions = HashBasedTable.create();
private final Map<Class<?>, NamespaceBehaviourWithListeners<?, ?, ?>> supportedNamespaces = new HashMap<>();
private final Map<ModelProcessingPhase, StatementSupportBundle> supports;
private ModelProcessingPhase finishedPhase = ModelProcessingPhase.INIT;
private final boolean enabledSemanticVersions;
+ private final Set<YangVersion> supportedVersions;
BuildGlobalContext(final Map<ModelProcessingPhase, StatementSupportBundle> supports,
final StatementParserMode statementParserMode, final Predicate<QName> isFeatureSupported) {
- super();
- this.supports = Preconditions.checkNotNull(supports, "BuildGlobalContext#supports cannot be null");
- Preconditions.checkNotNull(statementParserMode, "Statement parser mode must not be null.");
- this.enabledSemanticVersions = statementParserMode == StatementParserMode.SEMVER_MODE;
-
- addToNs(SupportedFeaturesNamespace.class, SupportedFeatures.SUPPORTED_FEATURES,
- Preconditions.checkNotNull(isFeatureSupported, "Supported feature predicate must not be null."));
+ this(supports, ImmutableMap.of(), statementParserMode, isFeatureSupported);
}
BuildGlobalContext(final Map<ModelProcessingPhase, StatementSupportBundle> supports,
addToNs(SupportedFeaturesNamespace.class, SupportedFeatures.SUPPORTED_FEATURES,
Preconditions.checkNotNull(isFeatureSupported, "Supported feature predicate must not be null."));
+ this.supportedVersions = ImmutableSet.copyOf(supports.get(ModelProcessingPhase.INIT).getSupportedVersions());
}
boolean isEnabledSemanticVersioning() {
return new SimpleNamespaceContext<>(potentialRaw);
}
- StatementDefinitionContext<?, ?, ?> getStatementDefinition(final QName name) {
- StatementDefinitionContext<?, ?, ?> potential = definitions.get(name);
+ StatementDefinitionContext<?, ?, ?> getStatementDefinition(final YangVersion version, final QName name) {
+ StatementDefinitionContext<?, ?, ?> potential = definitions.get(version, name);
if (potential == null) {
- final StatementSupport<?, ?, ?> potentialRaw = supports.get(currentPhase).getStatementDefinition(name);
+ final StatementSupport<?, ?, ?> potentialRaw = supports.get(currentPhase).getStatementDefinition(version,
+ name);
if (potentialRaw != null) {
potential = new StatementDefinitionContext<>(potentialRaw);
- definitions.put(name, potential);
+ definitions.put(version, name, potential);
}
}
return potential;
Set<SourceSpecificContext> getSources() {
return sources;
}
+
+ public Set<YangVersion> getSupportedVersions() {
+ return supportedVersions;
+ }
}