import static org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils.findFirstDeclaredSubstatement;
+import com.google.common.collect.ImmutableList;
import java.util.Collection;
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.BelongsToEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.BelongsToStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.PrefixStatement;
import org.opendaylight.yangtools.yang.model.repo.api.RevisionSourceIdentifier;
import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
-import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractStatementSupport;
+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.AbstractStringStatementSupport;
+import org.opendaylight.yangtools.yang.parser.spi.meta.EffectiveStmtCtx.Current;
import org.opendaylight.yangtools.yang.parser.spi.meta.InferenceException;
import org.opendaylight.yangtools.yang.parser.spi.meta.ModelActionBuilder;
import org.opendaylight.yangtools.yang.parser.spi.meta.ModelActionBuilder.InferenceAction;
import org.opendaylight.yangtools.yang.parser.spi.source.BelongsToPrefixToModuleCtx;
import org.opendaylight.yangtools.yang.parser.spi.source.ModuleNamespaceForBelongsTo;
-public final class BelongsToStatementSupport extends
- AbstractStatementSupport<String, BelongsToStatement, EffectiveStatement<String, BelongsToStatement>> {
+public final class BelongsToStatementSupport
+ extends AbstractStringStatementSupport<BelongsToStatement, BelongsToEffectiveStatement> {
private static final SubstatementValidator SUBSTATEMENT_VALIDATOR =
SubstatementValidator.builder(YangStmtMapping.BELONGS_TO).addMandatory(YangStmtMapping.PREFIX).build();
private static final BelongsToStatementSupport INSTANCE = new BelongsToStatementSupport();
private BelongsToStatementSupport() {
- super(YangStmtMapping.BELONGS_TO);
+ super(YangStmtMapping.BELONGS_TO, StatementPolicy.reject());
}
public static BelongsToStatementSupport getInstance() {
}
@Override
- public String parseArgumentValue(final StmtContext<?, ?, ?> ctx, final String value) {
- return value;
+ public void onPreLinkageDeclared(final Mutable<String, BelongsToStatement, BelongsToEffectiveStatement> ctx) {
+ ctx.addRequiredSource(getSourceIdentifier(ctx));
}
@Override
- public BelongsToStatement createDeclared(
- final StmtContext<String, BelongsToStatement, ?> ctx) {
- return new BelongsToStatementImpl(ctx);
- }
-
- @Override
- public EffectiveStatement<String, BelongsToStatement> createEffective(
- final StmtContext<String, BelongsToStatement, EffectiveStatement<String, BelongsToStatement>> ctx) {
- return new BelongsToEffectiveStatementImpl(ctx);
- }
-
- @Override
- public void onPreLinkageDeclared(final StmtContext.Mutable<String, BelongsToStatement,
- EffectiveStatement<String, BelongsToStatement>> belongsToCtx) {
- belongsToCtx.addRequiredSource(getSourceIdentifier(belongsToCtx));
- }
-
- @Override
- public void onLinkageDeclared(final Mutable<String, BelongsToStatement,
- EffectiveStatement<String, BelongsToStatement>> belongsToCtx) {
+ public void onLinkageDeclared(final Mutable<String, BelongsToStatement, BelongsToEffectiveStatement> belongsToCtx) {
ModelActionBuilder belongsToAction = belongsToCtx.newInferenceAction(ModelProcessingPhase.SOURCE_LINKAGE);
final SourceIdentifier belongsToSourceIdentifier = getSourceIdentifier(belongsToCtx);
final Prerequisite<StmtContext<?, ?, ?>> belongsToPrereq = belongsToAction.requiresCtx(belongsToCtx,
- ModuleNamespaceForBelongsTo.class, belongsToCtx.getStatementArgument(),
- ModelProcessingPhase.SOURCE_LINKAGE);
+ ModuleNamespaceForBelongsTo.class, belongsToCtx.getArgument(), ModelProcessingPhase.SOURCE_LINKAGE);
belongsToAction.apply(new InferenceAction() {
@Override
belongsToCtx.addToNs(BelongsToModuleContext.class, belongsToSourceIdentifier, belongsToModuleCtx);
belongsToCtx.addToNs(BelongsToPrefixToModuleCtx.class,
- findFirstDeclaredSubstatement(belongsToCtx, PrefixStatement.class).getStatementArgument(),
+ findFirstDeclaredSubstatement(belongsToCtx, PrefixStatement.class).getArgument(),
belongsToModuleCtx);
}
@Override
- public void prerequisiteFailed(final Collection<? extends ModelActionBuilder.Prerequisite<?>> failed) {
+ public void prerequisiteFailed(final Collection<? extends Prerequisite<?>> failed) {
if (failed.contains(belongsToPrereq)) {
- throw new InferenceException(belongsToCtx.getStatementSourceReference(),
- "Module '%s' from belongs-to was not found", belongsToCtx.getStatementArgument());
+ throw new InferenceException(belongsToCtx, "Module '%s' from belongs-to was not found",
+ belongsToCtx.argument());
}
}
});
}
+ @Override
+ protected BelongsToStatement createDeclared(final StmtContext<String, BelongsToStatement, ?> ctx,
+ final ImmutableList<? extends DeclaredStatement<?>> substatements) {
+ return DeclaredStatements.createBelongsTo(ctx.getRawArgument(), substatements);
+ }
+
+ @Override
+ protected BelongsToStatement createEmptyDeclared(final StmtContext<String, BelongsToStatement, ?> ctx) {
+ return DeclaredStatements.createBelongsTo(ctx.getRawArgument());
+ }
+
+ @Override
+ protected BelongsToEffectiveStatement createEffective(final Current<String, BelongsToStatement> stmt,
+ final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
+ return EffectiveStatements.createBelongsTo(stmt.declared(), substatements);
+ }
+
private static SourceIdentifier getSourceIdentifier(final StmtContext<String, BelongsToStatement,
- EffectiveStatement<String, BelongsToStatement>> belongsToCtx) {
- return RevisionSourceIdentifier.create(belongsToCtx.getStatementArgument());
+ BelongsToEffectiveStatement> belongsToCtx) {
+ return RevisionSourceIdentifier.create(belongsToCtx.getArgument());
}
@Override