|
1 /* |
|
2 * Copyright (c) 2006, 2019, Oracle and/or its affiliates. All rights reserved. |
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 * |
|
5 * This code is free software; you can redistribute it and/or modify it |
|
6 * under the terms of the GNU General Public License version 2 only, as |
|
7 * published by the Free Software Foundation. |
|
8 * |
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
|
13 * accompanied this code). |
|
14 * |
|
15 * You should have received a copy of the GNU General Public License version |
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 * |
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
20 * or visit www.oracle.com if you need additional information or have any |
|
21 * questions. |
|
22 */ |
|
23 |
|
24 /* |
|
25 * @test |
|
26 * @bug 8224177 |
|
27 * @summary Test warnings from the annotation processing runtime about malformed supported information from processors. |
|
28 * @compile TestRepeatedItemsRuntime.java |
|
29 * @compile/ref=gold_sv_none.out -XDrawDiagnostics -processor TestRepeatedItemsRuntime -proc:only TestRepeatedItemsRuntime.java |
|
30 * @compile/ref=auric_current.out -XDrawDiagnostics -processor TestRepeatedItemsRuntime -proc:only -Xlint:processing TestRepeatedItemsRuntime.java |
|
31 */ |
|
32 |
|
33 import java.lang.annotation.*; |
|
34 import java.util.*; |
|
35 import javax.annotation.processing.*; |
|
36 import javax.lang.model.SourceVersion; |
|
37 import javax.lang.model.element.TypeElement; |
|
38 |
|
39 /** |
|
40 * A warning should be issued by the logic in |
|
41 * javax.annotation.processing.AbstractProcessor for the repeated |
|
42 * information. The "Foo" option warnings occur regardless of source |
|
43 * level. The number of times the Baz annotation type is repeated |
|
44 * depends on whether or not the source level supports modules. |
|
45 */ |
|
46 @Quux |
|
47 public class TestRepeatedItemsRuntime extends AbstractProcessor { |
|
48 |
|
49 @Override |
|
50 public SourceVersion getSupportedSourceVersion() { |
|
51 return SourceVersion.latest(); |
|
52 } |
|
53 |
|
54 @Override |
|
55 public Set<String>getSupportedOptions() { |
|
56 IdentityHashMap<String, Integer> temp = new IdentityHashMap<>(); |
|
57 // Use String constructor for identity map. |
|
58 temp.put(new String("foo"), 1); |
|
59 temp.put(new String("foo"), 2); |
|
60 |
|
61 var returnValue = temp.keySet(); |
|
62 assert returnValue.size() == 2; |
|
63 return returnValue; |
|
64 } |
|
65 |
|
66 /** |
|
67 * Partial implementation of the Set interface with identity |
|
68 * semantics and predictable iteration order. |
|
69 * |
|
70 * The javax.annotation.processing.Processor protocol relies on |
|
71 * the iterator. |
|
72 */ |
|
73 private static class ArrayBackedSet implements Set<String> { |
|
74 private static String[] data = {"Quux", |
|
75 "Quux", |
|
76 "&&&/foo.Bar", |
|
77 "foo.Bar", |
|
78 "foo.Bar", |
|
79 "quux/Quux", |
|
80 "*"}; |
|
81 public ArrayBackedSet() {} |
|
82 |
|
83 // Return an iterator of known iteration order so the set warning messages will be predictable. |
|
84 @Override |
|
85 public Iterator<String> iterator() { |
|
86 return Arrays.asList(data).iterator(); |
|
87 } |
|
88 |
|
89 @Override |
|
90 public boolean add(String e) { |
|
91 throw new UnsupportedOperationException(); |
|
92 } |
|
93 |
|
94 @Override |
|
95 public boolean addAll(Collection<? extends String> c) { |
|
96 throw new UnsupportedOperationException(); |
|
97 } |
|
98 |
|
99 @Override |
|
100 public void clear() { |
|
101 throw new UnsupportedOperationException(); |
|
102 } |
|
103 |
|
104 @Override |
|
105 public boolean contains(Object o){ |
|
106 throw new UnsupportedOperationException(); |
|
107 } |
|
108 |
|
109 @Override |
|
110 public boolean containsAll(Collection<?> c) { |
|
111 throw new UnsupportedOperationException(); |
|
112 } |
|
113 |
|
114 @Override |
|
115 public boolean equals(Object o) { |
|
116 return o == this; |
|
117 } |
|
118 |
|
119 @Override |
|
120 public int hashCode() { |
|
121 int hash = 0; |
|
122 for (String s : data) { |
|
123 hash += s.hashCode(); |
|
124 } |
|
125 return hash; |
|
126 } |
|
127 |
|
128 @Override |
|
129 public boolean isEmpty() { |
|
130 return data.length > 0; |
|
131 } |
|
132 |
|
133 @Override |
|
134 public boolean remove(Object o) { |
|
135 throw new UnsupportedOperationException(); |
|
136 } |
|
137 |
|
138 @Override |
|
139 public boolean removeAll(Collection<?> c) { |
|
140 throw new UnsupportedOperationException(); |
|
141 } |
|
142 |
|
143 @Override |
|
144 public boolean retainAll(Collection<?> c) { |
|
145 throw new UnsupportedOperationException(); |
|
146 } |
|
147 |
|
148 @Override |
|
149 public int size() { |
|
150 return data.length; |
|
151 } |
|
152 |
|
153 @Override |
|
154 public Object[] toArray() { |
|
155 return data.clone(); |
|
156 } |
|
157 |
|
158 @Override |
|
159 public <T> T[] toArray(T[] a) { |
|
160 throw new UnsupportedOperationException(); |
|
161 } |
|
162 } |
|
163 |
|
164 @Override |
|
165 public Set<String>getSupportedAnnotationTypes() { |
|
166 return new ArrayBackedSet(); |
|
167 } |
|
168 |
|
169 public boolean process(Set<? extends TypeElement> annotations, |
|
170 RoundEnvironment roundEnvironment) { |
|
171 return true; |
|
172 } |
|
173 } |
|
174 |
|
175 @Retention(RetentionPolicy.RUNTIME) |
|
176 @interface Quux { |
|
177 } |