X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=binding%2Fmdsal-binding-model-ri%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fmdsal%2Fbinding%2Fmodel%2Fri%2FBindingTypes.java;h=26dd49ef12b0bf093c0da489dcb698e51ba45693;hb=refs%2Fchanges%2F17%2F100117%2F20;hp=c4beb7b174144d2a046e2a00e67efafee327a20b;hpb=56029dd8a38725d8c5149646a9348e58e769583a;p=mdsal.git diff --git a/binding/mdsal-binding-model-ri/src/main/java/org/opendaylight/mdsal/binding/model/ri/BindingTypes.java b/binding/mdsal-binding-model-ri/src/main/java/org/opendaylight/mdsal/binding/model/ri/BindingTypes.java index c4beb7b174..26dd49ef12 100644 --- a/binding/mdsal-binding-model-ri/src/main/java/org/opendaylight/mdsal/binding/model/ri/BindingTypes.java +++ b/binding/mdsal-binding-model-ri/src/main/java/org/opendaylight/mdsal/binding/model/ri/BindingTypes.java @@ -9,10 +9,13 @@ package org.opendaylight.mdsal.binding.model.ri; import static org.opendaylight.mdsal.binding.model.ri.Types.parameterizedTypeFor; import static org.opendaylight.mdsal.binding.model.ri.Types.typeForClass; +import static org.opendaylight.mdsal.binding.spec.naming.BindingMapping.VALUE_STATIC_FIELD_NAME; import com.google.common.annotations.VisibleForTesting; import org.eclipse.jdt.annotation.NonNull; import org.opendaylight.mdsal.binding.model.api.ConcreteType; +import org.opendaylight.mdsal.binding.model.api.GeneratedTransferObject; +import org.opendaylight.mdsal.binding.model.api.GeneratedType; import org.opendaylight.mdsal.binding.model.api.JavaTypeName; import org.opendaylight.mdsal.binding.model.api.ParameterizedType; import org.opendaylight.mdsal.binding.model.api.Type; @@ -43,6 +46,7 @@ import org.opendaylight.yangtools.yang.binding.TypeObject; import org.opendaylight.yangtools.yang.binding.annotations.RoutingContext; import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.common.RpcResult; +import org.opendaylight.yangtools.yang.model.api.type.BitsTypeDefinition; public final class BindingTypes { @@ -272,4 +276,42 @@ public final class BindingTypes { public static ParameterizedType scalarTypeObject(final Type type) { return parameterizedTypeFor(SCALAR_TYPE_OBJECT, type); } + + /** + * Check if specified type is generated for a {@code type bits}. + * + * @param type Type to examine + * @return {@code true} if the type is generated for a {@code type bits} + */ + public static boolean isBitsType(final Type type) { + return type instanceof GeneratedTransferObject && isBitsType((GeneratedTransferObject) type); + } + + /** + * Check if specified type is generated for a {@code type bits}. + * + * @param gto Type to examine + * @return {@code true} if the type is generated for a {@code type bits} + */ + public static boolean isBitsType(final GeneratedTransferObject gto) { + return gto.isTypedef() && gto.getBaseType() instanceof BitsTypeDefinition; + } + + /** + * Check if specified type is generated for an identity. + * + * @param type Type to examine + * @return {@code true} if the type is generated for an identity + */ + public static boolean isIdentityType(final Type type) { + if (type instanceof GeneratedType) { + for (var constant : ((GeneratedType) type).getConstantDefinitions()) { + if (VALUE_STATIC_FIELD_NAME.equals(constant.getName()) + && BaseIdentity.class.equals(constant.getValue())) { + return true; + } + } + } + return false; + } }