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;
16 import org.opendaylight.yangtools.yang.model.api.DocumentedNode.WithStatus;
17 import org.opendaylight.yangtools.yang.model.api.stmt.BitEffectiveStatement;
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;
22 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.enum_.EnumEffectiveStatementImpl;
25 final class EffectiveTypeUtil {
26 private EffectiveTypeUtil() {
30 static @NonNull Bit buildBit(final @NonNull BitEffectiveStatement stmt, final Uint32 effectivePos) {
31 verify(stmt instanceof DocumentedNode.WithStatus);
32 final DocumentedNode.WithStatus bit = (WithStatus) stmt;
34 // TODO: code duplication with EnumPairBuilder is indicating we could use a common Builder<?> interface
35 final BitBuilder builder = BitBuilder.create(stmt.argument(), effectivePos).setStatus(bit.getStatus());
36 bit.getDescription().ifPresent(builder::setDescription);
37 bit.getReference().ifPresent(builder::setReference);
39 return builder.build();
42 static @NonNull EnumPair buildEnumPair(final @NonNull EnumEffectiveStatementImpl stmt, final int effectiveValue) {
43 final EnumPairBuilder builder = EnumPairBuilder.create(stmt.getName(), effectiveValue)
44 .setStatus(stmt.getStatus()).setUnknownSchemaNodes(stmt.getUnknownSchemaNodes());
45 stmt.getDescription().ifPresent(builder::setDescription);
46 stmt.getReference().ifPresent(builder::setReference);
48 return builder.build();