X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=yang%2Fyang-parser-rfc7950%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fyangtools%2Fyang%2Fparser%2Frfc7950%2Fstmt%2Faction%2FActionStatementSupport.java;h=7a661f2fd40479e0d03e3b2241526aed6f3d29c1;hb=1dec11bcd187ebb6605f87338e9b96d57a91af41;hp=7a25df9de139aa4fc80b321a0958426efeacd89c;hpb=228a4c87ff818c52410b1e449fd1587b16aaf4e1;p=yangtools.git diff --git a/yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/action/ActionStatementSupport.java b/yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/action/ActionStatementSupport.java index 7a25df9de1..7a661f2fd4 100644 --- a/yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/action/ActionStatementSupport.java +++ b/yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/action/ActionStatementSupport.java @@ -7,10 +7,11 @@ */ 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.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; @@ -19,12 +20,12 @@ import org.opendaylight.yangtools.yang.model.api.stmt.ActionEffectiveStatement; import org.opendaylight.yangtools.yang.model.api.stmt.ActionStatement; import org.opendaylight.yangtools.yang.model.api.stmt.InputStatement; import org.opendaylight.yangtools.yang.model.api.stmt.OutputStatement; -import org.opendaylight.yangtools.yang.model.api.stmt.StatusEffectiveStatement; -import org.opendaylight.yangtools.yang.parser.rfc7950.namespace.ChildSchemaNodeNamespace; -import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.BaseQNameStatementSupport; -import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.EffectiveStatementMixins.EffectiveStatementWithFlags.FlagsBuilder; -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.BaseSchemaTreeStatementSupport; +import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.EffectiveStatementMixins; +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; @@ -33,7 +34,9 @@ import org.opendaylight.yangtools.yang.parser.spi.source.SourceException; import org.opendaylight.yangtools.yang.parser.spi.source.StatementSourceReference; import org.opendaylight.yangtools.yang.parser.stmt.reactor.StatementContextBase; -public final class ActionStatementSupport extends BaseQNameStatementSupport { +public final class ActionStatementSupport extends + BaseSchemaTreeStatementSupport { + private static final ImmutableSet ILLEGAL_PARENTS = ImmutableSet.of( YangStmtMapping.NOTIFICATION, YangStmtMapping.RPC, YangStmtMapping.ACTION); @@ -51,34 +54,39 @@ public final class ActionStatementSupport extends BaseQNameStatementSupport ctx, final String value) { - return StmtContextUtils.parseIdentifier(ctx, value); - } - @Override public void onStatementAdded(final Mutable stmt) { - stmt.coerceParentContext().addToNs(ChildSchemaNodeNamespace.class, stmt.coerceStatementArgument(), 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 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); } } @@ -90,47 +98,32 @@ public final class ActionStatementSupport extends BaseQNameStatementSupport ctx, final ImmutableList> substatements) { - return new RegularActionStatement(ctx.coerceStatementArgument(), substatements); + return new RegularActionStatement(ctx.getArgument(), substatements); } @Override protected ActionStatement createEmptyDeclared(final StmtContext ctx) { - return new EmptyActionStatement(ctx.coerceStatementArgument()); + return new EmptyActionStatement(ctx.getArgument()); } @Override - protected ActionEffectiveStatement createEffective( - final StmtContext ctx, final ActionStatement declared, + protected ActionEffectiveStatement createEffective(final Current stmt, final ImmutableList> 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(), computeFlags(ctx, substatements), - ctx, substatements); + final StatementSourceReference ref = stmt.sourceReference(); + verify(!substatements.isEmpty(), "Missing implicit input/output statements at %s", ref); + + try { + return new ActionEffectiveStatementImpl(stmt.declared(), stmt.wrapSchemaPath(), + EffectiveStatementMixins.historyAndStatusFlags(stmt.history(), substatements), substatements); + } catch (SubstatementIndexingException e) { + throw new SourceException(e.getMessage(), stmt, e); + } } @Override - protected ActionEffectiveStatement createEmptyEffective( - final StmtContext ctx, final ActionStatement declared) { - throw new IllegalStateException("Missing implicit input/output statements at " - + ctx.getStatementSourceReference()); + public ActionEffectiveStatement copyEffective(final Current stmt, + final ActionEffectiveStatement original) { + return new ActionEffectiveStatementImpl((ActionEffectiveStatementImpl) original, stmt.wrapSchemaPath(), + EffectiveStatementMixins.historyAndStatusFlags(stmt.history(), original.effectiveSubstatements())); } - - private static int computeFlags(final StmtContext ctx, - final ImmutableList> substatements) { - return new FlagsBuilder() - .setHistory(ctx.getCopyHistory()) - .setStatus(findFirstArgument(substatements, StatusEffectiveStatement.class, Status.CURRENT)) - .toFlags(); - } - }