2 * Copyright (c) 2014 Cisco Systems, Inc. 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.yangtools.sal.java.api.generator
10 import org.opendaylight.yangtools.sal.binding.model.api.Enumeration
11 import org.opendaylight.yangtools.sal.binding.model.api.GeneratedType
14 * Template for generating JAVA enumeration type.
16 class EnumTemplate extends BaseTemplate {
20 * Enumeration which will be transformed to JAVA source code for enumeration
25 * Constructs instance of this class with concrete <code>enums</code>.
27 * @param enums enumeration which will be transformed to JAVA source code
29 new(Enumeration enums) {
30 super(enums as GeneratedType )
36 * Generates only JAVA enumeration source code.
38 * @return string with JAVA enumeration source code
40 def generateAsInnerClass() {
44 def writeEnumItem(String name, int value, String description) '''
45 «asJavadoc(formatToParagraph(description))»
50 * Template method which generates enumeration body (declaration + enumeration items).
52 * @return string with the enumeration body
55 «wrapToDocumentation(formatDataForJavaDoc(enums))»
56 public enum «enums.name» {
57 «writeEnumeration(enums)»
61 static java.util.Map<java.lang.Integer, «enums.name»> valueMap;
64 valueMap = new java.util.HashMap<>();
65 for («enums.name» enumItem : «enums.name».values())
67 valueMap.put(enumItem.value, enumItem);
71 private «enums.name»(int value) {
76 * @return integer value
78 public int getIntValue() {
84 * @return corresponding «enums.name» item
86 public static «enums.name» forValue(int valueArg) {
87 return valueMap.get(valueArg);
92 def writeEnumeration(Enumeration enumeration)
94 «FOR v : enumeration.values SEPARATOR ",\n" AFTER ";"»
95 «writeEnumItem(v.name, v.value, v.description)»«