test/tools/javac/lambda/funcInterfaces/Helper.java

Tue, 12 Mar 2013 16:02:43 +0000

author
mcimadamore
date
Tue, 12 Mar 2013 16:02:43 +0000
changeset 1628
5ddecb91d843
parent 0
959103a6100f
permissions
-rw-r--r--

8009545: Graph inference: dependencies between inference variables should be set during incorporation
Summary: Move all transitivity checks into the incorporation round
Reviewed-by: jjg

     1 /*
     2  * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     8  *
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    12  * version 2 for more details (a copy is included in the LICENSE file that
    13  * accompanied this code).
    14  *
    15  * You should have received a copy of the GNU General Public License version
    16  * 2 along with this work; if not, write to the Free Software Foundation,
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    18  *
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    20  * or visit www.oracle.com if you need additional information or have any
    21  * questions.
    22  */
    24 /*SAM types:
    25          1. An interface that has a single abstract method
    26          2. Having more than one distinct methods, but only one is "real", the others are overriden public methods in Object - example: Comparator<T>
    27          3. Having more than one methods due to inheritance, but they have the same signature
    28          4. Having more than one methods due to inheritance, but one of them has a subsignature of all other methods
    29                 a) parameter types compatible
    30                 b) return type substitutable
    31                 c) thrown type not conflicting with the thrown clause of any other method
    32                 d) mixed up
    33          5. Type-dependent SAM types
    34   non-SAM types:
    35          6. An interface that has a single abstract method, which is also public method in Object
    36          7. Having more than one methods due to inheritance, and none of them has a subsignature of all other methods
    37 */
    39 import java.util.List;
    40 import java.util.Collection;
    41 import java.sql.SQLException;
    42 import java.sql.SQLTransientException;
    43 import java.util.concurrent.TimeoutException;
    44 import java.io.*;
    46 interface A {int getOldest(List<Number> list);}
    47 interface B {int getOldest(List list);}
    48 interface C {int getOldest(List<?> list);}
    49 interface D {int getOldest(List<Integer> list);}
    50 interface E {int getOldest(Collection<?> collection);}
    51 //Not SAM type, case #7
    52 interface DE extends D, E {}
    54 interface Foo {int getAge(Number n);}
    55 interface Bar {int getAge(Integer i);}
    56 //Not SAM type, case #7
    57 interface FooBar extends Foo, Bar {}
    59 //Not SAM type, case #6
    60 interface Planet {boolean equals(Object o);}
    62 // SAM type interfaces:
    63 // type #2:
    64 //only one abstract non-Ojbect method getAge()
    65 interface Mars<T> extends Planet {int getAge(T t);}
    66 //only one abstract non-Ojbect method increment()
    67 interface Jupiter {
    68     boolean equals(Object o);
    69     String toString();
    70     int increment(int i);
    71 }
    73 // type #3:
    74 interface X {int getTotal(List<String> arg);}
    75 interface Y {int getTotal(List<String> strs);}
    76 //SAM type ([List<String>], int, {})
    77 interface XY extends X, Y {}
    78 //SAM type ([List<String>], int, {})
    79 interface XYZ extends X, Y, XY {}
    81 // type #4 a):
    82 //SAM type ([List], int, {})
    83 interface AB extends A, B {}
    85 // type #4 b):
    86 interface F {Number getValue(String str);}
    87 interface G {Integer getValue(String str);}
    88 interface H {Serializable getValue(String str);}
    89 interface I {Object getValue(String str);}
    90 //SAM type ([String], Integer, {})
    91 interface FGHI extends F, G, H, I {}
    93 interface J {List<Number> getAll(String str);}
    94 interface K {List<?> getAll(String str);}
    95 interface L {List getAll(String str);}
    96 interface M {Collection getAll(String str);}
    97 //SAM type ([String], List<Number>/List, {}) - the return type is flexible to some degree
    98 interface JK extends J, K {}
    99 //SAM type ([String], List<Number>/List, {})
   100 interface JL extends J, L {}
   101 //SAM type ([String], List<Number>/List, {})
   102 interface JKL extends J, K, L {}
   103 //SAM type ([String], List<Number>/List, {})
   104 interface JKLM extends J, K, L, M {}
   106 // type #4 c):
   107 interface N {String getText(File f) throws IOException;}
   108 interface O {String getText(File f) throws FileNotFoundException;}
   109 interface P {String getText(File f) throws NullPointerException;}
   110 //SAM type ([File], String, {FileNotFoundException})
   111 interface NO extends N, O {}
   112 //SAM type ([File], String, {})
   113 interface NOP extends N, O, P {}
   115 interface Boo {int getAge(String s) throws IOException;}
   116 interface Doo {int getAge(String s) throws SQLException;}
   117 //SAM type ([String], int, {})
   118 interface BooDoo extends Boo, Doo {}
   120 // type #4 d):
   121 interface Q {Iterable m(Iterable<String> arg);}
   122 interface R {Iterable<String> m(Iterable arg);}
   123 //SAM type ([Iterable], Iterable<String>/Iterable, {})
   124 interface QR extends Q, R {}
   126 interface U {Collection foo(List<String> arg) throws IOException, SQLTransientException;}
   127 interface V {List<?> foo(List<String> arg) throws EOFException, SQLException, TimeoutException;}
   128 interface W {List<String> foo(List arg) throws Exception;}
   129 //SAM type ([List<String>], List<String>/List, {EOFException, SQLTransientException})
   130 interface UV extends U, V {}
   131 // SAM type ([List], List<String>/List, {EOFException, SQLTransientException})
   132 interface UVW extends U, V, W {}
   134 // type #5:
   135 // Not a SAM because sam-ness depends on instantiation of type-variables
   136 interface Qoo<T> {void m(T arg);}
   137 interface Roo<S extends Number> {void m(S arg);}
   138 interface QooRoo<T1, T2 extends Number, T3> extends Qoo<T1>, Roo<T2> {}

mercurial