import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
import org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition;
import org.opendaylight.yangtools.yang.model.api.meta.StatementSource;
-import org.opendaylight.yangtools.yang.parser.stmt.reactor.StatementContextBase;
/**
* Utility abstract base class for implementing declared statements.
* @param <A> Argument type.
*/
public abstract class AbstractDeclaredStatement<A> implements DeclaredStatement<A> {
-
-
private final A argument;
private final String rawArgument;
private final ImmutableList<? extends DeclaredStatement<?>> substatements;
* original collection, which may contains references to mutable context.
*/
substatements = ImmutableList.copyOf(Collections2.transform(context.declaredSubstatements(),
- StatementContextBase::buildDeclared));
+ StmtContext::buildDeclared));
}
protected final <S extends DeclaredStatement<?>> S firstDeclared(final Class<S> type) {
import static org.opendaylight.yangtools.yang.parser.spi.meta.ModelProcessingPhase.EFFECTIVE_MODEL;
-import com.google.common.base.Supplier;
import java.util.Collection;
import javax.annotation.Nonnull;
import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
*
* Action will be executed when:
* <ul>
- * <li> {@link InferenceAction#apply()} - all prerequisites (and declared forward references) are met,
+ * <li> {@link InferenceAction#apply(InferenceContext)} - all prerequisites (and declared forward references) are met,
* action could dereference them and start applying changes.
* </li>
* <li>{@link InferenceAction#prerequisiteFailed(Collection)} - semantic parser finished all other satisfied
*
*/
public interface ModelActionBuilder {
+ interface InferenceContext {
+
+ }
@FunctionalInterface
- interface Prerequisite<T> extends Supplier<T> {
+ interface Prerequisite<T> {
/**
* Returns associated prerequisite once it is resolved.
*
+ * @param ctx Inference context in which the prerequisite was satisfied
* @return associated prerequisite once it is resolved.
*/
- @Override
- T get();
+ T resolve(InferenceContext ctx);
}
/**
* User-defined inference action.
- *
*/
interface InferenceAction {
* Note that this exception be used for user to debug YANG sources,
* so should provide helpful context to fix issue in sources.
*/
- void apply() throws InferenceException;
+ void apply(InferenceContext ctx) throws InferenceException;
/**
* Invoked once one of prerequisites was not met,
}
/**
- * Action requires that the specified context transition to complete{@link ModelProcessingPhase#FULL_DECLARATION}
- * phase.
+ * Action requires that the specified context transition to complete {@link ModelProcessingPhase#FULL_DECLARATION}
+ * phase and produce a declared statement.
*
- * @param context Statement context which needs to
- * @return A {@link Prerequisite} returning the declared statement of the specified context.
+ * @param context Statement context which needs to complete the transition.
+ * @return A {@link Prerequisite} returning the declared statement of the requested context.
*/
@Nonnull <D extends DeclaredStatement<?>> Prerequisite<D> requiresDeclared(StmtContext<?, ? extends D, ?> context);
+ /**
+ * Action requires that the specified context completes specified phase.
+ *
+ * @param context Statement context which needs to complete the transition.
+ * @param phase ModelProcessingPhase which must have completed
+ * @return A {@link Prerequisite} returning the requested context.
+ */
@Nonnull <A, D extends DeclaredStatement<A>, E extends EffectiveStatement<A, D>>
Prerequisite<StmtContext<A, D, E>> requiresCtx(StmtContext<A, D, E> context, ModelProcessingPhase phase);
import com.google.common.base.Preconditions;
import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
-
public class ReactorException extends Exception {
-
private static final long serialVersionUID = 1L;
+
private final ModelProcessingPhase phase;
private final SourceIdentifier sourceIdentifier;
- public ReactorException(ModelProcessingPhase phase, String message, SourceIdentifier sourceId, Throwable cause) {
+ public ReactorException(final ModelProcessingPhase phase, final String message, final SourceIdentifier sourceId,
+ final Throwable cause) {
super(message, cause);
this.phase = Preconditions.checkNotNull(phase);
this.sourceIdentifier = sourceId;
}
- public ReactorException(ModelProcessingPhase phase, String message, SourceIdentifier sourceId) {
+ public ReactorException(final ModelProcessingPhase phase, final String message, final SourceIdentifier sourceId) {
super(message);
this.phase = Preconditions.checkNotNull(phase);
this.sourceIdentifier = sourceId;
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.SupportedFeaturesNamespace.SupportedFeatures;
-import org.opendaylight.yangtools.yang.parser.stmt.reactor.RootStatementContext;
-import org.opendaylight.yangtools.yang.parser.stmt.reactor.StatementContextBase;
import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.UnknownStatementImpl;
import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangDataStatementImpl;
final Set<QName> supportedFeatures) {
boolean isSupported = false;
boolean containsIfFeature = false;
- for (final StatementContextBase<?, ?, ?> stmt : stmtContext.declaredSubstatements()) {
+ for (final StmtContext<?, ?, ?> stmt : stmtContext.declaredSubstatements()) {
if (YangStmtMapping.IF_FEATURE.equals(stmt.getPublicDefinition())) {
if (stmtContext.isInYangDataExtensionBody()) {
break;
* statement context
* @return true if it is a presence container
*/
- public static boolean isPresenceContainer(final StatementContextBase<?, ?, ?> stmtCtx) {
+ public static boolean isPresenceContainer(final StmtContext<?, ?, ?> stmtCtx) {
return stmtCtx.getPublicDefinition() == YangStmtMapping.CONTAINER && containsPresenceSubStmt(stmtCtx);
}
* statement context
* @return true if it is a non-presence container
*/
- public static boolean isNonPresenceContainer(final StatementContextBase<?, ?, ?> stmtCtx) {
+ public static boolean isNonPresenceContainer(final StmtContext<?, ?, ?> stmtCtx) {
return stmtCtx.getPublicDefinition() == YangStmtMapping.CONTAINER && !containsPresenceSubStmt(stmtCtx);
}
- private static boolean containsPresenceSubStmt(final StatementContextBase<?, ?, ?> stmtCtx) {
+ private static boolean containsPresenceSubStmt(final StmtContext<?, ?, ?> stmtCtx) {
return findFirstSubstatement(stmtCtx, PresenceStatement.class) != null;
}
* @return true if it is a mandatory leaf, choice, anyxml, list or leaf-list
* according to RFC6020.
*/
- public static boolean isMandatoryNode(final StatementContextBase<?, ?, ?> stmtCtx) {
+ public static boolean isMandatoryNode(final StmtContext<?, ?, ?> stmtCtx) {
if (!(stmtCtx.getPublicDefinition() instanceof YangStmtMapping)) {
return false;
}
* statement definition and if it is not mandatory leaf, choice,
* anyxml, list or leaf-list according to RFC6020
*/
- public static boolean isNotMandatoryNodeOfType(final StatementContextBase<?, ?, ?> stmtCtx,
+ public static boolean isNotMandatoryNodeOfType(final StmtContext<?, ?, ?> stmtCtx,
final StatementDefinition stmtDef) {
return stmtCtx.getPublicDefinition().equals(stmtDef) && !isMandatoryNode(stmtCtx);
}
Preconditions.checkNotNull(ctx);
Preconditions.checkNotNull(ancestorType);
Preconditions.checkNotNull(ancestorChildType);
+
StmtContext<?, ?, ?> current = ctx.getParentContext();
- while (!(current instanceof RootStatementContext)) {
+ StmtContext<?, ?, ?> parent = current.getParentContext();
+ while (parent != null) {
if (ancestorType.equals(current.getPublicDefinition())) {
@SuppressWarnings("unchecked")
final Class<DT> ancestorChildTypeClass = (Class<DT>) ancestorChildType.getDeclaredRepresentationClass();
return false;
}
}
- current = current.getParentContext();
+
+ current = parent;
+ parent = current.getParentContext();
}
return true;
final class ModifierImpl implements ModelActionBuilder {
private static final Logger LOG = LoggerFactory.getLogger(ModifierImpl.class);
+ private final InferenceContext ctx = new InferenceContext() { };
+
private final Set<AbstractPrerequisite<?>> unsatisfied = new HashSet<>(1);
private final Set<AbstractPrerequisite<?>> mutations = new HashSet<>(1);
private void applyAction() {
Preconditions.checkState(!actionApplied);
- action.apply();
+ action.apply(ctx);
actionApplied = true;
}
private T value;
@Override
- public final T get() {
- Preconditions.checkState(isDone());
+ public final T resolve(final InferenceContext ctx) {
+ Preconditions.checkState(done);
+ Preconditions.checkArgument(ctx == ModifierImpl.this.ctx);
return value;
}
}
final <O> Prerequisite<O> transform(final Function<? super T, O> transformation) {
- return () -> transformation.apply(get());
+ return ctx -> transformation.apply(resolve(ctx));
}
@Override
import org.opendaylight.yangtools.yang.parser.spi.source.StmtOrderingNamespace;
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.stmt.reactor.RootStatementContext;
import org.opendaylight.yangtools.yang.parser.stmt.reactor.StatementContextBase;
import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.AugmentEffectiveStatementImpl;
import org.slf4j.Logger;
augmentAction.apply(new ModelActionBuilder.InferenceAction() {
@Override
- public void apply() {
- final StatementContextBase<?, ?, ?> augmentTargetCtx = (StatementContextBase<?, ?, ?>) target.get();
+ public void apply(final ModelActionBuilder.InferenceContext ctx) {
+ final StatementContextBase<?, ?, ?> augmentTargetCtx =
+ (StatementContextBase<?, ?, ?>) target.resolve(ctx);
if (!isSupportedAugmentTarget(augmentTargetCtx)
|| StmtContextUtils.isInExtensionBody(augmentTargetCtx)) {
augmentNode.setIsSupportedToBuildEffective(false);
* @return true if supplied statement context is conditional augment
* statement, otherwise false
*/
- private static boolean isConditionalAugmentStmt(final StatementContextBase<?, ?, ?> ctx) {
+ private static boolean isConditionalAugmentStmt(final StmtContext<?, ?, ?> ctx) {
return ctx.getPublicDefinition() == YangStmtMapping.AUGMENT
&& StmtContextUtils.findFirstSubstatement(ctx, WhenStatement.class) != null;
}
}
}
- private static void validateNodeCanBeCopiedByAugment(final StatementContextBase<?, ?, ?> sourceCtx,
- final StatementContextBase<?, ?, ?> targetCtx, final CopyType typeOfCopy, final boolean skipCheckOfMandatoryNodes) {
+ private static void validateNodeCanBeCopiedByAugment(final StmtContext<?, ?, ?> sourceCtx,
+ final StatementContextBase<?, ?, ?> targetCtx, final CopyType typeOfCopy,
+ final boolean skipCheckOfMandatoryNodes) {
if (WhenStatement.class.equals(sourceCtx.getPublicDefinition().getDeclaredRepresentationClass())) {
return;
.addAll(targetCtx.declaredSubstatements()).addAll(targetCtx.effectiveSubstatements()).build();
for (final StatementContextBase<?, ?, ?> subStatement : targetSubStatements) {
-
final boolean sourceIsDataNode = DataDefinitionStatement.class.isAssignableFrom(sourceCtx
.getPublicDefinition().getDeclaredRepresentationClass());
final boolean targetIsDataNode = DataDefinitionStatement.class.isAssignableFrom(subStatement
}
}
- private static void checkForMandatoryNodes(final StatementContextBase<?, ?, ?> sourceCtx) {
+ private static void checkForMandatoryNodes(final StmtContext<?, ?, ?> sourceCtx) {
if (StmtContextUtils.isNonPresenceContainer(sourceCtx)) {
/*
* We need to iterate over both declared and effective sub-statements,
sourceCtx.rawStatementArgument());
}
- private static boolean reguiredCheckOfMandatoryNodes(final StatementContextBase<?, ?, ?> sourceCtx,
- StatementContextBase<?, ?, ?> targetCtx) {
+ private static boolean reguiredCheckOfMandatoryNodes(final StmtContext<?, ?, ?> sourceCtx,
+ Mutable<?, ?, ?> targetCtx) {
/*
* If the statement argument is not QName, it cannot be mandatory
* statement, therefore return false and skip mandatory nodes validation
}
final QName sourceStmtQName = (QName) sourceCtx.getStatementArgument();
- final RootStatementContext<?, ?, ?> root = targetCtx.getRoot();
+ // RootStatementContext, for example
+ final Mutable<?, ?, ?> root = targetCtx.getRoot();
do {
Verify.verify(targetCtx.getStatementArgument() instanceof QName,
"Argument of augment target statement must be QName.");
return REUSED_DEF_SET.contains(stmtContext.getPublicDefinition());
}
- static boolean isSupportedAugmentTarget(final StatementContextBase<?, ?, ?> substatementCtx) {
-
+ static boolean isSupportedAugmentTarget(final StmtContext<?, ?, ?> substatementCtx) {
/*
* :TODO Substatement must be allowed augment target type e.g.
* Container, etc... and must not be for example grouping, identity etc.
* the same QName. We must find the Container and the Grouping must be
* ignored as disallowed augment target.
*/
-
- final Collection<?> allowedAugmentTargets = substatementCtx.getFromNamespace(ValidationBundlesNamespace.class,
- ValidationBundleType.SUPPORTED_AUGMENT_TARGETS);
+ final Collection<?> allowedAugmentTargets = substatementCtx.getFromNamespace(
+ ValidationBundlesNamespace.class, ValidationBundleType.SUPPORTED_AUGMENT_TARGETS);
// if no allowed target is returned we consider all targets allowed
return allowedAugmentTargets == null || allowedAugmentTargets.isEmpty()
protected SubstatementValidator getSubstatementValidator() {
return SUBSTATEMENT_VALIDATOR;
}
-
}
@Nonnull
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.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.StmtContext;
baseIdentityAction.apply(new InferenceAction() {
@Override
- public void apply() {
- List<StmtContext<?, ?, ?>> derivedIdentities =
- baseStmtCtx.getFromNamespace(DerivedIdentitiesNamespace.class, baseStmtCtx.getStatementArgument());
+ public void apply(final InferenceContext ctx) {
+ List<StmtContext<?, ?, ?>> derivedIdentities = baseStmtCtx.getFromNamespace(
+ DerivedIdentitiesNamespace.class, baseStmtCtx.getStatementArgument());
if (derivedIdentities == null) {
- derivedIdentities = new ArrayList<>();
+ derivedIdentities = new ArrayList<>(1);
baseStmtCtx.addToNs(DerivedIdentitiesNamespace.class, baseIdentityQName, derivedIdentities);
}
derivedIdentities.add(baseParentCtx);
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.ModelActionBuilder.InferenceContext;
import org.opendaylight.yangtools.yang.parser.spi.meta.ModelProcessingPhase;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils;
belongsToAction.apply(new InferenceAction() {
@Override
- public void apply() {
- StmtContext<?, ?, ?> belongsToModuleCtx = belongsToPrereq.get();
+ public void apply(final InferenceContext ctx) {
+ StmtContext<?, ?, ?> belongsToModuleCtx = belongsToPrereq.resolve(ctx);
belongsToCtx.addToNs(BelongsToModuleContext.class, belongsToModuleIdentifier, belongsToModuleCtx);
belongsToCtx.addToNs(BelongsToPrefixToModuleIdentifier.class,
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.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.StmtContext;
deviateAction.requiresCtx(deviateStmtCtx, ModelProcessingPhase.EFFECTIVE_MODEL);
final Prerequisite<StmtContext.Mutable<?, ?, EffectiveStatement<?, ?>>> targetCtxPrerequisite =
- deviateAction
- .mutatesEffectiveCtx(deviateStmtCtx.getRoot(), SchemaNodeIdentifierBuildNamespace.class,
- deviationTarget);
-
- deviateAction.apply(new InferenceAction() {
- @Override
- public void apply() throws InferenceException {
- // FIXME once BUG-7760 gets fixed, there will be no need for these dirty casts
- final StatementContextBase<?, ?, ?> sourceNodeStmtCtx =
- (StatementContextBase<?, ?, ?>) sourceCtxPrerequisite.get();
- final StatementContextBase<?, ?, ?> targetNodeStmtCtx =
- (StatementContextBase<?, ?, ?>) targetCtxPrerequisite.get();
-
- switch (deviateKind) {
- case NOT_SUPPORTED:
- targetNodeStmtCtx.setIsSupportedToBuildEffective(false);
- break;
- case ADD:
- performDeviateAdd(sourceNodeStmtCtx, targetNodeStmtCtx);
- break;
- case REPLACE:
- performDeviateReplace(sourceNodeStmtCtx, targetNodeStmtCtx);
- break;
- case DELETE:
- performDeviateDelete(sourceNodeStmtCtx, targetNodeStmtCtx);
- }
- }
-
- @Override
- public void prerequisiteFailed(final Collection<? extends Prerequisite<?>> failed) {
- throw new InferenceException(deviateStmtCtx.getParentContext().getStatementSourceReference(),
- "Deviation target '%s' not found.", deviationTarget);
- }
- });
+ deviateAction.mutatesEffectiveCtx(deviateStmtCtx.getRoot(),
+ SchemaNodeIdentifierBuildNamespace.class, deviationTarget);
+
+ deviateAction.apply(new InferenceAction() {
+ @Override
+ public void apply(final InferenceContext ctx) throws InferenceException {
+ // FIXME once BUG-7760 gets fixed, there will be no need for these dirty casts
+ final StatementContextBase<?, ?, ?> sourceNodeStmtCtx =
+ (StatementContextBase<?, ?, ?>) sourceCtxPrerequisite.resolve(ctx);
+ final StatementContextBase<?, ?, ?> targetNodeStmtCtx =
+ (StatementContextBase<?, ?, ?>) targetCtxPrerequisite.resolve(ctx);
+
+ switch (deviateKind) {
+ case NOT_SUPPORTED:
+ targetNodeStmtCtx.setIsSupportedToBuildEffective(false);
+ break;
+ case ADD:
+ performDeviateAdd(sourceNodeStmtCtx, targetNodeStmtCtx);
+ break;
+ case REPLACE:
+ performDeviateReplace(sourceNodeStmtCtx, targetNodeStmtCtx);
+ break;
+ case DELETE:
+ performDeviateDelete(sourceNodeStmtCtx, targetNodeStmtCtx);
+ }
+ }
+
+ @Override
+ public void prerequisiteFailed(final Collection<? extends Prerequisite<?>> failed) {
+ throw new InferenceException(deviateStmtCtx.getParentContext().getStatementSourceReference(),
+ "Deviation target '%s' not found.", deviationTarget);
+ }
+ });
}
private static boolean isDeviationSupported(final StmtContext.Mutable<DeviateKind, DeviateStatement,
}
}
- private static void deleteStatement(final StatementContextBase<?, ?, ?> stmtCtxToBeDeleted,
+ private static void deleteStatement(final StmtContext<?, ?, ?> stmtCtxToBeDeleted,
final StatementContextBase<?, ?, ?> targetCtx) {
final StatementDefinition stmtToBeDeleted = stmtCtxToBeDeleted.getPublicDefinition();
final String stmtArgument = stmtCtxToBeDeleted.rawStatementArgument();
return firstStmtDef.equals(secondStmtDef) && Objects.equals(firstStmtArg, secondStmtArg);
}
- private static void validateDeviationTarget(final StatementContextBase<?, ?, ?> deviateSubStmtCtx,
- final StatementContextBase<?, ?, ?> targetCtx) {
+ private static void validateDeviationTarget(final StmtContext<?, ?, ?> deviateSubStmtCtx,
+ final StmtContext<?, ?, ?> targetCtx) {
InferenceException.throwIf(!isSupportedDeviationTarget(deviateSubStmtCtx, targetCtx,
targetCtx.getRootVersion()), deviateSubStmtCtx.getStatementSourceReference(),
"%s is not a valid deviation target for substatement %s.",
targetCtx.getStatementArgument(), deviateSubStmtCtx.getPublicDefinition().getStatementName());
}
- private static boolean isSupportedDeviationTarget(final StatementContextBase<?, ?, ?> deviateSubstatementCtx,
- final StatementContextBase<?, ?, ?> deviateTargetCtx, final YangVersion yangVersion) {
+ private static boolean isSupportedDeviationTarget(final StmtContext<?, ?, ?> deviateSubstatementCtx,
+ final StmtContext<?, ?, ?> deviateTargetCtx, final YangVersion yangVersion) {
Set<StatementDefinition> supportedDeviationTargets =
YangValidationBundles.SUPPORTED_DEVIATION_TARGETS.get(deviateTargetCtx.getRootVersion(),
deviateSubstatementCtx.getPublicDefinition());
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.ModelActionBuilder.InferenceContext;
import org.opendaylight.yangtools.yang.parser.spi.meta.ModelActionBuilder.Prerequisite;
import org.opendaylight.yangtools.yang.parser.spi.meta.SemanticVersionModuleNamespace;
import org.opendaylight.yangtools.yang.parser.spi.meta.SemanticVersionNamespace;
importAction.apply(new InferenceAction() {
@Override
- public void apply() {
- final StmtContext<?, ?, ?> importedModuleContext = imported.get();
+ public void apply(final InferenceContext ctx) {
+ final StmtContext<?, ?, ?> importedModuleContext = imported.resolve(ctx);
Verify.verify(moduleName.equals(importedModuleContext.getStatementArgument()));
final URI importedModuleNamespace = importedModuleContext.getFromNamespace(ModuleNameToNamespace.class,
moduleName);
importAction.apply(new InferenceAction() {
@Override
- public void apply() {
+ public void apply(final InferenceContext ctx) {
StmtContext<?, ?, ?> importedModule = null;
ModuleIdentifier importedModuleIdentifier = null;
if (impIdentifier.getRevision() == SimpleDateFormatUtil.DEFAULT_DATE_IMP) {
}
if (importedModule == null || importedModuleIdentifier == null) {
- importedModule = imported.get();
+ importedModule = imported.resolve(ctx);
importedModuleIdentifier = impIdentifier;
}
- linkageTarget.get().addToNs(ImportedModuleContext.class, importedModuleIdentifier, importedModule);
+ linkageTarget.resolve(ctx).addToNs(ImportedModuleContext.class, importedModuleIdentifier, importedModule);
final String impPrefix = firstAttributeOf(stmt.declaredSubstatements(), PrefixStatement.class);
stmt.addToNs(ImpPrefixToModuleIdentifier.class, impPrefix, importedModuleIdentifier);
return recentModuleEntry;
}
- private static ModuleIdentifier getImportedModuleIdentifier(final Mutable<String, ImportStatement, ?> stmt) {
+ private static ModuleIdentifier getImportedModuleIdentifier(final StmtContext<String, ImportStatement, ?> stmt) {
Date revision = firstAttributeOf(stmt.declaredSubstatements(), RevisionDateStatement.class);
if (revision == null) {
revision = SimpleDateFormatUtil.DEFAULT_DATE_IMP;
importAction.apply(new InferenceAction() {
@Override
- public void apply() {
+ public void apply(final InferenceContext ctx) {
final Entry<SemVer, StmtContext<?, ?, ?>> importedModuleEntry= findRecentCompatibleModuleEntry(
impIdentifier.getName(), stmt);
.getName(), getRequestedImportVersion(stmt));
}
- linkageTarget.get().addToNs(ImportedModuleContext.class, importedModuleIdentifier, importedModule);
+ linkageTarget.resolve(ctx).addToNs(ImportedModuleContext.class, importedModuleIdentifier, importedModule);
final String impPrefix = firstAttributeOf(stmt.declaredSubstatements(), PrefixStatement.class);
stmt.addToNs(ImpPrefixToModuleIdentifier.class, impPrefix, importedModuleIdentifier);
stmt.addToNs(ImpPrefixToSemVerModuleIdentifier.class, impPrefix, semVerModuleIdentifier);
});
}
- private static SemVer getRequestedImportVersion(final Mutable<?, ?, ?> impStmt) {
+ private static SemVer getRequestedImportVersion(final StmtContext<?, ?, ?> impStmt) {
SemVer requestedImportVersion = impStmt.getFromNamespace(SemanticVersionNamespace.class, impStmt);
if (requestedImportVersion == null) {
requestedImportVersion = Module.DEFAULT_SEMANTIC_VERSION;
}
private static Entry<SemVer, StmtContext<?, ?, ?>> findRecentCompatibleModuleEntry(final String moduleName,
- final Mutable<String, ImportStatement, EffectiveStatement<String, ImportStatement>> impStmt) {
+ final StmtContext<String, ImportStatement, EffectiveStatement<String, ImportStatement>> impStmt) {
NavigableMap<SemVer, StmtContext<?, ?, ?>> allRelevantModulesMap = impStmt.getFromNamespace(
SemanticVersionModuleNamespace.class, moduleName);
if (allRelevantModulesMap == null) {
return null;
}
- private static ModuleIdentifier getImportedModuleIdentifier(final Mutable<String, ImportStatement, ?> impStmt) {
+ private static ModuleIdentifier getImportedModuleIdentifier(final StmtContext<String, ImportStatement, ?> impStmt) {
return ModuleIdentifierImpl.create(impStmt.getStatementArgument(), Optional.empty(),
Optional.of(SimpleDateFormatUtil.DEFAULT_DATE_IMP));
}
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.ModelActionBuilder.InferenceContext;
import org.opendaylight.yangtools.yang.parser.spi.meta.ModelActionBuilder.Prerequisite;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.Mutable;
includeAction.apply(new InferenceAction() {
@Override
- public void apply() {
- final StmtContext<?, ?, ?> includedSubModuleContext = requiresCtxPrerequisite.get();
+ public void apply(final InferenceContext ctx) {
+ final StmtContext<?, ?, ?> includedSubModuleContext = requiresCtxPrerequisite.resolve(ctx);
stmt.addToNs(IncludedModuleContext.class, includeSubmoduleIdentifier,
includedSubModuleContext);
});
}
- private static ModuleIdentifier getIncludeSubmoduleIdentifier(final Mutable<String, IncludeStatement, ?> stmt) {
+ private static ModuleIdentifier getIncludeSubmoduleIdentifier(final StmtContext<String, IncludeStatement, ?> stmt) {
final String subModuleName = stmt.getStatementArgument();
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.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;
*/
typeAction.apply(new InferenceAction() {
@Override
- public void apply() {
+ public void apply(final InferenceContext ctx) {
// Intentional NOOP
}
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.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.StmtContext;
usesAction.apply(new InferenceAction() {
@Override
- public void apply() {
- final StatementContextBase<?, ?, ?> targetNodeStmtCtx = (StatementContextBase<?, ?, ?>) targetNodePre.get();
- final StatementContextBase<?, ?, ?> sourceGrpStmtCtx = (StatementContextBase<?, ?, ?>) sourceGroupingPre.get();
+ public void apply(final InferenceContext ctx) {
+ final StatementContextBase<?, ?, ?> targetNodeStmtCtx = (StatementContextBase<?, ?, ?>) targetNodePre.resolve(ctx);
+ final StatementContextBase<?, ?, ?> sourceGrpStmtCtx = (StatementContextBase<?, ?, ?>) sourceGroupingPre.resolve(ctx);
try {
copyFromSourceToTarget(sourceGrpStmtCtx, targetNodeStmtCtx, usesNode);
* @throws SourceException
* instance of SourceException
*/
- private static void copyFromSourceToTarget(final StatementContextBase<?, ?, ?> sourceGrpStmtCtx,
+ private static void copyFromSourceToTarget(final StmtContext<?, ?, ?> sourceGrpStmtCtx,
final StatementContextBase<?, ?, ?> targetCtx,
final StmtContext.Mutable<QName, UsesStatement, EffectiveStatement<QName, UsesStatement>> usesNode) {
final Collection<StatementContextBase<?, ?, ?>> declared = sourceGrpStmtCtx.declaredSubstatements();
}
}
- private static boolean areFeaturesSupported(final StatementContextBase<?, ?, ?> subStmtCtx) {
+ private static boolean areFeaturesSupported(final Mutable<?, ?, ?> subStmtCtx) {
/*
* In case of Yang 1.1, checks whether features are supported.
*/
return ALLOWED_TO_ADD_BY_REFINE_DEF_SET.contains(publicDefinition);
}
- private static boolean isSupportedRefineSubstatement(final StatementContextBase<?, ?, ?> refineSubstatementCtx) {
+ private static boolean isSupportedRefineSubstatement(final StmtContext<?, ?, ?> refineSubstatementCtx) {
final Collection<?> supportedRefineSubstatements = refineSubstatementCtx.getFromNamespace(
ValidationBundlesNamespace.class, ValidationBundleType.SUPPORTED_REFINE_SUBSTATEMENTS);
|| StmtContextUtils.isUnknownStatement(refineSubstatementCtx);
}
- private static boolean isSupportedRefineTarget(final StatementContextBase<?, ?, ?> refineSubstatementCtx,
- final StatementContextBase<?, ?, ?> refineTargetNodeCtx) {
-
+ private static boolean isSupportedRefineTarget(final StmtContext<?, ?, ?> refineSubstatementCtx,
+ final StmtContext<?, ?, ?> refineTargetNodeCtx) {
final Collection<?> supportedRefineTargets = YangValidationBundles.SUPPORTED_REFINE_TARGETS
.get(refineSubstatementCtx.getPublicDefinition());
}
- private static QNameModule getNewQNameModule(final StatementContextBase<?, ?, ?> targetCtx,
+ private static QNameModule getNewQNameModule(final StmtContext<?, ?, ?> targetCtx,
final StmtContext<?, ?, ?> stmtContext) {
if (targetCtx.isRootContext()) {
return targetCtx.getFromNamespace(ModuleCtxToModuleQName.class, targetCtx);