*/
package org.opendaylight.mdsal.binding.java.api.generator
-import static org.opendaylight.mdsal.binding.model.util.Types.BOOLEAN;
-import static org.opendaylight.mdsal.binding.model.util.Types.BYTE_ARRAY;
-import static org.opendaylight.mdsal.binding.model.util.Types.STRING;
-import static org.opendaylight.mdsal.binding.model.util.Types.getOuterClassName;
+import static org.opendaylight.mdsal.binding.model.ri.BaseYangTypes.BINARY_TYPE;
+import static org.opendaylight.mdsal.binding.model.ri.BaseYangTypes.BOOLEAN_TYPE;
+import static org.opendaylight.mdsal.binding.model.ri.BaseYangTypes.EMPTY_TYPE;
+import static org.opendaylight.mdsal.binding.model.ri.BaseYangTypes.STRING_TYPE;
+import static org.opendaylight.mdsal.binding.model.ri.Types.STRING;
+import static org.opendaylight.mdsal.binding.model.ri.Types.getOuterClassName;
+import static org.opendaylight.mdsal.binding.spec.naming.BindingMapping.BUILDER_SUFFIX
import java.util.Base64;
import org.gaul.modernizer_maven_annotations.SuppressModernizer
def typeBuilder() {
val outerCls = getOuterClassName(type);
- if(outerCls !== null) {
- return outerCls + type.name + "Builder"
+ if (outerCls !== null) {
+ return outerCls + type.name + BUILDER_SUFFIX
}
- return type.name + "Builder"
+ return type.name + BUILDER_SUFFIX
}
private def unionConstructorsParentProperties() '''
«val field = property.fieldName»
if («field» != null) {
«val propRet = property.returnType»
- «IF STRING.equals(propRet)»
+ «IF STRING_TYPE.equals(propRet)»
««« type string
return «field»;
«ELSEIF "org.opendaylight.yangtools.yang.binding.InstanceIdentifier".equals(propRet.fullyQualifiedName)»
««« type instance-identifier
return «field».toString();
- «ELSEIF BYTE_ARRAY.equals(propRet)»
+ «ELSEIF BINARY_TYPE.equals(propRet)»
««« type binary
return new «STRING.importedName»(«field»);
- «ELSEIF propRet.fullyQualifiedName.startsWith("java.lang") || propRet instanceof Enumeration
- || propRet.fullyQualifiedName.startsWith("java.math")»
- ««« type int*, decimal64 or enumeration*
+ «ELSEIF propRet.fullyQualifiedName.startsWith("java.lang") || propRet instanceof Enumeration»
+ ««« type int* or enumeration*
return «field».toString();
«ELSEIF "org.opendaylight.yangtools.yang.common".equals(propRet.packageName)
- && propRet.name.startsWith("Uint")»
- ««« type uint*
+ && (propRet.name.startsWith("Uint") || "Decimal64".equals(propRet.name))»
+ ««« type uint*, decimal64
return «field».toCanonicalString();
«ELSEIF propRet instanceof GeneratedTransferObject && (propRet as GeneratedTransferObject).unionType»
««« union type
return «field».stringValue();
- «ELSEIF BOOLEAN.equals(propRet.typedefReturnType)»
+ «ELSEIF BOOLEAN_TYPE.equals(propRet.typedefReturnType)»
««« generated boolean typedef
return «field».isValue().toString();
- «ELSEIF BYTE_ARRAY.equals(propRet.typedefReturnType)»
+ «ELSEIF BINARY_TYPE.equals(propRet.typedefReturnType)»
««« generated byte[] typedef
return «Base64.importedName».getEncoder().encodeToString(«field».getValue());
- «ELSEIF Constants.EMPTY.equals(propRet) || Constants.EMPTY.equals(propRet.typedefReturnType)»
+ «ELSEIF EMPTY_TYPE.equals(propRet) || EMPTY_TYPE.equals(propRet.typedefReturnType)»
««« generated empty typedef
return "";
- «ELSEIF propRet instanceof GeneratedTransferObject // Is it a GeneratedTransferObject
- && (propRet as GeneratedTransferObject).typedef // Is it a typedef
- && (propRet as GeneratedTransferObject).baseType instanceof BitsTypeDefinition»
+ «ELSEIF propRet.isBitsType»
««« generated bits typedef
return «JU_ARRAYS.importedName».toString(«field».getValue());
«ELSE»
«ENDIF»
}
«ENDFOR»
-
- throw new IllegalStateException("No value assinged");
+ throw new IllegalStateException("No value assigned");
}
'''
+ private static def isBitsType(Type type) {
+ if (type instanceof GeneratedTransferObject) {
+ return type.typedef && type.baseType instanceof BitsTypeDefinition
+ }
+ return false
+ }
+
private static def Type typedefReturnType(Type type) {
if (!(type instanceof GeneratedTransferObject)) {
return null