import org.opendaylight.yangtools.yang.model.api.SchemaNode;
import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
+import org.opendaylight.yangtools.yang.model.util.type.CompatUtils;
public class TypeProviderWrapper {
private final TypeProvider typeProvider;
- public TypeProviderWrapper(TypeProvider typeProvider) {
+ public TypeProviderWrapper(final TypeProvider typeProvider) {
this.typeProvider = typeProvider;
}
* For input node, find if it contains config:java-name-prefix extension. If
* not found, convert local name of node converted to cammel case.
*/
- public static String findJavaNamePrefix(SchemaNode schemaNode) {
+ public static String findJavaNamePrefix(final SchemaNode schemaNode) {
return convertToJavaName(schemaNode, true);
}
- public static String findJavaParameter(SchemaNode schemaNode) {
+ public static String findJavaParameter(final SchemaNode schemaNode) {
return convertToJavaName(schemaNode, false);
}
- public static String convertToJavaName(SchemaNode schemaNode,
- boolean capitalizeFirstLetter) {
+ public static String convertToJavaName(final SchemaNode schemaNode,
+ final boolean capitalizeFirstLetter) {
for (UnknownSchemaNode unknownNode : schemaNode.getUnknownSchemaNodes()) {
if (ConfigConstants.JAVA_NAME_PREFIX_EXTENSION_QNAME
.equals(unknownNode.getNodeType())) {
capitalizeFirstLetter);
}
- public static String convertToJavaName(String localName,
- boolean capitalizeFirstLetter) {
+ public static String convertToJavaName(final String localName,
+ final boolean capitalizeFirstLetter) {
if (capitalizeFirstLetter) {
return BindingGeneratorUtil.parseToClassName(localName);
} else {
}
}
- public Type getType(LeafSchemaNode leaf) {
- TypeDefinition<?> type = leaf.getType();
+ public Type getType(final LeafSchemaNode leaf) {
+ TypeDefinition<?> type = CompatUtils.compatLeafType(leaf);
return getType(leaf, type);
}
- public String getDefault(LeafSchemaNode node) {
+ public String getDefault(final LeafSchemaNode node) {
return typeProvider.getTypeDefaultConstruction(node);
}
- public Type getType(SchemaNode leaf, TypeDefinition<?> type) {
+ public Type getType(final SchemaNode leaf, final TypeDefinition<?> type) {
Type javaType;
try {
javaType = typeProvider.javaTypeForSchemaDefinitionType(
}
// there is no getType in common interface
- public Type getType(LeafListSchemaNode leaf) {
+ public Type getType(final LeafListSchemaNode leaf) {
Type javaType;
try {
javaType = typeProvider.javaTypeForSchemaDefinitionType(
return javaType;
}
- public String getJMXParamForBaseType(TypeDefinition<?> baseType) {
+ public String getJMXParamForBaseType(final TypeDefinition<?> baseType) {
return typeProvider.getConstructorPropertyName(baseType);
}
- public String getJMXParamForUnionInnerType(TypeDefinition<?> unionInnerType) {
+ public String getJMXParamForUnionInnerType(final TypeDefinition<?> unionInnerType) {
return typeProvider.getParamNameFromType(unionInnerType);
}
}
import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition;
import org.opendaylight.yangtools.yang.model.api.type.IdentityrefTypeDefinition;
import org.opendaylight.yangtools.yang.model.api.type.UnionTypeDefinition;
+import org.opendaylight.yangtools.yang.model.util.type.CompatUtils;
public class JavaAttribute extends AbstractAttribute implements TypedAttribute {
private final TypeProviderWrapper typeProviderWrapper;
private final TypeDefinition<?> typeDefinition;
- public JavaAttribute(LeafSchemaNode leaf,
- TypeProviderWrapper typeProviderWrapper) {
+ public JavaAttribute(final LeafSchemaNode leaf,
+ final TypeProviderWrapper typeProviderWrapper) {
super(leaf);
this.type = typeProviderWrapper.getType(leaf);
- this.typeDefinition = leaf.getType();
+ this.typeDefinition = CompatUtils.compatLeafType(leaf);
this.typeProviderWrapper = typeProviderWrapper;
this.nullableDefault = leaf.getDefault();
this.nullableDefaultWrappedForCode = leaf.getDefault() == null ? null : typeProviderWrapper.getDefault(leaf);
this.nullableDescription = leaf.getDescription();
}
- public JavaAttribute(LeafListSchemaNode leaf,
- TypeProviderWrapper typeProviderWrapper) {
+ public JavaAttribute(final LeafListSchemaNode leaf,
+ final TypeProviderWrapper typeProviderWrapper) {
super(leaf);
this.type = typeProviderWrapper.getType(leaf);
this.typeDefinition = leaf.getType();
/**
* Returns the most base type
*/
- private TypeDefinition<?> getBaseType(TypeProviderWrapper typeProviderWrapper, TypeDefinition<?> baseType) {
+ private TypeDefinition<?> getBaseType(final TypeProviderWrapper typeProviderWrapper, TypeDefinition<?> baseType) {
while(baseType.getBaseType()!=null) {
baseType = baseType.getBaseType();
}
}
@Override
- public boolean equals(Object o) {
+ public boolean equals(final Object o) {
if (this == o) {
return true;
}
return typeDefinition instanceof IdentityrefTypeDefinition;
}
- private OpenType<?> getCompositeTypeForUnion(TypeDefinition<?> baseTypeDefinition) {
+ private OpenType<?> getCompositeTypeForUnion(final TypeDefinition<?> baseTypeDefinition) {
Preconditions.checkArgument(baseTypeDefinition instanceof UnionTypeDefinition,
"Expected %s instance but was %s", UnionTypeDefinition.class, baseTypeDefinition);
public static final Class<Character> TYPE_OF_ARTIFICIAL_UNION_PROPERTY = char.class;
- private void addArtificialPropertyToUnionCompositeType(TypeDefinition<?> baseTypeDefinition, String[] itemNames, OpenType<?>[] itemTypes) {
+ private void addArtificialPropertyToUnionCompositeType(final TypeDefinition<?> baseTypeDefinition, final String[] itemNames, final OpenType<?>[] itemTypes) {
String artificialPropertyName = typeProviderWrapper.getJMXParamForBaseType(baseTypeDefinition);
itemNames[0] = artificialPropertyName;
itemTypes[0] = artificialPropertyType;
}
- private OpenType<?> getSimpleType(Type type) {
+ private OpenType<?> getSimpleType(final Type type) {
SimpleType<?> simpleType = SimpleTypeResolver.getSimpleType(type);
return simpleType;
}
- private OpenType<?> getCompositeType(Type baseType, TypeDefinition<?> baseTypeDefinition) {
+ private OpenType<?> getCompositeType(final Type baseType, final TypeDefinition<?> baseTypeDefinition) {
SimpleType<?> innerItemType = SimpleTypeResolver.getSimpleType(baseType);
String innerItemName = typeProviderWrapper.getJMXParamForBaseType(baseTypeDefinition);
return getArrayOpenTypeForSimpleType(innerTypeFullyQName, innerSimpleType);
}
- private OpenType<?> getArrayOpenTypeForSimpleType(String innerTypeFullyQName, SimpleType<?> innerSimpleType) {
+ private OpenType<?> getArrayOpenTypeForSimpleType(final String innerTypeFullyQName, final SimpleType<?> innerSimpleType) {
try {
ArrayType<Object> arrayType = isPrimitive(innerTypeFullyQName) ? new ArrayType<>(innerSimpleType, true)
: new ArrayType<>(1, innerSimpleType);
}
// TODO verify
- private boolean isPrimitive(String innerTypeFullyQName) {
+ private boolean isPrimitive(final String innerTypeFullyQName) {
if (innerTypeFullyQName.contains(".")) {
return false;
}
return type.getName().endsWith("[]");
}
- private boolean isDerivedType(Type baseType, Type currentType) {
+ private boolean isDerivedType(final Type baseType, final Type currentType) {
return baseType.equals(currentType) == false;
}
- private static String getInnerType(Type type) {
+ private static String getInnerType(final Type type) {
String fullyQualifiedName = type.getFullyQualifiedName();
return fullyQualifiedName.substring(0, fullyQualifiedName.length() - 2);
}