langtools/test/tools/javac/T8010737/ParameterNamesAreNotCopiedToAnonymousInitTest.java
author akulyakh
Thu, 21 May 2015 11:41:04 -0700
changeset 30730 d3ce7619db2c
parent 27319 030080f03e4f
child 30846 2b3f379840f0
permissions -rw-r--r--
8076543: Add @modules as needed to the langtools tests Reviewed-by: jjg, shurailine
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
17999
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
     1
/*
30730
d3ce7619db2c 8076543: Add @modules as needed to the langtools tests
akulyakh
parents: 27319
diff changeset
     2
 * Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved.
17999
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
     4
 *
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
     7
 * published by the Free Software Foundation.
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
     8
 *
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
    13
 * accompanied this code).
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
    14
 *
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
    18
 *
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
    21
 * questions.
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
    22
 */
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
    23
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
    24
/*
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
    25
 * @test
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
    26
 * @bug 8010737
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
    27
 * @summary javac, known parameter's names should be copied to automatically
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
    28
 * generated constructors for inner classes
30730
d3ce7619db2c 8076543: Add @modules as needed to the langtools tests
akulyakh
parents: 27319
diff changeset
    29
 * @modules jdk.compiler/com.sun.tools.classfile
d3ce7619db2c 8076543: Add @modules as needed to the langtools tests
akulyakh
parents: 27319
diff changeset
    30
 *          jdk.compiler/com.sun.tools.javac.api
d3ce7619db2c 8076543: Add @modules as needed to the langtools tests
akulyakh
parents: 27319
diff changeset
    31
 *          jdk.compiler/com.sun.tools.javac.code
d3ce7619db2c 8076543: Add @modules as needed to the langtools tests
akulyakh
parents: 27319
diff changeset
    32
 *          jdk.compiler/com.sun.tools.javac.tree
d3ce7619db2c 8076543: Add @modules as needed to the langtools tests
akulyakh
parents: 27319
diff changeset
    33
 *          jdk.compiler/com.sun.tools.javac.util
17999
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
    34
 * @run main ParameterNamesAreNotCopiedToAnonymousInitTest check_class_file check_init_symbol
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
    35
 */
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
    36
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
    37
import java.io.File;
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
    38
import java.io.IOException;
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
    39
import java.lang.annotation.ElementType;
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
    40
import java.lang.annotation.Target;
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
    41
import java.nio.file.Paths;
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
    42
import java.util.Arrays;
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
    43
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
    44
import javax.tools.JavaCompiler;
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
    45
import javax.tools.JavaFileObject;
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
    46
import javax.tools.StandardJavaFileManager;
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
    47
import javax.tools.ToolProvider;
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
    48
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
    49
import com.sun.source.tree.CompilationUnitTree;
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
    50
import com.sun.source.tree.Tree;
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
    51
import com.sun.source.util.JavacTask;
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
    52
import com.sun.source.util.TaskEvent;
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
    53
import com.sun.source.util.TaskListener;
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
    54
import com.sun.tools.classfile.ClassFile;
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
    55
import com.sun.tools.classfile.Method;
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
    56
import com.sun.tools.javac.api.BasicJavacTask;
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
    57
import com.sun.tools.javac.code.Attribute.Compound;
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
    58
import com.sun.tools.javac.code.Symbol.ClassSymbol;
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
    59
import com.sun.tools.javac.code.Symbol.VarSymbol;
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
    60
import com.sun.tools.javac.tree.JCTree;
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
    61
import com.sun.tools.javac.tree.TreeScanner;
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
    62
import com.sun.tools.javac.util.Assert;
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
    63
import com.sun.tools.javac.util.Context;
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
    64
import com.sun.tools.javac.util.List;
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
    65
import com.sun.tools.javac.util.Names;
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
    66
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
    67
public class ParameterNamesAreNotCopiedToAnonymousInitTest {
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
    68
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
    69
    static final String noParamsErrorMsg =
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
    70
            "Test most be invoked with at least one parameter: check_class_file " +
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
    71
            "and/or check_init_symbol";
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
    72
    static final String wrongParamsErrorMsg =
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
    73
            "Accepted arguments are: check_class_file and check_init_symbol";
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
    74
    static final String paramNameNotCopiedAssertionMsg =
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
    75
            "The param name hasn't been copied to the init method";
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
    76
    static final String noAnnotationsForParameterMsg =
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
    77
            "No annotations for seek parameter";
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
    78
    static final String seekMethodNotFound =
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
    79
            "The seek init method was not found or conditions were not met";
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
    80
    static final String nonNullParamPositionsMsg =
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
    81
            "Parameter positions shold not be null";
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
    82
    static final String compilationFailed =
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
    83
            "Compilation failed";
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
    84
    static final String seekMethodNotFoundMsg =
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
    85
        "The seek method was not found";
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
    86
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
    87
    static final String ParamAnnotationClassName =
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
    88
            ParameterNamesAreNotCopiedToAnonymousInitTest.class.getSimpleName() + "." +
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
    89
            ParamAnnotation.class.getSimpleName();
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
    90
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
    91
    public static void main(String[] args) throws Exception {
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
    92
        if (args.length == 0) {
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
    93
            throw new Error(noParamsErrorMsg);
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
    94
        }
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
    95
        new ParameterNamesAreNotCopiedToAnonymousInitTest().run(args);
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
    96
    }
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
    97
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
    98
    void run(String[] args) throws Exception {
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
    99
        for (String arg : args) {
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
   100
            if (arg.equals("check_class_file")) {
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
   101
                checkClassFile(new File(Paths.get(System.getProperty("test.classes"),
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
   102
                        this.getClass().getName() + "$initParams$1.class").toUri()), 1);
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
   103
                checkClassFile(new File(Paths.get(System.getProperty("test.classes"),
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
   104
                        this.getClass().getName() + "$Generics$1.class").toUri()), 2);
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
   105
            } else if (arg.equals("check_init_symbol")) {
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
   106
                checkInitSymbol("m1", Arrays.asList(0), Arrays.asList("i"));
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
   107
                checkInitSymbol("m2", Arrays.asList(0, 1), Arrays.asList("t1", "t2"));
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
   108
            } else {
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
   109
                error(wrongParamsErrorMsg);
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
   110
            }
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
   111
        }
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
   112
    }
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
   113
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
   114
    void checkClassFile(final File cfile, int numberOfParams) throws Exception {
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
   115
        ClassFile classFile = ClassFile.read(cfile);
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
   116
        boolean methodFound = false;
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
   117
        for (Method method : classFile.methods) {
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
   118
            if (method.getName(classFile.constant_pool).equals("<init>")) {
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
   119
                methodFound = true;
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
   120
            }
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
   121
        }
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
   122
        Assert.check(methodFound, seekMethodNotFoundMsg);
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
   123
    }
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
   124
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
   125
    /*  This method expect a non-null ordered list of integers, listing the
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
   126
     *  position of the parameters to be checked on the init method. Position 0
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
   127
     *  corresponds to the first parameter.
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
   128
     *
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
   129
     *  As we are looking for a constructor of an anonymous class, the
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
   130
     *  classOwnerName parameter must be the name of the method where the
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
   131
     *  anonymous class is declared.
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
   132
     */
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
   133
    void checkInitSymbol(
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
   134
            final String classOwnerName,
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
   135
            final java.util.List<Integer> paramsToCheck,
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
   136
            final java.util.List<String> paramNames)
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
   137
            throws IOException {
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
   138
        Assert.checkNonNull(paramsToCheck, nonNullParamPositionsMsg);
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
   139
        JavaCompiler c = ToolProvider.getSystemJavaCompiler();
27319
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 17999
diff changeset
   140
        try (StandardJavaFileManager fm = c.getStandardFileManager(null, null, null)) {
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 17999
diff changeset
   141
            Iterable<? extends JavaFileObject> fos =
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 17999
diff changeset
   142
                    fm.getJavaFileObjectsFromFiles(
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 17999
diff changeset
   143
                    Arrays.asList(new File(System.getProperty("test.src"),
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 17999
diff changeset
   144
                    this.getClass().getName() + ".java")));
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 17999
diff changeset
   145
            JavacTask task = (JavacTask) c.getTask(null, fm, null,
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 17999
diff changeset
   146
                    Arrays.asList("-d", System.getProperty("user.dir")), null, fos);
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 17999
diff changeset
   147
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 17999
diff changeset
   148
            BasicJavacTask impl = (BasicJavacTask)task;
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 17999
diff changeset
   149
            Context context = impl.getContext();
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 17999
diff changeset
   150
            final Names names = Names.instance(context);
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 17999
diff changeset
   151
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 17999
diff changeset
   152
            task.addTaskListener(new TaskListener() {
17999
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
   153
27319
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 17999
diff changeset
   154
                @Override
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 17999
diff changeset
   155
                public void started(TaskEvent e) {}
17999
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
   156
27319
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 17999
diff changeset
   157
                @Override
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 17999
diff changeset
   158
                public void finished(TaskEvent e) {
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 17999
diff changeset
   159
                    class TheTreeScanner extends TreeScanner {
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 17999
diff changeset
   160
                        boolean foundAndCorrect = false;
17999
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
   161
27319
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 17999
diff changeset
   162
                        @Override
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 17999
diff changeset
   163
                        public void visitMethodDef(JCTree.JCMethodDecl tree) {
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 17999
diff changeset
   164
                            ClassSymbol clazz = (ClassSymbol)tree.sym.owner;
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 17999
diff changeset
   165
                            if (clazz.owner.name.toString().equals(classOwnerName) &&
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 17999
diff changeset
   166
                                tree.sym.name == names.init) {
17999
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
   167
27319
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 17999
diff changeset
   168
                                int currentParamPos = 0;
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 17999
diff changeset
   169
                                int paramArrayIndex = 0;
17999
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
   170
27319
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 17999
diff changeset
   171
                                List<VarSymbol> params = tree.sym.params;
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 17999
diff changeset
   172
                                while (params.nonEmpty() && paramArrayIndex < paramsToCheck.size()) {
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 17999
diff changeset
   173
                                    VarSymbol param = params.head;
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 17999
diff changeset
   174
                                    if (currentParamPos == paramsToCheck.get(paramArrayIndex)) {
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 17999
diff changeset
   175
                                        if (!param.name.toString()
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 17999
diff changeset
   176
                                                .equals(paramNames.get(paramArrayIndex))) {
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 17999
diff changeset
   177
                                            error(paramNameNotCopiedAssertionMsg);
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 17999
diff changeset
   178
                                        }
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 17999
diff changeset
   179
                                        paramArrayIndex++;
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 17999
diff changeset
   180
                                    }
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 17999
diff changeset
   181
                                    currentParamPos++;
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 17999
diff changeset
   182
                                    params = params.tail;
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 17999
diff changeset
   183
                                }
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 17999
diff changeset
   184
                                foundAndCorrect = paramArrayIndex >= paramsToCheck.size();
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 17999
diff changeset
   185
                            }
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 17999
diff changeset
   186
                            super.visitMethodDef(tree);
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 17999
diff changeset
   187
                        }
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 17999
diff changeset
   188
                    }
17999
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
   189
27319
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 17999
diff changeset
   190
                    if (e.getKind() == TaskEvent.Kind.ANALYZE) {
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 17999
diff changeset
   191
                        CompilationUnitTree compUnitTree = e.getCompilationUnit();
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 17999
diff changeset
   192
                        boolean foundAndCorrect = false;
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 17999
diff changeset
   193
                        for (Tree tree : compUnitTree.getTypeDecls()) {
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 17999
diff changeset
   194
                            TheTreeScanner scanner = new TheTreeScanner();
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 17999
diff changeset
   195
                            scanner.scan((JCTree) tree);
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 17999
diff changeset
   196
                            foundAndCorrect = foundAndCorrect | scanner.foundAndCorrect;
17999
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
   197
                        }
27319
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 17999
diff changeset
   198
                        if (!foundAndCorrect) {
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 17999
diff changeset
   199
                            error(seekMethodNotFound);
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 17999
diff changeset
   200
                        }
17999
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
   201
                    }
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
   202
                }
27319
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 17999
diff changeset
   203
            });
17999
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
   204
27319
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 17999
diff changeset
   205
            if (!task.call()) {
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 17999
diff changeset
   206
                error(compilationFailed);
17999
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
   207
            }
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
   208
        }
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
   209
    }
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
   210
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
   211
    void error(String msg) {
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
   212
        throw new AssertionError(msg);
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
   213
    }
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
   214
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
   215
    @Target(value = {ElementType.PARAMETER})
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
   216
    @interface ParamAnnotation {}
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
   217
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
   218
    /*  If more cases are added in the future, it should be taken into account
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
   219
     *  that method checkInitSymbol locates the inner class looking for its
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
   220
     *  container method, which in the cases below are m1 and m2. So new cases
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
   221
     *  must have different names for container methods or method checkInitSymbol
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
   222
     *  should be changed.
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
   223
     */
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
   224
    public class initParams {
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
   225
        public initParams(@ParamAnnotation int i) {}
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
   226
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
   227
        public void m1() {
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
   228
            new initParams(2) {};
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
   229
        }
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
   230
    }
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
   231
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
   232
    class Generics<T1> {
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
   233
        T1 obj1;
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
   234
        Object obj2;
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
   235
        <T2> Generics(@ParamAnnotation T1 t1, @ParamAnnotation T2 t2) {
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
   236
            obj1 = t1;
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
   237
            obj2 = t2;
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
   238
        }
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
   239
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
   240
        void m2() {
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
   241
            Generics<Integer> a = new <String>Generics<Integer>(
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
   242
                    new Integer(11), "foo") {};
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
   243
        }
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
   244
    }
42ae6fe53718 8010737: javac, known parameter's names should be copied to automatically generated constructors for inner classes
vromero
parents:
diff changeset
   245
}