langtools/test/tools/javac/annotations/typeAnnotations/classfile/SyntheticParameters.java
author emc
Fri, 21 Nov 2014 16:36:39 -0500
changeset 27853 746c658e8d35
parent 27545 9b19c6e31489
child 29050 76df9080086c
permissions -rw-r--r--
8065132: Parameter annotations not updated when synthetic parameters are prepended Summary: Cause javac to add synthetic parameters to Runtime[In]VisibleParameterAnnotations attributes Reviewed-by: jjg, jfranck

/*
 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 * or visit www.oracle.com if you need additional information or have any
 * questions.
 */

/*
 * @test SyntheticParameters
 * @summary Test generation of annotations on inner class parameters.
 * @library /lib/annotations/
 * @run main SyntheticParameters
 */

import annotations.classfile.ClassfileInspector;

import java.io.*;
import java.lang.annotation.*;

import com.sun.tools.classfile.*;

public class SyntheticParameters extends ClassfileInspector {

    private static final String Inner_class = "SyntheticParameters$Inner.class";
    private static final String Foo_class = "SyntheticParameters$Foo.class";
    private static final Expected Inner_expected =
        new Expected("SyntheticParameters$Inner",
                     null,
                     new ExpectedMethodTypeAnnotation[] {
                         (ExpectedMethodTypeAnnotation)
                         // Assert there is no annotation on the
                         // this$0 parameter.
                         new ExpectedMethodTypeAnnotation.Builder(
                             "<init>",
                             "A",
                             TypeAnnotation.TargetType.METHOD_FORMAL_PARAMETER,
                             false,
                             0).setParameterIndex(0).build(),
                         (ExpectedMethodTypeAnnotation)
                         // Assert there is an annotation on the
                         // first parameter.
                         new ExpectedMethodTypeAnnotation.Builder(
                             "<init>",
                             "A",
                             TypeAnnotation.TargetType.METHOD_FORMAL_PARAMETER,
                             false,
                             1).setParameterIndex(1).build(),
                         (ExpectedMethodTypeAnnotation)
                         new ExpectedMethodTypeAnnotation.Builder(
                             "foo",
                             "A",
                             TypeAnnotation.TargetType.METHOD_FORMAL_PARAMETER,
                             false,
                             1).setParameterIndex(0).build(),
                         (ExpectedMethodTypeAnnotation)
                         new ExpectedMethodTypeAnnotation.Builder(
                             "foo",
                             "A",
                             TypeAnnotation.TargetType.METHOD_FORMAL_PARAMETER,
                             false,
                             0).setParameterIndex(1).build()
                     },
                     null);
    private static final Expected Foo_expected =
        new Expected("SyntheticParameters$Foo",
                     null,
                     new ExpectedMethodTypeAnnotation[] {
                         (ExpectedMethodTypeAnnotation)
                         // Assert there is no annotation on the
                         // $enum$name parameter.
                         new ExpectedMethodTypeAnnotation.Builder(
                             "<init>",
                             "A",
                             TypeAnnotation.TargetType.METHOD_FORMAL_PARAMETER,
                             false,
                             0).setParameterIndex(0).build(),
                         (ExpectedMethodTypeAnnotation)
                         // Assert there is no annotation on the
                         // $enum$ordinal parameter.
                         new ExpectedMethodTypeAnnotation.Builder(
                             "<init>",
                             "A",
                             TypeAnnotation.TargetType.METHOD_FORMAL_PARAMETER,
                             false,
                             0).setParameterIndex(1).build(),
                         (ExpectedMethodTypeAnnotation)
                         // Assert there is an annotation on the
                         // first parameter.
                         new ExpectedMethodTypeAnnotation.Builder(
                             "<init>",
                             "A",
                             TypeAnnotation.TargetType.METHOD_FORMAL_PARAMETER,
                             false,
                             1).setParameterIndex(2).build()
                     },
                     null);

    public static void main(String... args) throws Exception {
        new SyntheticParameters().run(
            new ClassFile[] { getClassFile(Inner_class, Inner.class),
                              getClassFile(Foo_class, Foo.class) },
            new Expected[] { Inner_expected, Foo_expected });
    }

    public class Inner {
        public Inner(@A int a) {}
        public void foo(@A int a, int b) {}
    }

    public static enum Foo {
        ONE(null);
        Foo(@A Object a) {}
    }
}

@Target({ElementType.TYPE_USE})
@interface A {}