test/tools/javac/8015701/AnonymousParameters.java

changeset 1989
fcd768844b99
parent 1968
e431c9bfb171
parent 1988
96b6865eda94
child 1990
3f274927ec18
     1.1 --- a/test/tools/javac/8015701/AnonymousParameters.java	Thu Aug 29 09:42:12 2013 -0700
     1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 @@ -1,89 +0,0 @@
     1.4 -/*
     1.5 - * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
     1.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 - *
     1.8 - * This code is free software; you can redistribute it and/or modify it
     1.9 - * under the terms of the GNU General Public License version 2 only, as
    1.10 - * published by the Free Software Foundation.
    1.11 - *
    1.12 - * This code is distributed in the hope that it will be useful, but WITHOUT
    1.13 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.14 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.15 - * version 2 for more details (a copy is included in the LICENSE file that
    1.16 - * accompanied this code).
    1.17 - *
    1.18 - * You should have received a copy of the GNU General Public License version
    1.19 - * 2 along with this work; if not, write to the Free Software Foundation,
    1.20 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.21 - *
    1.22 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.23 - * or visit www.oracle.com if you need additional information or have any
    1.24 - * questions.
    1.25 - */
    1.26 -
    1.27 -/*
    1.28 - * @test
    1.29 - * @bug 8015701
    1.30 - * @summary javac should generate method parameters correctly.
    1.31 - * @compile -parameters AnonymousParameters.java
    1.32 - * @run main AnonymousParameters
    1.33 - */
    1.34 -import java.lang.Class;
    1.35 -import java.lang.reflect.Constructor;
    1.36 -import java.lang.reflect.Parameter;
    1.37 -import java.util.concurrent.Callable;
    1.38 -
    1.39 -public class AnonymousParameters {
    1.40 -
    1.41 -    String[] names = {
    1.42 -        "this$0",
    1.43 -        "val$message"
    1.44 -    };
    1.45 -
    1.46 -    public static void main(String... args) throws Exception {
    1.47 -        new AnonymousParameters().run();
    1.48 -    }
    1.49 -
    1.50 -    void run() throws Exception {
    1.51 -        Class<?> cls = new ParameterNames().makeInner("hello").getClass();
    1.52 -        Constructor<?> ctor = cls.getDeclaredConstructors()[0];
    1.53 -        Parameter[] params = ctor.getParameters();
    1.54 -
    1.55 -        if(params.length == 2) {
    1.56 -            for(int i = 0; i < 2; i++) {
    1.57 -                System.err.println("Testing parameter " + params[i].getName());
    1.58 -                if(!params[i].getName().equals(names[i]))
    1.59 -                    error("Expected parameter name " + names[i] +
    1.60 -                          " got " + params[i].getName());
    1.61 -            }
    1.62 -        } else
    1.63 -            error("Expected 2 parameters");
    1.64 -
    1.65 -        if(0 != errors)
    1.66 -            throw new Exception("MethodParameters test failed with " +
    1.67 -                                errors + " errors");
    1.68 -    }
    1.69 -
    1.70 -    void error(String msg) {
    1.71 -        System.err.println("Error: " + msg);
    1.72 -        errors++;
    1.73 -    }
    1.74 -
    1.75 -    int errors;
    1.76 -}
    1.77 -
    1.78 -class ParameterNames {
    1.79 -
    1.80 -    public Callable<String> makeInner(final String message) {
    1.81 -        return new Callable<String>()  {
    1.82 -            public String call() throws Exception {
    1.83 -                return message;
    1.84 -            }
    1.85 -        };
    1.86 -    }
    1.87 -
    1.88 -    public static void main(String... args) throws Exception {
    1.89 -        ParameterNames test = new ParameterNames();
    1.90 -        System.out.println(test.makeInner("Hello").call());
    1.91 -    }
    1.92 -}

mercurial