langtools/test/tools/javac/MethodParameters/ReflectionVisitor.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
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    24
import java.io.*;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    25
import java.lang.reflect.*;
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
 * Test MethodParameter attributs by reflection API
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    29
 */
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    30
public class ReflectionVisitor extends Tester.Visitor {
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    31
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    32
    public ReflectionVisitor(Tester tester) {
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    33
        super(tester);
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    34
    }
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    35
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    36
    public void error(String msg) {
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    37
        super.error("reflection: " + msg);
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    38
    }
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    39
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    40
    public void warn(String msg) {
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    41
        super.warn("reflection: " + msg);
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    42
    }
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    43
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    44
    boolean isEnum;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    45
    boolean isInterface;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    46
    boolean isAnon;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    47
    boolean isLocal;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    48
    boolean isMember;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    49
    boolean isStatic;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    50
    boolean isPublic;
21044
ffba9cdeff1a 8015372: Update tests for Method Parameter Reflection API to check whether a parameter is final
mnunez
parents: 18000
diff changeset
    51
    boolean isFinal;
16307
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    52
    Class clazz;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    53
    StringBuilder sb;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    54
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    55
    /**
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    56
     * Read class using {@code ClassFile}, and generate a list of methods
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    57
     * with parameter names as available in the MethodParameters attribute.
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    58
     */
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    59
    void visitClass(final String cl, final File cfile, final StringBuilder sb)
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    60
        throws Exception {
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    61
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    62
        this.sb = sb;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    63
        clazz = Class.forName(cl);
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    64
        isEnum = clazz.isEnum();
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    65
        isInterface = clazz.isInterface();
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    66
        isAnon = clazz.isAnonymousClass();
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    67
        isLocal = clazz.isLocalClass();
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    68
        isMember = clazz.isMemberClass();
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    69
        isStatic = ((clazz.getModifiers() & Modifier.STATIC) != 0);
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    70
        isPublic = ((clazz.getModifiers() & Modifier.PUBLIC) != 0);
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    71
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    72
        sb.append(isStatic ? "static " : "")
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    73
            .append(isPublic ? "public " : "")
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    74
            .append(isEnum ? "enum " : isInterface ? "interface " : "class ")
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    75
            .append(cl).append(" -- ")
21044
ffba9cdeff1a 8015372: Update tests for Method Parameter Reflection API to check whether a parameter is final
mnunez
parents: 18000
diff changeset
    76
            .append(isMember? "inner" : "" )
ffba9cdeff1a 8015372: Update tests for Method Parameter Reflection API to check whether a parameter is final
mnunez
parents: 18000
diff changeset
    77
            .append(isLocal? "inner" : "" )
16307
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    78
            .append(isAnon ?  "anon" : "")
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    79
            .append("\n");
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    80
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    81
        for (Constructor c : clazz.getDeclaredConstructors()) {
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    82
            testConstructor(c);
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    83
        }
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    84
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    85
        for (Method m :clazz.getDeclaredMethods()) {
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    86
            testMethod(m);
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    87
        }
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    88
    }
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    89
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    90
    void testConstructor(Constructor c) {
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    91
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    92
        String prefix = clazz.getName() + "." + c.getName() + "() - ";
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    93
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    94
        // Parameters must match parameter types
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    95
        Parameter params[] = c.getParameters();
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    96
        int paramTypes =  c.getParameterTypes().length;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    97
        if (paramTypes != params.length) {
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    98
            error(prefix + "number of parameter types (" + paramTypes
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    99
                  + ") != number of parameters (" + params.length + ")");
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   100
            return;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   101
        }
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   102
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   103
        sb.append(clazz.getName()).append(".").append("<init>").append("(");
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   104
        String sep = "";
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   105
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   106
        // Some paramters are expected
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   107
        if (params.length < 2 && isEnum) {
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   108
            error(prefix + "enum constuctor, two arguments expected");
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   109
        } else if (params.length < 1 && (isAnon || isLocal ||
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   110
                                         (isMember && !isStatic ))) {
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   111
            error(prefix + "class constuctor,expected implicit argument");
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
        int i = -1;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   115
        String param = null;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   116
        for (Parameter p : c.getParameters()) {
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   117
            i++;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   118
            String pname = p.getName();
21044
ffba9cdeff1a 8015372: Update tests for Method Parameter Reflection API to check whether a parameter is final
mnunez
parents: 18000
diff changeset
   119
            int pmodifier = p.getModifiers();
ffba9cdeff1a 8015372: Update tests for Method Parameter Reflection API to check whether a parameter is final
mnunez
parents: 18000
diff changeset
   120
            isFinal = false;
ffba9cdeff1a 8015372: Update tests for Method Parameter Reflection API to check whether a parameter is final
mnunez
parents: 18000
diff changeset
   121
            if (Modifier.isFinal(pmodifier)) {
ffba9cdeff1a 8015372: Update tests for Method Parameter Reflection API to check whether a parameter is final
mnunez
parents: 18000
diff changeset
   122
                isFinal = true;
ffba9cdeff1a 8015372: Update tests for Method Parameter Reflection API to check whether a parameter is final
mnunez
parents: 18000
diff changeset
   123
                pname = "final " + pname;
ffba9cdeff1a 8015372: Update tests for Method Parameter Reflection API to check whether a parameter is final
mnunez
parents: 18000
diff changeset
   124
            }
16307
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   125
            sb.append(sep).append(pname);
21044
ffba9cdeff1a 8015372: Update tests for Method Parameter Reflection API to check whether a parameter is final
mnunez
parents: 18000
diff changeset
   126
            if (p.isImplicit()) sb.append("/*implicit*/");
ffba9cdeff1a 8015372: Update tests for Method Parameter Reflection API to check whether a parameter is final
mnunez
parents: 18000
diff changeset
   127
            if (p.isSynthetic()) sb.append("/*synthetic*/");
16307
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   128
            sep = ", ";
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   129
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   130
            // Set expectations
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   131
            String expect = null;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   132
            boolean allowImplicit = false;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   133
            boolean allowSynthetic = false;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   134
            if (isEnum) {
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   135
                if (i == 0) {
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   136
                    expect = "\\$enum\\$name";
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   137
                    allowSynthetic = true;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   138
                } else if(i == 1) {
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   139
                    expect = "\\$enum\\$ordinal";
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   140
                    allowSynthetic = true;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   141
                }
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   142
            } else if (i == 0) {
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   143
                if (isAnon) {
21044
ffba9cdeff1a 8015372: Update tests for Method Parameter Reflection API to check whether a parameter is final
mnunez
parents: 18000
diff changeset
   144
                    expect = "this\\$[0-9]+";
16307
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   145
                    allowImplicit = true;
21044
ffba9cdeff1a 8015372: Update tests for Method Parameter Reflection API to check whether a parameter is final
mnunez
parents: 18000
diff changeset
   146
                    if (isFinal)
ffba9cdeff1a 8015372: Update tests for Method Parameter Reflection API to check whether a parameter is final
mnunez
parents: 18000
diff changeset
   147
                        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
   148
                } else if (isLocal) {
ffba9cdeff1a 8015372: Update tests for Method Parameter Reflection API to check whether a parameter is final
mnunez
parents: 18000
diff changeset
   149
                    expect = "this\\$[0-9]+";
ffba9cdeff1a 8015372: Update tests for Method Parameter Reflection API to check whether a parameter is final
mnunez
parents: 18000
diff changeset
   150
                    allowImplicit = true;
ffba9cdeff1a 8015372: Update tests for Method Parameter Reflection API to check whether a parameter is final
mnunez
parents: 18000
diff changeset
   151
                    if (isFinal)
ffba9cdeff1a 8015372: Update tests for Method Parameter Reflection API to check whether a parameter is final
mnunez
parents: 18000
diff changeset
   152
                        expect = "final this\\$[0-9]+";
16307
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   153
                } else if ((isMember && !isStatic)) {
21044
ffba9cdeff1a 8015372: Update tests for Method Parameter Reflection API to check whether a parameter is final
mnunez
parents: 18000
diff changeset
   154
                    expect = "this\\$[0-9]+";
16307
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   155
                    allowImplicit = true;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   156
                    if (!isPublic) {
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   157
                        // some but not all non-public inner classes
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   158
                        // have synthetic argument. For now we give
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   159
                        // the test a bit of slack and allow either.
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   160
                        allowSynthetic = true;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   161
                    }
21044
ffba9cdeff1a 8015372: Update tests for Method Parameter Reflection API to check whether a parameter is final
mnunez
parents: 18000
diff changeset
   162
                    if (isFinal)
ffba9cdeff1a 8015372: Update tests for Method Parameter Reflection API to check whether a parameter is final
mnunez
parents: 18000
diff changeset
   163
                        expect = "final this\\$[0-9]+";
16307
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   164
                }
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   165
            }
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   166
34751
32ee3b176042 8143133: Wrong MethodParameters on capturing local class with multiple constructors
mcimadamore
parents: 33364
diff changeset
   167
            if (p.isSynthetic() && !p.isImplicit() && !allowSynthetic) {
32ee3b176042 8143133: Wrong MethodParameters on capturing local class with multiple constructors
mcimadamore
parents: 33364
diff changeset
   168
                //patch treatment for local captures
32ee3b176042 8143133: Wrong MethodParameters on capturing local class with multiple constructors
mcimadamore
parents: 33364
diff changeset
   169
                if (isAnon || ((isLocal || isAnon) & !isStatic)) {
32ee3b176042 8143133: Wrong MethodParameters on capturing local class with multiple constructors
mcimadamore
parents: 33364
diff changeset
   170
                    expect = "val\\$.*";
32ee3b176042 8143133: Wrong MethodParameters on capturing local class with multiple constructors
mcimadamore
parents: 33364
diff changeset
   171
                    allowSynthetic = true;
32ee3b176042 8143133: Wrong MethodParameters on capturing local class with multiple constructors
mcimadamore
parents: 33364
diff changeset
   172
                    if (isFinal) {
32ee3b176042 8143133: Wrong MethodParameters on capturing local class with multiple constructors
mcimadamore
parents: 33364
diff changeset
   173
                        expect = "final val\\$.*";
32ee3b176042 8143133: Wrong MethodParameters on capturing local class with multiple constructors
mcimadamore
parents: 33364
diff changeset
   174
                    }
32ee3b176042 8143133: Wrong MethodParameters on capturing local class with multiple constructors
mcimadamore
parents: 33364
diff changeset
   175
                }
32ee3b176042 8143133: Wrong MethodParameters on capturing local class with multiple constructors
mcimadamore
parents: 33364
diff changeset
   176
            }
32ee3b176042 8143133: Wrong MethodParameters on capturing local class with multiple constructors
mcimadamore
parents: 33364
diff changeset
   177
16307
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   178
            // Check expected flags
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   179
            if (p.isSynthetic() && p.isImplicit()) {
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   180
                error(prefix + "param[" + i + "]='" + pname +
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   181
                      "' both isImplicit() and isSynthetic()");
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   182
                break;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   183
            }
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   184
            if (allowImplicit && allowSynthetic &&
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   185
                !(p.isSynthetic() || p.isImplicit())) {
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   186
                error(prefix + "param[" + i + "]='" + pname +
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   187
                      "' isImplicit() or isSynthetic() expected");
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   188
                break;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   189
            }
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   190
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   191
            if (allowImplicit && !allowSynthetic && !p.isImplicit()) {
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   192
                error(prefix + "param[" + i + "]='" + pname +
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   193
                      "' isImplicit() expected");
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   194
                break;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   195
            }
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   196
            if (!allowImplicit && allowSynthetic && !p.isSynthetic()) {
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   197
                error(prefix + "param[" + i + "]='" + pname +
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   198
                      "' isSynthetic() expected");
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   199
                break;
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
            if (!allowImplicit && p.isImplicit()) {
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   203
                error(prefix + "param[" + i + "]='" + pname +
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   204
                      "' isImplicit() unexpected");
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   205
                break;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   206
            }
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   207
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   208
            if (!allowSynthetic && p.isSynthetic()) {
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   209
                error(prefix + "param[" + i + "]='" + pname +
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   210
                      "' isSynthetic() unexpected");
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   211
                break;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   212
            }
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   213
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   214
            // Check expected names
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   215
            if (expect != null) {
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   216
                if (pname.matches(expect))  continue;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   217
                error(prefix + "param[" + i + "]='" + pname +
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   218
                      "' expected '" + expect + "'");
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   219
                break;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   220
            }
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   221
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   222
            // Test naming convention for explicit parameters.
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   223
            boolean fidelity = !isAnon;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   224
            if (param != null && fidelity) {
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   225
                char ch = param.charAt(0);
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   226
                expect =  (++ch) + param;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   227
            }
21044
ffba9cdeff1a 8015372: Update tests for Method Parameter Reflection API to check whether a parameter is final
mnunez
parents: 18000
diff changeset
   228
            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
   229
                expect = "final " + expect;
ffba9cdeff1a 8015372: Update tests for Method Parameter Reflection API to check whether a parameter is final
mnunez
parents: 18000
diff changeset
   230
            }
16307
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   231
            if (pname != null && fidelity) {
21044
ffba9cdeff1a 8015372: Update tests for Method Parameter Reflection API to check whether a parameter is final
mnunez
parents: 18000
diff changeset
   232
                if (isFinal) {
ffba9cdeff1a 8015372: Update tests for Method Parameter Reflection API to check whether a parameter is final
mnunez
parents: 18000
diff changeset
   233
                    param = pname.substring(6);
ffba9cdeff1a 8015372: Update tests for Method Parameter Reflection API to check whether a parameter is final
mnunez
parents: 18000
diff changeset
   234
                } else {
16307
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   235
                param = pname;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   236
            }
21044
ffba9cdeff1a 8015372: Update tests for Method Parameter Reflection API to check whether a parameter is final
mnunez
parents: 18000
diff changeset
   237
            }
16307
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   238
            if (expect != null && !expect.equals(pname)) {
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   239
                error(prefix + "param[" + i + "]='" + pname +
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   240
                      "' expected '" + expect + "'");
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   241
                break;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   242
            }
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   243
        }
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   244
        if  (c.isSynthetic()) {
21044
ffba9cdeff1a 8015372: Update tests for Method Parameter Reflection API to check whether a parameter is final
mnunez
parents: 18000
diff changeset
   245
            sb.append(")/*synthetic*/\n");
16307
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   246
        } else {
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   247
            sb.append(")\n");
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   248
        }
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   249
    }
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   250
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   251
    void testMethod(Method m) {
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   252
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   253
        String prefix = clazz.getName() + "." + m.getName() + "() - ";
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   254
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   255
        // Parameters must match parameter types
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   256
        int paramTypes =  m.getParameterTypes().length;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   257
        int params = m.getParameters().length;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   258
        if (paramTypes != params) {
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   259
            error(prefix + "number of parameter types (" + paramTypes
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   260
                  + ") != number of parameters (" + params + ")");
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   261
            return;
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
        sb.append(clazz.getName()).append(".").append(m.getName()).append("(");
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   265
        String sep = "";
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   266
        String param = null;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   267
        int i = -1;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   268
        // For methods we expect all parameters to follow
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   269
        // the test-case design pattern, except synthetic methods.
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   270
        for (Parameter p : m.getParameters()) {
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   271
            i++;
21044
ffba9cdeff1a 8015372: Update tests for Method Parameter Reflection API to check whether a parameter is final
mnunez
parents: 18000
diff changeset
   272
            isFinal = false;
ffba9cdeff1a 8015372: Update tests for Method Parameter Reflection API to check whether a parameter is final
mnunez
parents: 18000
diff changeset
   273
            int pmodifier = p.getModifiers();
16307
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   274
            if (param == null) {
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   275
                param = p.getName();
21044
ffba9cdeff1a 8015372: Update tests for Method Parameter Reflection API to check whether a parameter is final
mnunez
parents: 18000
diff changeset
   276
                if (Modifier.isFinal(pmodifier)) {
ffba9cdeff1a 8015372: Update tests for Method Parameter Reflection API to check whether a parameter is final
mnunez
parents: 18000
diff changeset
   277
                    isFinal = true;
ffba9cdeff1a 8015372: Update tests for Method Parameter Reflection API to check whether a parameter is final
mnunez
parents: 18000
diff changeset
   278
                    param = "final " + param;
ffba9cdeff1a 8015372: Update tests for Method Parameter Reflection API to check whether a parameter is final
mnunez
parents: 18000
diff changeset
   279
                }
16307
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   280
                sb.append(sep).append(param);
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   281
            } else  {
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   282
                char c = param.charAt(0);
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   283
                String expect =  m.isSynthetic() ? ("arg" + i) : ((++c) + param);
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   284
                param = p.getName();
21044
ffba9cdeff1a 8015372: Update tests for Method Parameter Reflection API to check whether a parameter is final
mnunez
parents: 18000
diff changeset
   285
                if (Modifier.isFinal(pmodifier)) {
ffba9cdeff1a 8015372: Update tests for Method Parameter Reflection API to check whether a parameter is final
mnunez
parents: 18000
diff changeset
   286
                    isFinal = true;
ffba9cdeff1a 8015372: Update tests for Method Parameter Reflection API to check whether a parameter is final
mnunez
parents: 18000
diff changeset
   287
                    expect = "final " + expect;
ffba9cdeff1a 8015372: Update tests for Method Parameter Reflection API to check whether a parameter is final
mnunez
parents: 18000
diff changeset
   288
                    param = "final " + param;
ffba9cdeff1a 8015372: Update tests for Method Parameter Reflection API to check whether a parameter is final
mnunez
parents: 18000
diff changeset
   289
                }
16307
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   290
                sb.append(sep).append(param);
33364
542040bb5990 8138729: javac -parameters should not emit parameter names for lambda expressions
sadayapalam
parents: 28452
diff changeset
   291
                if (!m.isBridge() && !expect.equals(param)) {
16307
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   292
                    error(prefix + "param[" + i + "]='"
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   293
                          + param + "' expected '" + expect + "'");
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   294
                    break;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   295
                }
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   296
            }
21044
ffba9cdeff1a 8015372: Update tests for Method Parameter Reflection API to check whether a parameter is final
mnunez
parents: 18000
diff changeset
   297
            if(isFinal)
ffba9cdeff1a 8015372: Update tests for Method Parameter Reflection API to check whether a parameter is final
mnunez
parents: 18000
diff changeset
   298
                param = param.substring(6);
ffba9cdeff1a 8015372: Update tests for Method Parameter Reflection API to check whether a parameter is final
mnunez
parents: 18000
diff changeset
   299
            if (p.isImplicit()) {
ffba9cdeff1a 8015372: Update tests for Method Parameter Reflection API to check whether a parameter is final
mnunez
parents: 18000
diff changeset
   300
                sb.append("/*implicit*/");
ffba9cdeff1a 8015372: Update tests for Method Parameter Reflection API to check whether a parameter is final
mnunez
parents: 18000
diff changeset
   301
            }
ffba9cdeff1a 8015372: Update tests for Method Parameter Reflection API to check whether a parameter is final
mnunez
parents: 18000
diff changeset
   302
            if (p.isSynthetic()) {
ffba9cdeff1a 8015372: Update tests for Method Parameter Reflection API to check whether a parameter is final
mnunez
parents: 18000
diff changeset
   303
                sb.append("/*synthetic*/");
ffba9cdeff1a 8015372: Update tests for Method Parameter Reflection API to check whether a parameter is final
mnunez
parents: 18000
diff changeset
   304
            }
16307
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   305
            sep = ", ";
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   306
        }
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   307
        if  (m.isSynthetic()) {
21044
ffba9cdeff1a 8015372: Update tests for Method Parameter Reflection API to check whether a parameter is final
mnunez
parents: 18000
diff changeset
   308
            sb.append(")/*synthetic*/\n");
16307
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   309
        } else {
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   310
            sb.append(")\n");
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   311
        }
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   312
    }
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   313
}