+++ /dev/null
-/*
- * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.yangtools.yang.parser.rfc7950.stmt.type;
-
-import org.eclipse.jdt.annotation.NonNull;
-import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
-import org.opendaylight.yangtools.yang.model.api.stmt.TypeEffectiveStatement;
-import org.opendaylight.yangtools.yang.model.api.stmt.TypeStatement.UnionSpecification;
-import org.opendaylight.yangtools.yang.model.api.type.UnionTypeDefinition;
-import org.opendaylight.yangtools.yang.model.util.type.BaseTypes;
-import org.opendaylight.yangtools.yang.model.util.type.UnionTypeBuilder;
-import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.DeclaredEffectiveStatementBase;
-import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
-
-final class UnionSpecificationEffectiveStatement extends DeclaredEffectiveStatementBase<String, UnionSpecification>
- implements TypeEffectiveStatement<UnionSpecification> {
-
- private final @NonNull UnionTypeDefinition typeDefinition;
-
- UnionSpecificationEffectiveStatement(
- final StmtContext<String, UnionSpecification, EffectiveStatement<String, UnionSpecification>> ctx) {
- super(ctx);
-
- final UnionTypeBuilder builder = BaseTypes.unionTypeBuilder(ctx.getSchemaPath().get());
-
- for (final EffectiveStatement<?, ?> stmt : effectiveSubstatements()) {
- if (stmt instanceof TypeEffectiveStatement) {
- builder.addType(((TypeEffectiveStatement<?>)stmt).getTypeDefinition());
- }
- if (stmt instanceof UnknownSchemaNode) {
- builder.addUnknownSchemaNode((UnknownSchemaNode)stmt);
- }
- }
-
- typeDefinition = builder.build();
- }
-
- @Override
- public UnionTypeDefinition getTypeDefinition() {
- return typeDefinition;
- }
-}
*/
package org.opendaylight.yangtools.yang.parser.rfc7950.stmt.type;
+import com.google.common.collect.ImmutableList;
+import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.TypeStatement.UnionSpecification;
-import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractDeclaredStatement;
+import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.AbstractDeclaredStatement.WithRawStringArgument.WithSubstatements;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
-final class UnionSpecificationImpl extends AbstractDeclaredStatement<String> implements UnionSpecification {
- UnionSpecificationImpl(final StmtContext<String, UnionSpecification, ?> context) {
- super(context);
+final class UnionSpecificationImpl extends WithSubstatements implements UnionSpecification {
+ UnionSpecificationImpl(final StmtContext<String, ?, ?> context,
+ final ImmutableList<? extends DeclaredStatement<?>> substatements) {
+ super(context, substatements);
}
}
*/
package org.opendaylight.yangtools.yang.parser.rfc7950.stmt.type;
+import com.google.common.collect.ImmutableList;
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.TypeEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.TypeStatement.UnionSpecification;
-import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractStatementSupport;
+import org.opendaylight.yangtools.yang.model.util.type.BaseTypes;
+import org.opendaylight.yangtools.yang.model.util.type.UnionTypeBuilder;
+import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.BaseStatementSupport;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
import org.opendaylight.yangtools.yang.parser.spi.meta.SubstatementValidator;
+import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
-final class UnionSpecificationSupport extends
- AbstractStatementSupport<String, UnionSpecification, EffectiveStatement<String, UnionSpecification>> {
+final class UnionSpecificationSupport
+ extends BaseStatementSupport<String, UnionSpecification, EffectiveStatement<String, UnionSpecification>> {
private static final SubstatementValidator SUBSTATEMENT_VALIDATOR = SubstatementValidator.builder(YangStmtMapping
.TYPE)
.addMultiple(YangStmtMapping.TYPE)
}
@Override
- public UnionSpecification createDeclared(final StmtContext<String, UnionSpecification, ?> ctx) {
- return new UnionSpecificationImpl(ctx);
+ protected SubstatementValidator getSubstatementValidator() {
+ return SUBSTATEMENT_VALIDATOR;
}
@Override
- public EffectiveStatement<String, UnionSpecification> createEffective(
- final StmtContext<String, UnionSpecification, EffectiveStatement<String, UnionSpecification>> ctx) {
- return new UnionSpecificationEffectiveStatement(ctx);
+ protected UnionSpecification createDeclared(final StmtContext<String, UnionSpecification, ?> ctx,
+ final ImmutableList<? extends DeclaredStatement<?>> substatements) {
+ return new UnionSpecificationImpl(ctx, substatements);
}
@Override
- protected SubstatementValidator getSubstatementValidator() {
- return SUBSTATEMENT_VALIDATOR;
+ protected UnionSpecification createEmptyDeclared(final StmtContext<String, UnionSpecification, ?> ctx) {
+ throw noType(ctx);
+ }
+
+ @Override
+ protected EffectiveStatement<String, UnionSpecification> createEffective(
+ final StmtContext<String, UnionSpecification, EffectiveStatement<String, UnionSpecification>> ctx,
+ final UnionSpecification declared, final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
+ final UnionTypeBuilder builder = BaseTypes.unionTypeBuilder(ctx.getSchemaPath().get());
+
+ for (final EffectiveStatement<?, ?> stmt : substatements) {
+ if (stmt instanceof TypeEffectiveStatement) {
+ builder.addType(((TypeEffectiveStatement<?>)stmt).getTypeDefinition());
+ }
+ }
+
+ return new TypeEffectiveStatementImpl<>(declared, substatements, builder);
+ }
+
+ @Override
+ protected EffectiveStatement<String, UnionSpecification> createEmptyEffective(
+ final StmtContext<String, UnionSpecification, EffectiveStatement<String, UnionSpecification>> ctx,
+ final UnionSpecification declared) {
+ throw noType(ctx);
+ }
+
+ private static SourceException noType(final StmtContext<?, ?, ?> ctx) {
+ /*
+ * https://tools.ietf.org/html/rfc7950#section-9.12
+ *
+ * When the type is "union", the "type" statement (Section 7.4) MUST be
+ * present.
+ */
+ return new SourceException("At least one type statement has to be present", ctx.getStatementSourceReference());
}
-}
\ No newline at end of file
+}