File: T6388543.java

package info (click to toggle)
libnb-javaparser-java 9%2B2018-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster
  • size: 65,172 kB
  • sloc: java: 440,096; xml: 6,359; sh: 865; makefile: 314
file content (101 lines) | stat: -rw-r--r-- 2,880 bytes parent folder | download | duplicates (18)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/*
 * @test    /nodynamiccopyright/
 * @bug     6388543
 * @summary improve accuracy of source positions for AnnotationValue param of Messager.printMessage
 * @library /tools/javac/lib
 * @modules jdk.compiler
 * @build   JavacTestingAbstractProcessor T6388543
 * @compile/ref=T6388543.out -XDrawDiagnostics -processor T6388543 -proc:only T6388543.java
 */

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.List;
import java.util.Set;
import javax.annotation.processing.RoundEnvironment;
import javax.lang.model.element.AnnotationMirror;
import javax.lang.model.element.AnnotationValue;
import javax.lang.model.element.Element;
import javax.lang.model.element.TypeElement;

import static javax.tools.Diagnostic.Kind.NOTE;

class Annotated {
    @A(1)
    int a1;

    @A(value = 2)
    int a2;

    @A(value = {3})
    int a3;

    @A(value = {4, 5})
    int a4;

    @B(x = @C(x = E.ONE, y = E.TWO), y = @C(x = E.ONE, y = E.TWO))
    int b;
}

@Retention(RetentionPolicy.RUNTIME)
@interface A {
    int[] value() default 0;
}

@Retention(RetentionPolicy.RUNTIME)
@interface B {
    C x() default @C;

    C y() default @C;
}

@Retention(RetentionPolicy.RUNTIME)
@interface C {
    E x() default E.ONE;

    E y() default E.ONE;
}

enum E {
    ONE,
    TWO
}

public class T6388543 extends JavacTestingAbstractProcessor {
    public boolean process(Set<? extends TypeElement> annos, RoundEnvironment roundEnv) {
        if (roundEnv.processingOver()) {
            return false;
        }
        for (Element e : elements.getTypeElement("Annotated").getEnclosedElements()) {
            for (AnnotationMirror a : e.getAnnotationMirrors()) {
                for (AnnotationValue v : a.getElementValues().values()) {
                    printValue(e, a, v);
                }
            }
        }
        return false;
    }

    private void printValue(Element e, AnnotationMirror a, AnnotationValue v) {
        messager.printMessage(NOTE, String.format("note:value %s + %s", a, v), e, a, v);
        v.accept(
                new SimpleAnnotationValueVisitor<Void, Void>() {
                    @Override
                    public Void visitArray(List<? extends AnnotationValue> values, Void unused) {
                        for (AnnotationValue value : values) {
                            printValue(e, a, value);
                        }
                        return null;
                    }

                    @Override
                    public Void visitAnnotation(AnnotationMirror nestedAnnotation, Void unused) {
                        for (AnnotationValue value : nestedAnnotation.getElementValues().values()) {
                            printValue(e, a, value);
                        }
                        return null;
                    }
                },
                null);
    }
}