langtools/test/tools/javac/MethodParameters/ReflectionVisitor.java
author vromero
Sat, 01 Jun 2013 22:09:18 +0100
changeset 18000 5d29ce00a7a2
parent 17999 42ae6fe53718
child 21044 ffba9cdeff1a
permissions -rw-r--r--
6695379: Copy method annotations and parameter annotations to synthetic bridge methods Reviewed-by: mcimadamore
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;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    51
    Class clazz;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    52
    StringBuilder sb;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    53
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    54
    /**
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    55
     * Read class using {@code ClassFile}, and generate a list of methods
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    56
     * with parameter names as available in the MethodParameters attribute.
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    57
     */
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    58
    void visitClass(final String cl, final File cfile, final StringBuilder sb)
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    59
        throws Exception {
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    60
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    61
        this.sb = sb;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    62
        clazz = Class.forName(cl);
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    63
        isEnum = clazz.isEnum();
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    64
        isInterface = clazz.isInterface();
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    65
        isAnon = clazz.isAnonymousClass();
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    66
        isLocal = clazz.isLocalClass();
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    67
        isMember = clazz.isMemberClass();
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    68
        isStatic = ((clazz.getModifiers() & Modifier.STATIC) != 0);
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    69
        isPublic = ((clazz.getModifiers() & Modifier.PUBLIC) != 0);
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    70
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    71
        sb.append(isStatic ? "static " : "")
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    72
            .append(isPublic ? "public " : "")
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    73
            .append(isEnum ? "enum " : isInterface ? "interface " : "class ")
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    74
            .append(cl).append(" -- ")
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    75
            .append(isMember? "member " : "" )
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    76
            .append(isLocal? "local " : "" )
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    77
            .append(isAnon ?  "anon" : "")
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    78
            .append("\n");
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    79
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    80
        for (Constructor c : clazz.getDeclaredConstructors()) {
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    81
            testConstructor(c);
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    82
        }
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    83
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    84
        for (Method m :clazz.getDeclaredMethods()) {
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
    85
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();
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   119
            sb.append(sep).append(pname);
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   120
            if (p.isImplicit()) sb.append("!");
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   121
            if (p.isSynthetic()) sb.append("!!");
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   122
            sep = ", ";
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   123
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   124
            // Set expectations
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   125
            String expect = null;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   126
            boolean allowImplicit = false;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   127
            boolean allowSynthetic = false;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   128
            if (isEnum) {
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   129
                if (i == 0) {
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   130
                    expect = "\\$enum\\$name";
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   131
                    allowSynthetic = true;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   132
                } else if(i == 1) {
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   133
                    expect = "\\$enum\\$ordinal";
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   134
                    allowSynthetic = true;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   135
                }
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   136
            } else if (i == 0) {
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   137
                if (isAnon) {
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   138
                    allowImplicit = true;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   139
                } else if (isLocal) {
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   140
                    allowImplicit = true;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   141
                    expect = "this\\$[0-n]*";
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   142
                } else if ((isMember && !isStatic)) {
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   143
                    allowImplicit = true;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   144
                    if (!isPublic) {
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   145
                        // some but not all non-public inner classes
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   146
                        // have synthetic argument. For now we give
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   147
                        // the test a bit of slack and allow either.
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   148
                        allowSynthetic = true;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   149
                    }
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   150
                    expect = "this\\$[0-n]*";
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   151
                }
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   152
            }
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   153
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   154
            // Check expected flags
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   155
            if (p.isSynthetic() && p.isImplicit()) {
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   156
                error(prefix + "param[" + i + "]='" + pname +
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   157
                      "' both isImplicit() and isSynthetic()");
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   158
                break;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   159
            }
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   160
            if (allowImplicit && allowSynthetic &&
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   161
                !(p.isSynthetic() || p.isImplicit())) {
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   162
                error(prefix + "param[" + i + "]='" + pname +
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   163
                      "' isImplicit() or isSynthetic() expected");
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   164
                break;
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
            if (allowImplicit && !allowSynthetic && !p.isImplicit()) {
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   168
                error(prefix + "param[" + i + "]='" + pname +
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   169
                      "' isImplicit() expected");
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   170
                break;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   171
            }
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   172
            if (!allowImplicit && allowSynthetic && !p.isSynthetic()) {
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   173
                error(prefix + "param[" + i + "]='" + pname +
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   174
                      "' isSynthetic() expected");
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   175
                break;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   176
            }
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   177
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   178
            if (!allowImplicit && p.isImplicit()) {
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   179
                error(prefix + "param[" + i + "]='" + pname +
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   180
                      "' isImplicit() unexpected");
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   181
                break;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   182
            }
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 (!allowSynthetic && p.isSynthetic()) {
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   185
                error(prefix + "param[" + i + "]='" + pname +
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   186
                      "' isSynthetic() unexpected");
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   187
                break;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   188
            }
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   189
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   190
            // Check expected names
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   191
            if (expect != null) {
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   192
                if (pname.matches(expect))  continue;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   193
                error(prefix + "param[" + i + "]='" + pname +
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   194
                      "' expected '" + expect + "'");
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   195
                break;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   196
            }
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   197
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   198
            // Test naming convention for explicit parameters.
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   199
            boolean fidelity = !isAnon;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   200
            if (param != null && fidelity) {
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   201
                char ch = param.charAt(0);
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   202
                expect =  (++ch) + param;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   203
            }
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   204
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   205
            if (pname != null && fidelity) {
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   206
                param = pname;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   207
            }
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   208
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   209
            if (expect != null && !expect.equals(pname)) {
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   210
                error(prefix + "param[" + i + "]='" + pname +
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   211
                      "' expected '" + expect + "'");
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   212
                break;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   213
            }
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   214
        }
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   215
        if  (c.isSynthetic()) {
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   216
            sb.append(")!!\n");
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   217
        } else {
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   218
            sb.append(")\n");
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   219
        }
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
    void testMethod(Method m) {
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   223
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   224
        String prefix = clazz.getName() + "." + m.getName() + "() - ";
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   225
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   226
        // Parameters must match parameter types
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   227
        int paramTypes =  m.getParameterTypes().length;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   228
        int params = m.getParameters().length;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   229
        if (paramTypes != params) {
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   230
            error(prefix + "number of parameter types (" + paramTypes
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   231
                  + ") != number of parameters (" + params + ")");
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   232
            return;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   233
        }
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   234
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   235
        sb.append(clazz.getName()).append(".").append(m.getName()).append("(");
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   236
        String sep = "";
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   237
        String param = null;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   238
        int i = -1;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   239
        // For methods we expect all parameters to follow
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   240
        // the test-case design pattern, except synthetic methods.
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   241
        for (Parameter p : m.getParameters()) {
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   242
            i++;
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   243
            if (param == null) {
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   244
                param = p.getName();
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   245
                sb.append(sep).append(param);
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
                char c = param.charAt(0);
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   248
                String expect =  m.isSynthetic() ? ("arg" + i) : ((++c) + param);
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   249
                param = p.getName();
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   250
                sb.append(sep).append(param);
18000
5d29ce00a7a2 6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents: 17999
diff changeset
   251
                if (!m.isBridge() && !expect.equals(param)) {
16307
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   252
                    error(prefix + "param[" + i + "]='"
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   253
                          + param + "' expected '" + expect + "'");
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   254
                    break;
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
            sep = ", ";
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   258
        }
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   259
        if  (m.isSynthetic()) {
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   260
            sb.append(")!!\n");
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   261
        } else {
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   262
            sb.append(")\n");
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   263
        }
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   264
    }
3027c91f329a 8006582: Test for parameter names feature
strarup
parents:
diff changeset
   265
}