import java.util.Map.Entry;
import java.util.Optional;
import java.util.Set;
+import java.util.stream.Stream;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.meta.IdentifierNamespace;
import org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition;
-import org.opendaylight.yangtools.yang.model.api.meta.StatementSource;
import org.opendaylight.yangtools.yang.model.api.stmt.AugmentStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.ConfigEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.DeviationStatement;
return getRoot().isEnabledSemanticVersioningImpl();
}
- @Override
- public StatementSource getStatementSource() {
- return getStatementSourceReference().getStatementSource();
- }
-
@Override
public final <K, V, N extends IdentifierNamespace<K, V>> Map<K, V> getAllFromCurrentStmtCtxNamespace(
final Class<N> type) {
final Iterator<? extends StmtContext<?, ?, ?>> iterator = effective.iterator();
while (iterator.hasNext()) {
final StmtContext<?, ?, ?> next = iterator.next();
- if (statementDef.equals(next.getPublicDefinition())) {
+ if (statementDef.equals(next.publicDefinition())) {
iterator.remove();
}
}
final Iterator<StatementContextBase<?, ?, ?>> iterator = effective.iterator();
while (iterator.hasNext()) {
final Mutable<?, ?, ?> next = iterator.next();
- if (statementDef.equals(next.getPublicDefinition()) && statementArg.equals(next.rawStatementArgument())) {
+ if (statementDef.equals(next.publicDefinition()) && statementArg.equals(next.rawArgument())) {
iterator.remove();
}
}
// FIXME: YANGTOOLS-652: This does not need to be a SubstatementContext, in can be a specialized
// StatementContextBase subclass.
final Mutable<X, Y, Z> ret = new SubstatementContext<>(this, new StatementDefinitionContext<>(support),
- ImplicitSubstatement.of(getStatementSourceReference()), rawArg);
+ ImplicitSubstatement.of(sourceReference()), rawArg);
support.onStatementAdded(ret);
addEffectiveSubstatement(ret);
return ret;
final List<StatementContextBase<?, ?, ?>> effective, final int toAdd) {
// We cannot allow statement to be further mutated
verify(completedPhase != ModelProcessingPhase.EFFECTIVE_MODEL, "Cannot modify finished statement at %s",
- getStatementSourceReference());
+ sourceReference());
return beforeAddEffectiveStatementUnsafe(effective, toAdd);
}
final ModelProcessingPhase inProgressPhase = getRoot().getSourceContext().getInProgressPhase();
checkState(inProgressPhase == ModelProcessingPhase.FULL_DECLARATION
|| inProgressPhase == ModelProcessingPhase.EFFECTIVE_MODEL,
- "Effective statement cannot be added in declared phase at: %s", getStatementSourceReference());
+ "Effective statement cannot be added in declared phase at: %s", sourceReference());
return effective.isEmpty() ? new ArrayList<>(toAdd) : effective;
}
}
private E loadEffective() {
- return effectiveInstance = definition.getFactory().createEffective(this);
+ return effectiveInstance = definition.getFactory().createEffective(new BaseCurrentEffectiveStmtCtx<>(this),
+ streamDeclared(), streamEffective());
}
+ abstract Stream<? extends StmtContext<?, ?, ?>> streamDeclared();
+
+ abstract Stream<? extends StmtContext<?, ?, ?>> streamEffective();
+
/**
* Try to execute current {@link ModelProcessingPhase} of source parsing. If the phase has already been executed,
* this method does nothing.
}
@Override
- public StatementDefinition getPublicDefinition() {
+ public final StatementDefinition publicDefinition() {
return definition.getPublicView();
}
@Override
- public ModelActionBuilder newInferenceAction(final ModelProcessingPhase phase) {
+ public final ModelActionBuilder newInferenceAction(final ModelProcessingPhase phase) {
return getRoot().getSourceContext().newInferenceAction(phase);
}
* @throws NullPointerException if any of the arguments is null
*/
void addPhaseCompletedListener(final ModelProcessingPhase phase, final OnPhaseFinished listener) {
- checkNotNull(phase, "Statement context processing phase cannot be null at: %s", getStatementSourceReference());
- checkNotNull(listener, "Statement context phase listener cannot be null at: %s", getStatementSourceReference());
+ checkNotNull(phase, "Statement context processing phase cannot be null at: %s", sourceReference());
+ checkNotNull(listener, "Statement context phase listener cannot be null at: %s", sourceReference());
ModelProcessingPhase finishedPhase = completedPhase;
while (finishedPhase != null) {
ModelProcessingPhase finishedPhase = completedPhase;
while (finishedPhase != null) {
checkState(!phase.equals(finishedPhase), "Mutation registered after phase was completed at: %s",
- getStatementSourceReference());
+ sourceReference());
finishedPhase = finishedPhase.getPreviousPhase();
}
private <X, Y extends DeclaredStatement<X>, Z extends EffectiveStatement<X, Y>> Mutable<X, Y, Z> childCopyOf(
final StatementContextBase<X, Y, Z> original, final CopyType type, final QNameModule targetModule) {
final Optional<StatementSupport<?, ?, ?>> implicitParent = definition.getImplicitParentFor(
- original.getPublicDefinition());
+ original.publicDefinition());
final StatementContextBase<X, Y, Z> result;
final InferredStatementContext<X, Y, Z> copy;
if (implicitParent.isPresent()) {
final StatementDefinitionContext<?, ?, ?> def = new StatementDefinitionContext<>(implicitParent.get());
- result = new SubstatementContext(this, def, original.getStatementSourceReference(),
- original.rawStatementArgument(), original.getStatementArgument(), type);
+ result = new SubstatementContext(this, def, original.sourceReference(), original.rawArgument(),
+ original.argument(), type);
final CopyType childCopyType;
switch (type) {
@Beta
public final StatementContextBase<?, ?, ?> wrapWithImplicit(final StatementContextBase<?, ?, ?> original) {
final Optional<StatementSupport<?, ?, ?>> optImplicit = definition.getImplicitParentFor(
- original.getPublicDefinition());
+ original.publicDefinition());
if (optImplicit.isEmpty()) {
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);
+ original.sourceReference(), original.rawArgument(), original.argument(), type);
result.addEffectiveSubstatement(original.reparent(result));
result.setCompletedPhase(original.getCompletedPhase());
isConfig = optConfig.orElseThrow();
if (isConfig) {
// Validity check: if parent is config=false this cannot be a config=true
- InferenceException.throwIf(!parent.isConfiguration(), getStatementSourceReference(),
+ InferenceException.throwIf(!parent.isConfiguration(), sourceReference(),
"Parent node has config=false, this node must not be specifed as config=true");
}
} else {
return false;
}
- // Exists only to support {SubstatementContext,InferredStatementContext}.getSchemaPath()
+ abstract @NonNull Optional<SchemaPath> schemaPath();
+
+ // Exists only to support {SubstatementContext,InferredStatementContext}.schemaPath()
@Deprecated
final @NonNull Optional<SchemaPath> substatementGetSchemaPath() {
SchemaPath local = schemaPath;
synchronized (this) {
local = schemaPath;
if (local == null) {
- schemaPath = local = createSchemaPath(coerceParentContext());
+ schemaPath = local = createSchemaPath((StatementContextBase<?, ?, ?>) coerceParentContext());
}
}
}
}
@Deprecated
- private SchemaPath createSchemaPath(final Mutable<?, ?, ?> parent) {
- final Optional<SchemaPath> maybeParentPath = parent.getSchemaPath();
+ private SchemaPath createSchemaPath(final StatementContextBase<?, ?, ?> parent) {
+ final Optional<SchemaPath> maybeParentPath = parent.schemaPath();
verify(maybeParentPath.isPresent(), "Parent %s does not have a SchemaPath", parent);
final SchemaPath parentPath = maybeParentPath.get();
if (StmtContextUtils.isUnknownStatement(this)) {
- return parentPath.createChild(getPublicDefinition().getStatementName());
+ return parentPath.createChild(publicDefinition().getStatementName());
}
final Object argument = getStatementArgument();
if (argument instanceof QName) {
}
protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
- return toStringHelper.add("definition", definition).add("rawArgument", rawStatementArgument());
+ return toStringHelper.add("definition", definition).add("rawArgument", rawArgument());
}
}