2 * Copyright (c) 2020 Pantheon Technologies, s.r.o. and others. All rights reserved.
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
8 package org.opendaylight.mdsal.binding.java.api.generator
10 import org.opendaylight.mdsal.binding.model.api.GeneratedProperty
11 import org.opendaylight.mdsal.binding.model.api.GeneratedType
12 import org.opendaylight.mdsal.binding.model.api.GeneratedTransferObject
13 import org.opendaylight.mdsal.binding.model.api.ParameterizedType;
14 import org.opendaylight.mdsal.binding.model.api.Type
15 import org.opendaylight.mdsal.binding.model.ri.BindingTypes
18 * Template for generating JAVA class.
20 final class ListKeyTemplate extends ClassTemplate {
22 * Creates instance of this class with concrete <code>genType</code>.
24 * @param genType generated transfer object which will be transformed to JAVA class source code
26 new(GeneratedTransferObject genType) {
30 override allValuesConstructor() '''
32 * Constructs an instance.
34 «FOR p : allProperties»
35 * @param «p.fieldName» the entity «p.getName»
37 * @throws NullPointerException if any of the arguments are null
39 public «type.name»(«allProperties.asNonNullArgumentsDeclaration») {
40 «FOR p : allProperties»
41 «val fieldName = p.fieldName»
42 this.«fieldName» = «CODEHELPERS.importedName».requireKeyProp(«fieldName», "«p.name»")«p.cloneCall»;
45 «generateRestrictions(type, p.fieldName, p.returnType)»
50 override getterMethod(GeneratedProperty field) '''
52 * Return «field.getName», guaranteed to be non-null.
54 * @return {@code «field.returnType.importedName»} «field.getName», guaranteed to be non-null.
56 public «field.returnType.importedNonNull» «field.getterMethodName»() {
57 return «field.fieldName»«field.cloneCall»;
61 override protected String formatDataForJavaDoc(GeneratedType type) {
62 val listType = findListType(type)
63 if (listType === null) {
67 val importedName = listType.importedName
69 This class represents the key of {@link «importedName»} class.
75 private static def Type findListType(GeneratedType type) {
76 for (Type implType : type.getImplements()) {
77 if (implType instanceof ParameterizedType) {
78 val identifiable = BindingTypes.extractIdentifiable(implType)
79 if (identifiable !== null) {