[groovy] branch java13-build updated (082fe05 -> 66e85f0)

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[groovy] branch java13-build updated (082fe05 -> 66e85f0)

Daniel.Sun
This is an automated email from the ASF dual-hosted git repository.

sunlan pushed a change to branch java13-build
in repository https://gitbox.apache.org/repos/asf/groovy.git.


 discard 082fe05  Fix method conflicts
     new 66e85f0  Fix method conflicts between JDK and GDK

This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version.  This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:

 * -- * -- B -- O -- O -- O   (082fe05)
            \
             N -- N -- N   refs/heads/java13-build (66e85f0)

You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.

Any revisions marked "omit" are not gone; other references still
refer to them.  Any revisions marked "discard" are gone forever.

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../groovy/runtime/StringGroovyMethods.java        | 22 ++++++++++++++++++++--
 1 file changed, 20 insertions(+), 2 deletions(-)

Apache Groovy committer & PMC member

Blog: http://blog.sunlan.me
Twitter: @daniel_sun
Reply | Threaded
Open this post in threaded view
|

[groovy] 01/01: Fix method conflicts between JDK and GDK

Daniel.Sun
This is an automated email from the ASF dual-hosted git repository.

sunlan pushed a commit to branch java13-build
in repository https://gitbox.apache.org/repos/asf/groovy.git

commit 66e85f0e3aae1b38fc52a7564c34c8f16167facc
Author: Daniel Sun <[hidden email]>
AuthorDate: Tue Jan 14 07:59:42 2020 +0800

    Fix method conflicts between JDK and GDK
---
 .../groovy/runtime/StringGroovyMethods.java        | 28 ++++++++++++++++++++++
 .../lang/ScriptSourcePositionInAstTest.groovy      |  4 ++--
 src/test/groovy/lang/StripMarginTest.groovy        |  4 ++--
 3 files changed, 32 insertions(+), 4 deletions(-)

diff --git a/src/main/java/org/codehaus/groovy/runtime/StringGroovyMethods.java b/src/main/java/org/codehaus/groovy/runtime/StringGroovyMethods.java
index 8500643..7191e04 100644
--- a/src/main/java/org/codehaus/groovy/runtime/StringGroovyMethods.java
+++ b/src/main/java/org/codehaus/groovy/runtime/StringGroovyMethods.java
@@ -21,12 +21,14 @@ package org.codehaus.groovy.runtime;
 import groovy.lang.Closure;
 import groovy.lang.EmptyRange;
 import groovy.lang.GString;
+import groovy.lang.GroovyRuntimeException;
 import groovy.lang.IntRange;
 import groovy.lang.Range;
 import groovy.transform.stc.ClosureParams;
 import groovy.transform.stc.FromString;
 import groovy.transform.stc.PickFirstResolver;
 import org.apache.groovy.io.StringBuilderWriter;
+import org.apache.groovy.lang.annotation.Incubating;
 import org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation;
 import org.codehaus.groovy.util.CharSequenceReader;
 
@@ -34,6 +36,9 @@ import java.io.BufferedWriter;
 import java.io.File;
 import java.io.IOException;
 import java.io.Writer;
+import java.lang.invoke.MethodHandle;
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.MethodType;
 import java.math.BigDecimal;
 import java.math.BigInteger;
 import java.util.ArrayList;
@@ -2600,6 +2605,29 @@ public class StringGroovyMethods extends DefaultGroovyMethodsSupport {
     }
 
     /**
+     * Same logic to {@link #stripIndent(CharSequence)} if {@code forceGroovyBehavior} is {@code true},
+     * otherwise Java13's {@code stripIndent} will be invoked
+     *
+     * @param self The CharSequence to strip the leading spaces from
+     * @param forceGroovyBehavior force groovy behavior to avoid conflicts with Java13's stripIndent
+     * @since 3.0.0
+     */
+    @Incubating
+    public static String stripIndent(CharSequence self, boolean forceGroovyBehavior) {
+        if (!forceGroovyBehavior) {
+            try {
+                MethodHandle mh = MethodHandles.lookup().findVirtual(self.getClass(), "stripIndent", MethodType.methodType(String.class));
+                return (String) mh.bindTo(self).invokeWithArguments();
+            } catch (NoSuchMethodException | IllegalAccessException ignored) {
+            } catch (Throwable t) {
+                throw new GroovyRuntimeException(t);
+            }
+        }
+
+        return stripIndent(self);
+    }
+
+    /**
      * Strip <tt>numChar</tt> leading characters from
      * every line in a CharSequence.
      * <pre class="groovyTestCase">
diff --git a/src/test/groovy/lang/ScriptSourcePositionInAstTest.groovy b/src/test/groovy/lang/ScriptSourcePositionInAstTest.groovy
index 9c96f21..a883535 100644
--- a/src/test/groovy/lang/ScriptSourcePositionInAstTest.groovy
+++ b/src/test/groovy/lang/ScriptSourcePositionInAstTest.groovy
@@ -49,7 +49,7 @@ class ScriptSourcePositionInAstTest extends GroovyTestCase {
         assert positionsForScript("""\
             println 'hello'
             println 'bye'
-        """.stripIndent()) == [[1, 1], [2, 14]]
+        """.stripIndent(true)) == [[1, 1], [2, 14]]
     }
 
     void testScriptWithClasses() {
@@ -58,6 +58,6 @@ class ScriptSourcePositionInAstTest extends GroovyTestCase {
             println 'hello'
             println 'bye'
             class Baz{}
-        """.stripIndent()) == [[2, 1], [3, 14]]
+        """.stripIndent(true)) == [[2, 1], [3, 14]]
     }
 }
diff --git a/src/test/groovy/lang/StripMarginTest.groovy b/src/test/groovy/lang/StripMarginTest.groovy
index 9862b4b..e37e2fd 100644
--- a/src/test/groovy/lang/StripMarginTest.groovy
+++ b/src/test/groovy/lang/StripMarginTest.groovy
@@ -57,7 +57,7 @@ class StripMarginTest extends GroovyTestCase {
             def method() {
                 return 'bar'
             }
-        """.stripIndent()
+        """.stripIndent(true)
 
         def expected = """
     return 'foo'
@@ -79,7 +79,7 @@ def method() {
             def method() {
                 return 'bar'
             }
-        """.stripIndent()
+        """.stripIndent(true)
         
         def expected = """\
     return 'foo'

Apache Groovy committer & PMC member

Blog: http://blog.sunlan.me
Twitter: @daniel_sun