changeset 6379:a5509d6347cf

Changes: *) Revert temporary workarounds to javac issue with spurious functional interface errors *) Fix tests in jdk/combo-tests to use new default method syntax
author mcimadamore
date Wed, 07 Nov 2012 11:42:56 +0000
parents 943163d2acab
children b734873a4c79
files combo-tests/tests/tools/javac/lambda/DefaultMethodAddTest.java combo-tests/tests/tools/javac/lambda/DefaultMethodRemoveTest.java combo-tests/tests/tools/javac/lambda/SourceTargetVersionTest.java src/share/classes/java/util/streams/Streams.java test-ng/tests/org/openjdk/tests/java/util/LambdaTestHelpers.java
diffstat 5 files changed, 26 insertions(+), 33 deletions(-) [+]
line wrap: on
line diff
--- a/combo-tests/tests/tools/javac/lambda/DefaultMethodAddTest.java	Wed Nov 07 11:12:21 2012 +0100
+++ b/combo-tests/tests/tools/javac/lambda/DefaultMethodAddTest.java	Wed Nov 07 11:42:56 2012 +0000
@@ -39,7 +39,7 @@
     String interfaceB =         "interface B #{SHAPE.B_DECL} {}";
     
     @SourceFile(value="A.java", group="B")
-    String interfaceA =         "interface A { String m() default { return \"A\"; } }";
+    String interfaceA =         "interface A { default String m() { return \"A\"; } }";
     
     @SourceFile(value="C.java", group="B")
     String classC = "#{SHAPE.C}";
@@ -62,20 +62,28 @@
         try {
             result = (String) m.invoke(obj);
         } catch (InvocationTargetException ex) {
-            output = ex.getCause().toString();            
+            output = ex.getCause().toString();
         }        
         if(shapeType == CShapes.C_B_A) {
-            if(addType == AddType.ADD)
+            if(addType == AddType.ADD) {
+                assertEquals(output, null);
                 assertEquals(result, "B");
+            }
             else //redeclare
                 assertEquals(output, "java.lang.AbstractMethodError: Method B.m()Ljava/lang/String; is abstract");
         }
-        else if(shapeType == CShapes.C_I_AB2)
+        else if(shapeType == CShapes.C_I_AB2) {
+            assertEquals(output, null);
             assertEquals(result, "A");
-        else if(shapeType == CShapes.C_CI)
+        }
+        else if(shapeType == CShapes.C_CI) {
+            assertEquals(output, null);
             assertEquals(result, "D");
-        else if(shapeType == CShapes.C_I_AB3)
+        }
+        else if(shapeType == CShapes.C_I_AB3) {
+            assertEquals(output, null);
             assertEquals(result, "AB");
+        }
         else            
             assertTrue(output.matches("java.lang.AbstractMethodError: Conflicting default methods: .+[.]m .+[.]m"));        
     }
@@ -93,11 +101,11 @@
            "class C implements AB {}"),
         //class C implments interface AB, AB extends interface A, B and explicitly inherits the default method in A
         C_I_AB2("", 
-        "interface AB extends A, B { String m() default { return A.super.m(); } }\n" + 
+        "interface AB extends A, B { default String m() { return A.super.m(); } }\n" + 
         "class C implements AB {}"),
         //class C implments interface AB, AB extends interface A, B and overrides the default method inherited
         C_I_AB3("", 
-        "interface AB extends A, B { String m() default { return \"AB\"; } }\n" + 
+        "interface AB extends A, B { default String m() { return \"AB\"; } }\n" + 
         "class C implements AB {}"),
         //class C extends Class D implements Interface B
         C_CI("", 
@@ -122,7 +130,7 @@
     }
     
     enum AddType implements Template { // add by adding default method or abstract interface method
-        ADD("String m() default { return \"B\"; }"),
+        ADD("default String m() { return \"B\"; }"),
         REDECLARE("String m();");
         
         final String newCode;
--- a/combo-tests/tests/tools/javac/lambda/DefaultMethodRemoveTest.java	Wed Nov 07 11:12:21 2012 +0100
+++ b/combo-tests/tests/tools/javac/lambda/DefaultMethodRemoveTest.java	Wed Nov 07 11:42:56 2012 +0000
@@ -35,10 +35,10 @@
     String interfaceBModified = "interface B #{SHAPE.B_DECL} { #{REMOVE} }";
       
     @SourceFile(value="A.java", group="B")
-    String interfaceA = "interface A { String m() default { return \"A\"; } }";
+    String interfaceA = "interface A { default String m() { return \"A\"; } }";
     
     @SourceFile(value="B.java", group="B")
-    String interfaceB = "interface B #{SHAPE.B_DECL} { String m() default { return \"B\"; } }";
+    String interfaceB = "interface B #{SHAPE.B_DECL} { default String m() { return \"B\"; } }";
         
     @SourceFile(value="C.java", group="B")
     String classC = "#{SHAPE.C}";
@@ -100,7 +100,7 @@
               "class C implements B {}"),
         //class C implments interface B, B extends interface A, D
         C_B_AD("extends A, D", 
-               "interface D { String m() default { return \"D\"; } }\n" + 
+               "interface D { default String m() { return \"D\"; } }\n" + 
                "class C implements B {}"),
         //class C extends Class D implements Interface B
         C_CI("", 
--- a/combo-tests/tests/tools/javac/lambda/SourceTargetVersionTest.java	Wed Nov 07 11:12:21 2012 +0100
+++ b/combo-tests/tests/tools/javac/lambda/SourceTargetVersionTest.java	Wed Nov 07 11:42:56 2012 +0000
@@ -39,7 +39,7 @@
     String interfaceA = "interface A { #{SHAPE.METHOD} }";    
     
     @SourceFile(value="B.java", group="A")
-    String interfaceB = "interface B #{SHAPE.EXTEND} { String m() default { return \"B\"; } }";
+    String interfaceB = "interface B #{SHAPE.EXTEND} { default String m() { return \"B\"; } }";
     
     @SourceFile(value="C.java", group="A")
     String classC = "class C #{SHAPE.IMPLEMENT} {\n" +
--- a/src/share/classes/java/util/streams/Streams.java	Wed Nov 07 11:12:21 2012 +0100
+++ b/src/share/classes/java/util/streams/Streams.java	Wed Nov 07 11:42:56 2012 +0000
@@ -196,10 +196,7 @@
 
     public static<T> Stream<T> repeat(final int n, final T t) {
         if (n < 0) {
-            // @@@ Compiler won't allow a lambda here
-            InfiniteIterator<T> iterator = new InfiniteIterator() {
-                public T next() { return t; }
-            };
+            InfiniteIterator<T> iterator = () -> t;
             return stream(iterator, StreamOpFlags.IS_ORDERED);
         }
         else
@@ -214,10 +211,7 @@
         Objects.requireNonNull(f);
 
         if (n < 0) {
-            // @@@ Compiler won't allow a method reference here here
-            InfiniteIterator<T> iterator = new InfiniteIterator() {
-                public T next() { return f.make(); }
-            };
+            InfiniteIterator<T> iterator = () -> f.make();
             return stream(iterator, StreamOpFlags.IS_ORDERED);
         }
         else {
--- a/test-ng/tests/org/openjdk/tests/java/util/LambdaTestHelpers.java	Wed Nov 07 11:12:21 2012 +0100
+++ b/test-ng/tests/org/openjdk/tests/java/util/LambdaTestHelpers.java	Wed Nov 07 11:42:56 2012 +0000
@@ -59,18 +59,9 @@
     public static final Predicate<Integer> pTrue = x -> true;
     public static final Predicate<Integer> pEven = x -> 0 == x % 2;
     public static final Predicate<Integer> pOdd = x -> 1 == x % 2;
-//    public static final BinaryOperator<Integer> rPlus = (x, y) -> x+y;
-//    public static final BinaryOperator<Integer> rMax = (x, y) -> Math.max(x, y);
-//    public static final BinaryOperator<Integer> rMin = (x, y) -> Math.min(x,y);
-    public static final BinaryOperator<Integer> rPlus = new BinaryOperator<Integer>() {
-       public Integer operate(Integer x, Integer y) { return x+y; }
-    };
-    public static final BinaryOperator<Integer> rMax = new BinaryOperator<Integer>() {
-       public Integer operate(Integer x, Integer y) { return Math.max(x,y); }
-    };
-    public static final BinaryOperator<Integer> rMin = new BinaryOperator<Integer>() {
-       public Integer operate(Integer x, Integer y) { return Math.min(x,y); }
-    };
+    public static final BinaryOperator<Integer> rPlus = (x, y) -> x+y;
+    public static final BinaryOperator<Integer> rMax = (x, y) -> Math.max(x, y);
+    public static final BinaryOperator<Integer> rMin = (x, y) -> Math.min(x,y);
     public static final IntBinaryOperator irPlus = (x, y) -> x+y;
     public static final LongBinaryOperator lrPlus = (x, y) -> x+y;
     public static final DoubleBinaryOperator drPlus = (x, y) -> x+y;