langtools/test/tools/javac/annotations/typeAnnotations/referenceinfos/Driver.java
author aeremeev
Fri, 06 Jun 2014 16:08:46 -0400
changeset 24896 986d876a9121
parent 24396 3c36c6afcbca
permissions -rw-r--r--
8042451: Write tests for all possible kinds of type annotation Summary: Add new tests for type annotations to improve case coverage Reviewed-by: jjg, emc, abuckley
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
     1
/*
22443
0922d94d0576 8028576: Incorrect RuntimeVisibleTypeAnnotations for exception parameters when not generating debuging info
jlahoda
parents: 17578
diff changeset
     2
 * Copyright (c) 2009, 2014, Oracle and/or its affiliates. All rights reserved.
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
     4
 *
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
     7
 * published by the Free Software Foundation.
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
     8
 *
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    13
 * accompanied this code).
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    14
 *
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    18
 *
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    21
 * questions.
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    22
 */
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    23
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    24
import java.io.BufferedWriter;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    25
import java.io.File;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    26
import java.io.FileWriter;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    27
import java.io.IOException;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    28
import java.io.PrintStream;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    29
import java.io.PrintWriter;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    30
import java.lang.annotation.*;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    31
import java.lang.reflect.*;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    32
import java.util.ArrayList;
22443
0922d94d0576 8028576: Incorrect RuntimeVisibleTypeAnnotations for exception parameters when not generating debuging info
jlahoda
parents: 17578
diff changeset
    33
import java.util.Arrays;
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    34
import java.util.Collections;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    35
import java.util.HashMap;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    36
import java.util.List;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    37
import java.util.Map;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    38
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    39
import com.sun.tools.classfile.ClassFile;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    40
import com.sun.tools.classfile.TypeAnnotation;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    41
import com.sun.tools.classfile.TypeAnnotation.TargetType;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    42
24896
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
    43
import static java.lang.String.format;
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
    44
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    45
public class Driver {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    46
24396
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 23393
diff changeset
    47
    private static final PrintStream out = System.err;
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    48
24896
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
    49
    private final Object testObject;
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
    50
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
    51
    public Driver(Class<?> clazz) throws IllegalAccessException, InstantiationException {
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
    52
        testObject = clazz.newInstance();
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
    53
    }
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
    54
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    55
    public static void main(String[] args) throws Exception {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    56
        if (args.length == 0 || args.length > 1)
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    57
            throw new IllegalArgumentException("Usage: java Driver <test-name>");
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    58
        String name = args[0];
24896
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
    59
        new Driver(Class.forName(name)).runDriver();
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    60
    }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    61
24896
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
    62
    private final String[][] extraParamsCombinations = new String[][] {
22443
0922d94d0576 8028576: Incorrect RuntimeVisibleTypeAnnotations for exception parameters when not generating debuging info
jlahoda
parents: 17578
diff changeset
    63
        new String[] { },
0922d94d0576 8028576: Incorrect RuntimeVisibleTypeAnnotations for exception parameters when not generating debuging info
jlahoda
parents: 17578
diff changeset
    64
        new String[] { "-g" },
0922d94d0576 8028576: Incorrect RuntimeVisibleTypeAnnotations for exception parameters when not generating debuging info
jlahoda
parents: 17578
diff changeset
    65
    };
0922d94d0576 8028576: Incorrect RuntimeVisibleTypeAnnotations for exception parameters when not generating debuging info
jlahoda
parents: 17578
diff changeset
    66
24896
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
    67
    private final String[] retentionPolicies = {RetentionPolicy.CLASS.toString(), RetentionPolicy.RUNTIME.toString()};
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
    68
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
    69
    protected void runDriver() {
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    70
        int passed = 0, failed = 0;
24896
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
    71
        Class<?> clazz = testObject.getClass();
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    72
        out.println("Tests for " + clazz.getName());
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    73
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    74
        // Find methods
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    75
        for (Method method : clazz.getMethods()) {
24896
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
    76
            try {
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
    77
                Map<String, TypeAnnotation.Position> expected = expectedOf(method);
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
    78
                if (expected == null)
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
    79
                    continue;
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
    80
                if (method.getReturnType() != String.class)
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
    81
                    throw new IllegalArgumentException("Test method needs to return a string: " + method);
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    82
24896
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
    83
                String compact = (String) method.invoke(testObject);
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
    84
                for (String retentionPolicy : retentionPolicies) {
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
    85
                    String testClassName = getTestClassName(method, retentionPolicy);
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
    86
                    String testClass = testClassOf(method, testClassName);
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
    87
                    String fullFile = wrap(compact, new HashMap<String, String>() {{
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
    88
                        put("%RETENTION_POLICY%", retentionPolicy);
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
    89
                        put("%TEST_CLASS_NAME%", testClassName);
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
    90
                    }});
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
    91
                    for (String[] extraParams : extraParamsCombinations) {
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
    92
                        try {
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
    93
                            ClassFile cf = compileAndReturn(fullFile, testClass, extraParams);
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
    94
                            List<TypeAnnotation> actual = ReferenceInfoUtil.extendedAnnotationsOf(cf);
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
    95
                            ReferenceInfoUtil.compare(expected, actual, cf);
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
    96
                            out.format("PASSED:  %s %s%n", testClassName, Arrays.toString(extraParams));
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
    97
                            ++passed;
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
    98
                        } catch (Throwable e) {
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
    99
                            out.format("FAILED:  %s %s%n", testClassName, Arrays.toString(extraParams));
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
   100
                            out.println(fullFile);
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
   101
                            out.println("    " + e.toString());
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
   102
                            e.printStackTrace(out);
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
   103
                            ++failed;
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
   104
                        }
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
   105
                    }
22443
0922d94d0576 8028576: Incorrect RuntimeVisibleTypeAnnotations for exception parameters when not generating debuging info
jlahoda
parents: 17578
diff changeset
   106
                }
24896
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
   107
            } catch (IllegalAccessException | InvocationTargetException e) {
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
   108
                out.println("FAILED:  " + method.getName());
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
   109
                out.println("    " + e.toString());
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
   110
                e.printStackTrace(out);
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
   111
                ++failed;
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   112
            }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   113
        }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   114
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   115
        out.println();
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   116
        int total = passed + failed;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   117
        out.println(total + " total tests: " + passed + " PASSED, " + failed + " FAILED");
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   118
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   119
        out.flush();
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   120
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   121
        if (failed != 0)
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   122
            throw new RuntimeException(failed + " tests failed");
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   123
    }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   124
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   125
    private Map<String, TypeAnnotation.Position> expectedOf(Method m) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   126
        TADescription ta = m.getAnnotation(TADescription.class);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   127
        TADescriptions tas = m.getAnnotation(TADescriptions.class);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   128
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   129
        if (ta == null && tas == null)
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   130
            return null;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   131
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   132
        Map<String, TypeAnnotation.Position> result =
24896
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
   133
            new HashMap<>();
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   134
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   135
        if (ta != null)
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   136
            result.putAll(expectedOf(ta));
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   137
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   138
        if (tas != null) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   139
            for (TADescription a : tas.value()) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   140
                result.putAll(expectedOf(a));
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   141
            }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   142
        }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   143
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   144
        return result;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   145
    }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   146
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   147
    private Map<String, TypeAnnotation.Position> expectedOf(TADescription d) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   148
        String annoName = d.annotation();
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   149
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   150
        TypeAnnotation.Position p = new TypeAnnotation.Position();
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   151
        p.type = d.type();
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   152
        if (d.offset() != NOT_SET)
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   153
            p.offset = d.offset();
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   154
        if (d.lvarOffset().length != 0)
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   155
            p.lvarOffset = d.lvarOffset();
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   156
        if (d.lvarLength().length != 0)
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   157
            p.lvarLength = d.lvarLength();
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   158
        if (d.lvarIndex().length != 0)
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   159
            p.lvarIndex = d.lvarIndex();
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   160
        if (d.boundIndex() != NOT_SET)
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   161
            p.bound_index = d.boundIndex();
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   162
        if (d.paramIndex() != NOT_SET)
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   163
            p.parameter_index = d.paramIndex();
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   164
        if (d.typeIndex() != NOT_SET)
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   165
            p.type_index = d.typeIndex();
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   166
        if (d.exceptionIndex() != NOT_SET)
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   167
            p.exception_index = d.exceptionIndex();
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   168
        if (d.genericLocation().length != 0) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   169
            p.location = TypeAnnotation.Position.getTypePathFromBinary(wrapIntArray(d.genericLocation()));
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   170
        }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   171
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   172
        return Collections.singletonMap(annoName, p);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   173
    }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   174
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   175
    private List<Integer> wrapIntArray(int[] ints) {
24896
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
   176
        List<Integer> list = new ArrayList<>(ints.length);
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   177
        for (int i : ints)
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   178
            list.add(i);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   179
        return list;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   180
    }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   181
24896
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
   182
    private String getTestClassName(Method m, String retentionPolicy) {
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
   183
        return format("%s_%s_%s", testObject.getClass().getSimpleName(),
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
   184
                m.getName(), retentionPolicy);
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
   185
    }
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
   186
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
   187
    private String testClassOf(Method m, String testClassName) {
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   188
        TestClass tc = m.getAnnotation(TestClass.class);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   189
        if (tc != null) {
24896
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
   190
            return tc.value().replace("%TEST_CLASS_NAME%", testClassName);
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   191
        } else {
24896
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
   192
            return testClassName;
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   193
        }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   194
    }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   195
22443
0922d94d0576 8028576: Incorrect RuntimeVisibleTypeAnnotations for exception parameters when not generating debuging info
jlahoda
parents: 17578
diff changeset
   196
    private ClassFile compileAndReturn(String fullFile, String testClass, String... extraParams) throws Exception {
24896
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
   197
        File source = writeTestFile(fullFile, testClass);
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
   198
        File clazzFile = compileTestFile(source, testClass, extraParams);
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   199
        return ClassFile.read(clazzFile);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   200
    }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   201
24896
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
   202
    protected File writeTestFile(String fullFile, String testClass) throws IOException {
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
   203
        File f = new File(getClassDir(), format("%s.java", testClass));
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
   204
        try (PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(f)))) {
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
   205
            out.println(fullFile);
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
   206
            return f;
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
   207
        }
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
   208
    }
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
   209
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
   210
    private String getClassDir() {
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
   211
        return System.getProperty("test.classes", Driver.class.getResource(".").getPath());
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   212
    }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   213
22443
0922d94d0576 8028576: Incorrect RuntimeVisibleTypeAnnotations for exception parameters when not generating debuging info
jlahoda
parents: 17578
diff changeset
   214
    protected File compileTestFile(File f, String testClass, String... extraParams) {
0922d94d0576 8028576: Incorrect RuntimeVisibleTypeAnnotations for exception parameters when not generating debuging info
jlahoda
parents: 17578
diff changeset
   215
        List<String> options = new ArrayList<>();
0922d94d0576 8028576: Incorrect RuntimeVisibleTypeAnnotations for exception parameters when not generating debuging info
jlahoda
parents: 17578
diff changeset
   216
        options.addAll(Arrays.asList(extraParams));
0922d94d0576 8028576: Incorrect RuntimeVisibleTypeAnnotations for exception parameters when not generating debuging info
jlahoda
parents: 17578
diff changeset
   217
        options.add(f.getPath());
0922d94d0576 8028576: Incorrect RuntimeVisibleTypeAnnotations for exception parameters when not generating debuging info
jlahoda
parents: 17578
diff changeset
   218
        int rc = com.sun.tools.javac.Main.compile(options.toArray(new String[options.size()]));
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   219
        if (rc != 0)
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   220
            throw new Error("compilation failed. rc=" + rc);
24896
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
   221
        String path = f.getParent() != null ? f.getParent() : "";
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
   222
        return new File(path, format("%s.class", testClass));
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   223
    }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   224
24896
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
   225
    private String wrap(String compact, Map<String, String> replacements) {
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   226
        StringBuilder sb = new StringBuilder();
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   227
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   228
        // Automatically import java.util
24896
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
   229
        sb.append("\nimport java.io.*;");
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   230
        sb.append("\nimport java.util.*;");
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   231
        sb.append("\nimport java.lang.annotation.*;");
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   232
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   233
        sb.append("\n\n");
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   234
        boolean isSnippet = !(compact.startsWith("class")
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   235
                              || compact.contains(" class"))
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   236
                            && !compact.contains("interface")
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   237
                            && !compact.contains("enum");
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   238
        if (isSnippet)
24896
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
   239
            sb.append("class %TEST_CLASS_NAME% {\n");
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   240
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   241
        sb.append(compact);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   242
        sb.append("\n");
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   243
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   244
        if (isSnippet)
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   245
            sb.append("}\n\n");
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   246
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   247
        if (isSnippet) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   248
            // Have a few common nested types for testing
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 15557
diff changeset
   249
            sb.append("class Outer { class Inner {} class Middle { class MInner {} } }");
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   250
            sb.append("class SOuter { static class SInner {} }");
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   251
            sb.append("class GOuter<X, Y> { class GInner<X, Y> {} }");
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   252
        }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   253
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   254
        // create A ... F annotation declarations
24896
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
   255
        sb.append("\n@Retention(RetentionPolicy.%RETENTION_POLICY%) @interface A {}");
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
   256
        sb.append("\n@Retention(RetentionPolicy.%RETENTION_POLICY%) @interface B {}");
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
   257
        sb.append("\n@Retention(RetentionPolicy.%RETENTION_POLICY%) @interface C {}");
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
   258
        sb.append("\n@Retention(RetentionPolicy.%RETENTION_POLICY%) @interface D {}");
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
   259
        sb.append("\n@Retention(RetentionPolicy.%RETENTION_POLICY%) @interface E {}");
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
   260
        sb.append("\n@Retention(RetentionPolicy.%RETENTION_POLICY%) @interface F {}");
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   261
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   262
        // create TA ... TF proper type annotations
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   263
        sb.append("\n");
24896
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
   264
        sb.append("\n@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})" +
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
   265
                " @Retention(RetentionPolicy.%RETENTION_POLICY%)  @interface TA {}");
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
   266
        sb.append("\n@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})" +
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
   267
                "@Retention(RetentionPolicy.%RETENTION_POLICY%) @interface TB {}");
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
   268
        sb.append("\n@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})" +
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
   269
                "@Retention(RetentionPolicy.%RETENTION_POLICY%) @interface TC {}");
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
   270
        sb.append("\n@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})" +
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
   271
                "@Retention(RetentionPolicy.%RETENTION_POLICY%) @interface TD {}");
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
   272
        sb.append("\n@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})" +
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
   273
                "@Retention(RetentionPolicy.%RETENTION_POLICY%) @interface TE {}");
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
   274
        sb.append("\n@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})" +
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
   275
                "@Retention(RetentionPolicy.%RETENTION_POLICY%) @interface TF {}");
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
   276
        sb.append("\n@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})" +
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
   277
                "@Retention(RetentionPolicy.%RETENTION_POLICY%) @interface TG {}");
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
   278
        sb.append("\n@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})" +
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
   279
                "@Retention(RetentionPolicy.%RETENTION_POLICY%) @interface TH {}");
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
   280
        sb.append("\n@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})" +
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
   281
                "@Retention(RetentionPolicy.%RETENTION_POLICY%) @interface TI {}");
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
   282
        sb.append("\n@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})" +
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
   283
                "@Retention(RetentionPolicy.%RETENTION_POLICY%) @interface TJ {}");
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
   284
        sb.append("\n@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})" +
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
   285
                "@Retention(RetentionPolicy.%RETENTION_POLICY%) @interface TK {}");
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
   286
        sb.append("\n@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})" +
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
   287
                "@Retention(RetentionPolicy.%RETENTION_POLICY%) @interface TL {}");
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
   288
        sb.append("\n@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})" +
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
   289
                "@Retention(RetentionPolicy.%RETENTION_POLICY%) @interface TM {}");
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   290
24896
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
   291
        // create RT?, RT?s for repeating type annotations
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   292
        sb.append("\n");
24896
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
   293
        sb.append("\n@Repeatable(RTAs.class) @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})" +
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
   294
                "@Retention(RetentionPolicy.%RETENTION_POLICY%) @interface RTA {}");
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
   295
        sb.append("\n@Repeatable(RTBs.class) @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})" +
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
   296
                "@Retention(RetentionPolicy.%RETENTION_POLICY%) @interface RTB {}");
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
   297
        sb.append("\n@Repeatable(RTCs.class) @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})" +
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
   298
                "@Retention(RetentionPolicy.%RETENTION_POLICY%) @interface RTC {}");
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
   299
        sb.append("\n@Repeatable(RTDs.class) @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})" +
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
   300
                "@Retention(RetentionPolicy.%RETENTION_POLICY%) @interface RTD {}");
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
   301
        sb.append("\n@Repeatable(RTEs.class) @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})" +
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
   302
                "@Retention(RetentionPolicy.%RETENTION_POLICY%) @interface RTE {}");
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
   303
        sb.append("\n@Repeatable(RTFs.class) @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})" +
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
   304
                "@Retention(RetentionPolicy.%RETENTION_POLICY%) @interface RTF {}");
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
   305
        sb.append("\n@Repeatable(RTGs.class) @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})" +
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
   306
                "@Retention(RetentionPolicy.%RETENTION_POLICY%) @interface RTG {}");
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
   307
        sb.append("\n@Repeatable(RTHs.class) @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})" +
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
   308
                "@Retention(RetentionPolicy.%RETENTION_POLICY%) @interface RTH {}");
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
   309
        sb.append("\n@Repeatable(RTIs.class) @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})" +
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
   310
                "@Retention(RetentionPolicy.%RETENTION_POLICY%) @interface RTI {}");
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
   311
        sb.append("\n@Repeatable(RTJs.class) @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})" +
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
   312
                "@Retention(RetentionPolicy.%RETENTION_POLICY%) @interface RTJ {}");
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
   313
        sb.append("\n@Repeatable(RTKs.class) @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})" +
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
   314
                "@Retention(RetentionPolicy.%RETENTION_POLICY%) @interface RTK {}");
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   315
24896
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
   316
        sb.append("\n@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})" +
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
   317
                "@Retention(RetentionPolicy.%RETENTION_POLICY%) @interface RTAs { RTA[] value(); }");
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
   318
        sb.append("\n@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})" +
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
   319
                "@Retention(RetentionPolicy.%RETENTION_POLICY%) @interface RTBs { RTB[] value(); }");
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
   320
        sb.append("\n@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})" +
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
   321
                "@Retention(RetentionPolicy.%RETENTION_POLICY%) @interface RTCs { RTC[] value(); }");
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
   322
        sb.append("\n@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})" +
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
   323
                "@Retention(RetentionPolicy.%RETENTION_POLICY%) @interface RTDs { RTD[] value(); }");
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
   324
        sb.append("\n@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})" +
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
   325
                "@Retention(RetentionPolicy.%RETENTION_POLICY%) @interface RTEs { RTE[] value(); }");
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
   326
        sb.append("\n@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})" +
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
   327
                "@Retention(RetentionPolicy.%RETENTION_POLICY%) @interface RTFs { RTF[] value(); }");
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
   328
        sb.append("\n@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})" +
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
   329
                "@Retention(RetentionPolicy.%RETENTION_POLICY%) @interface RTGs { RTG[] value(); }");
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
   330
        sb.append("\n@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})" +
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
   331
                "@Retention(RetentionPolicy.%RETENTION_POLICY%) @interface RTHs { RTH[] value(); }");
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
   332
        sb.append("\n@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})" +
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
   333
                "@Retention(RetentionPolicy.%RETENTION_POLICY%) @interface RTIs { RTI[] value(); }");
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
   334
        sb.append("\n@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})" +
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
   335
                "@Retention(RetentionPolicy.%RETENTION_POLICY%) @interface RTJs { RTJ[] value(); }");
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
   336
        sb.append("\n@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})" +
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
   337
                "@Retention(RetentionPolicy.%RETENTION_POLICY%) @interface RTKs { RTK[] value(); }");
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   338
24896
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
   339
        sb.append("\n@Target(value={ElementType.TYPE,ElementType.FIELD,ElementType.METHOD," +
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
   340
                "ElementType.PARAMETER,ElementType.CONSTRUCTOR,ElementType.LOCAL_VARIABLE})");
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
   341
        sb.append("\n@Retention(RetentionPolicy.%RETENTION_POLICY%) @interface Decl {}");
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   342
24896
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
   343
        return replaceAll(sb.toString(), replacements);
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
   344
    }
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
   345
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
   346
    private String replaceAll(String src, Map<String, String> replacements) {
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
   347
        for (Map.Entry<String, String> entry : replacements.entrySet()) {
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
   348
            src = src.replace(entry.getKey(), entry.getValue());
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
   349
        }
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
   350
        return src;
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   351
    }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   352
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   353
    public static final int NOT_SET = -888;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   354
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   355
}
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   356
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   357
@Retention(RetentionPolicy.RUNTIME)
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   358
@Target(ElementType.METHOD)
24896
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
   359
@Repeatable(TADescriptions.class)
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   360
@interface TADescription {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   361
    String annotation();
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   362
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   363
    TargetType type();
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   364
    int offset() default Driver.NOT_SET;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   365
    int[] lvarOffset() default { };
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   366
    int[] lvarLength() default { };
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   367
    int[] lvarIndex() default { };
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   368
    int boundIndex() default Driver.NOT_SET;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   369
    int paramIndex() default Driver.NOT_SET;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   370
    int typeIndex() default Driver.NOT_SET;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   371
    int exceptionIndex() default Driver.NOT_SET;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   372
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   373
    int[] genericLocation() default {};
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   374
}
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   375
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   376
@Retention(RetentionPolicy.RUNTIME)
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   377
@Target(ElementType.METHOD)
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   378
@interface TADescriptions {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   379
    TADescription[] value() default {};
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   380
}
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   381
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   382
/**
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   383
 * The name of the class that should be analyzed.
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   384
 * Should only need to be provided when analyzing inner classes.
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   385
 */
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   386
@Retention(RetentionPolicy.RUNTIME)
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   387
@Target(ElementType.METHOD)
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   388
@interface TestClass {
24896
986d876a9121 8042451: Write tests for all possible kinds of type annotation
aeremeev
parents: 24396
diff changeset
   389
    String value();
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   390
}