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
\r
10 import java.util.List
\r
11 import org.opendaylight.yangtools.binding.generator.util.TypeConstants
\r
12 import org.opendaylight.yangtools.sal.binding.model.api.Constant
\r
13 import org.opendaylight.yangtools.sal.binding.model.api.Enumeration
\r
14 import org.opendaylight.yangtools.sal.binding.model.api.GeneratedTransferObject
\r
15 import org.opendaylight.yangtools.sal.binding.model.api.GeneratedType
\r
16 import org.opendaylight.yangtools.sal.binding.model.api.MethodSignature
\rimport org.opendaylight.yangtools.sal.binding.model.api.AnnotationType
19 * Template for generating JAVA interfaces.
\r
21 class InterfaceTemplate extends BaseTemplate {
\r
24 * List of constant instances which are generated as JAVA public static final attributes.
\r
26 val List<Constant> consts
\r
29 * List of method signatures which are generated as method declarations.
\r
31 val List<MethodSignature> methods
\r
34 * List of enumeration which are generated as JAVA enum type.
\r
36 val List<Enumeration> enums
\r
39 * List of generated types which are enclosed inside <code>genType</code>
\r
41 val List<GeneratedType> enclosedGeneratedTypes
\r
44 * Creates the instance of this class which is used for generating the interface file source
\r
45 * code from <code>genType</code>.
\r
47 * @throws IllegalArgumentException if <code>genType</code> equals <code>null</code>
\r
49 new(GeneratedType genType) {
\r
51 if (genType == null) {
\r
52 throw new IllegalArgumentException("Generated type reference cannot be NULL!")
\r
55 consts = genType.constantDefinitions
\r
56 methods = genType.methodDefinitions
\r
57 enums = genType.enumerations
\r
58 enclosedGeneratedTypes = genType.enclosedTypes
\r
64 * Template method which generate the whole body of the interface.
\r
66 * @return string with code for interface body in JAVA format
\r
69 «type.comment.asJavadoc»
\r
70 public interface «type.name»
\r
74 «generateInnerClasses»
\r
87 def private generateAnnotations(List<AnnotationType> annotations) '''
\r
88 «IF annotations != null && !annotations.empty»
\r
89 «FOR annotation : annotations»
\r
91 «IF annotation.parameters != null && !annotation.parameters.empty»
\r
93 «FOR param : annotation.parameters SEPARATOR ","»
\r
94 «param.name»=«param.value»
\r
103 * Template method which generates the interface name declaration.
\r
105 * @return string with the code for the interface declaration in JAVA format
\r
107 def private superInterfaces()
\r
109 «IF (!type.implements.empty)»
\r
111 «FOR type : type.implements SEPARATOR ","»
\r
112 «type.importedName»
\r
118 * Template method which generates inner classes inside this interface.
\r
120 * @return string with the source code for inner classes in JAVA format
\r
122 def private generateInnerClasses() '''
\r
123 «IF !enclosedGeneratedTypes.empty»
\r
124 «FOR innerClass : enclosedGeneratedTypes SEPARATOR "\n"»
\r
125 «IF (innerClass instanceof GeneratedTransferObject)»
\r
126 «IF (innerClass as GeneratedTransferObject).unionType»
\r
127 «val unionTemplate = new UnionTemplate(innerClass as GeneratedTransferObject)»
\r
128 «unionTemplate.generateAsInnerClass»
\r
129 «this.importMap.putAll(unionTemplate.importMap)»
\r
131 «val classTemplate = new ClassTemplate(innerClass as GeneratedTransferObject)»
\r
132 «classTemplate.generateAsInnerClass»
\r
133 «this.importMap.putAll(classTemplate.importMap)»
\r
142 * Template method which generates JAVA enum type.
\r
144 * @return string with inner enum source code in JAVA format
\r
146 def private generateEnums() '''
\r
148 «FOR e : enums SEPARATOR "\n"»
\r
149 «val enumTemplate = new EnumTemplate(e)»
\r
150 «enumTemplate.generateAsInnerClass»
\r
156 * Template method wich generates JAVA constants.
\r
158 * @return string with constants in JAVA format
\r
160 def private generateConstants() '''
\r
163 «IF c.name != TypeConstants.PATTERN_CONSTANT_NAME»
\r
164 public static final «c.type.importedName» «c.name» = «c.value»;
\r
171 * Template method which generates the declaration of the methods.
\r
173 * @return string with the declaration of methods source code in JAVA format
\r
175 def private generateMethods() '''
\r
176 «IF !methods.empty»
\r
177 «FOR m : methods SEPARATOR "\n"»
\r
178 «m.comment.asJavadoc»
\r
179 «m.annotations.generateAnnotations»
\r
180 «m.returnType.importedName» «m.name»(«m.parameters.generateParameters»);
\r