0087e95aeb4e031ce0e91c33b8b7b850d4c226a0
[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 final class ListKeyTemplate extends ClassTemplate {
17     /**
18      * Creates instance of this class with concrete <code>genType</code>.
19      *
20      * @param genType generated transfer object which will be transformed to JAVA class source code
21      */
22     new(GeneratedTransferObject genType) {
23         super(genType)
24     }
25
26     override allValuesConstructor() '''
27         public «type.name»(«allProperties.asNonNullArgumentsDeclaration») {
28             «FOR p : allProperties»
29                 «val fieldName = p.fieldName»
30                 this.«fieldName» = «CODEHELPERS.importedName».requireKeyProp(«fieldName», "«p.name»")«p.cloneCall»;
31             «ENDFOR»
32             «FOR p : properties»
33                 «generateRestrictions(type, p.fieldName, p.returnType)»
34             «ENDFOR»
35         }
36     '''
37
38     override getterMethod(GeneratedProperty field) '''
39         public «field.returnType.importedNonNull» «field.getterMethodName»() {
40             return «field.fieldName»«field.cloneCall»;
41         }
42     '''
43 }