Remove unnecessary casts
[mdsal.git] / code-generator / binding-java-api-generator / src / main / java / org / opendaylight / yangtools / sal / java / api / generator / InterfaceTemplate.xtend
index e90b99c136bba015047d8ca290e2c5d88c530da1..606fd753718b096bee210193b44231bd9ef3318c 100644 (file)
-package org.opendaylight.yangtools.sal.java.api.generator\r
-\r
-import java.util.List\r
-import org.opendaylight.yangtools.binding.generator.util.TypeConstants\r
-import org.opendaylight.yangtools.sal.binding.model.api.Constant\r
-import org.opendaylight.yangtools.sal.binding.model.api.Enumeration\r
-import org.opendaylight.yangtools.sal.binding.model.api.GeneratedTransferObject\r
-import org.opendaylight.yangtools.sal.binding.model.api.GeneratedType\r
+/*
+ * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.sal.java.api.generator
+
+import java.util.List
+import org.opendaylight.yangtools.binding.generator.util.TypeConstants
+import org.opendaylight.yangtools.sal.binding.model.api.Constant
+import org.opendaylight.yangtools.sal.binding.model.api.Enumeration
+import org.opendaylight.yangtools.sal.binding.model.api.GeneratedTransferObject
+import org.opendaylight.yangtools.sal.binding.model.api.GeneratedType
 import org.opendaylight.yangtools.sal.binding.model.api.MethodSignature\rimport org.opendaylight.yangtools.sal.binding.model.api.AnnotationType
 
-/**\r
- * Template for generating JAVA interfaces. \r
- */\r
-class InterfaceTemplate extends BaseTemplate {\r
-    \r
-    /**\r
-     * List of constant instances which are generated as JAVA public static final attributes.\r
-     */\r
-    val List<Constant> consts\r
-    \r
-    /**\r
-     * List of method signatures which are generated as method declarations.\r
-     */\r
-    val List<MethodSignature> methods\r
-    \r
-    /**\r
-     * List of enumeration which are generated as JAVA enum type.\r
-     */\r
-    val List<Enumeration> enums\r
-    \r
-    /**\r
-     * List of generated types which are enclosed inside <code>genType</code>\r
-     */\r
-    val List<GeneratedType> enclosedGeneratedTypes\r
-    \r
-    /**\r
-     * Creates the instance of this class which is used for generating the interface file source \r
-     * code from <code>genType</code>.\r
-     * \r
-     * @throws IllegalArgumentException if <code>genType</code> equals <code>null</code>\r
-     */\r
-    new(GeneratedType genType) {\r
-        super(genType)\r
-        if (genType == null) {\r
-            throw new IllegalArgumentException("Generated type reference cannot be NULL!")\r
-        }\r
-        \r
-        consts = genType.constantDefinitions\r
-        methods = genType.methodDefinitions\r
-        enums = genType.enumerations\r
-        enclosedGeneratedTypes = genType.enclosedTypes\r
-    }\r
-    \r
-\r
-    \r
-    /**\r
-     * Template method which generate the whole body of the interface.\r
-     * \r
-     * @return string with code for interface body in JAVA format\r
-     */\r
-    override body() '''\r
-        «type.comment.generateComment»\r
-        public interface «type.name»\r
-            «superInterfaces»\r
-        {\r
-        \r
-            «generateInnerClasses»\r
-        \r
-            «generateEnums»\r
-        \r
-            «generateConstants»\r
-        \r
-            «generateMethods»\r
-        \r
-        }\r
-        \r
-    '''\r
-    \r
-    /**\r
-     * Template method which generates JAVA comment.\r
-     * \r
-     * @param comment \r
-     * string with the comment for whole JAVA interface\r
-     * @return string with comment in JAVA format\r
-     */\r
-    def private generateComment(String comment) '''\r
-        «IF comment != null && !comment.empty»\r
-            /*\r
-            «comment»\r
-            */\r
-        «ENDIF»\r
-    '''\r
-\r
-    def private generateAnnotations(List<AnnotationType> annotations) '''\r
-        «IF annotations != null && !annotations.empty»\r
-            «FOR annotation : annotations»\r
-                @«annotation.name»\r
-                «IF annotation.parameters != null && !annotation.parameters.empty»\r
-                (\r
-                «FOR param : annotation.parameters SEPARATOR ","»\r
-                    «param.name»=«param.value»\r
-                «ENDFOR»\r
-                )\r
-                «ENDIF»\r
-            «ENDFOR»\r
-        «ENDIF»\r
-    '''\r
-\r
-    /**\r
-     * Template method which generates the interface name declaration.\r
-     * \r
-     * @return string with the code for the interface declaration in JAVA format\r
-     */\r
-    def private superInterfaces() \r
-    '''\r
-    «IF (!type.implements.empty)»\r
-         extends\r
-         «FOR type : type.implements SEPARATOR ","»\r
-             «type.importedName»\r
-         «ENDFOR»\r
-     « ENDIF»\r
-     '''\r
-\r
-    /**\r
-     * Template method which generates inner classes inside this interface.\r
-     * \r
-     * @return string with the source code for inner classes in JAVA format\r
-     */\r
-    def private generateInnerClasses() '''\r
-        «IF !enclosedGeneratedTypes.empty»\r
-            «FOR innerClass : enclosedGeneratedTypes SEPARATOR "\n"»\r
-                «IF (innerClass instanceof GeneratedTransferObject)»\r
-                    «IF (innerClass as GeneratedTransferObject).unionType»\r
-                        «val unionTemplate = new UnionTemplate(innerClass as GeneratedTransferObject)»\r
-                        «unionTemplate.generateAsInnerClass»\r
-                        «this.importMap.putAll(unionTemplate.importMap)»\r
-                    «ELSE»\r
-                        «val classTemplate = new ClassTemplate(innerClass as GeneratedTransferObject)»\r
-                        «classTemplate.generateAsInnerClass»\r
-                        «this.importMap.putAll(classTemplate.importMap)»\r
-                    «ENDIF»\r
-\r
-                «ENDIF»\r
-            «ENDFOR»\r
-        «ENDIF»\r
-    '''\r
-\r
-    /**\r
-     * Template method which generates JAVA enum type.\r
-     * \r
-     * @return string with inner enum source code in JAVA format\r
-     */    \r
-    def private generateEnums() '''\r
-        «IF !enums.empty»\r
-            «FOR e : enums SEPARATOR "\n"»\r
-                «val enumTemplate = new EnumTemplate(e)»\r
-                «enumTemplate.generateAsInnerClass»\r
-            «ENDFOR»\r
-        «ENDIF»\r
-    '''\r
-    \r
-    /**\r
-     * Template method wich generates JAVA constants.\r
-     * \r
-     * @return string with constants in JAVA format \r
-     */    \r
-    def private generateConstants() '''\r
-        «IF !consts.empty»\r
-            «FOR c : consts»\r
-                «IF c.name != TypeConstants.PATTERN_CONSTANT_NAME»\r
-                    public static final «c.type.importedName» «c.name» = «c.value»;\r
-                «ENDIF»\r
-            «ENDFOR»\r
-        «ENDIF»\r
-    '''\r
-\r
-    /**\r
-     * Template method which generates the declaration of the methods.\r
-     * \r
-     * @return string with the declaration of methods source code in JAVA format \r
-     */    \r
-    def private generateMethods() '''\r
-        «IF !methods.empty»\r
-            «FOR m : methods SEPARATOR "\n"»\r
-                «m.comment.generateComment»\r
-                «m.annotations.generateAnnotations»\r
-                «m.returnType.importedName» «m.name»(«m.parameters.generateParameters»);\r
-            «ENDFOR»\r
-        «ENDIF»\r
-    '''\r
-\r
-}\r
-\r
+/**
+ * Template for generating JAVA interfaces. 
+ */
+class InterfaceTemplate extends BaseTemplate {
+    
+    /**
+     * List of constant instances which are generated as JAVA public static final attributes.
+     */
+    val List<Constant> consts
+    
+    /**
+     * List of method signatures which are generated as method declarations.
+     */
+    val List<MethodSignature> methods
+    
+    /**
+     * List of enumeration which are generated as JAVA enum type.
+     */
+    val List<Enumeration> enums
+    
+    /**
+     * List of generated types which are enclosed inside <code>genType</code>
+     */
+    val List<GeneratedType> enclosedGeneratedTypes
+    
+    /**
+     * Creates the instance of this class which is used for generating the interface file source 
+     * code from <code>genType</code>.
+     * 
+     * @throws IllegalArgumentException if <code>genType</code> equals <code>null</code>
+     */
+    new(GeneratedType genType) {
+        super(genType)
+        if (genType == null) {
+            throw new IllegalArgumentException("Generated type reference cannot be NULL!")
+        }
+        
+        consts = genType.constantDefinitions
+        methods = genType.methodDefinitions
+        enums = genType.enumerations
+        enclosedGeneratedTypes = genType.enclosedTypes
+    }
+    
+    /**
+     * Template method which generate the whole body of the interface.
+     * 
+     * @return string with code for interface body in JAVA format
+     */
+    override body() '''
+        «wrapToDocumentation(formatDataForJavaDoc(type))»
+        public interface «type.name»
+            «superInterfaces»
+        {
+        
+            «generateInnerClasses»
+        
+            «generateEnums»
+        
+            «generateConstants»
+        
+            «generateMethods»
+        
+        }
+        
+    '''
+   
+
+    def private generateAnnotations(List<AnnotationType> annotations) '''
+        «IF annotations != null && !annotations.empty»
+            «FOR annotation : annotations»
+                @«annotation.importedName»
+                «IF annotation.parameters != null && !annotation.parameters.empty»
+                (
+                «FOR param : annotation.parameters SEPARATOR ","»
+                    «param.name»=«param.value»
+                «ENDFOR»
+                )
+                «ENDIF»
+            «ENDFOR»
+        «ENDIF»
+    '''
+
+    /**
+     * Template method which generates the interface name declaration.
+     * 
+     * @return string with the code for the interface declaration in JAVA format
+     */
+    def private superInterfaces() 
+    '''
+    «IF (!type.implements.empty)»
+         extends
+         «FOR type : type.implements SEPARATOR ","»
+             «type.importedName»
+         «ENDFOR»
+     « ENDIF»
+     '''
+
+    /**
+     * Template method which generates inner classes inside this interface.
+     * 
+     * @return string with the source code for inner classes in JAVA format
+     */
+    def private generateInnerClasses() '''
+        «IF !enclosedGeneratedTypes.empty»
+            «FOR innerClass : enclosedGeneratedTypes SEPARATOR "\n"»
+                «IF (innerClass instanceof GeneratedTransferObject)»
+                    «IF innerClass.unionType»
+                        «val unionTemplate = new UnionTemplate(innerClass)»
+                        «unionTemplate.generateAsInnerClass»
+                        «this.importMap.putAll(unionTemplate.importMap)»
+                    «ELSE»
+                        «val classTemplate = new ClassTemplate(innerClass)»
+                        «classTemplate.generateAsInnerClass»
+                        «this.importMap.putAll(classTemplate.importMap)»
+                    «ENDIF»
+
+                «ENDIF»
+            «ENDFOR»
+        «ENDIF»
+    '''
+
+    /**
+     * Template method which generates JAVA enum type.
+     * 
+     * @return string with inner enum source code in JAVA format
+     */    
+    def private generateEnums() '''
+        «IF !enums.empty»
+            «FOR e : enums SEPARATOR "\n"»
+                «val enumTemplate = new EnumTemplate(e)»
+                «enumTemplate.generateAsInnerClass»
+            «ENDFOR»
+        «ENDIF»
+    '''
+    
+    /**
+     * Template method wich generates JAVA constants.
+     * 
+     * @return string with constants in JAVA format 
+     */    
+    def private generateConstants() '''
+        «IF !consts.empty»
+            «FOR c : consts»
+                «IF c.name != TypeConstants.PATTERN_CONSTANT_NAME»
+                    public static final «c.type.importedName» «c.name» = «c.value»;
+                «ENDIF»
+            «ENDFOR»
+        «ENDIF»
+    '''
+
+    /**
+     * Template method which generates the declaration of the methods.
+     * 
+     * @return string with the declaration of methods source code in JAVA format 
+     */    
+    def private generateMethods() '''
+        «IF !methods.empty»
+            «FOR m : methods SEPARATOR "\n"»
+                «m.comment.asJavadoc»
+                «m.annotations.generateAnnotations»
+                «m.returnType.importedName» «m.name»(«m.parameters.generateParameters»);
+            «ENDFOR»
+        «ENDIF»
+    '''
+
+}
+