import static com.google.common.base.Preconditions.checkState;
import static java.util.Objects.requireNonNull;
+import com.google.common.annotations.Beta;
import com.google.common.base.MoreObjects;
import com.google.common.base.MoreObjects.ToStringHelper;
import com.google.common.collect.ImmutableCollection;
import java.util.EnumMap;
import java.util.EventListener;
import java.util.Iterator;
+import java.util.List;
import java.util.Map.Entry;
import java.util.Objects;
import java.util.Optional;
import org.opendaylight.yangtools.yang.model.api.meta.StatementSource;
import org.opendaylight.yangtools.yang.parser.spi.meta.CopyHistory;
import org.opendaylight.yangtools.yang.parser.spi.meta.CopyType;
+import org.opendaylight.yangtools.yang.parser.spi.meta.ImplicitParentAwareStatementSupport;
import org.opendaylight.yangtools.yang.parser.spi.meta.ModelActionBuilder;
import org.opendaylight.yangtools.yang.parser.spi.meta.ModelProcessingPhase;
import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour;
private final @NonNull StatementDefinitionContext<A, D, E> definition;
private final @NonNull StatementSourceReference statementDeclSource;
private final StmtContext<?, ?, ?> originalCtx;
+ private final StmtContext<?, ?, ?> prevCopyCtx;
private final CopyHistory copyHistory;
private final String rawArgument;
private Multimap<ModelProcessingPhase, OnPhaseFinished> phaseListeners = ImmutableMultimap.of();
private Multimap<ModelProcessingPhase, ContextMutation> phaseMutation = ImmutableMultimap.of();
- private Collection<Mutable<?, ?, ?>> effective = ImmutableList.of();
- private Collection<StmtContext<?, ?, ?>> effectOfStatement = ImmutableList.of();
+ private List<Mutable<?, ?, ?>> effective = ImmutableList.of();
+ private List<StmtContext<?, ?, ?>> effectOfStatement = ImmutableList.of();
private StatementMap substatements = StatementMap.empty();
private boolean isSupportedToBuildEffective = true;
this.rawArgument = def.internArgument(rawArgument);
this.copyHistory = CopyHistory.original();
this.originalCtx = null;
+ this.prevCopyCtx = null;
+ }
+
+ StatementContextBase(final StatementDefinitionContext<A, D, E> def, final StatementSourceReference ref,
+ final String rawArgument, final CopyType copyType) {
+ this.definition = requireNonNull(def);
+ this.statementDeclSource = requireNonNull(ref);
+ this.rawArgument = rawArgument;
+ this.copyHistory = CopyHistory.of(copyType, CopyHistory.original());
+ this.originalCtx = null;
+ this.prevCopyCtx = null;
}
StatementContextBase(final StatementContextBase<A, D, E> original, final CopyType copyType) {
this.rawArgument = original.rawArgument;
this.copyHistory = CopyHistory.of(copyType, original.getCopyHistory());
this.originalCtx = original.getOriginalCtx().orElse(original);
+ this.prevCopyCtx = original;
+ }
+
+ StatementContextBase(final StatementContextBase<A, D, E> original) {
+ this.definition = original.definition;
+ this.statementDeclSource = original.statementDeclSource;
+ this.rawArgument = original.rawArgument;
+ this.copyHistory = original.getCopyHistory();
+ this.originalCtx = original.getOriginalCtx().orElse(original);
+ this.prevCopyCtx = original;
+ this.substatements = original.substatements;
+ this.effective = original.effective;
}
@Override
// If the set of supported features has not been provided, all features are supported by default.
final Set<QName> supportedFeatures = getFromNamespace(SupportedFeaturesNamespace.class,
SupportedFeatures.SUPPORTED_FEATURES);
- final boolean ret = supportedFeatures == null ? true
- : StmtContextUtils.checkFeatureSupport(this, supportedFeatures);
-
+ final boolean ret = supportedFeatures == null || StmtContextUtils.checkFeatureSupport(this, supportedFeatures);
supportedByFeatures = OptionalBoolean.of(ret);
return ret;
}
return Optional.ofNullable(originalCtx);
}
+ @Override
+ public Optional<? extends StmtContext<?, ?, ?>> getPreviousCopyCtx() {
+ return Optional.ofNullable(prevCopyCtx);
+ }
+
@Override
public ModelProcessingPhase getCompletedPhase() {
return completedPhase;
checkArgument(stmt instanceof SubstatementContext, "Unsupported statement %s", stmt);
final SubstatementContext<X, Y, Z> original = (SubstatementContext<X, Y, Z>)stmt;
- final SubstatementContext<X, Y, Z> copy = new SubstatementContext<>(original, this, type, targetModule);
+ final Optional<StatementSupport<?, ?, ?>> implicitParent = definition.getImplicitParentFor(
+ original.getPublicDefinition());
- original.definition().onStatementAdded(copy);
- original.copyTo(copy, type, targetModule);
+ final SubstatementContext<X, Y, Z> result;
+ final SubstatementContext<X, Y, Z> copy;
- return copy;
- }
+ if (implicitParent.isPresent()) {
+ final StatementDefinitionContext<?, ?, ?> def = new StatementDefinitionContext<>(implicitParent.get());
+ result = new SubstatementContext(this, def, original.getSourceReference(),
+ original.rawStatementArgument(), original.getStatementArgument(), type);
+
+ final CopyType childCopyType;
+ switch (type) {
+ case ADDED_BY_AUGMENTATION:
+ childCopyType = CopyType.ORIGINAL;
+ break;
+ case ADDED_BY_USES_AUGMENTATION:
+ childCopyType = CopyType.ADDED_BY_USES;
+ break;
+ case ADDED_BY_USES:
+ case ORIGINAL:
+ default:
+ childCopyType = type;
+ }
+
+ copy = new SubstatementContext<>(original, result, childCopyType, targetModule);
+ result.addEffectiveSubstatement(copy);
+ original.definition().onStatementAdded(copy);
+ } else {
+ result = copy = new SubstatementContext<>(original, this, type, targetModule);
+ original.definition().onStatementAdded(copy);
+ }
+ original.copyTo(copy, type, targetModule);
+ return result;
+ }
@Override
public @NonNull StatementDefinition getDefinition() {
return fullyDefined;
}
+ @Beta
+ public final boolean hasImplicitParentSupport() {
+ return definition.getFactory() instanceof ImplicitParentAwareStatementSupport;
+ }
+
+ @Beta
+ public final StatementContextBase<?, ?, ?> wrapWithImplicit(final StatementContextBase<?, ?, ?> original) {
+ final Optional<StatementSupport<?, ?, ?>> optImplicit = definition.getImplicitParentFor(
+ original.getPublicDefinition());
+ if (!optImplicit.isPresent()) {
+ return original;
+ }
+
+ final StatementDefinitionContext<?, ?, ?> def = new StatementDefinitionContext<>(optImplicit.get());
+ final CopyType type = original.getCopyHistory().getLastOperation();
+ final SubstatementContext<?, ?, ?> result = new SubstatementContext(original.getParentContext(), def,
+ original.getStatementSourceReference(), original.rawStatementArgument(), original.getStatementArgument(),
+ type);
+
+ result.addEffectiveSubstatement(new SubstatementContext<>(original, result));
+ result.setCompletedPhase(original.getCompletedPhase());
+ return result;
+ }
+
final void copyTo(final StatementContextBase<?, ?, ?> target, final CopyType typeOfCopy,
@Nullable final QNameModule targetModule) {
final Collection<Mutable<?, ?, ?>> buffer = new ArrayList<>(substatements.size() + effective.size());
}
// FIXME: revise this, as it seems to be wrong
- private static final Set<YangStmtMapping> NOCOPY_FROM_GROUPING_SET = ImmutableSet.of(
+ private static final ImmutableSet<YangStmtMapping> NOCOPY_FROM_GROUPING_SET = ImmutableSet.of(
YangStmtMapping.DESCRIPTION,
YangStmtMapping.REFERENCE,
YangStmtMapping.STATUS);
- private static final Set<YangStmtMapping> REUSED_DEF_SET = ImmutableSet.of(
+ private static final ImmutableSet<YangStmtMapping> REUSED_DEF_SET = ImmutableSet.of(
YangStmtMapping.TYPE,
YangStmtMapping.TYPEDEF,
YangStmtMapping.USES);