You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by pa...@apache.org on 2017/10/23 11:13:38 UTC
groovy git commit: minor refactor
Repository: groovy
Updated Branches:
refs/heads/GROOVY_2_6_X 7f7da9985 -> 5861d8106
minor refactor
Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/5861d810
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/5861d810
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/5861d810
Branch: refs/heads/GROOVY_2_6_X
Commit: 5861d8106b0872650c2964e3b957fdd503f2654e
Parents: 7f7da99
Author: paulk <pa...@asert.com.au>
Authored: Mon Oct 23 21:13:29 2017 +1000
Committer: paulk <pa...@asert.com.au>
Committed: Mon Oct 23 21:13:29 2017 +1000
----------------------------------------------------------------------
.../parser/antlr4/GroovyParserTest.groovy | 24 ++++-----
.../src/test/resources/core/Lambda_01x.groovy | 15 +-----
.../test/resources/core/Lambda_01x_1_7.groovy | 37 -------------
.../test/resources/core/Lambda_01x_1_8.groovy | 35 ++++++++++++
.../resources/core/MethodReference_01x.groovy | 54 ++++---------------
.../core/MethodReference_01x_1_7.groovy | 57 --------------------
.../core/MethodReference_01x_1_8.groovy | 49 +++++++++++++++++
7 files changed, 108 insertions(+), 163 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/groovy/blob/5861d810/subprojects/parser-antlr4/src/test/groovy/org/apache/groovy/parser/antlr4/GroovyParserTest.groovy
----------------------------------------------------------------------
diff --git a/subprojects/parser-antlr4/src/test/groovy/org/apache/groovy/parser/antlr4/GroovyParserTest.groovy b/subprojects/parser-antlr4/src/test/groovy/org/apache/groovy/parser/antlr4/GroovyParserTest.groovy
index a4227fb..40650a3 100644
--- a/subprojects/parser-antlr4/src/test/groovy/org/apache/groovy/parser/antlr4/GroovyParserTest.groovy
+++ b/subprojects/parser-antlr4/src/test/groovy/org/apache/groovy/parser/antlr4/GroovyParserTest.groovy
@@ -34,10 +34,11 @@ import static org.apache.groovy.parser.antlr4.TestUtils.doRunAndTest
* Some basic test cases for the new parser
*/
class GroovyParserTest extends GroovyTestCase {
+ private boolean jdk8orGreater
- void setUp() {}
-
- void tearDown() {}
+ void setUp() {
+ jdk8orGreater = System.getProperty('java.specification.version') >= '1.8'
+ }
void "test groovy core - Comments"() {
doTest('core/Comments_01.groovy', [ExpressionStatement])
@@ -141,18 +142,16 @@ class GroovyParserTest extends GroovyTestCase {
}
void "test groovy core - Lambda"() {
- if (Runtime.class.getPackage().getImplementationVersion().startsWith("1.7.")) {
- doRunAndTest('core/Lambda_01x_1_7.groovy')
- } else {
- doRunAndTest('core/Lambda_01x.groovy')
+ doRunAndTest('core/Lambda_01x.groovy ')
+ if (jdk8orGreater) {
+ doRunAndTest('core/Lambda_01x_1_8.groovy')
}
}
void "test groovy core - MethodReference"() {
- if (Runtime.class.getPackage().getImplementationVersion().startsWith("1.7.")) {
- doRunAndTest('core/MethodReference_01x_1_7.groovy')
- } else {
- doRunAndTest('core/MethodReference_01x.groovy')
+ doRunAndTest('core/MethodReference_01x.groovy ')
+ if (jdk8orGreater) {
+ doRunAndTest('core/MethodReference_01x_1_8.groovy')
}
}
@@ -288,7 +287,6 @@ class GroovyParserTest extends GroovyTestCase {
void "test groovy core - LocalVariableDeclaration"() {
doTest('core/LocalVariableDeclaration_01.groovy', [Token]) // [class org.codehaus.groovy.syntax.Token][startLine]:: 9 != 8
doRunAndTest('core/LocalVariableDeclaration_02x.groovy')
-
}
void "test groovy core - MethodDeclaration"() {
@@ -388,7 +386,7 @@ class GroovyParserTest extends GroovyTestCase {
doTest('bugs/BUG-GROOVY-8161.groovy')
doRunAndTest('bugs/GROOVY-3898.groovy')
doRunAndTest('bugs/BUG-GROOVY-8311.groovy')
- if (System.getProperty('java.specification.version') < '1.8') return
+ if (!jdk8orGreater) return
doRunAndTest('bugs/GROOVY-8228.groovy')
}
}
http://git-wip-us.apache.org/repos/asf/groovy/blob/5861d810/subprojects/parser-antlr4/src/test/resources/core/Lambda_01x.groovy
----------------------------------------------------------------------
diff --git a/subprojects/parser-antlr4/src/test/resources/core/Lambda_01x.groovy b/subprojects/parser-antlr4/src/test/resources/core/Lambda_01x.groovy
index 5c147ac..dbab616 100644
--- a/subprojects/parser-antlr4/src/test/resources/core/Lambda_01x.groovy
+++ b/subprojects/parser-antlr4/src/test/resources/core/Lambda_01x.groovy
@@ -16,10 +16,6 @@
* specific language governing permissions and limitations
* under the License.
*/
-assert 9 == [1, 2, 3].stream().map(e -> e + 1).reduce(0, (r, e) -> r + e)
-assert 9 == [1, 2, 3].stream().map(e -> {e + 1}).reduce(0, (r, e) -> r + e)
-assert 9 == [1, 2, 3].stream().map((e) -> e + 1).reduce(0, (r, e) -> r + e)
-assert 9 == [1, 2, 3].stream().map((e) -> e + 1).reduce(0, (r, e) -> {r + e})
assert 32 == ((e) -> e + 1)(2) + ((e, f) -> e + f)(2, 3) + ((e, f, g) -> e * f * g)(2, 3, 4)
assert 24 == ((e, f, g) -> {e * f * g})(2, 3, 4)
@@ -49,18 +45,11 @@ assert 1 == lambda(1)
lambda = e -> e + 1;
assert 2 == lambda(1)
-int sum = 0;
-[1, 2, 3].forEach(e -> {
- sum += e
-})
-assert 6 == sum;
-
def c = { (e) -> e * 2 }
assert 6 == c()(3)
c = { (e) -> { e * 2 } }
assert 6 == c()(3)
-assert ['1', '2', '3'] == [0, 1, 2].collect(e -> String.valueOf e + 1)
-assert [3, 4, 5] == ['0', '1', '2'].collect(e -> Integer.parseInt e plus 1 plus 2)
-assert [4] == ['0'].collect(e -> e.length() plus 1 plus 2)
\ No newline at end of file
+
+
http://git-wip-us.apache.org/repos/asf/groovy/blob/5861d810/subprojects/parser-antlr4/src/test/resources/core/Lambda_01x_1_7.groovy
----------------------------------------------------------------------
diff --git a/subprojects/parser-antlr4/src/test/resources/core/Lambda_01x_1_7.groovy b/subprojects/parser-antlr4/src/test/resources/core/Lambda_01x_1_7.groovy
deleted file mode 100644
index 5df9858..0000000
--- a/subprojects/parser-antlr4/src/test/resources/core/Lambda_01x_1_7.groovy
+++ /dev/null
@@ -1,37 +0,0 @@
-assert 32 == ((e) -> e + 1)(2) + ((e, f) -> e + f)(2, 3) + ((e, f, g) -> e * f * g)(2, 3, 4)
-
-assert 24 == ((e, f, g) -> {e * f * g})(2, 3, 4)
-assert 24 == ((int e, int f, int g) -> {
- int tmpE = e;
- int tmpF = f;
- int tmpG = g;
- return tmpE * tmpF * tmpG;
-})(2, 3, 4)
-assert 24 == ((int e, int f, int g=4) -> {
- int tmpE = e;
- int tmpF = f;
- int tmpG = g;
- return tmpE * tmpF * tmpG;
-})(2, 3)
-
-def list = [2, 3, 1]
-Collections.sort(list, (n1, n2) -> n1 <=> n2)
-assert [1, 2, 3] == list
-
-assert 1 == (e -> e)(1)
-assert 2 == (() -> 2)()
-
-def lambda = e -> e;
-assert 1 == lambda(1)
-
-lambda = e -> e + 1;
-assert 2 == lambda(1)
-
-def c = { (e) -> e * 2 }
-assert 6 == c()(3)
-
-c = { (e) -> { e * 2 } }
-assert 6 == c()(3)
-
-
-
http://git-wip-us.apache.org/repos/asf/groovy/blob/5861d810/subprojects/parser-antlr4/src/test/resources/core/Lambda_01x_1_8.groovy
----------------------------------------------------------------------
diff --git a/subprojects/parser-antlr4/src/test/resources/core/Lambda_01x_1_8.groovy b/subprojects/parser-antlr4/src/test/resources/core/Lambda_01x_1_8.groovy
new file mode 100644
index 0000000..81c2c35
--- /dev/null
+++ b/subprojects/parser-antlr4/src/test/resources/core/Lambda_01x_1_8.groovy
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+// additional tests that use jdk8 api calls
+
+assert 9 == [1, 2, 3].stream().map(e -> e + 1).reduce(0, (r, e) -> r + e)
+assert 9 == [1, 2, 3].stream().map(e -> {e + 1}).reduce(0, (r, e) -> r + e)
+assert 9 == [1, 2, 3].stream().map((e) -> e + 1).reduce(0, (r, e) -> r + e)
+assert 9 == [1, 2, 3].stream().map((e) -> e + 1).reduce(0, (r, e) -> {r + e})
+
+int sum = 0;
+[1, 2, 3].forEach(e -> {
+ sum += e
+})
+assert 6 == sum;
+
+assert ['1', '2', '3'] == [0, 1, 2].collect(e -> String.valueOf e + 1)
+assert [3, 4, 5] == ['0', '1', '2'].collect(e -> Integer.parseInt e plus 1 plus 2)
+assert [4] == ['0'].collect(e -> e.length() plus 1 plus 2)
http://git-wip-us.apache.org/repos/asf/groovy/blob/5861d810/subprojects/parser-antlr4/src/test/resources/core/MethodReference_01x.groovy
----------------------------------------------------------------------
diff --git a/subprojects/parser-antlr4/src/test/resources/core/MethodReference_01x.groovy b/subprojects/parser-antlr4/src/test/resources/core/MethodReference_01x.groovy
index 4816adf..dfeede3 100644
--- a/subprojects/parser-antlr4/src/test/resources/core/MethodReference_01x.groovy
+++ b/subprojects/parser-antlr4/src/test/resources/core/MethodReference_01x.groovy
@@ -16,60 +16,35 @@
* specific language governing permissions and limitations
* under the License.
*/
-import java.util.stream.Collectors
-// class::staticMethod
-assert ['1', '2', '3'] == [1, 2, 3].stream().map(Integer::toString).collect(Collectors.toList())
+def robot = new Robot()
-// class::instanceMethod
-assert ['A', 'B', 'C'] == ['a', 'b', 'c'].stream().map(String::toUpperCase).collect(Collectors.toList())
-
-
-
-def robot = new Robot();
-
-// instance::instanceMethod
-assert ['Hi, Jochen', 'Hi, Paul', 'Hi, Daniel'] == [new Person('Jochen'), new Person('Paul'), new Person('Daniel')].stream().map(robot::greet).collect(Collectors.toList())
-
-// class::staticMethod
-assert ['Jochen', 'Paul', 'Daniel'] == [new Person('Jochen'), new Person('Paul'), new Person('Daniel')].stream().map(Person::getText).collect(Collectors.toList())
-assert ['Jochen', 'Paul', 'Daniel'] == [new Person('Jochen'), new Person('Paul'), new Person('Daniel')].stream().map(BasePerson::getText).collect(Collectors.toList())
-
-// instance::staticMethod
-assert ['J', 'P', 'D'] == [new Person('Jochen'), new Person('Paul'), new Person('Daniel')].stream().map(robot::firstCharOfName).collect(Collectors.toList())
-
-// class::instanceMethod
-assert ['Jochen', 'Paul', 'Daniel'] == [new Person('Jochen'), new Person('Paul'), new Person('Daniel')].stream().map(Person::getName).collect(Collectors.toList())
-
-// class::instanceMethod
-assert 6 == java.util.stream.Stream.of(1, 2, 3).reduce(0, BigDecimal::add)
-
-// ----------------------------------
class BasePerson {
- public static String getText(Person p) {
- return p.name;
+ static String getText(Person p) {
+ return p.name
}
}
class Person extends BasePerson {
- private String name;
+ private String name
- public Person(String name) {
+ Person(String name) {
this.name = name
}
- public String getName() {
- return this.name;
+ String getName() {
+ return this.name
}
}
+
class Robot {
- public String greet(Person p) {
+ String greet(Person p) {
return "Hi, ${p.name}"
}
- public static char firstCharOfName(Person p) {
- return p.getName().charAt(0);
+ static char firstCharOfName(Person p) {
+ return p.getName().charAt(0)
}
}
@@ -85,10 +60,6 @@ assert new String[0] == String[]::new('0')
assert new String[1][2] == String[][]::new(1, 2)
assert new String[1][2][3] == String[][][]::new(1, 2, 3)
-assert [new String[1], new String[2], new String[3]] == [1, 2, 3].stream().map(String[]::new).collect(Collectors.toList())
-assert [1, 2, 3] as String[] == [1, 2, 3].stream().map(String::valueOf).toArray(String[]::new)
-
-
def a = String[][]::new(1, 2)
def b = new String[1][2]
assert a.class == b.class && a == b
@@ -100,6 +71,3 @@ assert a.class == b.class && a == b
a = String[][][][]::new(1, 2)
b = new String[1][2][][]
assert a.class == b.class && a == b
-
-
-
http://git-wip-us.apache.org/repos/asf/groovy/blob/5861d810/subprojects/parser-antlr4/src/test/resources/core/MethodReference_01x_1_7.groovy
----------------------------------------------------------------------
diff --git a/subprojects/parser-antlr4/src/test/resources/core/MethodReference_01x_1_7.groovy b/subprojects/parser-antlr4/src/test/resources/core/MethodReference_01x_1_7.groovy
deleted file mode 100644
index 25d5b1f..0000000
--- a/subprojects/parser-antlr4/src/test/resources/core/MethodReference_01x_1_7.groovy
+++ /dev/null
@@ -1,57 +0,0 @@
-
-def robot = new Robot();
-
-// ----------------------------------
-class BasePerson {
- public static String getText(Person p) {
- return p.name;
- }
-}
-
-class Person extends BasePerson {
- private String name;
-
- public Person(String name) {
- this.name = name
- }
-
- public String getName() {
- return this.name;
- }
-
-}
-class Robot {
- public String greet(Person p) {
- return "Hi, ${p.name}"
- }
-
- public static char firstCharOfName(Person p) {
- return p.getName().charAt(0);
- }
-}
-
-def mr = String::toUpperCase
-assert 'ABC' == mr('abc')
-assert 'ABC' == String::toUpperCase('abc')
-
-assert new HashSet() == HashSet::new()
-assert new String() == String::new()
-assert 1 == Integer::new(1)
-assert new String[0] == String[]::new(0)
-assert new String[0] == String[]::new('0')
-assert new String[1][2] == String[][]::new(1, 2)
-assert new String[1][2][3] == String[][][]::new(1, 2, 3)
-
-
-def a = String[][]::new(1, 2)
-def b = new String[1][2]
-assert a.class == b.class && a == b
-
-a = String[][][]::new(1, 2)
-b = new String[1][2][]
-assert a.class == b.class && a == b
-
-a = String[][][][]::new(1, 2)
-b = new String[1][2][][]
-assert a.class == b.class && a == b
-
http://git-wip-us.apache.org/repos/asf/groovy/blob/5861d810/subprojects/parser-antlr4/src/test/resources/core/MethodReference_01x_1_8.groovy
----------------------------------------------------------------------
diff --git a/subprojects/parser-antlr4/src/test/resources/core/MethodReference_01x_1_8.groovy b/subprojects/parser-antlr4/src/test/resources/core/MethodReference_01x_1_8.groovy
new file mode 100644
index 0000000..617c20a
--- /dev/null
+++ b/subprojects/parser-antlr4/src/test/resources/core/MethodReference_01x_1_8.groovy
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+// additional tests that use jdk8 api calls
+
+import java.util.stream.Collectors
+
+// class::staticMethod
+assert ['1', '2', '3'] == [1, 2, 3].stream().map(Integer::toString).collect(Collectors.toList())
+
+// class::instanceMethod
+assert ['A', 'B', 'C'] == ['a', 'b', 'c'].stream().map(String::toUpperCase).collect(Collectors.toList())
+
+
+// instance::instanceMethod
+assert ['Hi, Jochen', 'Hi, Paul', 'Hi, Daniel'] == [new Person('Jochen'), new Person('Paul'), new Person('Daniel')].stream().map(robot::greet).collect(Collectors.toList())
+
+// class::staticMethod
+assert ['Jochen', 'Paul', 'Daniel'] == [new Person('Jochen'), new Person('Paul'), new Person('Daniel')].stream().map(Person::getText).collect(Collectors.toList())
+assert ['Jochen', 'Paul', 'Daniel'] == [new Person('Jochen'), new Person('Paul'), new Person('Daniel')].stream().map(BasePerson::getText).collect(Collectors.toList())
+
+// instance::staticMethod
+assert ['J', 'P', 'D'] == [new Person('Jochen'), new Person('Paul'), new Person('Daniel')].stream().map(robot::firstCharOfName).collect(Collectors.toList())
+
+// class::instanceMethod
+assert ['Jochen', 'Paul', 'Daniel'] == [new Person('Jochen'), new Person('Paul'), new Person('Daniel')].stream().map(Person::getName).collect(Collectors.toList())
+
+// class::instanceMethod
+assert 6 == java.util.stream.Stream.of(1, 2, 3).reduce(0, BigDecimal::add)
+
+
+assert [new String[1], new String[2], new String[3]] == [1, 2, 3].stream().map(String[]::new).collect(Collectors.toList())
+assert [1, 2, 3] as String[] == [1, 2, 3].stream().map(String::valueOf).toArray(String[]::new)