X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;ds=sidebyside;f=yang%2Fyang-parser-rfc7950%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fyangtools%2Fyang%2Fparser%2Frfc7950%2Fstmt%2Faction%2FActionStatementSupport.java;h=9dd646c8853a7e6e8965bb79bec41b4b27db0425;hb=a36fd793d86133286a46bf277f90c9a52f74b992;hp=f4fb7be2201116cfc4a9baed656fd20aa45bb174;hpb=6a3d3bfeda9ac4337ac151b472244fc447b1efbb;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 f4fb7be220..9dd646c885 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,7 +7,7 @@ */ package org.opendaylight.yangtools.yang.parser.rfc7950.stmt.action; -import static com.google.common.base.Preconditions.checkState; +import static com.google.common.base.Verify.verify; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; @@ -21,8 +21,9 @@ 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.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; @@ -52,24 +53,39 @@ public final class ActionStatementSupport extends 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 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); } } @@ -93,19 +109,13 @@ public final class ActionStatementSupport extends protected ActionEffectiveStatement createEffective(final Current stmt, final ImmutableList> substatements) { final StatementSourceReference ref = stmt.sourceReference(); - checkState(!substatements.isEmpty(), "Missing implicit input/output statements at %s", ref); - final QName argument = stmt.getArgument(); - SourceException.throwIf(StmtContextUtils.hasAncestorOfType(stmt, ILLEGAL_PARENTS), ref, - "Action %s is defined within a notification, rpc or another action", argument); - SourceException.throwIf( - !StmtContextUtils.hasAncestorOfTypeWithChildOfType(stmt, YangStmtMapping.LIST, YangStmtMapping.KEY), ref, - "Action %s is defined within a list that has no key statement", argument); - SourceException.throwIf(StmtContextUtils.hasParentOfType(stmt, YangStmtMapping.CASE), ref, - "Action %s is defined within a case statement", argument); - SourceException.throwIf(StmtContextUtils.hasParentOfType(stmt, YangStmtMapping.MODULE), ref, - "Action %s is defined at the top level of a module", argument); + verify(!substatements.isEmpty(), "Missing implicit input/output statements at %s", ref); - return new ActionEffectiveStatementImpl(stmt.declared(), stmt.getSchemaPath(), - historyAndStatusFlags(stmt.history(), substatements), substatements, stmt.sourceReference()); + try { + return new ActionEffectiveStatementImpl(stmt.declared(), stmt.wrapSchemaPath(), + historyAndStatusFlags(stmt.history(), substatements), substatements); + } catch (SubstatementIndexingException e) { + throw new SourceException(e.getMessage(), stmt, e); + } } }