langtools/test/tools/javac/lambda/8068399/T8068399.java
author sadayapalam
Thu, 12 Feb 2015 10:16:19 +0530
changeset 28891 dc7d89f2e25c
child 29052 d1bc1685d7ce
permissions -rw-r--r--
8069545: javac shouldn't check nested stuck lambdas during overload resolution Summary: Nested lambdas should not be considered while overload resolution is in progress Reviewed-by: mcimadamore Contributed-by: vicente.romero@oracle.com, srikanth.adayapalam@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
28891
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
     1
/*
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
     2
 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
     4
 *
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
    10
 *
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
    15
 * accompanied this code).
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
    16
 *
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
    20
 *
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
    23
 * questions.
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
    24
 */
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
    25
/*
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
    26
 * @test
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
    27
 * @bug 8068399
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
    28
 * @summary structural most specific and stuckness
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
    29
 */
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
    30
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
    31
import java.util.function.Function;
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
    32
import java.util.stream.IntStream;
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
    33
import java.util.stream.Stream;
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
    34
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
    35
public class T8068399 {
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
    36
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
    37
    public static class Spectrum {
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
    38
        public double[] getEnergy() {
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
    39
            return new double[0];
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
    40
        }
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
    41
    }
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
    42
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
    43
    protected Spectrum spectrum;
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
    44
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
    45
    public static class Ref<T> {
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
    46
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
    47
        T value;
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
    48
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
    49
        public Ref() {
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
    50
        }
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
    51
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
    52
        public Ref(T value) {
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
    53
            this.value = value;
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
    54
        }
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
    55
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
    56
        public boolean isNull() {
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
    57
            return value == null;
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
    58
        }
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
    59
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
    60
        public T get() {
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
    61
            return value;
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
    62
        }
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
    63
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
    64
        public void set(T value) {
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
    65
            this.value = value;
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
    66
        }
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
    67
    }
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
    68
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
    69
    public static <T>T maxKey(Stream<T> stream, Function<T, Double> function) {
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
    70
        Ref<Double> max = new Ref<>();
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
    71
        Ref<T> index = new Ref<>();
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
    72
        stream.forEach(v -> {
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
    73
            Double value = function.apply(v);
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
    74
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
    75
            if (max.isNull() || value > max.get()) {
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
    76
                max.set(value);
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
    77
                index.set(v);
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
    78
            }
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
    79
        });
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
    80
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
    81
        return index.get();
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
    82
    }
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
    83
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
    84
    public static int interpolate(int x, int x0, int x1, int y0, int y1) {
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
    85
        return y0 + (x - x0) * (y1 - y0) / (x1 - x0);
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
    86
    }
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
    87
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
    88
    public static double interpolate(double x, double x0, double x1, double y0, double y1) {
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
    89
        return y0 + (x - x0) * (y1 - y0) / (x1 - x0);
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
    90
    }
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
    91
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
    92
    protected int getXByFrequency(double frequency) {
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
    93
        return (int) Math.round(interpolate(frequency,
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
    94
                                            getMinSpectrumCoord(),
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
    95
                                            getMaxSpectrumCoord(),
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
    96
                                            0, getWidth()));
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
    97
    }
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
    98
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
    99
    private int getWidth() {
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
   100
        return 0;
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
   101
    }
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
   102
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
   103
    private double getMaxSpectrumCoord() {
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
   104
        return 0;
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
   105
    }
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
   106
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
   107
    private double getMinSpectrumCoord() {
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
   108
        return 0;
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
   109
    }
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
   110
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
   111
    void foo() {
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
   112
        int maxBpmIndex = 0;
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
   113
        int xcur = getXByFrequency(maxKey(IntStream.range(0, maxBpmIndex).boxed(),
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
   114
                                          i -> Math.abs(spectrum.getEnergy()[i])));
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
   115
    }
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
   116
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
   117
    public static void main(String [] args) {
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
   118
    }
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
   119
}