langtools/test/tools/javac/processing/model/inheritedByType/EnsureOrder.java
author akulyakh
Thu, 21 May 2015 11:41:04 -0700
changeset 30730 d3ce7619db2c
parent 19126 20123a84b35a
child 36526 3b41f1c69604
permissions -rw-r--r--
8076543: Add @modules as needed to the langtools tests Reviewed-by: jjg, shurailine
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
19126
20123a84b35a 8007961: javax.lang.model tests for repeating annotations fail in getAnnotationsByType
jfranck
parents:
diff changeset
     1
/*
30730
d3ce7619db2c 8076543: Add @modules as needed to the langtools tests
akulyakh
parents: 19126
diff changeset
     2
 * Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved.
19126
20123a84b35a 8007961: javax.lang.model tests for repeating annotations fail in getAnnotationsByType
jfranck
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
20123a84b35a 8007961: javax.lang.model tests for repeating annotations fail in getAnnotationsByType
jfranck
parents:
diff changeset
     4
 *
20123a84b35a 8007961: javax.lang.model tests for repeating annotations fail in getAnnotationsByType
jfranck
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
20123a84b35a 8007961: javax.lang.model tests for repeating annotations fail in getAnnotationsByType
jfranck
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
20123a84b35a 8007961: javax.lang.model tests for repeating annotations fail in getAnnotationsByType
jfranck
parents:
diff changeset
     7
 * published by the Free Software Foundation.
20123a84b35a 8007961: javax.lang.model tests for repeating annotations fail in getAnnotationsByType
jfranck
parents:
diff changeset
     8
 *
20123a84b35a 8007961: javax.lang.model tests for repeating annotations fail in getAnnotationsByType
jfranck
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
20123a84b35a 8007961: javax.lang.model tests for repeating annotations fail in getAnnotationsByType
jfranck
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20123a84b35a 8007961: javax.lang.model tests for repeating annotations fail in getAnnotationsByType
jfranck
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
20123a84b35a 8007961: javax.lang.model tests for repeating annotations fail in getAnnotationsByType
jfranck
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
20123a84b35a 8007961: javax.lang.model tests for repeating annotations fail in getAnnotationsByType
jfranck
parents:
diff changeset
    13
 * accompanied this code).
20123a84b35a 8007961: javax.lang.model tests for repeating annotations fail in getAnnotationsByType
jfranck
parents:
diff changeset
    14
 *
20123a84b35a 8007961: javax.lang.model tests for repeating annotations fail in getAnnotationsByType
jfranck
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
20123a84b35a 8007961: javax.lang.model tests for repeating annotations fail in getAnnotationsByType
jfranck
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
20123a84b35a 8007961: javax.lang.model tests for repeating annotations fail in getAnnotationsByType
jfranck
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20123a84b35a 8007961: javax.lang.model tests for repeating annotations fail in getAnnotationsByType
jfranck
parents:
diff changeset
    18
 *
20123a84b35a 8007961: javax.lang.model tests for repeating annotations fail in getAnnotationsByType
jfranck
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20123a84b35a 8007961: javax.lang.model tests for repeating annotations fail in getAnnotationsByType
jfranck
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
20123a84b35a 8007961: javax.lang.model tests for repeating annotations fail in getAnnotationsByType
jfranck
parents:
diff changeset
    21
 * questions.
20123a84b35a 8007961: javax.lang.model tests for repeating annotations fail in getAnnotationsByType
jfranck
parents:
diff changeset
    22
 */
20123a84b35a 8007961: javax.lang.model tests for repeating annotations fail in getAnnotationsByType
jfranck
parents:
diff changeset
    23
20123a84b35a 8007961: javax.lang.model tests for repeating annotations fail in getAnnotationsByType
jfranck
parents:
diff changeset
    24
/**
20123a84b35a 8007961: javax.lang.model tests for repeating annotations fail in getAnnotationsByType
jfranck
parents:
diff changeset
    25
 * @test
20123a84b35a 8007961: javax.lang.model tests for repeating annotations fail in getAnnotationsByType
jfranck
parents:
diff changeset
    26
 * @summary test that order is respected when inheriting both legacy container and single anno
20123a84b35a 8007961: javax.lang.model tests for repeating annotations fail in getAnnotationsByType
jfranck
parents:
diff changeset
    27
 * @bug 8007961
20123a84b35a 8007961: javax.lang.model tests for repeating annotations fail in getAnnotationsByType
jfranck
parents:
diff changeset
    28
 * @library /tools/javac/lib
30730
d3ce7619db2c 8076543: Add @modules as needed to the langtools tests
akulyakh
parents: 19126
diff changeset
    29
 * @modules jdk.compiler/com.sun.tools.javac.util
19126
20123a84b35a 8007961: javax.lang.model tests for repeating annotations fail in getAnnotationsByType
jfranck
parents:
diff changeset
    30
 * @build   JavacTestingAbstractProcessor EnsureOrder
20123a84b35a 8007961: javax.lang.model tests for repeating annotations fail in getAnnotationsByType
jfranck
parents:
diff changeset
    31
 * @compile -processor EnsureOrder -proc:only EnsureOrder.java
20123a84b35a 8007961: javax.lang.model tests for repeating annotations fail in getAnnotationsByType
jfranck
parents:
diff changeset
    32
 */
20123a84b35a 8007961: javax.lang.model tests for repeating annotations fail in getAnnotationsByType
jfranck
parents:
diff changeset
    33
20123a84b35a 8007961: javax.lang.model tests for repeating annotations fail in getAnnotationsByType
jfranck
parents:
diff changeset
    34
import java.util.Set;
20123a84b35a 8007961: javax.lang.model tests for repeating annotations fail in getAnnotationsByType
jfranck
parents:
diff changeset
    35
import java.lang.annotation.*;
20123a84b35a 8007961: javax.lang.model tests for repeating annotations fail in getAnnotationsByType
jfranck
parents:
diff changeset
    36
import javax.annotation.processing.*;
20123a84b35a 8007961: javax.lang.model tests for repeating annotations fail in getAnnotationsByType
jfranck
parents:
diff changeset
    37
import javax.lang.model.SourceVersion;
20123a84b35a 8007961: javax.lang.model tests for repeating annotations fail in getAnnotationsByType
jfranck
parents:
diff changeset
    38
import static javax.lang.model.SourceVersion.*;
20123a84b35a 8007961: javax.lang.model tests for repeating annotations fail in getAnnotationsByType
jfranck
parents:
diff changeset
    39
import javax.lang.model.element.*;
20123a84b35a 8007961: javax.lang.model tests for repeating annotations fail in getAnnotationsByType
jfranck
parents:
diff changeset
    40
import javax.lang.model.util.*;
20123a84b35a 8007961: javax.lang.model tests for repeating annotations fail in getAnnotationsByType
jfranck
parents:
diff changeset
    41
import static javax.lang.model.util.ElementFilter.*;
20123a84b35a 8007961: javax.lang.model tests for repeating annotations fail in getAnnotationsByType
jfranck
parents:
diff changeset
    42
import static javax.tools.Diagnostic.Kind.*;
20123a84b35a 8007961: javax.lang.model tests for repeating annotations fail in getAnnotationsByType
jfranck
parents:
diff changeset
    43
import static javax.tools.StandardLocation.*;
20123a84b35a 8007961: javax.lang.model tests for repeating annotations fail in getAnnotationsByType
jfranck
parents:
diff changeset
    44
import com.sun.tools.javac.util.Assert;
20123a84b35a 8007961: javax.lang.model tests for repeating annotations fail in getAnnotationsByType
jfranck
parents:
diff changeset
    45
20123a84b35a 8007961: javax.lang.model tests for repeating annotations fail in getAnnotationsByType
jfranck
parents:
diff changeset
    46
@Target({ElementType.TYPE_PARAMETER, ElementType.TYPE})
20123a84b35a 8007961: javax.lang.model tests for repeating annotations fail in getAnnotationsByType
jfranck
parents:
diff changeset
    47
@Inherited
20123a84b35a 8007961: javax.lang.model tests for repeating annotations fail in getAnnotationsByType
jfranck
parents:
diff changeset
    48
@Retention(RetentionPolicy.RUNTIME)
20123a84b35a 8007961: javax.lang.model tests for repeating annotations fail in getAnnotationsByType
jfranck
parents:
diff changeset
    49
@Repeatable(Foos.class)
20123a84b35a 8007961: javax.lang.model tests for repeating annotations fail in getAnnotationsByType
jfranck
parents:
diff changeset
    50
@interface Foo {
20123a84b35a 8007961: javax.lang.model tests for repeating annotations fail in getAnnotationsByType
jfranck
parents:
diff changeset
    51
    int value();
20123a84b35a 8007961: javax.lang.model tests for repeating annotations fail in getAnnotationsByType
jfranck
parents:
diff changeset
    52
}
20123a84b35a 8007961: javax.lang.model tests for repeating annotations fail in getAnnotationsByType
jfranck
parents:
diff changeset
    53
20123a84b35a 8007961: javax.lang.model tests for repeating annotations fail in getAnnotationsByType
jfranck
parents:
diff changeset
    54
@Target({ElementType.TYPE_PARAMETER, ElementType.TYPE})
20123a84b35a 8007961: javax.lang.model tests for repeating annotations fail in getAnnotationsByType
jfranck
parents:
diff changeset
    55
@Inherited
20123a84b35a 8007961: javax.lang.model tests for repeating annotations fail in getAnnotationsByType
jfranck
parents:
diff changeset
    56
@Retention(RetentionPolicy.RUNTIME)
20123a84b35a 8007961: javax.lang.model tests for repeating annotations fail in getAnnotationsByType
jfranck
parents:
diff changeset
    57
@interface Foos {
20123a84b35a 8007961: javax.lang.model tests for repeating annotations fail in getAnnotationsByType
jfranck
parents:
diff changeset
    58
    Foo[] value();
20123a84b35a 8007961: javax.lang.model tests for repeating annotations fail in getAnnotationsByType
jfranck
parents:
diff changeset
    59
}
20123a84b35a 8007961: javax.lang.model tests for repeating annotations fail in getAnnotationsByType
jfranck
parents:
diff changeset
    60
20123a84b35a 8007961: javax.lang.model tests for repeating annotations fail in getAnnotationsByType
jfranck
parents:
diff changeset
    61
@Foos({@Foo(0), @Foo(1)}) @Foo(2)
20123a84b35a 8007961: javax.lang.model tests for repeating annotations fail in getAnnotationsByType
jfranck
parents:
diff changeset
    62
class Base {}
20123a84b35a 8007961: javax.lang.model tests for repeating annotations fail in getAnnotationsByType
jfranck
parents:
diff changeset
    63
20123a84b35a 8007961: javax.lang.model tests for repeating annotations fail in getAnnotationsByType
jfranck
parents:
diff changeset
    64
class Sub extends Base {}
20123a84b35a 8007961: javax.lang.model tests for repeating annotations fail in getAnnotationsByType
jfranck
parents:
diff changeset
    65
20123a84b35a 8007961: javax.lang.model tests for repeating annotations fail in getAnnotationsByType
jfranck
parents:
diff changeset
    66
public class EnsureOrder<@Foos({@Foo(0), @Foo(1)}) @Foo(2)T> extends JavacTestingAbstractProcessor {
20123a84b35a 8007961: javax.lang.model tests for repeating annotations fail in getAnnotationsByType
jfranck
parents:
diff changeset
    67
    public boolean process(Set<? extends TypeElement> annotations,
20123a84b35a 8007961: javax.lang.model tests for repeating annotations fail in getAnnotationsByType
jfranck
parents:
diff changeset
    68
                           RoundEnvironment roundEnv) {
20123a84b35a 8007961: javax.lang.model tests for repeating annotations fail in getAnnotationsByType
jfranck
parents:
diff changeset
    69
        if (!roundEnv.processingOver()) {
20123a84b35a 8007961: javax.lang.model tests for repeating annotations fail in getAnnotationsByType
jfranck
parents:
diff changeset
    70
            int hasRun = 0;
20123a84b35a 8007961: javax.lang.model tests for repeating annotations fail in getAnnotationsByType
jfranck
parents:
diff changeset
    71
            for (Element element : roundEnv.getRootElements()) {
20123a84b35a 8007961: javax.lang.model tests for repeating annotations fail in getAnnotationsByType
jfranck
parents:
diff changeset
    72
                Name elemName = element.getSimpleName();
20123a84b35a 8007961: javax.lang.model tests for repeating annotations fail in getAnnotationsByType
jfranck
parents:
diff changeset
    73
                if (elemName.contentEquals("Base")) {
20123a84b35a 8007961: javax.lang.model tests for repeating annotations fail in getAnnotationsByType
jfranck
parents:
diff changeset
    74
                    hasRun++;
20123a84b35a 8007961: javax.lang.model tests for repeating annotations fail in getAnnotationsByType
jfranck
parents:
diff changeset
    75
                    Foo[] foos = element.getAnnotationsByType(Foo.class);
20123a84b35a 8007961: javax.lang.model tests for repeating annotations fail in getAnnotationsByType
jfranck
parents:
diff changeset
    76
                    Assert.check(foos.length == 3);
20123a84b35a 8007961: javax.lang.model tests for repeating annotations fail in getAnnotationsByType
jfranck
parents:
diff changeset
    77
                    Assert.check(foos[0].value() == 0);
20123a84b35a 8007961: javax.lang.model tests for repeating annotations fail in getAnnotationsByType
jfranck
parents:
diff changeset
    78
                    Assert.check(foos[1].value() == 1);
20123a84b35a 8007961: javax.lang.model tests for repeating annotations fail in getAnnotationsByType
jfranck
parents:
diff changeset
    79
                    Assert.check(foos[2].value() == 2);
20123a84b35a 8007961: javax.lang.model tests for repeating annotations fail in getAnnotationsByType
jfranck
parents:
diff changeset
    80
                }
20123a84b35a 8007961: javax.lang.model tests for repeating annotations fail in getAnnotationsByType
jfranck
parents:
diff changeset
    81
                if (elemName.contentEquals("Sub")) {
20123a84b35a 8007961: javax.lang.model tests for repeating annotations fail in getAnnotationsByType
jfranck
parents:
diff changeset
    82
                    hasRun++;
20123a84b35a 8007961: javax.lang.model tests for repeating annotations fail in getAnnotationsByType
jfranck
parents:
diff changeset
    83
                    Foo[] foos = element.getAnnotationsByType(Foo.class);
20123a84b35a 8007961: javax.lang.model tests for repeating annotations fail in getAnnotationsByType
jfranck
parents:
diff changeset
    84
                    Assert.check(foos.length == 3);
20123a84b35a 8007961: javax.lang.model tests for repeating annotations fail in getAnnotationsByType
jfranck
parents:
diff changeset
    85
                    Assert.check(foos[0].value() == 0);
20123a84b35a 8007961: javax.lang.model tests for repeating annotations fail in getAnnotationsByType
jfranck
parents:
diff changeset
    86
                    Assert.check(foos[1].value() == 1);
20123a84b35a 8007961: javax.lang.model tests for repeating annotations fail in getAnnotationsByType
jfranck
parents:
diff changeset
    87
                    Assert.check(foos[2].value() == 2);
20123a84b35a 8007961: javax.lang.model tests for repeating annotations fail in getAnnotationsByType
jfranck
parents:
diff changeset
    88
                }
20123a84b35a 8007961: javax.lang.model tests for repeating annotations fail in getAnnotationsByType
jfranck
parents:
diff changeset
    89
                if (elemName.contentEquals("EnsureOrder")) {
20123a84b35a 8007961: javax.lang.model tests for repeating annotations fail in getAnnotationsByType
jfranck
parents:
diff changeset
    90
                    for (TypeParameterElement t : ((TypeElement)element).getTypeParameters()) {
20123a84b35a 8007961: javax.lang.model tests for repeating annotations fail in getAnnotationsByType
jfranck
parents:
diff changeset
    91
                        if (t.getSimpleName().contentEquals("T")) {
20123a84b35a 8007961: javax.lang.model tests for repeating annotations fail in getAnnotationsByType
jfranck
parents:
diff changeset
    92
                            hasRun++;
20123a84b35a 8007961: javax.lang.model tests for repeating annotations fail in getAnnotationsByType
jfranck
parents:
diff changeset
    93
                            Foo[] foos = t.getAnnotationsByType(Foo.class);
20123a84b35a 8007961: javax.lang.model tests for repeating annotations fail in getAnnotationsByType
jfranck
parents:
diff changeset
    94
                            Assert.check(foos.length == 3);
20123a84b35a 8007961: javax.lang.model tests for repeating annotations fail in getAnnotationsByType
jfranck
parents:
diff changeset
    95
                            Assert.check(foos[0].value() == 0);
20123a84b35a 8007961: javax.lang.model tests for repeating annotations fail in getAnnotationsByType
jfranck
parents:
diff changeset
    96
                            Assert.check(foos[1].value() == 1);
20123a84b35a 8007961: javax.lang.model tests for repeating annotations fail in getAnnotationsByType
jfranck
parents:
diff changeset
    97
                            Assert.check(foos[2].value() == 2);
20123a84b35a 8007961: javax.lang.model tests for repeating annotations fail in getAnnotationsByType
jfranck
parents:
diff changeset
    98
                        }
20123a84b35a 8007961: javax.lang.model tests for repeating annotations fail in getAnnotationsByType
jfranck
parents:
diff changeset
    99
                    }
20123a84b35a 8007961: javax.lang.model tests for repeating annotations fail in getAnnotationsByType
jfranck
parents:
diff changeset
   100
                }
20123a84b35a 8007961: javax.lang.model tests for repeating annotations fail in getAnnotationsByType
jfranck
parents:
diff changeset
   101
            }
20123a84b35a 8007961: javax.lang.model tests for repeating annotations fail in getAnnotationsByType
jfranck
parents:
diff changeset
   102
            if (hasRun != 3)
20123a84b35a 8007961: javax.lang.model tests for repeating annotations fail in getAnnotationsByType
jfranck
parents:
diff changeset
   103
                throw new RuntimeException("Couldn't find elements");
20123a84b35a 8007961: javax.lang.model tests for repeating annotations fail in getAnnotationsByType
jfranck
parents:
diff changeset
   104
        }
20123a84b35a 8007961: javax.lang.model tests for repeating annotations fail in getAnnotationsByType
jfranck
parents:
diff changeset
   105
        return true;
20123a84b35a 8007961: javax.lang.model tests for repeating annotations fail in getAnnotationsByType
jfranck
parents:
diff changeset
   106
    }
20123a84b35a 8007961: javax.lang.model tests for repeating annotations fail in getAnnotationsByType
jfranck
parents:
diff changeset
   107
}