*/
package org.opendaylight.yangtools.yang.parser.rfc7950.stmt.deviate;
+import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Iterables;
import com.google.common.collect.Maps;
import com.google.common.collect.SetMultimap;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import org.opendaylight.yangtools.yang.common.YangVersion;
import org.opendaylight.yangtools.yang.model.api.DeviateKind;
import org.opendaylight.yangtools.yang.model.api.YangStmtMapping;
+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.StatementDefinition;
+import org.opendaylight.yangtools.yang.model.api.stmt.DeviateEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.DeviateStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier;
-import org.opendaylight.yangtools.yang.parser.rfc7950.namespace.ChildSchemaNodeNamespace;
import org.opendaylight.yangtools.yang.parser.rfc7950.reactor.YangValidationBundles;
-import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractStatementSupport;
+import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.BaseStatementSupport;
+import org.opendaylight.yangtools.yang.parser.spi.SchemaTreeNamespace;
import org.opendaylight.yangtools.yang.parser.spi.meta.CopyType;
import org.opendaylight.yangtools.yang.parser.spi.meta.InferenceException;
import org.opendaylight.yangtools.yang.parser.spi.meta.ModelActionBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-abstract class AbstractDeviateStatementSupport extends AbstractStatementSupport<DeviateKind, DeviateStatement,
- EffectiveStatement<DeviateKind, DeviateStatement>> {
+abstract class AbstractDeviateStatementSupport
+ extends BaseStatementSupport<DeviateKind, DeviateStatement, DeviateEffectiveStatement> {
private static final Logger LOG = LoggerFactory.getLogger(AbstractDeviateStatementSupport.class);
private static final SubstatementValidator DEVIATE_NOT_SUPPORTED_SUBSTATEMENT_VALIDATOR =
}
@Override
- public final DeviateStatement createDeclared(final StmtContext<DeviateKind, DeviateStatement, ?> ctx) {
- return new DeviateStatementImpl(ctx);
- }
-
- @Override
- public final EffectiveStatement<DeviateKind, DeviateStatement> createEffective(
- final StmtContext<DeviateKind, DeviateStatement, EffectiveStatement<DeviateKind,
- DeviateStatement>> ctx) {
- return new DeviateEffectiveStatementImpl(ctx);
- }
-
- @Override
- public final void onFullDefinitionDeclared(final Mutable<DeviateKind, DeviateStatement,
- EffectiveStatement<DeviateKind, DeviateStatement>> deviateStmtCtx) {
+ public final void onFullDefinitionDeclared(
+ final Mutable<DeviateKind, DeviateStatement, DeviateEffectiveStatement> deviateStmtCtx) {
final DeviateKind deviateKind = deviateStmtCtx.getStatementArgument();
getSubstatementValidatorForDeviate(deviateKind).validate(deviateStmtCtx);
final ModelActionBuilder deviateAction = deviateStmtCtx.newInferenceAction(
ModelProcessingPhase.EFFECTIVE_MODEL);
- final Prerequisite<StmtContext<DeviateKind, DeviateStatement, EffectiveStatement<DeviateKind,
- DeviateStatement>>> sourceCtxPrerequisite =
+ final Prerequisite<StmtContext<DeviateKind, DeviateStatement,
+ DeviateEffectiveStatement>> sourceCtxPrerequisite =
deviateAction.requiresCtx(deviateStmtCtx, ModelProcessingPhase.EFFECTIVE_MODEL);
final Prerequisite<Mutable<?, ?, EffectiveStatement<?, ?>>> targetCtxPrerequisite =
deviateAction.mutatesEffectiveCtxPath(deviateStmtCtx.getRoot(),
- ChildSchemaNodeNamespace.class, deviationTarget.getPathFromRoot());
+ SchemaTreeNamespace.class, deviationTarget.getNodeIdentifiers());
deviateAction.apply(new InferenceAction() {
@Override
return null;
}
+ @Override
+ protected final DeviateStatement createDeclared(final StmtContext<DeviateKind, DeviateStatement, ?> ctx,
+ final ImmutableList<? extends DeclaredStatement<?>> substatements) {
+ return new DeviateStatementImpl(ctx, substatements);
+ }
+
+ @Override
+ protected final DeviateStatement createEmptyDeclared(final StmtContext<DeviateKind, DeviateStatement, ?> ctx) {
+ // This is exceedingly unlikely, just reuse the implementation
+ return createDeclared(ctx, ImmutableList.of());
+ }
+
+ @Override
+ protected final DeviateEffectiveStatement createEffective(
+ final StmtContext<DeviateKind, DeviateStatement, DeviateEffectiveStatement> ctx,
+ final DeviateStatement declared, final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
+ return new DeviateEffectiveStatementImpl(declared, substatements);
+ }
+
+ @Override
+ protected final DeviateEffectiveStatement createEmptyEffective(
+ final StmtContext<DeviateKind, DeviateStatement, DeviateEffectiveStatement> ctx,
+ final DeviateStatement declared) {
+ // This is exceedingly unlikely, just reuse the implementation
+ return createEffective(ctx, declared, ImmutableList.of());
+ }
+
protected SubstatementValidator getSubstatementValidatorForDeviate(final DeviateKind deviateKind) {
switch (deviateKind) {
case NOT_SUPPORTED:
}
}
- private static boolean isDeviationSupported(final Mutable<DeviateKind, DeviateStatement,
- EffectiveStatement<DeviateKind, DeviateStatement>> deviateStmtCtx,
+ private static boolean isDeviationSupported(
+ final Mutable<DeviateKind, DeviateStatement, DeviateEffectiveStatement> deviateStmtCtx,
final SchemaNodeIdentifier deviationTarget) {
final SetMultimap<QNameModule, QNameModule> modulesDeviatedByModules = deviateStmtCtx.getFromNamespace(
ModulesDeviatedByModules.class, SupportedModules.SUPPORTED_MODULES);
final QNameModule currentModule = deviateStmtCtx.getFromNamespace(ModuleCtxToModuleQName.class,
deviateStmtCtx.getRoot());
- final QNameModule targetModule = deviationTarget.getLastComponent().getModule();
+ final QNameModule targetModule = Iterables.getLast(deviationTarget.getNodeIdentifiers()).getModule();
final Set<QNameModule> deviationModulesSupportedByTargetModule = modulesDeviatedByModules.get(targetModule);
if (deviationModulesSupportedByTargetModule != null) {