/* * Copyright (c) 2018, Google LLC. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package com.sun.tools.javac.comp; import java.util.function.BiFunction; import java.util.function.Consumer; import java.util.function.Function; import java.util.function.Supplier; public class Deduplication { void groupEquals(Object... xs) {} void groupNotEquals(Object... xs) {} void group(Object... xs) {} void test() { groupEquals( (Runnable) () -> { ( (Runnable) () -> {} ).run(); }, (Runnable) () -> { ( (Runnable) () -> {} ).run(); } ); groupEquals( (Runnable) () -> { Deduplication.class.toString(); }, (Runnable) () -> { Deduplication.class.toString(); } ); groupEquals( (Runnable) () -> { Integer[].class.toString(); }, (Runnable) () -> { Integer[].class.toString(); } ); groupEquals( (Runnable) () -> { char.class.toString(); }, (Runnable) () -> { char.class.toString(); } ); groupEquals( (Runnable) () -> { Void.class.toString(); }, (Runnable) () -> { Void.class.toString(); } ); groupEquals( (Runnable) () -> { void.class.toString(); }, (Runnable) () -> { void.class.toString(); } ); groupEquals((Function) x -> x.hashCode()); groupEquals((Function) x -> x.hashCode()); { int x = 1; groupEquals((Supplier) () -> x + 1); } { int x = 1; groupEquals((Supplier) () -> x + 1); } groupEquals( (BiFunction) (x, y) -> x + ((y)), (BiFunction) (x, y) -> x + (y), (BiFunction) (x, y) -> x + y, (BiFunction) (x, y) -> (x) + ((y)), (BiFunction) (x, y) -> (x) + (y), (BiFunction) (x, y) -> (x) + y, (BiFunction) (x, y) -> ((x)) + ((y)), (BiFunction) (x, y) -> ((x)) + (y), (BiFunction) (x, y) -> ((x)) + y); groupEquals( (Function) x -> x + (1 + 2 + 3), (Function) x -> x + 6); groupEquals((Function) x -> x + 1, (Function) y -> y + 1); groupEquals((Consumer) x -> this.f(), (Consumer) x -> this.f()); groupEquals((Consumer) y -> this.g()); groupEquals((Consumer) x -> f(), (Consumer) x -> f()); groupEquals((Consumer) y -> g()); groupEquals((Function) x -> this.i, (Function) x -> this.i); groupEquals((Function) y -> this.j); groupEquals((Function) x -> i, (Function) x -> i); groupEquals((Function) y -> j); groupEquals( (Function) y -> { while (true) { break; } return 42; }, (Function) y -> { while (true) { break; } return 42; }); groupEquals( (Function) x -> { int y = x; return y; }, (Function) x -> { int y = x; return y; }); groupEquals( (Function) x -> { int y = 0, z = x; return y; }); groupEquals( (Function) x -> { int y = 0, z = x; return z; }); class Local { int i; void f() {} { groupEquals((Function) x -> this.i); groupEquals((Consumer) x -> this.f()); groupEquals((Function) x -> Deduplication.this.i); groupEquals((Consumer) x -> Deduplication.this.f()); } } groupEquals((Function) x -> switch (x) { default: yield x; }, (Function) x -> switch (x) { default: yield x; }); groupEquals((Function) x -> x instanceof Integer i ? i : -1, (Function) x -> x instanceof Integer i ? i : -1); groupEquals((Function) x -> x instanceof R(var i1, var i2) ? i1 : -1, (Function) x -> x instanceof R(var i1, var i2) ? i1 : -1 ); groupEquals((Function) x -> x instanceof R(Integer i1, int i2) ? i2 : -1, (Function) x -> x instanceof R(Integer i1, int i2) ? i2 : -1 ); groupEquals((Function) x -> x instanceof int i2 ? i2 : -1, (Function) x -> x instanceof int i2 ? i2 : -1); groupEquals((Function) x -> switch (x) { case String s -> s.length(); default -> -1; }, (Function) x -> switch (x) { case String s -> s.length(); default -> -1; }); groupEquals((Function) x -> { int y1 = -1; return y1; }, (Function) x -> { int y2 = -1; return y2; }); groupNotEquals((Function) x -> {class C {} new C(); return 42; }, (Function) x -> {class C {} new C(); return 42; }); } void f() {} void g() {} int i; int j; record R(Integer i1, int i2) {} }