langtools/test/tools/javac/MethodParameters/ClassFileVisitor.java
author vasya
Mon, 14 Dec 2015 20:18:19 +0100
changeset 34752 9c262a013456
parent 34751 32ee3b176042
child 40316 20b50a99fe8d
permissions -rw-r--r--
8145342: Some copyright notices are inconsistently and ill formatted Summary: Adjusted formatting of copyright notices. Reviewed-by: darcy, alundblad
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
16307
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
     1
/*
34752
9c262a013456 8145342: Some copyright notices are inconsistently and ill formatted
vasya
parents: 34751
diff changeset
     2
 * Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved.
16307
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
     4
 *
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
     7
 * published by the Free Software Foundation.
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
     8
 *
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    13
 * accompanied this code).
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    14
 *
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    18
 *
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    21
 * questions.
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    22
 */
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    23
18000
5d29ce00a7a2 6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents: 17999
diff changeset
    24
import java.io.*;
16307
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    25
import com.sun.tools.classfile.*;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    26
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    27
/**
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    28
 * The {@code ClassFileVisitor} reads a class file using the
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    29
 * {@code com.sun.tools.classfile} library. It iterates over the methods
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    30
 * in a class, and checks MethodParameters attributes against JLS
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    31
 * requirements, as well as assumptions about the javac implementations.
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    32
 * <p>
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    33
 * It enforces the following rules:
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    34
 * <ul>
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    35
 * <li>All non-synthetic methods with arguments must have the
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    36
 * MethodParameters attribute. </li>
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    37
 * <li>At most one MethodParameters attribute per method.</li>
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    38
 * <li>An empty MethodParameters attribute is not allowed (i.e. no
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    39
 * attribute for methods taking no parameters).</li>
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    40
 * <li>The number of recorded parameter names much equal the number
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    41
 * of parameters, including any implicit or synthetic parameters generated
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    42
 * by the compiler.</li>
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    43
 * <li>Although the spec allow recording parameters with no name, the javac
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    44
 * implementation is assumed to record a name for all parameters. That is,
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    45
 * the Methodparameters attribute must record a non-zero, valid constant
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    46
 * pool index for each parameter.</li>
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    47
 * <li>Check presence, expected names (e.g. this$N, $enum$name, ...) and flags
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    48
 * (e.g. ACC_SYNTHETIC, ACC_MANDATED) for compiler generated parameters.</li>
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    49
 * <li>Names of explicit parameters must reflect the names in the Java source.
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    50
 * This is checked by assuming a design pattern where any name is permitted
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    51
 * for the first explicit parameter. For subsequent parameters the following
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    52
 * rule is checked: <i>param[n] == ++param[n-1].charAt(0) + param[n-1]</i>
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    53
 * </ul>
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    54
 */
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    55
class ClassFileVisitor extends Tester.Visitor {
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    56
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    57
    Tester tester;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    58
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    59
    public String cname;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    60
    public boolean isEnum;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    61
    public boolean isInterface;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    62
    public boolean isInner;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    63
    public boolean isPublic;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    64
    public boolean isStatic;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    65
    public boolean isAnon;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    66
    public ClassFile classFile;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    67
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    68
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    69
    public ClassFileVisitor(Tester tester) {
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    70
        super(tester);
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    71
    }
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    72
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    73
    public void error(String msg) {
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    74
        super.error("classfile: " + msg);
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    75
    }
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    76
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    77
    public void warn(String msg) {
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    78
        super.warn("classfile: " + msg);
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    79
    }
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    80
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    81
    /**
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    82
     * Read the class and determine some key characteristics, like if it's
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    83
     * an enum, or inner class, etc.
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    84
     */
21044
ffba9cdeff1a 8015372: Update tests for Method Parameter Reflection API to check whether a parameter is final
mnunez
parents: 18000
diff changeset
    85
    void visitClass(final String cname, final File cfile, final StringBuilder sb) throws Exception {
16307
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    86
        this.cname = cname;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    87
        classFile = ClassFile.read(cfile);
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    88
        isEnum = classFile.access_flags.is(AccessFlags.ACC_ENUM);
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    89
        isInterface = classFile.access_flags.is(AccessFlags.ACC_INTERFACE);
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    90
        isPublic = classFile.access_flags.is(AccessFlags.ACC_PUBLIC);
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    91
        isInner = false;
21044
ffba9cdeff1a 8015372: Update tests for Method Parameter Reflection API to check whether a parameter is final
mnunez
parents: 18000
diff changeset
    92
        isStatic = false;
16307
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    93
        isAnon = false;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    94
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    95
        Attribute attr = classFile.getAttribute("InnerClasses");
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    96
        if (attr != null) attr.accept(new InnerClassVisitor(), null);
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    97
        isAnon = isInner & isAnon;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    98
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    99
        sb.append(isStatic ? "static " : "")
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   100
            .append(isPublic ? "public " : "")
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   101
            .append(isEnum ? "enum " : isInterface ? "interface " : "class ")
21044
ffba9cdeff1a 8015372: Update tests for Method Parameter Reflection API to check whether a parameter is final
mnunez
parents: 18000
diff changeset
   102
            .append(cname).append(" -- ");
ffba9cdeff1a 8015372: Update tests for Method Parameter Reflection API to check whether a parameter is final
mnunez
parents: 18000
diff changeset
   103
        if (isInner) {
ffba9cdeff1a 8015372: Update tests for Method Parameter Reflection API to check whether a parameter is final
mnunez
parents: 18000
diff changeset
   104
            sb.append(isAnon ? "anon" : "inner");
ffba9cdeff1a 8015372: Update tests for Method Parameter Reflection API to check whether a parameter is final
mnunez
parents: 18000
diff changeset
   105
        }
ffba9cdeff1a 8015372: Update tests for Method Parameter Reflection API to check whether a parameter is final
mnunez
parents: 18000
diff changeset
   106
        sb.append("\n");
16307
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   107
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   108
        for (Method method : classFile.methods) {
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   109
            new MethodVisitor().visitMethod(method, sb);
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   110
        }
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   111
    }
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   112
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   113
    /**
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   114
     * Used to visit InnerClasses_attribute of a class,
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   115
     * to determne if this class is an local class, and anonymous
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   116
     * inner class or a none-static member class. These types of
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   117
     * classes all have an containing class instances field that
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   118
     * requires an implicit or synthetic constructor argument.
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   119
     */
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   120
    class InnerClassVisitor extends AttributeVisitor<Void, Void> {
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   121
        public Void visitInnerClasses(InnerClasses_attribute iattr, Void v) {
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   122
            try{
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   123
                for (InnerClasses_attribute.Info info : iattr.classes) {
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   124
                    if (info.getInnerClassInfo(classFile.constant_pool) == null) continue;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   125
                    String in = info.getInnerClassInfo(classFile.constant_pool).getName();
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   126
                    if (in == null || !cname.equals(in)) continue;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   127
                    isInner = true;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   128
                    isAnon = null == info.getInnerName(classFile.constant_pool);
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   129
                    isStatic = info.inner_class_access_flags.is(AccessFlags.ACC_STATIC);
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   130
                    break;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   131
                }
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   132
            } catch(Exception e) {
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   133
                throw new IllegalStateException(e);
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   134
            }
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   135
            return null;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   136
        }
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   137
    }
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   138
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   139
    /**
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   140
     * Check the MethodParameters attribute of a method.
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   141
     */
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   142
    class MethodVisitor extends AttributeVisitor<Void, StringBuilder> {
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   143
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   144
        public String mName;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   145
        public Descriptor mDesc;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   146
        public int mParams;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   147
        public int mAttrs;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   148
        public int mNumParams;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   149
        public boolean mSynthetic;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   150
        public boolean mIsConstructor;
21044
ffba9cdeff1a 8015372: Update tests for Method Parameter Reflection API to check whether a parameter is final
mnunez
parents: 18000
diff changeset
   151
        public boolean mIsClinit;
18000
5d29ce00a7a2 6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents: 17999
diff changeset
   152
        public boolean mIsBridge;
21044
ffba9cdeff1a 8015372: Update tests for Method Parameter Reflection API to check whether a parameter is final
mnunez
parents: 18000
diff changeset
   153
        public boolean isFinal;
16307
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   154
        public String prefix;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   155
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   156
        void visitMethod(Method method, StringBuilder sb) throws Exception {
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   157
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   158
            mName = method.getName(classFile.constant_pool);
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   159
            mDesc = method.descriptor;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   160
            mParams =  mDesc.getParameterCount(classFile.constant_pool);
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   161
            mAttrs = method.attributes.attrs.length;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   162
            mNumParams = -1; // no MethodParameters attribute found
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   163
            mSynthetic = method.access_flags.is(AccessFlags.ACC_SYNTHETIC);
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   164
            mIsConstructor = mName.equals("<init>");
21044
ffba9cdeff1a 8015372: Update tests for Method Parameter Reflection API to check whether a parameter is final
mnunez
parents: 18000
diff changeset
   165
            mIsClinit = mName.equals("<clinit>");
16307
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   166
            prefix = cname + "." + mName + "() - ";
18000
5d29ce00a7a2 6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents: 17999
diff changeset
   167
            mIsBridge = method.access_flags.is(AccessFlags.ACC_BRIDGE);
16307
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   168
21044
ffba9cdeff1a 8015372: Update tests for Method Parameter Reflection API to check whether a parameter is final
mnunez
parents: 18000
diff changeset
   169
            if (mIsClinit) {
ffba9cdeff1a 8015372: Update tests for Method Parameter Reflection API to check whether a parameter is final
mnunez
parents: 18000
diff changeset
   170
                sb = new StringBuilder(); // Discard output
ffba9cdeff1a 8015372: Update tests for Method Parameter Reflection API to check whether a parameter is final
mnunez
parents: 18000
diff changeset
   171
            }
16307
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   172
            sb.append(cname).append(".").append(mName).append("(");
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   173
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   174
            for (Attribute a : method.attributes) {
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   175
                a.accept(this, sb);
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   176
            }
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   177
            if (mNumParams == -1) {
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   178
                if (mSynthetic) {
21044
ffba9cdeff1a 8015372: Update tests for Method Parameter Reflection API to check whether a parameter is final
mnunez
parents: 18000
diff changeset
   179
                    // We don't generate MethodParameters attribute for synthetic
ffba9cdeff1a 8015372: Update tests for Method Parameter Reflection API to check whether a parameter is final
mnunez
parents: 18000
diff changeset
   180
                    // methods, so we are creating a parameter pattern to match
ffba9cdeff1a 8015372: Update tests for Method Parameter Reflection API to check whether a parameter is final
mnunez
parents: 18000
diff changeset
   181
                    // ReflectionVisitor API output.
ffba9cdeff1a 8015372: Update tests for Method Parameter Reflection API to check whether a parameter is final
mnunez
parents: 18000
diff changeset
   182
                    for (int i = 0; i < mParams; i++) {
ffba9cdeff1a 8015372: Update tests for Method Parameter Reflection API to check whether a parameter is final
mnunez
parents: 18000
diff changeset
   183
                        if (i == 0)
ffba9cdeff1a 8015372: Update tests for Method Parameter Reflection API to check whether a parameter is final
mnunez
parents: 18000
diff changeset
   184
                            sb.append("arg").append(i);
ffba9cdeff1a 8015372: Update tests for Method Parameter Reflection API to check whether a parameter is final
mnunez
parents: 18000
diff changeset
   185
                        else
ffba9cdeff1a 8015372: Update tests for Method Parameter Reflection API to check whether a parameter is final
mnunez
parents: 18000
diff changeset
   186
                            sb.append(", arg").append(i);
ffba9cdeff1a 8015372: Update tests for Method Parameter Reflection API to check whether a parameter is final
mnunez
parents: 18000
diff changeset
   187
                    }
ffba9cdeff1a 8015372: Update tests for Method Parameter Reflection API to check whether a parameter is final
mnunez
parents: 18000
diff changeset
   188
                    sb.append(")/*synthetic*/");
16307
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   189
                } else {
21044
ffba9cdeff1a 8015372: Update tests for Method Parameter Reflection API to check whether a parameter is final
mnunez
parents: 18000
diff changeset
   190
                    sb.append(")");
16307
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   191
                }
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   192
            }
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   193
            sb.append("\n");
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   194
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   195
            // IMPL: methods with arguments must have a MethodParameters
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   196
            // attribute, except possibly some synthetic methods.
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   197
            if (mNumParams == -1 && mParams > 0 && ! mSynthetic) {
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   198
                error(prefix + "missing MethodParameters attribute");
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   199
            }
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   200
        }
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   201
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   202
        public Void visitMethodParameters(MethodParameters_attribute mp,
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   203
                                          StringBuilder sb) {
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   204
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   205
            // SPEC: At most one MethodParameters attribute allowed
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   206
            if (mNumParams != -1) {
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   207
                error(prefix + "Multiple MethodParameters attributes");
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   208
                return null;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   209
            }
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   210
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   211
            mNumParams = mp.method_parameter_table_length;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   212
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   213
            // SPEC: An empty attribute is not allowed!
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   214
            if (mNumParams == 0) {
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   215
                error(prefix + "0 length MethodParameters attribute");
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   216
                return null;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   217
            }
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   218
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   219
            // SPEC: one name per parameter.
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   220
            if (mNumParams != mParams) {
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   221
                error(prefix + "found " + mNumParams +
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   222
                      " parameters, expected " + mParams);
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   223
                return null;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   224
            }
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   225
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   226
            // IMPL: Whether MethodParameters attributes will be generated
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   227
            // for some synthetics is unresolved. For now, assume no.
33364
542040bb5990 8138729: javac -parameters should not emit parameter names for lambda expressions
sadayapalam
parents: 28452
diff changeset
   228
            if (mSynthetic) {
16307
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   229
                warn(prefix + "synthetic has MethodParameter attribute");
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   230
            }
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   231
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   232
            String sep = "";
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   233
            String userParam = null;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   234
            for (int x = 0; x <  mNumParams; x++) {
21044
ffba9cdeff1a 8015372: Update tests for Method Parameter Reflection API to check whether a parameter is final
mnunez
parents: 18000
diff changeset
   235
                isFinal = (mp.method_parameter_table[x].flags & AccessFlags.ACC_FINAL) != 0;
16307
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   236
                // IMPL: Assume all parameters are named, something.
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   237
                int cpi = mp.method_parameter_table[x].name_index;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   238
                if (cpi == 0) {
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   239
                    error(prefix + "name expected, param[" + x + "]");
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   240
                    return null;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   241
                }
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   242
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   243
                // SPEC: a non 0 index, must be valid!
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   244
                String param = null;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   245
                try {
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   246
                    param = classFile.constant_pool.getUTF8Value(cpi);
21044
ffba9cdeff1a 8015372: Update tests for Method Parameter Reflection API to check whether a parameter is final
mnunez
parents: 18000
diff changeset
   247
                    if (isFinal)
ffba9cdeff1a 8015372: Update tests for Method Parameter Reflection API to check whether a parameter is final
mnunez
parents: 18000
diff changeset
   248
                        param = "final " + param;
16307
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   249
                    sb.append(sep).append(param);
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   250
                    sep = ", ";
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   251
                } catch(ConstantPoolException e) {
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   252
                    error(prefix + "invalid index " + cpi + " for param["
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   253
                          + x + "]");
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   254
                    return null;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   255
                }
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   256
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   257
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   258
                // Check availability, flags and special names
21044
ffba9cdeff1a 8015372: Update tests for Method Parameter Reflection API to check whether a parameter is final
mnunez
parents: 18000
diff changeset
   259
                int check = checkParam(mp, param, x, sb, isFinal);
16307
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   260
                if (check < 0) {
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   261
                    return null;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   262
                }
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   263
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   264
                // TEST: check test assumptions about parameter name.
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   265
                // Expected names are calculated starting with the
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   266
                // 2nd explicit (user given) parameter.
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   267
                // param[n] == ++param[n-1].charAt(0) + param[n-1]
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   268
                String expect = null;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   269
                if (userParam != null) {
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   270
                    char c = userParam.charAt(0);
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   271
                    expect =  (++c) + userParam;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   272
                }
21044
ffba9cdeff1a 8015372: Update tests for Method Parameter Reflection API to check whether a parameter is final
mnunez
parents: 18000
diff changeset
   273
                if(isFinal && expect != null)
ffba9cdeff1a 8015372: Update tests for Method Parameter Reflection API to check whether a parameter is final
mnunez
parents: 18000
diff changeset
   274
                    expect = "final " + expect;
16307
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   275
                if (check > 0) {
21044
ffba9cdeff1a 8015372: Update tests for Method Parameter Reflection API to check whether a parameter is final
mnunez
parents: 18000
diff changeset
   276
                    if(isFinal) {
ffba9cdeff1a 8015372: Update tests for Method Parameter Reflection API to check whether a parameter is final
mnunez
parents: 18000
diff changeset
   277
                        userParam = param.substring(6);
ffba9cdeff1a 8015372: Update tests for Method Parameter Reflection API to check whether a parameter is final
mnunez
parents: 18000
diff changeset
   278
                    } else {
16307
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   279
                    userParam = param;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   280
                }
21044
ffba9cdeff1a 8015372: Update tests for Method Parameter Reflection API to check whether a parameter is final
mnunez
parents: 18000
diff changeset
   281
                }
34751
32ee3b176042 8143133: Wrong MethodParameters on capturing local class with multiple constructors
mcimadamore
parents: 33364
diff changeset
   282
                if (check > 0 && expect != null && !param.equals(expect)) {
16307
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   283
                    error(prefix + "param[" + x + "]='"
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   284
                          + param + "' expected '" + expect + "'");
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   285
                    return null;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   286
                }
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   287
            }
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   288
            if (mSynthetic) {
21044
ffba9cdeff1a 8015372: Update tests for Method Parameter Reflection API to check whether a parameter is final
mnunez
parents: 18000
diff changeset
   289
                sb.append(")/*synthetic*/");
16307
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   290
            } else {
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   291
                sb.append(")");
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   292
            }
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   293
            return null;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   294
        }
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   295
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   296
        /*
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   297
         * Check a parameter for conformity to JLS and javac specific
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   298
         * assumptions.
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   299
         * Return -1, if an error is detected. Otherwise, return 0, if
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   300
         * the parameter is compiler generated, or 1 for an (presumably)
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   301
         * explicitly declared parameter.
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   302
         */
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   303
        int checkParam(MethodParameters_attribute mp, String param, int index,
21044
ffba9cdeff1a 8015372: Update tests for Method Parameter Reflection API to check whether a parameter is final
mnunez
parents: 18000
diff changeset
   304
                       StringBuilder sb, boolean isFinal) {
16307
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   305
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   306
            boolean synthetic = (mp.method_parameter_table[index].flags
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   307
                                 & AccessFlags.ACC_SYNTHETIC) != 0;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   308
            boolean mandated = (mp.method_parameter_table[index].flags
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   309
                                & AccessFlags.ACC_MANDATED) != 0;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   310
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   311
            // Setup expectations for flags and special names
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   312
            String expect = null;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   313
            boolean allowMandated = false;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   314
            boolean allowSynthetic = false;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   315
            if (mSynthetic || synthetic) {
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   316
                // not an implementation gurantee, but okay for now
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   317
                expect = "arg" + index; // default
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   318
            }
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   319
            if (mIsConstructor) {
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   320
                if (isEnum) {
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   321
                    if (index == 0) {
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   322
                        expect = "\\$enum\\$name";
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   323
                        allowSynthetic = true;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   324
                    } else if(index == 1) {
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   325
                        expect = "\\$enum\\$ordinal";
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   326
                        allowSynthetic = true;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   327
                    }
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   328
                } else if (index == 0) {
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   329
                    if (isAnon) {
21044
ffba9cdeff1a 8015372: Update tests for Method Parameter Reflection API to check whether a parameter is final
mnunez
parents: 18000
diff changeset
   330
                        expect = "this\\$[0-9]+";
16307
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   331
                        allowMandated = true;
21044
ffba9cdeff1a 8015372: Update tests for Method Parameter Reflection API to check whether a parameter is final
mnunez
parents: 18000
diff changeset
   332
                        if (isFinal) {
ffba9cdeff1a 8015372: Update tests for Method Parameter Reflection API to check whether a parameter is final
mnunez
parents: 18000
diff changeset
   333
                            expect = "final this\\$[0-9]+";
ffba9cdeff1a 8015372: Update tests for Method Parameter Reflection API to check whether a parameter is final
mnunez
parents: 18000
diff changeset
   334
                        }
16307
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   335
                    } else if (isInner && !isStatic) {
21044
ffba9cdeff1a 8015372: Update tests for Method Parameter Reflection API to check whether a parameter is final
mnunez
parents: 18000
diff changeset
   336
                        expect = "this\\$[0-9]+";
16307
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   337
                        allowMandated = true;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   338
                        if (!isPublic) {
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   339
                            // some but not all non-public inner classes
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   340
                            // have synthetic argument. For now we give
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   341
                            // the test a bit of slack and allow either.
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   342
                            allowSynthetic = true;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   343
                        }
21044
ffba9cdeff1a 8015372: Update tests for Method Parameter Reflection API to check whether a parameter is final
mnunez
parents: 18000
diff changeset
   344
                        if (isFinal) {
ffba9cdeff1a 8015372: Update tests for Method Parameter Reflection API to check whether a parameter is final
mnunez
parents: 18000
diff changeset
   345
                            expect = "final this\\$[0-9]+";
ffba9cdeff1a 8015372: Update tests for Method Parameter Reflection API to check whether a parameter is final
mnunez
parents: 18000
diff changeset
   346
                        }
16307
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   347
                    }
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   348
                }
34751
32ee3b176042 8143133: Wrong MethodParameters on capturing local class with multiple constructors
mcimadamore
parents: 33364
diff changeset
   349
32ee3b176042 8143133: Wrong MethodParameters on capturing local class with multiple constructors
mcimadamore
parents: 33364
diff changeset
   350
                if (synthetic && !mandated && !allowSynthetic) {
32ee3b176042 8143133: Wrong MethodParameters on capturing local class with multiple constructors
mcimadamore
parents: 33364
diff changeset
   351
                    //patch treatment for local captures
32ee3b176042 8143133: Wrong MethodParameters on capturing local class with multiple constructors
mcimadamore
parents: 33364
diff changeset
   352
                    if (isAnon || (isInner & !isStatic)) {
32ee3b176042 8143133: Wrong MethodParameters on capturing local class with multiple constructors
mcimadamore
parents: 33364
diff changeset
   353
                        expect = "val\\$.*";
32ee3b176042 8143133: Wrong MethodParameters on capturing local class with multiple constructors
mcimadamore
parents: 33364
diff changeset
   354
                        allowSynthetic = true;
32ee3b176042 8143133: Wrong MethodParameters on capturing local class with multiple constructors
mcimadamore
parents: 33364
diff changeset
   355
                        if (isFinal) {
32ee3b176042 8143133: Wrong MethodParameters on capturing local class with multiple constructors
mcimadamore
parents: 33364
diff changeset
   356
                            expect = "final val\\$.*";
32ee3b176042 8143133: Wrong MethodParameters on capturing local class with multiple constructors
mcimadamore
parents: 33364
diff changeset
   357
                        }
32ee3b176042 8143133: Wrong MethodParameters on capturing local class with multiple constructors
mcimadamore
parents: 33364
diff changeset
   358
                    }
32ee3b176042 8143133: Wrong MethodParameters on capturing local class with multiple constructors
mcimadamore
parents: 33364
diff changeset
   359
                }
16307
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   360
            } else if (isEnum && mNumParams == 1 && index == 0 && mName.equals("valueOf")) {
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   361
                expect = "name";
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   362
                allowMandated = true;
33364
542040bb5990 8138729: javac -parameters should not emit parameter names for lambda expressions
sadayapalam
parents: 28452
diff changeset
   363
            } else if (mIsBridge) {
18000
5d29ce00a7a2 6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents: 17999
diff changeset
   364
                allowSynthetic = true;
5d29ce00a7a2 6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents: 17999
diff changeset
   365
                /*  you can't expect an special name for bridges' parameters.
33364
542040bb5990 8138729: javac -parameters should not emit parameter names for lambda expressions
sadayapalam
parents: 28452
diff changeset
   366
                 *  The name of the original parameters are now copied.
18000
5d29ce00a7a2 6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents: 17999
diff changeset
   367
                 */
5d29ce00a7a2 6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents: 17999
diff changeset
   368
                expect = null;
16307
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   369
            }
21044
ffba9cdeff1a 8015372: Update tests for Method Parameter Reflection API to check whether a parameter is final
mnunez
parents: 18000
diff changeset
   370
            if (mandated) sb.append("/*implicit*/");
ffba9cdeff1a 8015372: Update tests for Method Parameter Reflection API to check whether a parameter is final
mnunez
parents: 18000
diff changeset
   371
            if (synthetic) sb.append("/*synthetic*/");
16307
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   372
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   373
            // IMPL: our rules a somewhat fuzzy, sometimes allowing both mandated
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   374
            // and synthetic. However, a parameters cannot be both.
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   375
            if (mandated && synthetic) {
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   376
                error(prefix + "param[" + index + "] == \"" + param
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   377
                      + "\" ACC_SYNTHETIC and ACC_MANDATED");
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   378
                return -1;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   379
            }
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   380
            // ... but must be either, if both "allowed".
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   381
            if (!(mandated || synthetic) && allowMandated && allowSynthetic) {
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   382
                error(prefix + "param[" + index + "] == \"" + param
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   383
                      + "\" expected ACC_MANDATED or ACC_SYNTHETIC");
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   384
                return -1;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   385
            }
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   386
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   387
            // ... if only one is "allowed", we meant "required".
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   388
            if (!mandated && allowMandated && !allowSynthetic) {
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   389
                error(prefix + "param[" + index + "] == \"" + param
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   390
                      + "\" expected ACC_MANDATED");
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   391
                return -1;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   392
            }
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   393
            if (!synthetic && !allowMandated && allowSynthetic) {
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   394
                error(prefix + "param[" + index + "] == \"" + param
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   395
                      + "\" expected ACC_SYNTHETIC");
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   396
                return -1;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   397
            }
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   398
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   399
            // ... and not "allowed", means prohibited.
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   400
            if (mandated && !allowMandated) {
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   401
                error(prefix + "param[" + index + "] == \"" + param
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   402
                      + "\" unexpected, is ACC_MANDATED");
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   403
                return -1;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   404
            }
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   405
            if (synthetic && !allowSynthetic) {
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   406
                error(prefix + "param[" + index + "] == \"" + param
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   407
                      + "\" unexpected, is ACC_SYNTHETIC");
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   408
                return -1;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   409
            }
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   410
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   411
            // Test special name expectations
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   412
            if (expect != null) {
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   413
                if (param.matches(expect)) {
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   414
                    return 0;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   415
                }
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   416
                error(prefix + "param[" + index + "]='" + param +
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   417
                      "' expected '" + expect + "'");
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   418
                return -1;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   419
            }
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   420
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   421
            // No further checking for synthetic methods.
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   422
            if (mSynthetic) {
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   423
                return 0;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   424
            }
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   425
            // Otherwise, do check test parameter naming convention.
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   426
            return 1;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   427
        }
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   428
    }
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   429
}