import static org.opendaylight.mdsal.binding.model.ri.BaseYangTypes.UINT64_TYPE
import static org.opendaylight.mdsal.binding.model.ri.BaseYangTypes.UINT8_TYPE
import static org.opendaylight.mdsal.binding.model.ri.BindingTypes.SCALAR_TYPE_OBJECT
+import static org.opendaylight.mdsal.binding.model.ri.BindingTypes.BITS_TYPE_OBJECT
import static org.opendaylight.mdsal.binding.model.ri.Types.STRING;
import static extension org.apache.commons.text.StringEscapeUtils.escapeJava
-import static extension org.opendaylight.mdsal.binding.model.ri.BindingTypes.isBitsType
import com.google.common.base.Preconditions
import com.google.common.collect.ImmutableList
+import com.google.common.collect.ImmutableSet
import com.google.common.collect.Lists
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings
import java.util.ArrayList
import org.opendaylight.mdsal.binding.model.ri.Types
import org.opendaylight.mdsal.binding.spec.naming.BindingMapping
import org.opendaylight.yangtools.yang.common.Empty
+import org.opendaylight.yangtools.yang.model.api.type.BitsTypeDefinition
/**
* Template for generating JAVA class.
*/
static val BOOLEAN = JavaTypeName.create(Boolean)
+ /**
+ * {@code com.google.common.collect.ImmutableSet} as a JavaTypeName.
+ */
+ static val IMMUTABLE_SET = JavaTypeName.create(ImmutableSet)
+
protected val List<GeneratedProperty> properties
protected val List<GeneratedProperty> finalProperties
protected val List<GeneratedProperty> parentProperties
«propertyMethods»
- «IF genTO.isBitsType»
- «generateGetValueForBitsTypeDef»
+ «IF isBitsTypeObject»
+ «validNamesAndValues»
«ENDIF»
«generateHashCode»
return false
}
+ def private isBitsTypeObject() {
+ var wlk = genTO
+ while (wlk !== null) {
+ for (impl : wlk.implements) {
+ if (BITS_TYPE_OBJECT.identifier.equals(impl.identifier)) {
+ return true
+ }
+ }
+ wlk = wlk.superType
+ }
+ return false
+ }
+
def private defaultProperties() '''
«FOR field : properties SEPARATOR "\n"»
«field.getterMethod»
}
'''
- /**
- * Template method which generates the method <code>getValue()</code> for typedef,
- * which base type is BitsDefinition.
- *
- * @return string with the <code>getValue()</code> method definition in JAVA format
- */
- def protected generateGetValueForBitsTypeDef() '''
+ def private validNamesAndValues() {
+ for (c : consts) {
+ if (TypeConstants.VALID_NAMES_NAME.equals(c.name)) {
+ return validNamesAndValues(c.value as BitsTypeDefinition)
+ }
+ }
+ return ""
+ }
- public boolean[] getValue() {
- return new boolean[]{
- «FOR property: genTO.properties SEPARATOR ','»
- «property.fieldName»
- «ENDFOR»
- };
+ def private validNamesAndValues(BitsTypeDefinition typedef) '''
+
+ @«OVERRIDE.importedName»
+ public «IMMUTABLE_SET.importedName»<«STRING.importedName»> validNames() {
+ return «TypeConstants.VALID_NAMES_NAME»;
+ }
+
+ @«OVERRIDE.importedName»
+ public boolean[] values() {
+ return new boolean[] {
+ «FOR bit : typedef.bits SEPARATOR ','»
+ «BindingMapping.getPropertyName(bit.name).getterMethodName»()
+ «ENDFOR»
+ };
}
'''
private static final String[] «Constants.MEMBER_REGEX_LIST» = { «
FOR v : cValue.values SEPARATOR ", "»"«v.escapeJava»"«ENDFOR» };
«ENDIF»
+ «ELSEIF TypeConstants.VALID_NAMES_NAME.equals(c.name)»
+ «val cValue = c.value as BitsTypeDefinition»
+ «val immutableSet = IMMUTABLE_SET.importedName»
+ protected static final «immutableSet»<«STRING.importedName»> «TypeConstants.VALID_NAMES_NAME» = «immutableSet».of(«
+ FOR bit : cValue.bits SEPARATOR ", "»"«bit.name»"«ENDFOR»);
«ELSE»
«emitConstant(c)»
«ENDIF»