langtools/test/tools/javac/processing/model/element/8009367/TestQualifiedNameUsed.java
author akulyakh
Thu, 21 May 2015 11:41:04 -0700
changeset 30730 d3ce7619db2c
parent 19248 46cb3cd6023b
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:
19248
46cb3cd6023b 8009367: Wrong kind of name used in comparison in javax.lang.model code for repeatable annotations
jfranck
parents:
diff changeset
     1
/*
30730
d3ce7619db2c 8076543: Add @modules as needed to the langtools tests
akulyakh
parents: 19248
diff changeset
     2
 * Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved.
19248
46cb3cd6023b 8009367: Wrong kind of name used in comparison in javax.lang.model code for repeatable annotations
jfranck
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
46cb3cd6023b 8009367: Wrong kind of name used in comparison in javax.lang.model code for repeatable annotations
jfranck
parents:
diff changeset
     4
 *
46cb3cd6023b 8009367: Wrong kind of name used in comparison in javax.lang.model code for repeatable annotations
jfranck
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
46cb3cd6023b 8009367: Wrong kind of name used in comparison in javax.lang.model code for repeatable annotations
jfranck
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
46cb3cd6023b 8009367: Wrong kind of name used in comparison in javax.lang.model code for repeatable annotations
jfranck
parents:
diff changeset
     7
 * published by the Free Software Foundation.
46cb3cd6023b 8009367: Wrong kind of name used in comparison in javax.lang.model code for repeatable annotations
jfranck
parents:
diff changeset
     8
 *
46cb3cd6023b 8009367: Wrong kind of name used in comparison in javax.lang.model code for repeatable annotations
jfranck
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
46cb3cd6023b 8009367: Wrong kind of name used in comparison in javax.lang.model code for repeatable annotations
jfranck
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
46cb3cd6023b 8009367: Wrong kind of name used in comparison in javax.lang.model code for repeatable annotations
jfranck
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
46cb3cd6023b 8009367: Wrong kind of name used in comparison in javax.lang.model code for repeatable annotations
jfranck
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
46cb3cd6023b 8009367: Wrong kind of name used in comparison in javax.lang.model code for repeatable annotations
jfranck
parents:
diff changeset
    13
 * accompanied this code).
46cb3cd6023b 8009367: Wrong kind of name used in comparison in javax.lang.model code for repeatable annotations
jfranck
parents:
diff changeset
    14
 *
46cb3cd6023b 8009367: Wrong kind of name used in comparison in javax.lang.model code for repeatable annotations
jfranck
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
46cb3cd6023b 8009367: Wrong kind of name used in comparison in javax.lang.model code for repeatable annotations
jfranck
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
46cb3cd6023b 8009367: Wrong kind of name used in comparison in javax.lang.model code for repeatable annotations
jfranck
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
46cb3cd6023b 8009367: Wrong kind of name used in comparison in javax.lang.model code for repeatable annotations
jfranck
parents:
diff changeset
    18
 *
46cb3cd6023b 8009367: Wrong kind of name used in comparison in javax.lang.model code for repeatable annotations
jfranck
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
46cb3cd6023b 8009367: Wrong kind of name used in comparison in javax.lang.model code for repeatable annotations
jfranck
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
46cb3cd6023b 8009367: Wrong kind of name used in comparison in javax.lang.model code for repeatable annotations
jfranck
parents:
diff changeset
    21
 * questions.
46cb3cd6023b 8009367: Wrong kind of name used in comparison in javax.lang.model code for repeatable annotations
jfranck
parents:
diff changeset
    22
 */
46cb3cd6023b 8009367: Wrong kind of name used in comparison in javax.lang.model code for repeatable annotations
jfranck
parents:
diff changeset
    23
46cb3cd6023b 8009367: Wrong kind of name used in comparison in javax.lang.model code for repeatable annotations
jfranck
parents:
diff changeset
    24
/*
46cb3cd6023b 8009367: Wrong kind of name used in comparison in javax.lang.model code for repeatable annotations
jfranck
parents:
diff changeset
    25
 * @test
46cb3cd6023b 8009367: Wrong kind of name used in comparison in javax.lang.model code for repeatable annotations
jfranck
parents:
diff changeset
    26
 * @bug 8009367
46cb3cd6023b 8009367: Wrong kind of name used in comparison in javax.lang.model code for repeatable annotations
jfranck
parents:
diff changeset
    27
 * @summary Test that the correct kind of names (binary) are used when comparing
46cb3cd6023b 8009367: Wrong kind of name used in comparison in javax.lang.model code for repeatable annotations
jfranck
parents:
diff changeset
    28
 *          Class and Symbol for repeatable Classes.
46cb3cd6023b 8009367: Wrong kind of name used in comparison in javax.lang.model code for repeatable annotations
jfranck
parents:
diff changeset
    29
 * @library /tools/javac/lib
30730
d3ce7619db2c 8076543: Add @modules as needed to the langtools tests
akulyakh
parents: 19248
diff changeset
    30
 * @modules jdk.compiler/com.sun.tools.javac.util
19248
46cb3cd6023b 8009367: Wrong kind of name used in comparison in javax.lang.model code for repeatable annotations
jfranck
parents:
diff changeset
    31
 * @build   JavacTestingAbstractProcessor TestQualifiedNameUsed p.Q p.QQ p.R p.RR
46cb3cd6023b 8009367: Wrong kind of name used in comparison in javax.lang.model code for repeatable annotations
jfranck
parents:
diff changeset
    32
 * @run compile -processor TestQualifiedNameUsed -proc:only TestQualifiedNameUsed.java
46cb3cd6023b 8009367: Wrong kind of name used in comparison in javax.lang.model code for repeatable annotations
jfranck
parents:
diff changeset
    33
 */
46cb3cd6023b 8009367: Wrong kind of name used in comparison in javax.lang.model code for repeatable annotations
jfranck
parents:
diff changeset
    34
46cb3cd6023b 8009367: Wrong kind of name used in comparison in javax.lang.model code for repeatable annotations
jfranck
parents:
diff changeset
    35
import java.lang.annotation.Repeatable;
46cb3cd6023b 8009367: Wrong kind of name used in comparison in javax.lang.model code for repeatable annotations
jfranck
parents:
diff changeset
    36
import java.util.Set;
46cb3cd6023b 8009367: Wrong kind of name used in comparison in javax.lang.model code for repeatable annotations
jfranck
parents:
diff changeset
    37
import javax.annotation.processing.*;
46cb3cd6023b 8009367: Wrong kind of name used in comparison in javax.lang.model code for repeatable annotations
jfranck
parents:
diff changeset
    38
import javax.lang.model.element.*;
46cb3cd6023b 8009367: Wrong kind of name used in comparison in javax.lang.model code for repeatable annotations
jfranck
parents:
diff changeset
    39
import static javax.lang.model.util.ElementFilter.*;
46cb3cd6023b 8009367: Wrong kind of name used in comparison in javax.lang.model code for repeatable annotations
jfranck
parents:
diff changeset
    40
46cb3cd6023b 8009367: Wrong kind of name used in comparison in javax.lang.model code for repeatable annotations
jfranck
parents:
diff changeset
    41
import com.sun.tools.javac.util.Assert;
46cb3cd6023b 8009367: Wrong kind of name used in comparison in javax.lang.model code for repeatable annotations
jfranck
parents:
diff changeset
    42
46cb3cd6023b 8009367: Wrong kind of name used in comparison in javax.lang.model code for repeatable annotations
jfranck
parents:
diff changeset
    43
import java.util.Arrays;
46cb3cd6023b 8009367: Wrong kind of name used in comparison in javax.lang.model code for repeatable annotations
jfranck
parents:
diff changeset
    44
46cb3cd6023b 8009367: Wrong kind of name used in comparison in javax.lang.model code for repeatable annotations
jfranck
parents:
diff changeset
    45
public class TestQualifiedNameUsed extends JavacTestingAbstractProcessor {
46cb3cd6023b 8009367: Wrong kind of name used in comparison in javax.lang.model code for repeatable annotations
jfranck
parents:
diff changeset
    46
    @Q
46cb3cd6023b 8009367: Wrong kind of name used in comparison in javax.lang.model code for repeatable annotations
jfranck
parents:
diff changeset
    47
    @p.Q
46cb3cd6023b 8009367: Wrong kind of name used in comparison in javax.lang.model code for repeatable annotations
jfranck
parents:
diff changeset
    48
    @p.R.Q
46cb3cd6023b 8009367: Wrong kind of name used in comparison in javax.lang.model code for repeatable annotations
jfranck
parents:
diff changeset
    49
    public boolean process(Set<? extends TypeElement> annotations,
46cb3cd6023b 8009367: Wrong kind of name used in comparison in javax.lang.model code for repeatable annotations
jfranck
parents:
diff changeset
    50
                           RoundEnvironment roundEnv) {
46cb3cd6023b 8009367: Wrong kind of name used in comparison in javax.lang.model code for repeatable annotations
jfranck
parents:
diff changeset
    51
        if (!roundEnv.processingOver()) {
46cb3cd6023b 8009367: Wrong kind of name used in comparison in javax.lang.model code for repeatable annotations
jfranck
parents:
diff changeset
    52
            boolean hasRun = false;
46cb3cd6023b 8009367: Wrong kind of name used in comparison in javax.lang.model code for repeatable annotations
jfranck
parents:
diff changeset
    53
            for (Element element : roundEnv.getRootElements()) {
46cb3cd6023b 8009367: Wrong kind of name used in comparison in javax.lang.model code for repeatable annotations
jfranck
parents:
diff changeset
    54
                for (ExecutableElement e : methodsIn(element.getEnclosedElements())) {
46cb3cd6023b 8009367: Wrong kind of name used in comparison in javax.lang.model code for repeatable annotations
jfranck
parents:
diff changeset
    55
                    if (e.getSimpleName().contentEquals("value"))
46cb3cd6023b 8009367: Wrong kind of name used in comparison in javax.lang.model code for repeatable annotations
jfranck
parents:
diff changeset
    56
                        continue; // don't want to look Q.value() in this file
46cb3cd6023b 8009367: Wrong kind of name used in comparison in javax.lang.model code for repeatable annotations
jfranck
parents:
diff changeset
    57
46cb3cd6023b 8009367: Wrong kind of name used in comparison in javax.lang.model code for repeatable annotations
jfranck
parents:
diff changeset
    58
                    hasRun = true;
46cb3cd6023b 8009367: Wrong kind of name used in comparison in javax.lang.model code for repeatable annotations
jfranck
parents:
diff changeset
    59
                    Q[] qs = e.getAnnotationsByType(Q.class);
46cb3cd6023b 8009367: Wrong kind of name used in comparison in javax.lang.model code for repeatable annotations
jfranck
parents:
diff changeset
    60
                    Assert.check(qs.length == 1);
46cb3cd6023b 8009367: Wrong kind of name used in comparison in javax.lang.model code for repeatable annotations
jfranck
parents:
diff changeset
    61
                    Assert.check(qs[0] instanceof Q);
46cb3cd6023b 8009367: Wrong kind of name used in comparison in javax.lang.model code for repeatable annotations
jfranck
parents:
diff changeset
    62
46cb3cd6023b 8009367: Wrong kind of name used in comparison in javax.lang.model code for repeatable annotations
jfranck
parents:
diff changeset
    63
                    p.Q[] ps = e.getAnnotationsByType(p.Q.class);
46cb3cd6023b 8009367: Wrong kind of name used in comparison in javax.lang.model code for repeatable annotations
jfranck
parents:
diff changeset
    64
                    Assert.check(ps.length == 1);
46cb3cd6023b 8009367: Wrong kind of name used in comparison in javax.lang.model code for repeatable annotations
jfranck
parents:
diff changeset
    65
                    Assert.check(ps[0] instanceof p.Q);
46cb3cd6023b 8009367: Wrong kind of name used in comparison in javax.lang.model code for repeatable annotations
jfranck
parents:
diff changeset
    66
46cb3cd6023b 8009367: Wrong kind of name used in comparison in javax.lang.model code for repeatable annotations
jfranck
parents:
diff changeset
    67
                    p.R.Q[] rs = e.getAnnotationsByType(p.R.Q.class);
46cb3cd6023b 8009367: Wrong kind of name used in comparison in javax.lang.model code for repeatable annotations
jfranck
parents:
diff changeset
    68
                    Assert.check(rs.length == 1);
46cb3cd6023b 8009367: Wrong kind of name used in comparison in javax.lang.model code for repeatable annotations
jfranck
parents:
diff changeset
    69
                    Assert.check(rs[0] instanceof p.R.Q);
46cb3cd6023b 8009367: Wrong kind of name used in comparison in javax.lang.model code for repeatable annotations
jfranck
parents:
diff changeset
    70
                }
46cb3cd6023b 8009367: Wrong kind of name used in comparison in javax.lang.model code for repeatable annotations
jfranck
parents:
diff changeset
    71
            }
46cb3cd6023b 8009367: Wrong kind of name used in comparison in javax.lang.model code for repeatable annotations
jfranck
parents:
diff changeset
    72
            if (!hasRun) throw new RuntimeException("No methods!");
46cb3cd6023b 8009367: Wrong kind of name used in comparison in javax.lang.model code for repeatable annotations
jfranck
parents:
diff changeset
    73
        }
46cb3cd6023b 8009367: Wrong kind of name used in comparison in javax.lang.model code for repeatable annotations
jfranck
parents:
diff changeset
    74
        return true;
46cb3cd6023b 8009367: Wrong kind of name used in comparison in javax.lang.model code for repeatable annotations
jfranck
parents:
diff changeset
    75
    }
46cb3cd6023b 8009367: Wrong kind of name used in comparison in javax.lang.model code for repeatable annotations
jfranck
parents:
diff changeset
    76
}
46cb3cd6023b 8009367: Wrong kind of name used in comparison in javax.lang.model code for repeatable annotations
jfranck
parents:
diff changeset
    77
46cb3cd6023b 8009367: Wrong kind of name used in comparison in javax.lang.model code for repeatable annotations
jfranck
parents:
diff changeset
    78
@Repeatable(QQ.class)
46cb3cd6023b 8009367: Wrong kind of name used in comparison in javax.lang.model code for repeatable annotations
jfranck
parents:
diff changeset
    79
@interface Q {}
46cb3cd6023b 8009367: Wrong kind of name used in comparison in javax.lang.model code for repeatable annotations
jfranck
parents:
diff changeset
    80
46cb3cd6023b 8009367: Wrong kind of name used in comparison in javax.lang.model code for repeatable annotations
jfranck
parents:
diff changeset
    81
@interface QQ {
46cb3cd6023b 8009367: Wrong kind of name used in comparison in javax.lang.model code for repeatable annotations
jfranck
parents:
diff changeset
    82
    Q[] value();
46cb3cd6023b 8009367: Wrong kind of name used in comparison in javax.lang.model code for repeatable annotations
jfranck
parents:
diff changeset
    83
}