2 * Copyright (c) 2017 Pantheon Technologies, s.r.o. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.yangtools.yang.parser.rfc7950.stmt.type;
10 import static com.google.common.base.Verify.verify;
12 import com.google.common.annotations.Beta;
13 import org.eclipse.jdt.annotation.NonNull;
14 import org.opendaylight.yangtools.yang.common.Uint32;
15 import org.opendaylight.yangtools.yang.model.api.DocumentedNode.WithStatus;
16 import org.opendaylight.yangtools.yang.model.api.stmt.BitEffectiveStatement;
17 import org.opendaylight.yangtools.yang.model.api.stmt.EnumEffectiveStatement;
18 import org.opendaylight.yangtools.yang.model.api.type.BitsTypeDefinition.Bit;
19 import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition.EnumPair;
20 import org.opendaylight.yangtools.yang.model.util.type.BitBuilder;
21 import org.opendaylight.yangtools.yang.model.util.type.EnumPairBuilder;
24 final class EffectiveTypeUtil {
25 private EffectiveTypeUtil() {
29 static @NonNull Bit buildBit(final @NonNull BitEffectiveStatement stmt, final Uint32 effectivePos) {
30 verify(stmt instanceof WithStatus);
31 final WithStatus bit = (WithStatus) stmt;
33 // TODO: code duplication with EnumPairBuilder is indicating we could use a common Builder<?> interface
34 final BitBuilder builder = BitBuilder.create(stmt.argument(), effectivePos).setStatus(bit.getStatus());
35 bit.getDescription().ifPresent(builder::setDescription);
36 bit.getReference().ifPresent(builder::setReference);
38 return builder.build();
41 static @NonNull EnumPair buildEnumPair(final @NonNull EnumEffectiveStatement stmt, final int effectiveValue) {
42 verify(stmt instanceof WithStatus);
43 final WithStatus node = (WithStatus) stmt;
45 final EnumPairBuilder builder = EnumPairBuilder.create(stmt.getDeclared().rawArgument(), effectiveValue)
46 .setStatus(node.getStatus()).setUnknownSchemaNodes(node.getUnknownSchemaNodes());
47 node.getDescription().ifPresent(builder::setDescription);
48 node.getReference().ifPresent(builder::setReference);
50 return builder.build();