package org.opendaylight.yangtools.yang.parser.rfc7950.stmt.status;
import com.google.common.collect.ImmutableList;
-import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.yangtools.yang.model.api.Status;
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.stmt.StatusEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.StatusStatement;
-import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.BaseStatementSupport;
+import org.opendaylight.yangtools.yang.model.ri.stmt.DeclaredStatements;
+import org.opendaylight.yangtools.yang.model.ri.stmt.EffectiveStatements;
+import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractStatementSupport;
import org.opendaylight.yangtools.yang.parser.spi.meta.EffectiveStmtCtx.Current;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
import org.opendaylight.yangtools.yang.parser.spi.meta.SubstatementValidator;
import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
public final class StatusStatementSupport
- extends BaseStatementSupport<Status, StatusStatement, StatusEffectiveStatement> {
- private static final SubstatementValidator SUBSTATEMENT_VALIDATOR = SubstatementValidator.builder(YangStmtMapping
- .STATUS)
- .build();
+ extends AbstractStatementSupport<Status, StatusStatement, StatusEffectiveStatement> {
+ private static final SubstatementValidator SUBSTATEMENT_VALIDATOR =
+ SubstatementValidator.builder(YangStmtMapping.STATUS).build();
private static final StatusStatementSupport INSTANCE = new StatusStatementSupport();
- /*
- * status has low argument cardinality, hence we can reuse them in case declaration does not have any
- * substatements (which is the usual case). Yeah, we could consider an EnumMap, but this is not too bad, either.
- */
- private static final @NonNull EmptyStatusStatement EMPTY_CURRENT_DECL =
- new EmptyStatusStatement(Status.CURRENT);
- private static final @NonNull EmptyStatusStatement EMPTY_DEPRECATED_DECL =
- new EmptyStatusStatement(Status.DEPRECATED);
- private static final @NonNull EmptyStatusStatement EMPTY_OBSOLETE_DECL =
- new EmptyStatusStatement(Status.OBSOLETE);
- private static final @NonNull EmptyStatusEffectiveStatement EMPTY_CURRENT_EFF =
- new EmptyStatusEffectiveStatement(EMPTY_CURRENT_DECL);
- private static final @NonNull EmptyStatusEffectiveStatement EMPTY_DEPRECATED_EFF =
- new EmptyStatusEffectiveStatement(EMPTY_DEPRECATED_DECL);
- private static final @NonNull EmptyStatusEffectiveStatement EMPTY_OBSOLETE_EFF =
- new EmptyStatusEffectiveStatement(EMPTY_OBSOLETE_DECL);
-
private StatusStatementSupport() {
- super(YangStmtMapping.STATUS, CopyPolicy.CONTEXT_INDEPENDENT);
+ super(YangStmtMapping.STATUS, StatementPolicy.contextIndependent());
}
public static StatusStatementSupport getInstance() {
case "obsolete":
return Status.OBSOLETE;
default:
- throw new SourceException(ctx.sourceReference(),
+ throw new SourceException(ctx,
"Invalid status '%s', must be one of 'current', 'deprecated' or 'obsolete'", value);
}
}
@Override
protected StatusStatement createDeclared(final StmtContext<Status, StatusStatement, ?> ctx,
final ImmutableList<? extends DeclaredStatement<?>> substatements) {
- return new RegularStatusStatement(ctx.getArgument(), substatements);
+ return DeclaredStatements.createStatus(ctx.getArgument(), substatements);
}
@Override
protected StatusStatement createEmptyDeclared(final StmtContext<Status, StatusStatement, ?> ctx) {
- final Status argument = ctx.getArgument();
- switch (argument) {
- case CURRENT:
- return EMPTY_CURRENT_DECL;
- case DEPRECATED:
- return EMPTY_DEPRECATED_DECL;
- case OBSOLETE:
- return EMPTY_OBSOLETE_DECL;
- default:
- throw new IllegalStateException("Unhandled argument " + argument);
- }
+ return DeclaredStatements.createStatus(ctx.getArgument());
}
@Override
protected StatusEffectiveStatement createEffective(final Current<Status, StatusStatement> stmt,
final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
- return substatements.isEmpty() ? createEmptyEffective(stmt.declared())
- : new RegularStatusEffectiveStatement(stmt.declared(), substatements);
- }
-
- private static @NonNull StatusEffectiveStatement createEmptyEffective(final StatusStatement declared) {
- // Aggressively reuse effective instances which are backed by the corresponding empty declared instance, as this
- // is the case unless there is a weird extension in use.
- if (EMPTY_DEPRECATED_DECL.equals(declared)) {
- // Most likely to be seen (as current is the default)
- return EMPTY_DEPRECATED_EFF;
- } else if (EMPTY_OBSOLETE_DECL.equals(declared)) {
- // less likely
- return EMPTY_OBSOLETE_EFF;
- } else if (EMPTY_CURRENT_DECL.equals(declared)) {
- // ... okay, why is this there? :)
- return EMPTY_CURRENT_EFF;
- } else {
- return new EmptyStatusEffectiveStatement(declared);
- }
+ return EffectiveStatements.createStatus(stmt.declared(), substatements);
}
}