*/
package org.opendaylight.yangtools.yang.parser.rfc7950.stmt.type;
+import static com.google.common.base.Verify.verify;
+import static com.google.common.base.Verify.verifyNotNull;
+
import com.google.common.collect.ImmutableList;
import java.util.Collection;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.IdentitySchemaNode;
-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.BaseEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.BaseStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.IdentityEffectiveStatement;
-import org.opendaylight.yangtools.yang.model.api.stmt.IdentityStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.TypeStatement.IdentityRefSpecification;
-import org.opendaylight.yangtools.yang.model.util.type.BaseTypes;
-import org.opendaylight.yangtools.yang.model.util.type.IdentityrefTypeBuilder;
-import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.BaseStatementSupport;
+import org.opendaylight.yangtools.yang.model.parser.api.YangParserConfiguration;
+import org.opendaylight.yangtools.yang.model.ri.type.BaseTypes;
+import org.opendaylight.yangtools.yang.model.ri.type.IdentityrefTypeBuilder;
import org.opendaylight.yangtools.yang.parser.spi.IdentityNamespace;
import org.opendaylight.yangtools.yang.parser.spi.meta.CommonStmtCtx;
import org.opendaylight.yangtools.yang.parser.spi.meta.EffectiveStmtCtx.Current;
import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
abstract class AbstractIdentityRefSpecificationSupport
- extends BaseStatementSupport<String, IdentityRefSpecification,
- EffectiveStatement<String, IdentityRefSpecification>> {
- AbstractIdentityRefSpecificationSupport() {
- super(YangStmtMapping.TYPE, CopyPolicy.DECLARED_COPY);
+ extends AbstractTypeSupport<IdentityRefSpecification> {
+ AbstractIdentityRefSpecificationSupport(final YangParserConfiguration config) {
+ super(config);
}
@Override
- public final String parseArgumentValue(final StmtContext<?, ?, ?> ctx, final String value) {
- return value;
- }
-
- @Override
- public final void onFullDefinitionDeclared(final Mutable<String, IdentityRefSpecification,
- EffectiveStatement<String, IdentityRefSpecification>> stmt) {
+ public final void onFullDefinitionDeclared(final Mutable<QName, IdentityRefSpecification,
+ EffectiveStatement<QName, IdentityRefSpecification>> stmt) {
super.onFullDefinitionDeclared(stmt);
final Collection<StmtContext<QName, BaseStatement, ?>> baseStatements =
}
@Override
- protected final IdentityRefSpecification createDeclared(final StmtContext<String, IdentityRefSpecification, ?> ctx,
+ protected final IdentityRefSpecification createDeclared(final StmtContext<QName, IdentityRefSpecification, ?> ctx,
final ImmutableList<? extends DeclaredStatement<?>> substatements) {
- return new IdentityRefSpecificationImpl(ctx.getRawArgument(), substatements);
- }
-
- @Override
- protected final IdentityRefSpecification createEmptyDeclared(
- final StmtContext<String, IdentityRefSpecification, ?> ctx) {
- throw noBase(ctx);
+ if (substatements.isEmpty()) {
+ throw noBase(ctx);
+ }
+ return new IdentityRefSpecificationImpl(ctx.getRawArgument(), ctx.getArgument(), substatements);
}
@Override
- protected final EffectiveStatement<String, IdentityRefSpecification> createEffective(
- final Current<String, IdentityRefSpecification> stmt,
+ protected final EffectiveStatement<QName, IdentityRefSpecification> createEffective(
+ final Current<QName, IdentityRefSpecification> stmt,
final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
if (substatements.isEmpty()) {
throw noBase(stmt);
}
- final IdentityrefTypeBuilder builder = BaseTypes.identityrefTypeBuilder(stmt.wrapSchemaPath());
+ final IdentityrefTypeBuilder builder = BaseTypes.identityrefTypeBuilder(stmt.argumentAsTypeQName());
for (final EffectiveStatement<?, ?> subStmt : substatements) {
if (subStmt instanceof BaseEffectiveStatement) {
final QName identityQName = ((BaseEffectiveStatement) subStmt).argument();
- final StmtContext<?, IdentityStatement, IdentityEffectiveStatement> identityCtx =
- stmt.getFromNamespace(IdentityNamespace.class, identityQName);
- builder.addIdentity((IdentitySchemaNode) identityCtx.buildEffective());
+ final IdentityEffectiveStatement baseIdentity =
+ verifyNotNull(stmt.getFromNamespace(IdentityNamespace.class, identityQName)).buildEffective();
+ verify(baseIdentity instanceof IdentitySchemaNode, "Statement %s is not an IdentitySchemaNode",
+ baseIdentity);
+ builder.addIdentity((IdentitySchemaNode) baseIdentity);
}
}