langtools/test/tools/javac/lambda/methodReferenceExecution/MethodReferenceTestNewInnerImplicitArgs.java
author alundblad
Wed, 26 Aug 2015 09:02:02 +0200
changeset 32337 c9d3ab9f601c
parent 17286 fec581c36de4
permissions -rw-r--r--
8133671: langtools tests have bad license Summary: Dropped classpath exception from copyright notice in tests. Reviewed-by: jjg
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
17286
fec581c36de4 8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
diff changeset
     1
/*
fec581c36de4 8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
diff changeset
     2
 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
fec581c36de4 8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
fec581c36de4 8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
diff changeset
     4
 *
fec581c36de4 8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
fec581c36de4 8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
32337
c9d3ab9f601c 8133671: langtools tests have bad license
alundblad
parents: 17286
diff changeset
     7
 * published by the Free Software Foundation.
17286
fec581c36de4 8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
diff changeset
     8
 *
fec581c36de4 8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
fec581c36de4 8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
fec581c36de4 8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
fec581c36de4 8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
fec581c36de4 8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
diff changeset
    13
 * accompanied this code).
fec581c36de4 8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
diff changeset
    14
 *
fec581c36de4 8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
fec581c36de4 8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
fec581c36de4 8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
fec581c36de4 8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
diff changeset
    18
 *
fec581c36de4 8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
fec581c36de4 8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
fec581c36de4 8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
diff changeset
    21
 * questions.
fec581c36de4 8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
diff changeset
    22
 */
fec581c36de4 8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
diff changeset
    23
fec581c36de4 8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
diff changeset
    24
/**
fec581c36de4 8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
diff changeset
    25
 * @test
fec581c36de4 8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
diff changeset
    26
 * @bug 8011591
fec581c36de4 8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
diff changeset
    27
 * @summary BootstrapMethodError when capturing constructor ref to local classes
fec581c36de4 8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
diff changeset
    28
 * @run testng MethodReferenceTestNewInnerImplicitArgs
fec581c36de4 8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
diff changeset
    29
 */
fec581c36de4 8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
diff changeset
    30
fec581c36de4 8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
diff changeset
    31
import org.testng.annotations.Test;
fec581c36de4 8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
diff changeset
    32
fec581c36de4 8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
diff changeset
    33
import static org.testng.Assert.assertEquals;
fec581c36de4 8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
diff changeset
    34
fec581c36de4 8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
diff changeset
    35
/**
fec581c36de4 8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
diff changeset
    36
 * Test the case that a constructor has implicit parameters added to
fec581c36de4 8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
diff changeset
    37
 * access local variables and that this constructor is used in a
fec581c36de4 8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
diff changeset
    38
 * method reference.
fec581c36de4 8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
diff changeset
    39
 * @author Robert Field
fec581c36de4 8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
diff changeset
    40
 */
fec581c36de4 8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
diff changeset
    41
fec581c36de4 8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
diff changeset
    42
@Test
fec581c36de4 8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
diff changeset
    43
public class MethodReferenceTestNewInnerImplicitArgs {
fec581c36de4 8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
diff changeset
    44
fec581c36de4 8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
diff changeset
    45
fec581c36de4 8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
diff changeset
    46
    static class S {
fec581c36de4 8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
diff changeset
    47
        String b;
fec581c36de4 8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
diff changeset
    48
        S(String s, String s2) { b = s + s2; }
fec581c36de4 8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
diff changeset
    49
    }
fec581c36de4 8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
diff changeset
    50
fec581c36de4 8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
diff changeset
    51
    interface I {
fec581c36de4 8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
diff changeset
    52
        S m();
fec581c36de4 8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
diff changeset
    53
    }
fec581c36de4 8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
diff changeset
    54
fec581c36de4 8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
diff changeset
    55
    interface I2 {
fec581c36de4 8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
diff changeset
    56
        S m(int i, int j);
fec581c36de4 8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
diff changeset
    57
    }
fec581c36de4 8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
diff changeset
    58
fec581c36de4 8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
diff changeset
    59
    public static void testConstructorReferenceImplicitParameters() {
fec581c36de4 8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
diff changeset
    60
        String title = "Hey";
fec581c36de4 8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
diff changeset
    61
        String a2 = "!!!";
fec581c36de4 8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
diff changeset
    62
        class MS extends S {
fec581c36de4 8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
diff changeset
    63
            MS() {
fec581c36de4 8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
diff changeset
    64
                super(title, a2);
fec581c36de4 8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
diff changeset
    65
            }
fec581c36de4 8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
diff changeset
    66
        }
fec581c36de4 8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
diff changeset
    67
fec581c36de4 8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
diff changeset
    68
        I result = MS::new;
fec581c36de4 8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
diff changeset
    69
        assertEquals(result.m().b, "Hey!!!");
fec581c36de4 8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
diff changeset
    70
fec581c36de4 8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
diff changeset
    71
        class MS2 extends S {
fec581c36de4 8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
diff changeset
    72
            MS2(int x, int y) {
fec581c36de4 8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
diff changeset
    73
                super(title+x, a2+y);
fec581c36de4 8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
diff changeset
    74
            }
fec581c36de4 8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
diff changeset
    75
        }
fec581c36de4 8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
diff changeset
    76
fec581c36de4 8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
diff changeset
    77
        I2 result2 = MS2::new;
fec581c36de4 8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
diff changeset
    78
        assertEquals(result2.m(8, 4).b, "Hey8!!!4");
fec581c36de4 8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
diff changeset
    79
    }
fec581c36de4 8011591: BootstrapMethodError when capturing constructor ref to local classes
rfield
parents:
diff changeset
    80
}