import com.google.common.annotations.Beta;
import com.google.common.collect.ImmutableList;
+import java.util.Collection;
import java.util.Optional;
import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.stmt.DefaultEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.MandatoryEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.StatusEffectiveStatement;
+import org.opendaylight.yangtools.yang.model.ri.stmt.DeclaredStatements;
+import org.opendaylight.yangtools.yang.model.ri.stmt.EffectiveStatements;
+import org.opendaylight.yangtools.yang.model.spi.meta.EffectiveStatementMixins.EffectiveStatementWithFlags.FlagsBuilder;
+import org.opendaylight.yangtools.yang.model.spi.meta.SubstatementIndexingException;
import org.opendaylight.yangtools.yang.parser.rfc7950.reactor.YangValidationBundles;
-import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.BaseSchemaTreeStatementSupport;
-import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.EffectiveStatementMixins.EffectiveStatementWithFlags.FlagsBuilder;
-import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.SubstatementIndexingException;
import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.case_.CaseStatementSupport;
+import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractSchemaTreeStatementSupport;
import org.opendaylight.yangtools.yang.parser.spi.meta.EffectiveStmtCtx.Current;
import org.opendaylight.yangtools.yang.parser.spi.meta.ImplicitParentAwareStatementSupport;
import org.opendaylight.yangtools.yang.parser.spi.meta.InferenceException;
@Beta
public final class ChoiceStatementSupport
- extends BaseSchemaTreeStatementSupport<ChoiceStatement, ChoiceEffectiveStatement>
+ extends AbstractSchemaTreeStatementSupport<ChoiceStatement, ChoiceEffectiveStatement>
implements ImplicitParentAwareStatementSupport {
private static final @NonNull ChoiceStatementSupport RFC6020_INSTANCE = new ChoiceStatementSupport(
SubstatementValidator.builder(YangStmtMapping.CHOICE)
private final SubstatementValidator validator;
private final CaseStatementSupport implicitCase;
- private ChoiceStatementSupport(final SubstatementValidator validator,
- final CaseStatementSupport implicitCase) {
- super(YangStmtMapping.CHOICE, CopyPolicy.DECLARED_COPY);
+ private ChoiceStatementSupport(final SubstatementValidator validator, final CaseStatementSupport implicitCase) {
+ super(YangStmtMapping.CHOICE, instantiatedPolicy());
this.validator = requireNonNull(validator);
this.implicitCase = requireNonNull(implicitCase);
}
@Override
protected ChoiceStatement createDeclared(@NonNull final StmtContext<QName, ChoiceStatement, ?> ctx,
final ImmutableList<? extends DeclaredStatement<?>> substatements) {
- return new RegularChoiceStatement(ctx.getArgument(), substatements);
+ return DeclaredStatements.createChoice(ctx.getArgument(), substatements);
}
@Override
protected ChoiceStatement createEmptyDeclared(@NonNull final StmtContext<QName, ChoiceStatement, ?> ctx) {
- return new EmptyChoiceStatement(ctx.getArgument());
+ return DeclaredStatements.createChoice(ctx.getArgument());
+ }
+
+ @Override
+ public ChoiceEffectiveStatement copyEffective(final Current<QName, ChoiceStatement> stmt,
+ final ChoiceEffectiveStatement original) {
+ return EffectiveStatements.copyChoice(original, stmt.effectivePath(),
+ computeFlags(stmt, original.effectiveSubstatements()), stmt.original(ChoiceSchemaNode.class));
}
@Override
defaultCase = null;
}
- final int flags = new FlagsBuilder()
- .setHistory(stmt.history())
- .setStatus(findFirstArgument(substatements, StatusEffectiveStatement.class, Status.CURRENT))
- .setConfiguration(stmt.effectiveConfig().asNullable())
- .setMandatory(findFirstArgument(substatements, MandatoryEffectiveStatement.class, Boolean.FALSE))
- .toFlags();
try {
- return new ChoiceEffectiveStatementImpl(stmt.declared(), substatements, flags, stmt.wrapSchemaPath(),
- defaultCase, (ChoiceSchemaNode) stmt.original());
+ return EffectiveStatements.createChoice(stmt.declared(), stmt.effectivePath(),
+ computeFlags(stmt, substatements), substatements, defaultCase, stmt.original(ChoiceSchemaNode.class));
} catch (SubstatementIndexingException e) {
throw new SourceException(e.getMessage(), stmt, e);
}
}
+ private static int computeFlags(final Current<?, ?> stmt,
+ final Collection<? extends EffectiveStatement<?, ?>> substatements) {
+ return new FlagsBuilder()
+ .setHistory(stmt.history())
+ .setStatus(findFirstArgument(substatements, StatusEffectiveStatement.class, Status.CURRENT))
+ .setConfiguration(stmt.effectiveConfig().asNullable())
+ .setMandatory(findFirstArgument(substatements, MandatoryEffectiveStatement.class, Boolean.FALSE))
+ .toFlags();
+ }
+
private static CaseSchemaNode findCase(final QName qname,
final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
for (final EffectiveStatement<?, ?> effectiveStatement : substatements) {