1 package org.opendaylight.yangtools.sal.java.api.generator
\r
3 import java.util.List
\r
4 import org.opendaylight.yangtools.binding.generator.util.TypeConstants
\r
5 import org.opendaylight.yangtools.sal.binding.model.api.Constant
\r
6 import org.opendaylight.yangtools.sal.binding.model.api.Enumeration
\r
7 import org.opendaylight.yangtools.sal.binding.model.api.GeneratedTransferObject
\r
8 import org.opendaylight.yangtools.sal.binding.model.api.GeneratedType
\r
9 import org.opendaylight.yangtools.sal.binding.model.api.MethodSignature
\rimport org.opendaylight.yangtools.sal.binding.model.api.AnnotationType
12 * Template for generating JAVA interfaces.
\r
14 class InterfaceTemplate extends BaseTemplate {
\r
17 * List of constant instances which are generated as JAVA public static final attributes.
\r
19 val List<Constant> consts
\r
22 * List of method signatures which are generated as method declarations.
\r
24 val List<MethodSignature> methods
\r
27 * List of enumeration which are generated as JAVA enum type.
\r
29 val List<Enumeration> enums
\r
32 * List of generated types which are enclosed inside <code>genType</code>
\r
34 val List<GeneratedType> enclosedGeneratedTypes
\r
37 * Creates the instance of this class which is used for generating the interface file source
\r
38 * code from <code>genType</code>.
\r
40 * @throws IllegalArgumentException if <code>genType</code> equals <code>null</code>
\r
42 new(GeneratedType genType) {
\r
44 if (genType == null) {
\r
45 throw new IllegalArgumentException("Generated type reference cannot be NULL!")
\r
48 consts = genType.constantDefinitions
\r
49 methods = genType.methodDefinitions
\r
50 enums = genType.enumerations
\r
51 enclosedGeneratedTypes = genType.enclosedTypes
\r
57 * Template method which generate the whole body of the interface.
\r
59 * @return string with code for interface body in JAVA format
\r
62 «type.comment.generateComment»
\r
63 public interface «type.name»
\r
67 «generateInnerClasses»
\r
80 * Template method which generates JAVA comment.
\r
83 * string with the comment for whole JAVA interface
\r
84 * @return string with comment in JAVA format
\r
86 def private generateComment(String comment) '''
\r
87 «IF comment != null && !comment.empty»
\r
94 def private generateAnnotations(List<AnnotationType> annotations) '''
\r
95 «IF annotations != null && !annotations.empty»
\r
96 «FOR annotation : annotations»
\r
98 «IF annotation.parameters != null && !annotation.parameters.empty»
\r
100 «FOR param : annotation.parameters SEPARATOR ","»
\r
101 «param.name»=«param.value»
\r
110 * Template method which generates the interface name declaration.
\r
112 * @return string with the code for the interface declaration in JAVA format
\r
114 def private superInterfaces()
\r
116 «IF (!type.implements.empty)»
\r
118 «FOR type : type.implements SEPARATOR ","»
\r
119 «type.importedName»
\r
125 * Template method which generates inner classes inside this interface.
\r
127 * @return string with the source code for inner classes in JAVA format
\r
129 def private generateInnerClasses() '''
\r
130 «IF !enclosedGeneratedTypes.empty»
\r
131 «FOR innerClass : enclosedGeneratedTypes SEPARATOR "\n"»
\r
132 «IF (innerClass instanceof GeneratedTransferObject)»
\r
133 «IF (innerClass as GeneratedTransferObject).unionType»
\r
134 «val unionTemplate = new UnionTemplate(innerClass as GeneratedTransferObject)»
\r
135 «unionTemplate.generateAsInnerClass»
\r
136 «this.importMap.putAll(unionTemplate.importMap)»
\r
138 «val classTemplate = new ClassTemplate(innerClass as GeneratedTransferObject)»
\r
139 «classTemplate.generateAsInnerClass»
\r
140 «this.importMap.putAll(classTemplate.importMap)»
\r
149 * Template method which generates JAVA enum type.
\r
151 * @return string with inner enum source code in JAVA format
\r
153 def private generateEnums() '''
\r
155 «FOR e : enums SEPARATOR "\n"»
\r
156 «val enumTemplate = new EnumTemplate(e)»
\r
157 «enumTemplate.generateAsInnerClass»
\r
163 * Template method wich generates JAVA constants.
\r
165 * @return string with constants in JAVA format
\r
167 def private generateConstants() '''
\r
170 «IF c.name != TypeConstants.PATTERN_CONSTANT_NAME»
\r
171 public static final «c.type.importedName» «c.name» = «c.value»;
\r
178 * Template method which generates the declaration of the methods.
\r
180 * @return string with the declaration of methods source code in JAVA format
\r
182 def private generateMethods() '''
\r
183 «IF !methods.empty»
\r
184 «FOR m : methods SEPARATOR "\n"»
\r
185 «m.comment.generateComment»
\r
186 «m.annotations.generateAnnotations»
\r
187 «m.returnType.importedName» «m.name»(«m.parameters.generateParameters»);
\r