Bump to odlparent-6.0.0-SNAPSHOT
[yangtools.git] / binding / mdsal-binding-java-api-generator / src / main / java / org / opendaylight / mdsal / binding / java / api / generator / BaseTemplate.xtend
index a3aca129c5d36377c622b1bd28a00944da833ba0..529b1f00e39b4d5afd81f25d754bc77f9e752f7f 100644 (file)
@@ -15,9 +15,11 @@ import com.google.common.base.Splitter
 import com.google.common.collect.Iterables
 import java.util.Collection
 import java.util.List
+import java.util.Locale
 import java.util.Map.Entry
 import java.util.StringTokenizer
 import java.util.regex.Pattern
+import org.gaul.modernizer_maven_annotations.SuppressModernizer
 import org.opendaylight.mdsal.binding.model.api.ConcreteType
 import org.opendaylight.mdsal.binding.model.api.Constant
 import org.opendaylight.mdsal.binding.model.api.GeneratedProperty
@@ -45,13 +47,14 @@ import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement
 import org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement
 import org.opendaylight.yangtools.yang.model.export.DeclaredStatementFormatter
 
+@SuppressModernizer
 abstract class BaseTemplate extends JavaFileTemplate {
     static final char NEW_LINE = '\n'
+    static final char SPACE = ' '
     static val AMP_MATCHER = CharMatcher.is('&')
-    static val NL_MATCHER = CharMatcher.is(NEW_LINE)
-    static val TAB_MATCHER = CharMatcher.is('\t')
+    static val WS_MATCHER = CharMatcher.anyOf("\n\t")
     static val SPACES_PATTERN = Pattern.compile(" +")
-    static val NL_SPLITTER = Splitter.on(NL_MATCHER)
+    static val NL_SPLITTER = Splitter.on(NEW_LINE)
     static val TAIL_COMMENT_PATTERN = Pattern.compile("*/", Pattern.LITERAL);
     static val YANG_FORMATTER = DeclaredStatementFormatter.builder()
         .addIgnoredStatement(YangStmtMapping.CONTACT)
@@ -163,14 +166,11 @@ abstract class BaseTemplate extends JavaFileTemplate {
      * @return string with comment in JAVA format
      */
     def protected CharSequence asJavadoc(String comment) {
-        if(comment === null) return ''
-        var txt = comment
-
-        txt = comment.trim
-        txt = formatToParagraph(txt)
-
+        if (comment === null) {
+            return ''
+        }
         return '''
-            «wrapToDocumentation(txt
+            «wrapToDocumentation(formatToParagraph(comment.trim)
         '''
     }
 
@@ -182,8 +182,7 @@ abstract class BaseTemplate extends JavaFileTemplate {
         for (String t : NL_SPLITTER.split(text)) {
             sb.append(" *")
             if (!t.isEmpty()) {
-                sb.append(' ');
-                sb.append(t)
+                sb.append(SPACE).append(t)
             }
             sb.append(NEW_LINE)
         }
@@ -333,7 +332,7 @@ abstract class BaseTemplate extends JavaFileTemplate {
     def asLink(String text) {
         val StringBuilder sb = new StringBuilder()
         var tempText = text
-        var char lastChar = ' '
+        var char lastChar = SPACE
         var boolean badEnding = false
 
         if (text.endsWith('.') || text.endsWith(':') || text.endsWith(',')) {
@@ -363,16 +362,17 @@ abstract class BaseTemplate extends JavaFileTemplate {
         var boolean isFirstElementOnNewLineEmptyChar = false;
 
         formattedText = encodeJavadocSymbols(formattedText)
-        formattedText = NL_MATCHER.removeFrom(formattedText)
-        formattedText = TAB_MATCHER.removeFrom(formattedText)
+        formattedText = WS_MATCHER.replaceFrom(formattedText, SPACE)
         formattedText = SPACES_PATTERN.matcher(formattedText).replaceAll(" ")
 
         val StringTokenizer tokenizer = new StringTokenizer(formattedText, " ", true);
 
-        while (tokenizer.hasMoreElements) {
-            val nextElement = tokenizer.nextElement.toString
+        while (tokenizer.hasMoreTokens) {
+            val nextElement = tokenizer.nextToken
 
             if (lineBuilder.length != 0 && lineBuilder.length + nextElement.length > 80) {
+                // FIXME: what tricks are we playing here? Equality probably does not trigger ever
+                //        and then the setLength()/append() combo does not work, either
                 if (lineBuilder.charAt(lineBuilder.length - 1) == ' ') {
                     lineBuilder.setLength(0)
                     lineBuilder.append(lineBuilder.substring(0, lineBuilder.length - 1))
@@ -382,27 +382,22 @@ abstract class BaseTemplate extends JavaFileTemplate {
                     lineBuilder.append(lineBuilder.substring(1))
                 }
 
-                sb.append(lineBuilder);
+                sb.append(lineBuilder).append(NEW_LINE)
                 lineBuilder.setLength(0)
-                sb.append(NEW_LINE)
 
-                if(nextElement.toString == ' ') {
+                if (nextElement == " ") {
                     isFirstElementOnNewLineEmptyChar = !isFirstElementOnNewLineEmptyChar;
                 }
             }
 
             if (isFirstElementOnNewLineEmptyChar) {
                 isFirstElementOnNewLineEmptyChar = !isFirstElementOnNewLineEmptyChar
-            }
-
-            else {
+            } else {
                 lineBuilder.append(nextElement)
             }
         }
-        sb.append(lineBuilder)
-        sb.append(NEW_LINE)
 
-        return sb.toString
+        return sb.append(lineBuilder).append(NEW_LINE).toString
     }
 
     def protected generateToString(Collection<GeneratedProperty> properties) '''
@@ -468,7 +463,7 @@ abstract class BaseTemplate extends JavaFileTemplate {
            «ENDIF»
        «ENDIF»
 
-       «val fieldUpperCase = property.fieldName.toString.toUpperCase()»
+       «val fieldUpperCase = property.fieldName.toString.toUpperCase(Locale.ENGLISH
        «FOR currentConstant : type.getConstantDefinitions»
            «IF currentConstant.getName.startsWith(TypeConstants.PATTERN_CONSTANT_NAME)
                && fieldUpperCase.equals(currentConstant.getName.substring(TypeConstants.PATTERN_CONSTANT_NAME.length))»