Bug 1512 - generated builder java file for a leaf containing a union
[yangtools.git] / code-generator / binding-generator-impl / src / main / java / org / opendaylight / yangtools / sal / binding / generator / impl / YangTemplate.xtend
index 98d7ef1d9e120bc4540bf7fa7e8d910ac58cf125..a9759d885fd73804172f86fb8000e1e98bbdac25 100644 (file)
@@ -7,7 +7,6 @@
  */
 package org.opendaylight.yangtools.sal.binding.generator.impl
 
-import java.text.SimpleDateFormat
 import java.util.Collection
 import java.util.Date
 import java.util.List
@@ -40,11 +39,16 @@ import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode
 import org.opendaylight.yangtools.yang.model.api.UsesNode
 import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition
 import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition.EnumPair
+import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil
+import com.google.common.base.CharMatcher
 
 class YangTemplate {
 
+    // FIXME: this is not thread-safe and seems to be unused!
     private static var Module module = null
 
+    private static val CharMatcher NEWLINE_OR_TAB = CharMatcher.anyOf("\n\t")
+
     def static String generateYangSnipet(SchemaNode schemaNode) {
         if (schemaNode == null)
             return ''
@@ -121,16 +125,11 @@ class YangTemplate {
         '''
     }
 
-    def static formatDate(Date moduleRevision) {
-        val SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-mm-dd")
-        return dateFormat.format(moduleRevision)
-    }
-
     def static writeRevision(Date moduleRevision, String moduleDescription) {
         val revisionIndent = 12
 
         '''
-            revision «formatDate(moduleRevision)» {
+            revision «SimpleDateFormatUtil.getRevisionFormat.format(moduleRevision)» {
                 description "«formatToParagraph(moduleDescription, revisionIndent)»";
             }
         '''
@@ -240,7 +239,7 @@ class YangTemplate {
 
         '''
             input {
-                «IF input instanceof DataSchemaNode && !input.childNodes.nullOrEmpty»
+                «IF !input.childNodes.nullOrEmpty»
                 «writeDataSchemaNodes(input.childNodes)»
                 «ENDIF»
             }
@@ -254,7 +253,7 @@ class YangTemplate {
 
         '''
             output {
-                «IF output instanceof DataSchemaNode && !output.childNodes.nullOrEmpty»
+                «IF !output.childNodes.nullOrEmpty»
                 «writeDataSchemaNodes(output.childNodes)»
                 «ENDIF»
             }
@@ -736,8 +735,7 @@ class YangTemplate {
         val lineIndent = computeNextLineIndent(nextLineIndent);
 
         formattedText = formattedText.replace("*/", "*/");
-        formattedText = formattedText.replace("\n", "");
-        formattedText = formattedText.replace("\t", "");
+        formattedText = NEWLINE_OR_TAB.removeFrom(formattedText);
         formattedText = formattedText.replaceAll(" +", " ");
 
         val StringTokenizer tokenizer = new StringTokenizer(formattedText, " ", true);
@@ -785,8 +783,7 @@ class YangTemplate {
             val ns = pathElement.namespace
             val localName = pathElement.localName
 
-            sb.append("\\")
-            sb.append('(')
+            sb.append("\\(")
             sb.append(ns)
             sb.append(')')
             sb.append(localName)