Fix list Key data object nullness guarantees
[mdsal.git] / binding / mdsal-binding-java-api-generator / src / main / java / org / opendaylight / mdsal / binding / java / api / generator / ListKeyTemplate.xtend
1 /*
2  * Copyright (c) 2020 Pantheon Technologies, s.r.o. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.mdsal.binding.java.api.generator
9
10 import org.opendaylight.mdsal.binding.model.api.GeneratedProperty
11 import org.opendaylight.mdsal.binding.model.api.GeneratedTransferObject
12
13 /**
14  * Template for generating JAVA class.
15  */
16 class ListKeyTemplate extends ClassTemplate {
17
18     /**
19      * Creates instance of this class with concrete <code>genType</code>.
20      *
21      * @param genType generated transfer object which will be transformed to JAVA class source code
22      */
23     new(GeneratedTransferObject genType) {
24         super(genType)
25     }
26
27
28     override final allValuesConstructor() '''
29         public «type.name»(«allProperties.asNonNullArgumentsDeclaration») {
30             «FOR p : allProperties»
31                 «CODEHELPERS.importedName».requireValue(«p.fieldName»);
32             «ENDFOR»
33             «FOR p : properties»
34                 «generateRestrictions(type, p.fieldName, p.returnType)»
35             «ENDFOR»
36
37             «FOR p : allProperties»
38                 «val fieldName = p.fieldName»
39                 «IF p.returnType.name.endsWith("[]")»
40                     this.«fieldName» = «fieldName».clone();
41                 «ELSE»
42                     this.«fieldName» = «fieldName»;
43                 «ENDIF»
44             «ENDFOR»
45         }
46     '''
47
48     override final def getterMethod(GeneratedProperty field) {
49         '''
50             public «field.returnType.importedNonNull» «field.getterMethodName»() {
51                 «val fieldName = field.fieldName»
52                 «IF field.returnType.name.endsWith("[]")»
53                 return «fieldName».clone();
54                 «ELSE»
55                 return «fieldName»;
56                 «ENDIF»
57             }
58         '''
59     }
60 }