langtools/test/tools/javac/MethodParameters/ReflectionVisitor.java
author mnunez
Thu, 17 Oct 2013 13:27:36 +0200
changeset 21044 ffba9cdeff1a
parent 18000 5d29ce00a7a2
child 28452 6afa05455443
permissions -rw-r--r--
8015372: Update tests for Method Parameter Reflection API to check whether a parameter is final Reviewed-by: jjg, jfranck
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
16307
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
     1
/*
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
     2
 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
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
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   167
            // Check expected flags
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   168
            if (p.isSynthetic() && p.isImplicit()) {
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   169
                error(prefix + "param[" + i + "]='" + pname +
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   170
                      "' both isImplicit() and isSynthetic()");
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   171
                break;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   172
            }
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   173
            if (allowImplicit && allowSynthetic &&
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   174
                !(p.isSynthetic() || p.isImplicit())) {
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   175
                error(prefix + "param[" + i + "]='" + pname +
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   176
                      "' isImplicit() or isSynthetic() expected");
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   177
                break;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   178
            }
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   179
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   180
            if (allowImplicit && !allowSynthetic && !p.isImplicit()) {
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   181
                error(prefix + "param[" + i + "]='" + pname +
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   182
                      "' isImplicit() expected");
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   183
                break;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   184
            }
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   185
            if (!allowImplicit && allowSynthetic && !p.isSynthetic()) {
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
                      "' 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 && 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() unexpected");
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
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   197
            if (!allowSynthetic && p.isSynthetic()) {
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   198
                error(prefix + "param[" + i + "]='" + pname +
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   199
                      "' isSynthetic() unexpected");
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   200
                break;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   201
            }
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   202
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   203
            // Check expected names
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   204
            if (expect != null) {
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   205
                if (pname.matches(expect))  continue;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   206
                error(prefix + "param[" + i + "]='" + pname +
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   207
                      "' expected '" + expect + "'");
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   208
                break;
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
            // Test naming convention for explicit parameters.
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   212
            boolean fidelity = !isAnon;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   213
            if (param != null && fidelity) {
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   214
                char ch = param.charAt(0);
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   215
                expect =  (++ch) + param;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   216
            }
21044
ffba9cdeff1a 8015372: Update tests for Method Parameter Reflection API to check whether a parameter is final
mnunez
parents: 18000
diff changeset
   217
            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
   218
                expect = "final " + expect;
ffba9cdeff1a 8015372: Update tests for Method Parameter Reflection API to check whether a parameter is final
mnunez
parents: 18000
diff changeset
   219
            }
16307
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   220
            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
   221
                if (isFinal) {
ffba9cdeff1a 8015372: Update tests for Method Parameter Reflection API to check whether a parameter is final
mnunez
parents: 18000
diff changeset
   222
                    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
   223
                } else {
16307
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   224
                param = pname;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   225
            }
21044
ffba9cdeff1a 8015372: Update tests for Method Parameter Reflection API to check whether a parameter is final
mnunez
parents: 18000
diff changeset
   226
            }
16307
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   227
            if (expect != null && !expect.equals(pname)) {
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   228
                error(prefix + "param[" + i + "]='" + pname +
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   229
                      "' expected '" + expect + "'");
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   230
                break;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   231
            }
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   232
        }
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   233
        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
   234
            sb.append(")/*synthetic*/\n");
16307
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   235
        } else {
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   236
            sb.append(")\n");
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   237
        }
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   238
    }
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   239
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   240
    void testMethod(Method m) {
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   241
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   242
        String prefix = clazz.getName() + "." + m.getName() + "() - ";
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   243
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   244
        // Parameters must match parameter types
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   245
        int paramTypes =  m.getParameterTypes().length;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   246
        int params = m.getParameters().length;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   247
        if (paramTypes != params) {
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   248
            error(prefix + "number of parameter types (" + paramTypes
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   249
                  + ") != number of parameters (" + params + ")");
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   250
            return;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   251
        }
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   252
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   253
        sb.append(clazz.getName()).append(".").append(m.getName()).append("(");
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   254
        String sep = "";
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   255
        String param = null;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   256
        int i = -1;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   257
        // For methods we expect all parameters to follow
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   258
        // the test-case design pattern, except synthetic methods.
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   259
        for (Parameter p : m.getParameters()) {
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   260
            i++;
21044
ffba9cdeff1a 8015372: Update tests for Method Parameter Reflection API to check whether a parameter is final
mnunez
parents: 18000
diff changeset
   261
            isFinal = false;
ffba9cdeff1a 8015372: Update tests for Method Parameter Reflection API to check whether a parameter is final
mnunez
parents: 18000
diff changeset
   262
            int pmodifier = p.getModifiers();
16307
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   263
            if (param == null) {
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   264
                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
   265
                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
   266
                    isFinal = true;
ffba9cdeff1a 8015372: Update tests for Method Parameter Reflection API to check whether a parameter is final
mnunez
parents: 18000
diff changeset
   267
                    param = "final " + param;
ffba9cdeff1a 8015372: Update tests for Method Parameter Reflection API to check whether a parameter is final
mnunez
parents: 18000
diff changeset
   268
                }
16307
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   269
                sb.append(sep).append(param);
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   270
            } else  {
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   271
                char c = param.charAt(0);
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   272
                String expect =  m.isSynthetic() ? ("arg" + i) : ((++c) + param);
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   273
                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
   274
                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
   275
                    isFinal = true;
ffba9cdeff1a 8015372: Update tests for Method Parameter Reflection API to check whether a parameter is final
mnunez
parents: 18000
diff changeset
   276
                    expect = "final " + expect;
ffba9cdeff1a 8015372: Update tests for Method Parameter Reflection API to check whether a parameter is final
mnunez
parents: 18000
diff changeset
   277
                    param = "final " + param;
ffba9cdeff1a 8015372: Update tests for Method Parameter Reflection API to check whether a parameter is final
mnunez
parents: 18000
diff changeset
   278
                }
16307
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   279
                sb.append(sep).append(param);
18000
5d29ce00a7a2 6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents: 17999
diff changeset
   280
                if (!m.isBridge() && !expect.equals(param)) {
16307
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   281
                    error(prefix + "param[" + i + "]='"
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   282
                          + param + "' expected '" + expect + "'");
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   283
                    break;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   284
                }
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   285
            }
21044
ffba9cdeff1a 8015372: Update tests for Method Parameter Reflection API to check whether a parameter is final
mnunez
parents: 18000
diff changeset
   286
            if(isFinal)
ffba9cdeff1a 8015372: Update tests for Method Parameter Reflection API to check whether a parameter is final
mnunez
parents: 18000
diff changeset
   287
                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
   288
            if (p.isImplicit()) {
ffba9cdeff1a 8015372: Update tests for Method Parameter Reflection API to check whether a parameter is final
mnunez
parents: 18000
diff changeset
   289
                sb.append("/*implicit*/");
ffba9cdeff1a 8015372: Update tests for Method Parameter Reflection API to check whether a parameter is final
mnunez
parents: 18000
diff changeset
   290
            }
ffba9cdeff1a 8015372: Update tests for Method Parameter Reflection API to check whether a parameter is final
mnunez
parents: 18000
diff changeset
   291
            if (p.isSynthetic()) {
ffba9cdeff1a 8015372: Update tests for Method Parameter Reflection API to check whether a parameter is final
mnunez
parents: 18000
diff changeset
   292
                sb.append("/*synthetic*/");
ffba9cdeff1a 8015372: Update tests for Method Parameter Reflection API to check whether a parameter is final
mnunez
parents: 18000
diff changeset
   293
            }
16307
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   294
            sep = ", ";
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   295
        }
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   296
        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
   297
            sb.append(")/*synthetic*/\n");
16307
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   298
        } else {
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   299
            sb.append(")\n");
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   300
        }
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   301
    }
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   302
}