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 com.google.common.annotations.Beta;
11 import org.eclipse.jdt.annotation.NonNull;
12 import org.opendaylight.yangtools.yang.model.api.type.BitsTypeDefinition.Bit;
13 import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition.EnumPair;
14 import org.opendaylight.yangtools.yang.model.util.type.BitBuilder;
15 import org.opendaylight.yangtools.yang.model.util.type.EnumPairBuilder;
16 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.bit.BitEffectiveStatementImpl;
17 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.enum_.EnumEffectiveStatementImpl;
20 final class EffectiveTypeUtil {
21 private EffectiveTypeUtil() {
22 throw new UnsupportedOperationException();
25 static @NonNull Bit buildBit(final @NonNull BitEffectiveStatementImpl stmt, final long effectivePos) {
26 // TODO: code duplication with EnumPairBuilder is indicating we could use a common Builder<?> interface
27 final BitBuilder builder = BitBuilder.create(stmt.getPath(), effectivePos).setStatus(stmt.getStatus());
28 stmt.getDescription().ifPresent(builder::setDescription);
29 stmt.getReference().ifPresent(builder::setReference);
31 return builder.build();
34 static @NonNull EnumPair buildEnumPair(final @NonNull EnumEffectiveStatementImpl stmt, final int effectiveValue) {
35 final EnumPairBuilder builder = EnumPairBuilder.create(stmt.getName(), effectiveValue)
36 .setStatus(stmt.getStatus()).setUnknownSchemaNodes(stmt.getUnknownSchemaNodes());
37 stmt.getDescription().ifPresent(builder::setDescription);
38 stmt.getReference().ifPresent(builder::setReference);
40 return builder.build();