*/
package org.opendaylight.yangtools.yang.parser.rfc7950.stmt.action;
+import static com.google.common.base.Verify.verify;
+
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.stmt.InputStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.OutputStatement;
import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.BaseSchemaTreeStatementSupport;
-import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.input.InputStatementRFC7950Support;
-import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.output.OutputStatementRFC7950Support;
+import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.SubstatementIndexingException;
+import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.input.InputStatementSupport;
+import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.output.OutputStatementSupport;
+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.StmtContext.Mutable;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils;
private static final ActionStatementSupport INSTANCE = new ActionStatementSupport();
private ActionStatementSupport() {
- super(YangStmtMapping.ACTION);
+ super(YangStmtMapping.ACTION, CopyPolicy.DECLARED_COPY);
}
public static ActionStatementSupport getInstance() {
return INSTANCE;
}
+ @Override
+ public void onStatementAdded(final Mutable<QName, ActionStatement, ActionEffectiveStatement> stmt) {
+ final QName argument = stmt.getArgument();
+ SourceException.throwIf(StmtContextUtils.hasAncestorOfType(stmt, ILLEGAL_PARENTS), stmt,
+ "Action %s is defined within a notification, rpc or another action", argument);
+ SourceException.throwIf(StmtContextUtils.hasParentOfType(stmt, YangStmtMapping.CASE), stmt,
+ "Action %s is defined within a case statement", argument);
+ SourceException.throwIf(StmtContextUtils.hasParentOfType(stmt, YangStmtMapping.MODULE), stmt,
+ "Action %s is defined at the top level of a module", stmt.getArgument());
+ StmtContextUtils.validateNoKeylessListAncestorOf(stmt, "Action");
+
+ super.onStatementAdded(stmt);
+ }
+
@Override
public void onFullDefinitionDeclared(final Mutable<QName, ActionStatement, ActionEffectiveStatement> stmt) {
super.onFullDefinitionDeclared(stmt);
+ verify(stmt instanceof StatementContextBase);
if (StmtContextUtils.findFirstDeclaredSubstatement(stmt, InputStatement.class) == null) {
((StatementContextBase<?, ?, ?>) stmt).appendImplicitSubstatement(
- InputStatementRFC7950Support.getInstance(), null);
+ InputStatementSupport.rfc7950Instance(), null);
}
if (StmtContextUtils.findFirstDeclaredSubstatement(stmt, OutputStatement.class) == null) {
((StatementContextBase<?, ?, ?>) stmt).appendImplicitSubstatement(
- OutputStatementRFC7950Support.getInstance(), null);
+ OutputStatementSupport.rfc7950Instance(), null);
}
}
@Override
protected ActionStatement createDeclared(final StmtContext<QName, ActionStatement, ?> ctx,
final ImmutableList<? extends DeclaredStatement<?>> substatements) {
- return new RegularActionStatement(ctx.coerceStatementArgument(), substatements);
+ return new RegularActionStatement(ctx.getArgument(), substatements);
}
@Override
protected ActionStatement createEmptyDeclared(final StmtContext<QName, ActionStatement, ?> ctx) {
- return new EmptyActionStatement(ctx.coerceStatementArgument());
+ return new EmptyActionStatement(ctx.getArgument());
}
@Override
- protected ActionEffectiveStatement createEffective(
- final StmtContext<QName, ActionStatement, ActionEffectiveStatement> ctx, final ActionStatement declared,
+ protected ActionEffectiveStatement createEffective(final Current<QName, ActionStatement> stmt,
final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
- final QName argument = ctx.coerceStatementArgument();
- final StatementSourceReference ref = ctx.getStatementSourceReference();
- SourceException.throwIf(StmtContextUtils.hasAncestorOfType(ctx, ILLEGAL_PARENTS), ref,
- "Action %s is defined within a notification, rpc or another action", argument);
- SourceException.throwIf(
- !StmtContextUtils.hasAncestorOfTypeWithChildOfType(ctx, YangStmtMapping.LIST, YangStmtMapping.KEY), ref,
- "Action %s is defined within a list that has no key statement", argument);
- SourceException.throwIf(StmtContextUtils.hasParentOfType(ctx, YangStmtMapping.CASE), ref,
- "Action %s is defined within a case statement", argument);
- SourceException.throwIf(StmtContextUtils.hasParentOfType(ctx, YangStmtMapping.MODULE), ref,
- "Action %s is defined at the top level of a module", argument);
-
- return new ActionEffectiveStatementImpl(declared, ctx.getSchemaPath().get(),
- historyAndStatusFlags(ctx, substatements), ctx, substatements);
- }
+ final StatementSourceReference ref = stmt.sourceReference();
+ verify(!substatements.isEmpty(), "Missing implicit input/output statements at %s", ref);
- @Override
- protected ActionEffectiveStatement createEmptyEffective(
- final StmtContext<QName, ActionStatement, ActionEffectiveStatement> ctx, final ActionStatement declared) {
- throw new IllegalStateException("Missing implicit input/output statements at "
- + ctx.getStatementSourceReference());
+ try {
+ return new ActionEffectiveStatementImpl(stmt.declared(), stmt.wrapSchemaPath(),
+ historyAndStatusFlags(stmt.history(), substatements), substatements);
+ } catch (SubstatementIndexingException e) {
+ throw new SourceException(e.getMessage(), stmt, e);
+ }
}
}