groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sun...@apache.org
Subject [3/7] groovy git commit: Rename element getters of tuples to support groovy style better
Date Sat, 17 Nov 2018 17:28:15 GMT
http://git-wip-us.apache.org/repos/asf/groovy/blob/c5e83397/src/main/groovy/groovy/util/function/Function8.java
----------------------------------------------------------------------
diff --git a/src/main/groovy/groovy/util/function/Function8.java b/src/main/groovy/groovy/util/function/Function8.java
index 5729d84..21544bb 100644
--- a/src/main/groovy/groovy/util/function/Function8.java
+++ b/src/main/groovy/groovy/util/function/Function8.java
@@ -42,7 +42,7 @@ public interface Function8<T1, T2, T3, T4, T5, T6, T7, T8, R> {
      * @param args The arguments as a tuple.
      */
     default R apply(Tuple8<? extends T1, ? extends T2, ? extends T3, ? extends T4, ? extends
T5, ? extends T6, ? extends T7, ? extends T8> args) {
-        return apply(args.v1(), args.v2(), args.v3(), args.v4(), args.v5(), args.v6(), args.v7(),
args.v8());
+        return apply(args.getV1(), args.getV2(), args.getV3(), args.getV4(), args.getV5(),
args.getV6(), args.getV7(), args.getV8());
     }
 
     /**
@@ -110,56 +110,56 @@ public interface Function8<T1, T2, T3, T4, T5, T6, T7, T8, R>
{
      * Partially apply this function to the arguments.
      */
     default Function7<T2, T3, T4, T5, T6, T7, T8, R> applyPartially(Tuple1<? extends
T1> args) {
-        return (v2, v3, v4, v5, v6, v7, v8) -> apply(args.v1(), v2, v3, v4, v5, v6, v7,
v8);
+        return (v2, v3, v4, v5, v6, v7, v8) -> apply(args.getV1(), v2, v3, v4, v5, v6,
v7, v8);
     }
 
     /**
      * Partially apply this function to the arguments.
      */
     default Function6<T3, T4, T5, T6, T7, T8, R> applyPartially(Tuple2<? extends
T1, ? extends T2> args) {
-        return (v3, v4, v5, v6, v7, v8) -> apply(args.v1(), args.v2(), v3, v4, v5, v6,
v7, v8);
+        return (v3, v4, v5, v6, v7, v8) -> apply(args.getV1(), args.getV2(), v3, v4, v5,
v6, v7, v8);
     }
 
     /**
      * Partially apply this function to the arguments.
      */
     default Function5<T4, T5, T6, T7, T8, R> applyPartially(Tuple3<? extends T1,
? extends T2, ? extends T3> args) {
-        return (v4, v5, v6, v7, v8) -> apply(args.v1(), args.v2(), args.v3(), v4, v5,
v6, v7, v8);
+        return (v4, v5, v6, v7, v8) -> apply(args.getV1(), args.getV2(), args.getV3(),
v4, v5, v6, v7, v8);
     }
 
     /**
      * Partially apply this function to the arguments.
      */
     default Function4<T5, T6, T7, T8, R> applyPartially(Tuple4<? extends T1, ? extends
T2, ? extends T3, ? extends T4> args) {
-        return (v5, v6, v7, v8) -> apply(args.v1(), args.v2(), args.v3(), args.v4(), v5,
v6, v7, v8);
+        return (v5, v6, v7, v8) -> apply(args.getV1(), args.getV2(), args.getV3(), args.getV4(),
v5, v6, v7, v8);
     }
 
     /**
      * Partially apply this function to the arguments.
      */
     default Function3<T6, T7, T8, R> applyPartially(Tuple5<? extends T1, ? extends
T2, ? extends T3, ? extends T4, ? extends T5> args) {
-        return (v6, v7, v8) -> apply(args.v1(), args.v2(), args.v3(), args.v4(), args.v5(),
v6, v7, v8);
+        return (v6, v7, v8) -> apply(args.getV1(), args.getV2(), args.getV3(), args.getV4(),
args.getV5(), v6, v7, v8);
     }
 
     /**
      * Partially apply this function to the arguments.
      */
     default Function2<T7, T8, R> applyPartially(Tuple6<? extends T1, ? extends T2,
? extends T3, ? extends T4, ? extends T5, ? extends T6> args) {
-        return (v7, v8) -> apply(args.v1(), args.v2(), args.v3(), args.v4(), args.v5(),
args.v6(), v7, v8);
+        return (v7, v8) -> apply(args.getV1(), args.getV2(), args.getV3(), args.getV4(),
args.getV5(), args.getV6(), v7, v8);
     }
 
     /**
      * Partially apply this function to the arguments.
      */
     default Function1<T8, R> applyPartially(Tuple7<? extends T1, ? extends T2, ?
extends T3, ? extends T4, ? extends T5, ? extends T6, ? extends T7> args) {
-        return (v8) -> apply(args.v1(), args.v2(), args.v3(), args.v4(), args.v5(), args.v6(),
args.v7(), v8);
+        return (v8) -> apply(args.getV1(), args.getV2(), args.getV3(), args.getV4(), args.getV5(),
args.getV6(), args.getV7(), v8);
     }
 
     /**
      * Partially apply this function to the arguments.
      */
     default Function0<R> applyPartially(Tuple8<? extends T1, ? extends T2, ? extends
T3, ? extends T4, ? extends T5, ? extends T6, ? extends T7, ? extends T8> args) {
-        return () -> apply(args.v1(), args.v2(), args.v3(), args.v4(), args.v5(), args.v6(),
args.v7(), args.v8());
+        return () -> apply(args.getV1(), args.getV2(), args.getV3(), args.getV4(), args.getV5(),
args.getV6(), args.getV7(), args.getV8());
     }
 
 }

http://git-wip-us.apache.org/repos/asf/groovy/blob/c5e83397/src/main/groovy/groovy/util/function/Function9.java
----------------------------------------------------------------------
diff --git a/src/main/groovy/groovy/util/function/Function9.java b/src/main/groovy/groovy/util/function/Function9.java
index a82be5e..59af2bb 100644
--- a/src/main/groovy/groovy/util/function/Function9.java
+++ b/src/main/groovy/groovy/util/function/Function9.java
@@ -43,7 +43,7 @@ public interface Function9<T1, T2, T3, T4, T5, T6, T7, T8, T9, R>
{
      * @param args The arguments as a tuple.
      */
     default R apply(Tuple9<? extends T1, ? extends T2, ? extends T3, ? extends T4, ? extends
T5, ? extends T6, ? extends T7, ? extends T8, ? extends T9> args) {
-        return apply(args.v1(), args.v2(), args.v3(), args.v4(), args.v5(), args.v6(), args.v7(),
args.v8(), args.v9());
+        return apply(args.getV1(), args.getV2(), args.getV3(), args.getV4(), args.getV5(),
args.getV6(), args.getV7(), args.getV8(), args.getV9());
     }
 
     /**
@@ -118,63 +118,63 @@ public interface Function9<T1, T2, T3, T4, T5, T6, T7, T8, T9, R>
{
      * Partially apply this function to the arguments.
      */
     default Function8<T2, T3, T4, T5, T6, T7, T8, T9, R> applyPartially(Tuple1<?
extends T1> args) {
-        return (v2, v3, v4, v5, v6, v7, v8, v9) -> apply(args.v1(), v2, v3, v4, v5, v6,
v7, v8, v9);
+        return (v2, v3, v4, v5, v6, v7, v8, v9) -> apply(args.getV1(), v2, v3, v4, v5,
v6, v7, v8, v9);
     }
 
     /**
      * Partially apply this function to the arguments.
      */
     default Function7<T3, T4, T5, T6, T7, T8, T9, R> applyPartially(Tuple2<? extends
T1, ? extends T2> args) {
-        return (v3, v4, v5, v6, v7, v8, v9) -> apply(args.v1(), args.v2(), v3, v4, v5,
v6, v7, v8, v9);
+        return (v3, v4, v5, v6, v7, v8, v9) -> apply(args.getV1(), args.getV2(), v3, v4,
v5, v6, v7, v8, v9);
     }
 
     /**
      * Partially apply this function to the arguments.
      */
     default Function6<T4, T5, T6, T7, T8, T9, R> applyPartially(Tuple3<? extends
T1, ? extends T2, ? extends T3> args) {
-        return (v4, v5, v6, v7, v8, v9) -> apply(args.v1(), args.v2(), args.v3(), v4,
v5, v6, v7, v8, v9);
+        return (v4, v5, v6, v7, v8, v9) -> apply(args.getV1(), args.getV2(), args.getV3(),
v4, v5, v6, v7, v8, v9);
     }
 
     /**
      * Partially apply this function to the arguments.
      */
     default Function5<T5, T6, T7, T8, T9, R> applyPartially(Tuple4<? extends T1,
? extends T2, ? extends T3, ? extends T4> args) {
-        return (v5, v6, v7, v8, v9) -> apply(args.v1(), args.v2(), args.v3(), args.v4(),
v5, v6, v7, v8, v9);
+        return (v5, v6, v7, v8, v9) -> apply(args.getV1(), args.getV2(), args.getV3(),
args.getV4(), v5, v6, v7, v8, v9);
     }
 
     /**
      * Partially apply this function to the arguments.
      */
     default Function4<T6, T7, T8, T9, R> applyPartially(Tuple5<? extends T1, ? extends
T2, ? extends T3, ? extends T4, ? extends T5> args) {
-        return (v6, v7, v8, v9) -> apply(args.v1(), args.v2(), args.v3(), args.v4(), args.v5(),
v6, v7, v8, v9);
+        return (v6, v7, v8, v9) -> apply(args.getV1(), args.getV2(), args.getV3(), args.getV4(),
args.getV5(), v6, v7, v8, v9);
     }
 
     /**
      * Partially apply this function to the arguments.
      */
     default Function3<T7, T8, T9, R> applyPartially(Tuple6<? extends T1, ? extends
T2, ? extends T3, ? extends T4, ? extends T5, ? extends T6> args) {
-        return (v7, v8, v9) -> apply(args.v1(), args.v2(), args.v3(), args.v4(), args.v5(),
args.v6(), v7, v8, v9);
+        return (v7, v8, v9) -> apply(args.getV1(), args.getV2(), args.getV3(), args.getV4(),
args.getV5(), args.getV6(), v7, v8, v9);
     }
 
     /**
      * Partially apply this function to the arguments.
      */
     default Function2<T8, T9, R> applyPartially(Tuple7<? extends T1, ? extends T2,
? extends T3, ? extends T4, ? extends T5, ? extends T6, ? extends T7> args) {
-        return (v8, v9) -> apply(args.v1(), args.v2(), args.v3(), args.v4(), args.v5(),
args.v6(), args.v7(), v8, v9);
+        return (v8, v9) -> apply(args.getV1(), args.getV2(), args.getV3(), args.getV4(),
args.getV5(), args.getV6(), args.getV7(), v8, v9);
     }
 
     /**
      * Partially apply this function to the arguments.
      */
     default Function1<T9, R> applyPartially(Tuple8<? extends T1, ? extends T2, ?
extends T3, ? extends T4, ? extends T5, ? extends T6, ? extends T7, ? extends T8> args)
{
-        return (v9) -> apply(args.v1(), args.v2(), args.v3(), args.v4(), args.v5(), args.v6(),
args.v7(), args.v8(), v9);
+        return (v9) -> apply(args.getV1(), args.getV2(), args.getV3(), args.getV4(), args.getV5(),
args.getV6(), args.getV7(), args.getV8(), v9);
     }
 
     /**
      * Partially apply this function to the arguments.
      */
     default Function0<R> applyPartially(Tuple9<? extends T1, ? extends T2, ? extends
T3, ? extends T4, ? extends T5, ? extends T6, ? extends T7, ? extends T8, ? extends T9>
args) {
-        return () -> apply(args.v1(), args.v2(), args.v3(), args.v4(), args.v5(), args.v6(),
args.v7(), args.v8(), args.v9());
+        return () -> apply(args.getV1(), args.getV2(), args.getV3(), args.getV4(), args.getV5(),
args.getV6(), args.getV7(), args.getV8(), args.getV9());
     }
 
 }

http://git-wip-us.apache.org/repos/asf/groovy/blob/c5e83397/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
index f9b0a2a..284fc72 100644
--- a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
+++ b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
@@ -1147,7 +1147,7 @@ public class StaticTypeCheckingVisitor extends ClassCodeVisitorSupport
{
                     GenericsType[] genericsTypes = cn.getGenericsTypes();
                     for (int j = 0; j < i; j++) {
                         // the index of element in tuple starts with 1
-                        MethodCallExpression mce = new MethodCallExpression(expression, "v"
+ (j + 1), ArgumentListExpression.EMPTY_ARGUMENTS);
+                        MethodCallExpression mce = new MethodCallExpression(expression, "getV"
+ (j + 1), ArgumentListExpression.EMPTY_ARGUMENTS);
                         ClassNode elementType = null != genericsTypes ? genericsTypes[j].getType()
: ClassHelper.OBJECT_TYPE;
                         mce.setType(elementType);
                         storeType(mce, elementType);

http://git-wip-us.apache.org/repos/asf/groovy/blob/c5e83397/src/test/groovy/lang/TupleTest.java
----------------------------------------------------------------------
diff --git a/src/test/groovy/lang/TupleTest.java b/src/test/groovy/lang/TupleTest.java
index 45c71a8..1e49736 100644
--- a/src/test/groovy/lang/TupleTest.java
+++ b/src/test/groovy/lang/TupleTest.java
@@ -18,10 +18,10 @@
  */
 package groovy.lang;
 
+import groovy.util.GroovyTestCase;
 import groovy.util.function.Consumer0;
 import groovy.util.function.Consumer1;
 import groovy.util.function.Consumer2;
-import junit.framework.TestCase;
 
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -47,7 +47,7 @@ import static java.util.stream.Collectors.mapping;
 /**
  * @author James Strachan
  */
-public class TupleTest extends TestCase {
+public class TupleTest extends GroovyTestCase {
 
     final Object[] data = {"a", "b", "c"};
     final Tuple t = new Tuple(data);
@@ -617,4 +617,11 @@ public class TupleTest extends TestCase {
         assertEquals(3, result);
     }
 
+    public void testGroovyStyleAccessor() {
+        try {
+            assertScript("def t = new Tuple1<String>('Daniel'); assert 'Daniel' ==
t.v1");
+        } catch (Exception e) {
+            assert false: e.getMessage();
+        }
+    }
 }


Mime
View raw message