test/langtools/tools/javac/lambda/deduplication/Deduplication.java
author cushon
Tue, 27 Mar 2018 13:48:16 -0400
changeset 49429 752ecccb0b7f
child 49541 4f6887eade94
permissions -rw-r--r--
8200301: deduplicate lambda methods Reviewed-by: vromero, mcimadamore
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
49429
752ecccb0b7f 8200301: deduplicate lambda methods
cushon
parents:
diff changeset
     1
/*
752ecccb0b7f 8200301: deduplicate lambda methods
cushon
parents:
diff changeset
     2
 * Copyright (c) 2018, Google LLC. All rights reserved.
752ecccb0b7f 8200301: deduplicate lambda methods
cushon
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
752ecccb0b7f 8200301: deduplicate lambda methods
cushon
parents:
diff changeset
     4
 *
752ecccb0b7f 8200301: deduplicate lambda methods
cushon
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
752ecccb0b7f 8200301: deduplicate lambda methods
cushon
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
752ecccb0b7f 8200301: deduplicate lambda methods
cushon
parents:
diff changeset
     7
 * published by the Free Software Foundation.
752ecccb0b7f 8200301: deduplicate lambda methods
cushon
parents:
diff changeset
     8
 *
752ecccb0b7f 8200301: deduplicate lambda methods
cushon
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
752ecccb0b7f 8200301: deduplicate lambda methods
cushon
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
752ecccb0b7f 8200301: deduplicate lambda methods
cushon
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
752ecccb0b7f 8200301: deduplicate lambda methods
cushon
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
752ecccb0b7f 8200301: deduplicate lambda methods
cushon
parents:
diff changeset
    13
 * accompanied this code).
752ecccb0b7f 8200301: deduplicate lambda methods
cushon
parents:
diff changeset
    14
 *
752ecccb0b7f 8200301: deduplicate lambda methods
cushon
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
752ecccb0b7f 8200301: deduplicate lambda methods
cushon
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
752ecccb0b7f 8200301: deduplicate lambda methods
cushon
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
752ecccb0b7f 8200301: deduplicate lambda methods
cushon
parents:
diff changeset
    18
 *
752ecccb0b7f 8200301: deduplicate lambda methods
cushon
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
752ecccb0b7f 8200301: deduplicate lambda methods
cushon
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
752ecccb0b7f 8200301: deduplicate lambda methods
cushon
parents:
diff changeset
    21
 * questions.
752ecccb0b7f 8200301: deduplicate lambda methods
cushon
parents:
diff changeset
    22
 */
752ecccb0b7f 8200301: deduplicate lambda methods
cushon
parents:
diff changeset
    23
752ecccb0b7f 8200301: deduplicate lambda methods
cushon
parents:
diff changeset
    24
package com.sun.tools.javac.comp;
752ecccb0b7f 8200301: deduplicate lambda methods
cushon
parents:
diff changeset
    25
752ecccb0b7f 8200301: deduplicate lambda methods
cushon
parents:
diff changeset
    26
import java.util.function.BiFunction;
752ecccb0b7f 8200301: deduplicate lambda methods
cushon
parents:
diff changeset
    27
import java.util.function.Consumer;
752ecccb0b7f 8200301: deduplicate lambda methods
cushon
parents:
diff changeset
    28
import java.util.function.Function;
752ecccb0b7f 8200301: deduplicate lambda methods
cushon
parents:
diff changeset
    29
import java.util.function.Supplier;
752ecccb0b7f 8200301: deduplicate lambda methods
cushon
parents:
diff changeset
    30
752ecccb0b7f 8200301: deduplicate lambda methods
cushon
parents:
diff changeset
    31
public class Deduplication {
752ecccb0b7f 8200301: deduplicate lambda methods
cushon
parents:
diff changeset
    32
    void group(Object... xs) {}
752ecccb0b7f 8200301: deduplicate lambda methods
cushon
parents:
diff changeset
    33
752ecccb0b7f 8200301: deduplicate lambda methods
cushon
parents:
diff changeset
    34
    void test() {
752ecccb0b7f 8200301: deduplicate lambda methods
cushon
parents:
diff changeset
    35
        group((Function<String, Integer>) x -> x.hashCode());
752ecccb0b7f 8200301: deduplicate lambda methods
cushon
parents:
diff changeset
    36
        group((Function<Object, Integer>) x -> x.hashCode());
752ecccb0b7f 8200301: deduplicate lambda methods
cushon
parents:
diff changeset
    37
752ecccb0b7f 8200301: deduplicate lambda methods
cushon
parents:
diff changeset
    38
        {
752ecccb0b7f 8200301: deduplicate lambda methods
cushon
parents:
diff changeset
    39
            int x = 1;
752ecccb0b7f 8200301: deduplicate lambda methods
cushon
parents:
diff changeset
    40
            group((Supplier<Integer>) () -> x + 1);
752ecccb0b7f 8200301: deduplicate lambda methods
cushon
parents:
diff changeset
    41
        }
752ecccb0b7f 8200301: deduplicate lambda methods
cushon
parents:
diff changeset
    42
        {
752ecccb0b7f 8200301: deduplicate lambda methods
cushon
parents:
diff changeset
    43
            int x = 1;
752ecccb0b7f 8200301: deduplicate lambda methods
cushon
parents:
diff changeset
    44
            group((Supplier<Integer>) () -> x + 1);
752ecccb0b7f 8200301: deduplicate lambda methods
cushon
parents:
diff changeset
    45
        }
752ecccb0b7f 8200301: deduplicate lambda methods
cushon
parents:
diff changeset
    46
        group(
752ecccb0b7f 8200301: deduplicate lambda methods
cushon
parents:
diff changeset
    47
                (BiFunction<Integer, Integer, ?>) (x, y) -> x + ((y)),
752ecccb0b7f 8200301: deduplicate lambda methods
cushon
parents:
diff changeset
    48
                (BiFunction<Integer, Integer, ?>) (x, y) -> x + (y),
752ecccb0b7f 8200301: deduplicate lambda methods
cushon
parents:
diff changeset
    49
                (BiFunction<Integer, Integer, ?>) (x, y) -> x + y,
752ecccb0b7f 8200301: deduplicate lambda methods
cushon
parents:
diff changeset
    50
                (BiFunction<Integer, Integer, ?>) (x, y) -> (x) + ((y)),
752ecccb0b7f 8200301: deduplicate lambda methods
cushon
parents:
diff changeset
    51
                (BiFunction<Integer, Integer, ?>) (x, y) -> (x) + (y),
752ecccb0b7f 8200301: deduplicate lambda methods
cushon
parents:
diff changeset
    52
                (BiFunction<Integer, Integer, ?>) (x, y) -> (x) + y,
752ecccb0b7f 8200301: deduplicate lambda methods
cushon
parents:
diff changeset
    53
                (BiFunction<Integer, Integer, ?>) (x, y) -> ((x)) + ((y)),
752ecccb0b7f 8200301: deduplicate lambda methods
cushon
parents:
diff changeset
    54
                (BiFunction<Integer, Integer, ?>) (x, y) -> ((x)) + (y),
752ecccb0b7f 8200301: deduplicate lambda methods
cushon
parents:
diff changeset
    55
                (BiFunction<Integer, Integer, ?>) (x, y) -> ((x)) + y);
752ecccb0b7f 8200301: deduplicate lambda methods
cushon
parents:
diff changeset
    56
752ecccb0b7f 8200301: deduplicate lambda methods
cushon
parents:
diff changeset
    57
        group(
752ecccb0b7f 8200301: deduplicate lambda methods
cushon
parents:
diff changeset
    58
                (Function<Integer, Integer>) x -> x + (1 + 2 + 3),
752ecccb0b7f 8200301: deduplicate lambda methods
cushon
parents:
diff changeset
    59
                (Function<Integer, Integer>) x -> x + 6);
752ecccb0b7f 8200301: deduplicate lambda methods
cushon
parents:
diff changeset
    60
752ecccb0b7f 8200301: deduplicate lambda methods
cushon
parents:
diff changeset
    61
        group((Function<Integer, Integer>) x -> x + 1, (Function<Integer, Integer>) y -> y + 1);
752ecccb0b7f 8200301: deduplicate lambda methods
cushon
parents:
diff changeset
    62
752ecccb0b7f 8200301: deduplicate lambda methods
cushon
parents:
diff changeset
    63
        group((Consumer<Integer>) x -> this.f(), (Consumer<Integer>) x -> this.f());
752ecccb0b7f 8200301: deduplicate lambda methods
cushon
parents:
diff changeset
    64
752ecccb0b7f 8200301: deduplicate lambda methods
cushon
parents:
diff changeset
    65
        group((Consumer<Integer>) y -> this.g());
752ecccb0b7f 8200301: deduplicate lambda methods
cushon
parents:
diff changeset
    66
752ecccb0b7f 8200301: deduplicate lambda methods
cushon
parents:
diff changeset
    67
        group((Consumer<Integer>) x -> f(), (Consumer<Integer>) x -> f());
752ecccb0b7f 8200301: deduplicate lambda methods
cushon
parents:
diff changeset
    68
752ecccb0b7f 8200301: deduplicate lambda methods
cushon
parents:
diff changeset
    69
        group((Consumer<Integer>) y -> g());
752ecccb0b7f 8200301: deduplicate lambda methods
cushon
parents:
diff changeset
    70
752ecccb0b7f 8200301: deduplicate lambda methods
cushon
parents:
diff changeset
    71
        group((Function<Integer, Integer>) x -> this.i, (Function<Integer, Integer>) x -> this.i);
752ecccb0b7f 8200301: deduplicate lambda methods
cushon
parents:
diff changeset
    72
752ecccb0b7f 8200301: deduplicate lambda methods
cushon
parents:
diff changeset
    73
        group((Function<Integer, Integer>) y -> this.j);
752ecccb0b7f 8200301: deduplicate lambda methods
cushon
parents:
diff changeset
    74
752ecccb0b7f 8200301: deduplicate lambda methods
cushon
parents:
diff changeset
    75
        group((Function<Integer, Integer>) x -> i, (Function<Integer, Integer>) x -> i);
752ecccb0b7f 8200301: deduplicate lambda methods
cushon
parents:
diff changeset
    76
752ecccb0b7f 8200301: deduplicate lambda methods
cushon
parents:
diff changeset
    77
        group((Function<Integer, Integer>) y -> j);
752ecccb0b7f 8200301: deduplicate lambda methods
cushon
parents:
diff changeset
    78
752ecccb0b7f 8200301: deduplicate lambda methods
cushon
parents:
diff changeset
    79
        group(
752ecccb0b7f 8200301: deduplicate lambda methods
cushon
parents:
diff changeset
    80
                (Function<Integer, Integer>) y -> {
752ecccb0b7f 8200301: deduplicate lambda methods
cushon
parents:
diff changeset
    81
                        while (true) {
752ecccb0b7f 8200301: deduplicate lambda methods
cushon
parents:
diff changeset
    82
                              break;
752ecccb0b7f 8200301: deduplicate lambda methods
cushon
parents:
diff changeset
    83
                        }
752ecccb0b7f 8200301: deduplicate lambda methods
cushon
parents:
diff changeset
    84
                        return 42;
752ecccb0b7f 8200301: deduplicate lambda methods
cushon
parents:
diff changeset
    85
                },
752ecccb0b7f 8200301: deduplicate lambda methods
cushon
parents:
diff changeset
    86
                (Function<Integer, Integer>) y -> {
752ecccb0b7f 8200301: deduplicate lambda methods
cushon
parents:
diff changeset
    87
                        while (true) {
752ecccb0b7f 8200301: deduplicate lambda methods
cushon
parents:
diff changeset
    88
                              break;
752ecccb0b7f 8200301: deduplicate lambda methods
cushon
parents:
diff changeset
    89
                        }
752ecccb0b7f 8200301: deduplicate lambda methods
cushon
parents:
diff changeset
    90
                        return 42;
752ecccb0b7f 8200301: deduplicate lambda methods
cushon
parents:
diff changeset
    91
                });
752ecccb0b7f 8200301: deduplicate lambda methods
cushon
parents:
diff changeset
    92
752ecccb0b7f 8200301: deduplicate lambda methods
cushon
parents:
diff changeset
    93
        class Local {
752ecccb0b7f 8200301: deduplicate lambda methods
cushon
parents:
diff changeset
    94
            int i;
752ecccb0b7f 8200301: deduplicate lambda methods
cushon
parents:
diff changeset
    95
752ecccb0b7f 8200301: deduplicate lambda methods
cushon
parents:
diff changeset
    96
            void f() {}
752ecccb0b7f 8200301: deduplicate lambda methods
cushon
parents:
diff changeset
    97
752ecccb0b7f 8200301: deduplicate lambda methods
cushon
parents:
diff changeset
    98
            {
752ecccb0b7f 8200301: deduplicate lambda methods
cushon
parents:
diff changeset
    99
                group((Function<Integer, Integer>) x -> this.i);
752ecccb0b7f 8200301: deduplicate lambda methods
cushon
parents:
diff changeset
   100
                group((Consumer<Integer>) x -> this.f());
752ecccb0b7f 8200301: deduplicate lambda methods
cushon
parents:
diff changeset
   101
                group((Function<Integer, Integer>) x -> Deduplication.this.i);
752ecccb0b7f 8200301: deduplicate lambda methods
cushon
parents:
diff changeset
   102
                group((Consumer<Integer>) x -> Deduplication.this.f());
752ecccb0b7f 8200301: deduplicate lambda methods
cushon
parents:
diff changeset
   103
            }
752ecccb0b7f 8200301: deduplicate lambda methods
cushon
parents:
diff changeset
   104
        }
752ecccb0b7f 8200301: deduplicate lambda methods
cushon
parents:
diff changeset
   105
    }
752ecccb0b7f 8200301: deduplicate lambda methods
cushon
parents:
diff changeset
   106
752ecccb0b7f 8200301: deduplicate lambda methods
cushon
parents:
diff changeset
   107
    void f() {}
752ecccb0b7f 8200301: deduplicate lambda methods
cushon
parents:
diff changeset
   108
752ecccb0b7f 8200301: deduplicate lambda methods
cushon
parents:
diff changeset
   109
    void g() {}
752ecccb0b7f 8200301: deduplicate lambda methods
cushon
parents:
diff changeset
   110
752ecccb0b7f 8200301: deduplicate lambda methods
cushon
parents:
diff changeset
   111
    int i;
752ecccb0b7f 8200301: deduplicate lambda methods
cushon
parents:
diff changeset
   112
    int j;
752ecccb0b7f 8200301: deduplicate lambda methods
cushon
parents:
diff changeset
   113
}