Repository: groovy
Updated Branches:
  refs/heads/GROOVY_2_6_X 139d3ade9 -> d00b01834


Minor refactoring: remove duplicated code and add `serialVersionUID`

(cherry picked from commit 0aba754)


Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/d00b0183
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/d00b0183
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/d00b0183

Branch: refs/heads/GROOVY_2_6_X
Commit: d00b0183443e1a890b65c812f81d010cd88862ae
Parents: 139d3ad
Author: sunlan <sun...@apache.org>
Authored: Sat Feb 24 12:35:14 2018 +0800
Committer: sunlan <sun...@apache.org>
Committed: Sat Feb 24 12:36:09 2018 +0800

----------------------------------------------------------------------
 .../groovy/text/GStringTemplateEngine.java      | 19 +++++++----------
 .../groovy/text/StreamingTemplateEngine.java    | 22 +++++++++-----------
 .../groovy/text/TemplateExecutionException.java |  1 +
 .../groovy/text/TemplateParseException.java     |  1 +
 .../text/markup/AutoNewLineTransformer.java     |  4 ++--
 .../groovy/groovy/text/markup/BaseTemplate.java |  2 ++
 6 files changed, 23 insertions(+), 26 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/d00b0183/subprojects/groovy-templates/src/main/groovy/groovy/text/GStringTemplateEngine.java
----------------------------------------------------------------------
diff --git 
a/subprojects/groovy-templates/src/main/groovy/groovy/text/GStringTemplateEngine.java
 
b/subprojects/groovy-templates/src/main/groovy/groovy/text/GStringTemplateEngine.java
index a4a99d1..f6cf414 100644
--- 
a/subprojects/groovy-templates/src/main/groovy/groovy/text/GStringTemplateEngine.java
+++ 
b/subprojects/groovy-templates/src/main/groovy/groovy/text/GStringTemplateEngine.java
@@ -262,6 +262,12 @@ public class GStringTemplateEngine extends TemplateEngine {
             }
             templateExpressions.append((char) pendingC);
 
+            readAndAppend(reader, templateExpressions);
+
+            templateExpressions.append(";\n ");
+        }
+
+        private static void readAndAppend(Reader reader, StringBuilder 
templateExpressions) throws IOException {
             while (true) {
                 int c = reader.read();
                 if (c == -1) break;
@@ -272,8 +278,6 @@ public class GStringTemplateEngine extends TemplateEngine {
                 }
                 templateExpressions.append((char) c);
             }
-
-            templateExpressions.append(";\n ");
         }
 
         /**
@@ -294,16 +298,7 @@ public class GStringTemplateEngine extends TemplateEngine {
 
             templateExpressions.append("${");
 
-            while (true) {
-                int c = reader.read();
-                if (c == -1) break;
-                if (c == '%') {
-                    c = reader.read();
-                    if (c == '>') break;
-                    templateExpressions.append('%');
-                }
-                templateExpressions.append((char) c);
-            }
+            readAndAppend(reader, templateExpressions);
 
             templateExpressions.append('}');
         }

http://git-wip-us.apache.org/repos/asf/groovy/blob/d00b0183/subprojects/groovy-templates/src/main/groovy/groovy/text/StreamingTemplateEngine.java
----------------------------------------------------------------------
diff --git 
a/subprojects/groovy-templates/src/main/groovy/groovy/text/StreamingTemplateEngine.java
 
b/subprojects/groovy-templates/src/main/groovy/groovy/text/StreamingTemplateEngine.java
index 6d1640e..6b8433a 100644
--- 
a/subprojects/groovy-templates/src/main/groovy/groovy/text/StreamingTemplateEngine.java
+++ 
b/subprojects/groovy-templates/src/main/groovy/groovy/text/StreamingTemplateEngine.java
@@ -261,7 +261,9 @@ public class StreamingTemplateEngine extends TemplateEngine 
{
 
         String scriptSource;
 
-        private static class FinishedReadingException extends Exception {}
+        private static class FinishedReadingException extends Exception {
+            private static final long serialVersionUID = -3786157136157691230L;
+        }
 
         //WE USE THIS AS REUSABLE        
         //CHECKSTYLE.OFF: ConstantNameCheck - special case with a reusable 
exception
@@ -744,6 +746,12 @@ public class StreamingTemplateEngine extends 
TemplateEngine {
             append(target, targetPosition, "          ");
             append(target, targetPosition, (char) pendingC);
 
+            readAndAppend(reader, target, sourcePosition, targetPosition);
+
+            append(target, targetPosition, ';');
+        }
+
+        private void readAndAppend(Reader reader, StringBuilder target, 
Position sourcePosition, Position targetPosition) throws IOException, 
FinishedReadingException {
             while (true) {
                 int c = read(reader, sourcePosition);
                 if (c == '%') {
@@ -753,8 +761,6 @@ public class StreamingTemplateEngine extends TemplateEngine 
{
                 }
                 append(target, targetPosition, (char) c);
             }
-
-            append(target, targetPosition, ';');
         }
 
         /**
@@ -766,15 +772,7 @@ public class StreamingTemplateEngine extends 
TemplateEngine {
                 final Position targetPosition) throws IOException, 
FinishedReadingException {
             append(target, targetPosition, "out<<\"\"\"${");
 
-            while (true) {
-                int c = read(reader, sourcePosition);
-                if (c == '%') {
-                    c = read(reader, sourcePosition);
-                    if (c == '>') break;
-                    append(target, targetPosition, '%');
-                }
-                append(target, targetPosition, (char) c);
-            }
+            readAndAppend(reader, target, sourcePosition, targetPosition);
 
             append(target, targetPosition, "}\"\"\";");
         }

http://git-wip-us.apache.org/repos/asf/groovy/blob/d00b0183/subprojects/groovy-templates/src/main/groovy/groovy/text/TemplateExecutionException.java
----------------------------------------------------------------------
diff --git 
a/subprojects/groovy-templates/src/main/groovy/groovy/text/TemplateExecutionException.java
 
b/subprojects/groovy-templates/src/main/groovy/groovy/text/TemplateExecutionException.java
index 641d4e4..49643c2 100644
--- 
a/subprojects/groovy-templates/src/main/groovy/groovy/text/TemplateExecutionException.java
+++ 
b/subprojects/groovy-templates/src/main/groovy/groovy/text/TemplateExecutionException.java
@@ -22,6 +22,7 @@ package groovy.text;
  * A custom exception class to flag template execution errors
  */
 public class TemplateExecutionException extends Exception  {
+    private static final long serialVersionUID = 3940987189684210921L;
     private int lineNumber;
 
     public TemplateExecutionException(int lineNumber) {

http://git-wip-us.apache.org/repos/asf/groovy/blob/d00b0183/subprojects/groovy-templates/src/main/groovy/groovy/text/TemplateParseException.java
----------------------------------------------------------------------
diff --git 
a/subprojects/groovy-templates/src/main/groovy/groovy/text/TemplateParseException.java
 
b/subprojects/groovy-templates/src/main/groovy/groovy/text/TemplateParseException.java
index aed3eda..d24c0cd 100644
--- 
a/subprojects/groovy-templates/src/main/groovy/groovy/text/TemplateParseException.java
+++ 
b/subprojects/groovy-templates/src/main/groovy/groovy/text/TemplateParseException.java
@@ -22,6 +22,7 @@ package groovy.text;
  * A custom exception class to flag template parsing errors
  */
 public class TemplateParseException extends RuntimeException {
+    private static final long serialVersionUID = 1607958968337123274L;
     private int lineNumber;
     private int column;
 

http://git-wip-us.apache.org/repos/asf/groovy/blob/d00b0183/subprojects/groovy-templates/src/main/groovy/groovy/text/markup/AutoNewLineTransformer.java
----------------------------------------------------------------------
diff --git 
a/subprojects/groovy-templates/src/main/groovy/groovy/text/markup/AutoNewLineTransformer.java
 
b/subprojects/groovy-templates/src/main/groovy/groovy/text/markup/AutoNewLineTransformer.java
index a9950d8..8662743 100644
--- 
a/subprojects/groovy-templates/src/main/groovy/groovy/text/markup/AutoNewLineTransformer.java
+++ 
b/subprojects/groovy-templates/src/main/groovy/groovy/text/markup/AutoNewLineTransformer.java
@@ -32,7 +32,7 @@ import org.codehaus.groovy.ast.stmt.ExpressionStatement;
 import org.codehaus.groovy.ast.stmt.Statement;
 import org.codehaus.groovy.control.SourceUnit;
 
-import java.util.Arrays;
+import java.util.Collections;
 import java.util.List;
 
 /**
@@ -84,7 +84,7 @@ class AutoNewLineTransformer extends ClassCodeVisitorSupport {
             Statement oldCode = expression.getCode();
             BlockStatement block = oldCode instanceof BlockStatement?
                     ((BlockStatement)oldCode):
-                    new BlockStatement(Arrays.asList(oldCode), new 
VariableScope());
+                    new BlockStatement(Collections.singletonList(oldCode), new 
VariableScope());
             List<Statement> statements = block.getStatements();
             if (!statements.isEmpty()) {
                 Statement first = statements.get(0);

http://git-wip-us.apache.org/repos/asf/groovy/blob/d00b0183/subprojects/groovy-templates/src/main/groovy/groovy/text/markup/BaseTemplate.java
----------------------------------------------------------------------
diff --git 
a/subprojects/groovy-templates/src/main/groovy/groovy/text/markup/BaseTemplate.java
 
b/subprojects/groovy-templates/src/main/groovy/groovy/text/markup/BaseTemplate.java
index 02ed5c6..0ceaccc 100644
--- 
a/subprojects/groovy-templates/src/main/groovy/groovy/text/markup/BaseTemplate.java
+++ 
b/subprojects/groovy-templates/src/main/groovy/groovy/text/markup/BaseTemplate.java
@@ -435,6 +435,8 @@ public abstract class BaseTemplate implements Writable {
      */
     public Closure contents(final Closure cl) {
         return new Closure(cl.getOwner(), cl.getThisObject()) {
+            private static final long serialVersionUID = -5733727697043906478L;
+
             @Override
             public Object call() {
                 cl.call();

Reply via email to