package org.opendaylight.yangtools.yang.model.api.stmt;
import com.google.common.annotations.Beta;
+import org.opendaylight.yangtools.yang.model.api.YangStmtMapping;
import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
+import org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition;
@Beta
public interface EnumEffectiveStatement extends EffectiveStatement<String, EnumStatement> {
-
+ @Override
+ default StatementDefinition statementDefinition() {
+ return YangStmtMapping.ENUM;
+ }
}
import java.util.Optional;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
+import org.opendaylight.yangtools.yang.model.api.YangStmtMapping;
+import org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition;
public interface EnumStatement extends DocumentedDeclaredStatement.WithStatus<String>,
IfFeatureAwareDeclaredStatement<String> {
+ @Override
+ default StatementDefinition statementDefinition() {
+ return YangStmtMapping.ENUM;
+ }
+
default @NonNull String getName() {
// FIXME: YANGTOOLS-908: verifyNotNull() should not be needed here
return verifyNotNull(argument());
*/
package org.opendaylight.yangtools.yang.parser.rfc7950.stmt.enum_;
+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.EnumEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.EnumStatement;
-import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractStatementSupport;
+import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.BaseStatementSupport;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
abstract class AbstractEnumStatementSupport
- extends AbstractStatementSupport<String, EnumStatement, EnumEffectiveStatement> {
+ extends BaseStatementSupport<String, EnumStatement, EnumEffectiveStatement> {
AbstractEnumStatementSupport() {
super(YangStmtMapping.ENUM);
}
}
@Override
- public final EnumStatement createDeclared(final StmtContext<String, EnumStatement, ?> ctx) {
- return new EnumStatementImpl(ctx);
+ protected final EnumStatement createDeclared(final StmtContext<String, EnumStatement, ?> ctx,
+ final ImmutableList<? extends DeclaredStatement<?>> substatements) {
+ return new RegularEnumStatement(ctx, substatements);
}
@Override
- public final EnumEffectiveStatement createEffective(
- final StmtContext<String, EnumStatement, EnumEffectiveStatement> ctx) {
- return new EnumEffectiveStatementImpl(ctx);
+ protected final EnumStatement createEmptyDeclared(final StmtContext<String, EnumStatement, ?> ctx) {
+ return new EmptyEnumStatement(ctx);
+ }
+
+ @Override
+ protected final EnumEffectiveStatement createEffective(
+ final StmtContext<String, EnumStatement, EnumEffectiveStatement> ctx, final EnumStatement declared,
+ final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
+ return new RegularEnumEffectiveStatement(declared, substatements);
+ }
+
+ @Override
+ protected final EnumEffectiveStatement createEmptyEffective(
+ final StmtContext<String, EnumStatement, EnumEffectiveStatement> ctx, final EnumStatement declared) {
+ return new EmptyEnumEffectiveStatement(declared);
}
}
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (c) 2020 PANTHEON.tech, s.r.o. 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.enum_;
+
+import org.opendaylight.yangtools.yang.model.api.DocumentedNode.WithStatus;
+import org.opendaylight.yangtools.yang.model.api.Status;
+import org.opendaylight.yangtools.yang.model.api.stmt.EnumEffectiveStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.EnumStatement;
+import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.AbstractDeclaredEffectiveStatement.DefaultArgument;
+import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.EffectiveStatementMixins.DocumentedNodeMixin;
+
+final class EmptyEnumEffectiveStatement extends DefaultArgument<String, EnumStatement>
+ implements EnumEffectiveStatement, DocumentedNodeMixin<String, EnumStatement>, WithStatus {
+ EmptyEnumEffectiveStatement(final EnumStatement declared) {
+ super(declared);
+ }
+
+ @Override
+ public Status getStatus() {
+ return Status.CURRENT;
+ }
+}
/*
- * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
+ * Copyright (c) 2020 PANTHEON.tech, s.r.o. 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,
package org.opendaylight.yangtools.yang.parser.rfc7950.stmt.enum_;
import org.opendaylight.yangtools.yang.model.api.stmt.EnumStatement;
-import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractDeclaredStatement;
+import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.AbstractDeclaredStatement.WithArgument;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
-final class EnumStatementImpl extends AbstractDeclaredStatement<String> implements EnumStatement {
- EnumStatementImpl(final StmtContext<String, EnumStatement, ?> context) {
+final class EmptyEnumStatement extends WithArgument<String> implements EnumStatement {
+ EmptyEnumStatement(final StmtContext<String, ?, ?> context) {
super(context);
}
}
+++ /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.enum_;
-
-import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
-import org.opendaylight.yangtools.yang.model.api.stmt.EnumEffectiveStatement;
-import org.opendaylight.yangtools.yang.model.api.stmt.EnumStatement;
-import org.opendaylight.yangtools.yang.model.api.stmt.ValueEffectiveStatement;
-import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.AbstractEffectiveDocumentedNodeWithStatus;
-import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
-
-// FIXME: 6.0.0: hide this class
-public final class EnumEffectiveStatementImpl extends AbstractEffectiveDocumentedNodeWithStatus<String, EnumStatement>
- implements EnumEffectiveStatement {
- private final String name;
- private final Integer declaredValue;
-
- EnumEffectiveStatementImpl(final StmtContext<String, EnumStatement, ?> ctx) {
- super(ctx);
-
- name = ctx.rawStatementArgument();
-
- Integer declaredValueInit = null;
- for (final EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements()) {
- if (effectiveStatement instanceof ValueEffectiveStatement) {
- declaredValueInit = ((ValueEffectiveStatement) effectiveStatement).argument();
- }
- }
-
- declaredValue = declaredValueInit;
- }
-
- public String getName() {
- return name;
- }
-
- public Integer getDeclaredValue() {
- return declaredValue;
- }
-}
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (c) 2020 PANTHEON.tech, s.r.o. 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.enum_;
+
+import com.google.common.collect.ImmutableList;
+import org.opendaylight.yangtools.yang.model.api.DocumentedNode.WithStatus;
+import org.opendaylight.yangtools.yang.model.api.Status;
+import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.EnumEffectiveStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.EnumStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.StatusEffectiveStatement;
+import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.AbstractDeclaredEffectiveStatement.DefaultArgument.WithSubstatements;
+import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.EffectiveStatementMixins.DocumentedNodeMixin;
+
+final class RegularEnumEffectiveStatement extends WithSubstatements<String, EnumStatement>
+ implements EnumEffectiveStatement, DocumentedNodeMixin<String, EnumStatement>, WithStatus {
+ RegularEnumEffectiveStatement(final EnumStatement declared,
+ final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
+ super(declared, substatements);
+ }
+
+ @Override
+ public Status getStatus() {
+ return findFirstEffectiveSubstatementArgument(StatusEffectiveStatement.class).orElse(Status.CURRENT);
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2020 PANTHEON.tech, s.r.o. 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.enum_;
+
+import com.google.common.collect.ImmutableList;
+import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.EnumStatement;
+import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.AbstractDeclaredStatement.WithArgument.WithSubstatements;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
+
+final class RegularEnumStatement extends WithSubstatements<String> implements EnumStatement {
+ RegularEnumStatement(final StmtContext<String, ?, ?> context,
+ final ImmutableList<? extends DeclaredStatement<?>> substatements) {
+ super(context, substatements);
+ }
+}
import com.google.common.annotations.Beta;
import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.yangtools.yang.common.Uint32;
-import org.opendaylight.yangtools.yang.model.api.DocumentedNode;
import org.opendaylight.yangtools.yang.model.api.DocumentedNode.WithStatus;
import org.opendaylight.yangtools.yang.model.api.stmt.BitEffectiveStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.EnumEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.type.BitsTypeDefinition.Bit;
import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition.EnumPair;
import org.opendaylight.yangtools.yang.model.util.type.BitBuilder;
import org.opendaylight.yangtools.yang.model.util.type.EnumPairBuilder;
-import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.enum_.EnumEffectiveStatementImpl;
@Beta
final class EffectiveTypeUtil {
}
static @NonNull Bit buildBit(final @NonNull BitEffectiveStatement stmt, final Uint32 effectivePos) {
- verify(stmt instanceof DocumentedNode.WithStatus);
- final DocumentedNode.WithStatus bit = (WithStatus) stmt;
+ verify(stmt instanceof WithStatus);
+ final WithStatus bit = (WithStatus) stmt;
// TODO: code duplication with EnumPairBuilder is indicating we could use a common Builder<?> interface
final BitBuilder builder = BitBuilder.create(stmt.argument(), effectivePos).setStatus(bit.getStatus());
return builder.build();
}
- static @NonNull EnumPair buildEnumPair(final @NonNull EnumEffectiveStatementImpl stmt, final int effectiveValue) {
- final EnumPairBuilder builder = EnumPairBuilder.create(stmt.getName(), effectiveValue)
- .setStatus(stmt.getStatus()).setUnknownSchemaNodes(stmt.getUnknownSchemaNodes());
- stmt.getDescription().ifPresent(builder::setDescription);
- stmt.getReference().ifPresent(builder::setReference);
+ static @NonNull EnumPair buildEnumPair(final @NonNull EnumEffectiveStatement stmt, final int effectiveValue) {
+ verify(stmt instanceof WithStatus);
+ final WithStatus node = (WithStatus) stmt;
+
+ final EnumPairBuilder builder = EnumPairBuilder.create(stmt.getDeclared().rawArgument(), effectiveValue)
+ .setStatus(node.getStatus()).setUnknownSchemaNodes(node.getUnknownSchemaNodes());
+ node.getDescription().ifPresent(builder::setDescription);
+ node.getReference().ifPresent(builder::setReference);
return builder.build();
}
*/
package org.opendaylight.yangtools.yang.parser.rfc7950.stmt.type;
+import java.util.Optional;
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.EnumEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.TypeEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.TypeStatement.EnumSpecification;
+import org.opendaylight.yangtools.yang.model.api.stmt.ValueEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition;
import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition.EnumPair;
import org.opendaylight.yangtools.yang.model.util.type.BaseTypes;
import org.opendaylight.yangtools.yang.model.util.type.EnumerationTypeBuilder;
import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.DeclaredEffectiveStatementBase;
-import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.enum_.EnumEffectiveStatementImpl;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
final EnumerationTypeBuilder builder = BaseTypes.enumerationTypeBuilder(ctx.getSchemaPath().get());
Integer highestValue = null;
for (final EffectiveStatement<?, ?> stmt : effectiveSubstatements()) {
- if (stmt instanceof EnumEffectiveStatementImpl) {
- final EnumEffectiveStatementImpl enumSubStmt = (EnumEffectiveStatementImpl) stmt;
+ if (stmt instanceof EnumEffectiveStatement) {
+ final EnumEffectiveStatement enumSubStmt = (EnumEffectiveStatement) stmt;
+ final Optional<Integer> declaredValue =
+ enumSubStmt.findFirstEffectiveSubstatementArgument(ValueEffectiveStatement.class);
final int effectiveValue;
- if (enumSubStmt.getDeclaredValue() == null) {
+ if (declaredValue.isEmpty()) {
if (highestValue != null) {
SourceException.throwIf(highestValue == 2147483647, ctx.getStatementSourceReference(),
"Enum '%s' must have a value statement", enumSubStmt);
effectiveValue = 0;
}
} else {
- effectiveValue = enumSubStmt.getDeclaredValue();
+ effectiveValue = declaredValue.orElseThrow();
}
final EnumPair pair = EffectiveTypeUtil.buildEnumPair(enumSubStmt, effectiveValue);
package org.opendaylight.yangtools.yang.parser.rfc7950.stmt.type;
+import java.util.Optional;
import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.yangtools.yang.common.YangVersion;
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.EnumEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.TypeEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.TypeStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.ValueEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition;
import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition.EnumPair;
import org.opendaylight.yangtools.yang.model.util.type.EnumerationTypeBuilder;
import org.opendaylight.yangtools.yang.model.util.type.RestrictedTypes;
import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.DeclaredEffectiveStatementBase;
-import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.enum_.EnumEffectiveStatementImpl;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
final YangVersion yangVersion = ctx.getRootVersion();
for (final EffectiveStatement<?, ?> stmt : effectiveSubstatements()) {
- if (stmt instanceof EnumEffectiveStatementImpl) {
+ if (stmt instanceof EnumEffectiveStatement) {
SourceException.throwIf(yangVersion != YangVersion.VERSION_1_1, ctx.getStatementSourceReference(),
"Restricted enumeration type is allowed only in YANG 1.1 version.");
- final EnumEffectiveStatementImpl enumSubStmt = (EnumEffectiveStatementImpl) stmt;
-
+ final EnumEffectiveStatement enumSubStmt = (EnumEffectiveStatement) stmt;
+ final Optional<Integer> declaredValue =
+ enumSubStmt.findFirstEffectiveSubstatementArgument(ValueEffectiveStatement.class);
final int effectiveValue;
- if (enumSubStmt.getDeclaredValue() == null) {
- effectiveValue = getBaseTypeEnumValue(enumSubStmt.getName(), baseType, ctx);
+ if (declaredValue.isEmpty()) {
+ effectiveValue = getBaseTypeEnumValue(enumSubStmt.getDeclared().rawArgument(), baseType, ctx);
} else {
- effectiveValue = enumSubStmt.getDeclaredValue();
+ effectiveValue = declaredValue.orElseThrow();
}
builder.addEnum(EffectiveTypeUtil.buildEnumPair(enumSubStmt, effectiveValue));