Wed, 07 Nov 2012 17:20:12 -0800
8003134: CheckResourceKeys issues
Reviewed-by: jjh, bpatel
darcy@699 | 1 | /* |
jjg@932 | 2 | * Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved. |
darcy@699 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
darcy@699 | 4 | * |
darcy@699 | 5 | * This code is free software; you can redistribute it and/or modify it |
darcy@699 | 6 | * under the terms of the GNU General Public License version 2 only, as |
darcy@699 | 7 | * published by the Free Software Foundation. |
darcy@699 | 8 | * |
darcy@699 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
darcy@699 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
darcy@699 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
darcy@699 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
darcy@699 | 13 | * accompanied this code). |
darcy@699 | 14 | * |
darcy@699 | 15 | * You should have received a copy of the GNU General Public License version |
darcy@699 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
darcy@699 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
darcy@699 | 18 | * |
darcy@699 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
darcy@699 | 20 | * or visit www.oracle.com if you need additional information or have any |
darcy@699 | 21 | * questions. |
darcy@699 | 22 | */ |
darcy@699 | 23 | |
darcy@699 | 24 | import java.util.*; |
darcy@699 | 25 | import javax.annotation.processing.*; |
darcy@699 | 26 | import javax.lang.model.SourceVersion; |
darcy@699 | 27 | import javax.lang.model.util.*; |
darcy@1054 | 28 | import static javax.lang.model.SourceVersion.*; |
darcy@699 | 29 | |
darcy@699 | 30 | /** |
darcy@699 | 31 | * An abstract annotation processor tailored to javac regression testing. |
darcy@699 | 32 | */ |
darcy@699 | 33 | public abstract class JavacTestingAbstractProcessor extends AbstractProcessor { |
darcy@699 | 34 | private static final Set<String> allAnnotations; |
darcy@699 | 35 | |
darcy@699 | 36 | static { |
darcy@699 | 37 | Set<String> tmp = new HashSet<>(); |
darcy@699 | 38 | tmp.add("*"); |
darcy@699 | 39 | allAnnotations = Collections.unmodifiableSet(tmp); |
darcy@699 | 40 | } |
darcy@699 | 41 | |
darcy@699 | 42 | protected Elements eltUtils; |
darcy@699 | 43 | protected Elements elements; |
darcy@699 | 44 | protected Types typeUtils; |
darcy@699 | 45 | protected Types types; |
darcy@699 | 46 | protected Filer filer; |
darcy@699 | 47 | protected Messager messager; |
darcy@699 | 48 | protected Map<String, String> options; |
darcy@699 | 49 | |
darcy@699 | 50 | /** |
darcy@699 | 51 | * Constructor for subclasses to call. |
darcy@699 | 52 | */ |
darcy@699 | 53 | protected JavacTestingAbstractProcessor() { |
darcy@699 | 54 | super(); |
darcy@699 | 55 | } |
darcy@699 | 56 | |
darcy@699 | 57 | /** |
darcy@699 | 58 | * Return the latest source version. Unless this method is |
darcy@699 | 59 | * overridden, an {@code IllegalStateException} will be thrown if a |
darcy@699 | 60 | * subclass has a {@code SupportedSourceVersion} annotation. |
darcy@699 | 61 | */ |
darcy@699 | 62 | @Override |
darcy@699 | 63 | public SourceVersion getSupportedSourceVersion() { |
darcy@699 | 64 | SupportedSourceVersion ssv = this.getClass().getAnnotation(SupportedSourceVersion.class); |
darcy@699 | 65 | if (ssv != null) |
darcy@699 | 66 | throw new IllegalStateException("SupportedSourceVersion annotation not supported here."); |
darcy@699 | 67 | |
darcy@699 | 68 | return SourceVersion.latest(); |
darcy@699 | 69 | } |
darcy@699 | 70 | |
darcy@699 | 71 | /** |
darcy@699 | 72 | * If the processor class is annotated with {@link |
darcy@699 | 73 | * SupportedAnnotationTypes}, return an unmodifiable set with the |
darcy@699 | 74 | * same set of strings as the annotation. If the class is not so |
darcy@699 | 75 | * annotated, a one-element set containing {@code "*"} is returned |
darcy@699 | 76 | * to indicate all annotations are processed. |
darcy@699 | 77 | * |
darcy@699 | 78 | * @return the names of the annotation types supported by this |
darcy@699 | 79 | * processor, or an empty set if none |
darcy@699 | 80 | */ |
darcy@699 | 81 | @Override |
darcy@699 | 82 | public Set<String> getSupportedAnnotationTypes() { |
darcy@699 | 83 | SupportedAnnotationTypes sat = this.getClass().getAnnotation(SupportedAnnotationTypes.class); |
darcy@699 | 84 | if (sat != null) |
darcy@699 | 85 | return super.getSupportedAnnotationTypes(); |
darcy@699 | 86 | else |
darcy@699 | 87 | return allAnnotations; |
darcy@699 | 88 | } |
darcy@699 | 89 | |
darcy@699 | 90 | @Override |
darcy@699 | 91 | public void init(ProcessingEnvironment processingEnv) { |
darcy@699 | 92 | super.init(processingEnv); |
darcy@699 | 93 | elements = eltUtils = processingEnv.getElementUtils(); |
darcy@699 | 94 | types = typeUtils = processingEnv.getTypeUtils(); |
darcy@699 | 95 | filer = processingEnv.getFiler(); |
darcy@699 | 96 | messager = processingEnv.getMessager(); |
darcy@699 | 97 | options = processingEnv.getOptions(); |
darcy@699 | 98 | } |
darcy@1054 | 99 | |
darcy@1054 | 100 | /* |
darcy@1054 | 101 | * The set of visitors below will directly extend the most recent |
darcy@1054 | 102 | * corresponding platform visitor type. |
darcy@1054 | 103 | */ |
darcy@1054 | 104 | |
darcy@1054 | 105 | @SupportedSourceVersion(RELEASE_8) |
darcy@1054 | 106 | public static abstract class AbstractAnnotationValueVisitor<R, P> extends AbstractAnnotationValueVisitor8<R, P> { |
darcy@1054 | 107 | |
darcy@1054 | 108 | /** |
darcy@1054 | 109 | * Constructor for concrete subclasses to call. |
darcy@1054 | 110 | */ |
darcy@1054 | 111 | protected AbstractAnnotationValueVisitor() { |
darcy@1054 | 112 | super(); |
darcy@1054 | 113 | } |
darcy@1054 | 114 | } |
darcy@1054 | 115 | |
darcy@1054 | 116 | @SupportedSourceVersion(RELEASE_8) |
darcy@1054 | 117 | public static abstract class AbstractElementVisitor<R, P> extends AbstractElementVisitor8<R, P> { |
darcy@1054 | 118 | /** |
darcy@1054 | 119 | * Constructor for concrete subclasses to call. |
darcy@1054 | 120 | */ |
darcy@1054 | 121 | protected AbstractElementVisitor(){ |
darcy@1054 | 122 | super(); |
darcy@1054 | 123 | } |
darcy@1054 | 124 | } |
darcy@1054 | 125 | |
darcy@1054 | 126 | @SupportedSourceVersion(RELEASE_8) |
darcy@1054 | 127 | public static abstract class AbstractTypeVisitor<R, P> extends AbstractTypeVisitor8<R, P> { |
darcy@1054 | 128 | /** |
darcy@1054 | 129 | * Constructor for concrete subclasses to call. |
darcy@1054 | 130 | */ |
darcy@1054 | 131 | protected AbstractTypeVisitor() { |
darcy@1054 | 132 | super(); |
darcy@1054 | 133 | } |
darcy@1054 | 134 | } |
darcy@1054 | 135 | |
darcy@1054 | 136 | @SupportedSourceVersion(RELEASE_8) |
darcy@1054 | 137 | public static class ElementKindVisitor<R, P> extends ElementKindVisitor8<R, P> { |
darcy@1054 | 138 | /** |
darcy@1054 | 139 | * Constructor for concrete subclasses; uses {@code null} for the |
darcy@1054 | 140 | * default value. |
darcy@1054 | 141 | */ |
darcy@1054 | 142 | protected ElementKindVisitor() { |
darcy@1054 | 143 | super(null); |
darcy@1054 | 144 | } |
darcy@1054 | 145 | |
darcy@1054 | 146 | /** |
darcy@1054 | 147 | * Constructor for concrete subclasses; uses the argument for the |
darcy@1054 | 148 | * default value. |
darcy@1054 | 149 | * |
darcy@1054 | 150 | * @param defaultValue the value to assign to {@link #DEFAULT_VALUE} |
darcy@1054 | 151 | */ |
darcy@1054 | 152 | protected ElementKindVisitor(R defaultValue) { |
darcy@1054 | 153 | super(defaultValue); |
darcy@1054 | 154 | } |
darcy@1054 | 155 | } |
darcy@1054 | 156 | |
darcy@1054 | 157 | @SupportedSourceVersion(RELEASE_8) |
darcy@1054 | 158 | public static class ElementScanner<R, P> extends ElementScanner8<R, P> { |
darcy@1054 | 159 | /** |
darcy@1054 | 160 | * Constructor for concrete subclasses; uses {@code null} for the |
darcy@1054 | 161 | * default value. |
darcy@1054 | 162 | */ |
darcy@1054 | 163 | protected ElementScanner(){ |
darcy@1054 | 164 | super(null); |
darcy@1054 | 165 | } |
darcy@1054 | 166 | |
darcy@1054 | 167 | /** |
darcy@1054 | 168 | * Constructor for concrete subclasses; uses the argument for the |
darcy@1054 | 169 | * default value. |
darcy@1054 | 170 | */ |
darcy@1054 | 171 | protected ElementScanner(R defaultValue){ |
darcy@1054 | 172 | super(defaultValue); |
darcy@1054 | 173 | } |
darcy@1054 | 174 | } |
darcy@1054 | 175 | |
darcy@1054 | 176 | @SupportedSourceVersion(RELEASE_8) |
darcy@1054 | 177 | public static class SimpleAnnotationValueVisitor<R, P> extends SimpleAnnotationValueVisitor8<R, P> { |
darcy@1054 | 178 | /** |
darcy@1054 | 179 | * Constructor for concrete subclasses; uses {@code null} for the |
darcy@1054 | 180 | * default value. |
darcy@1054 | 181 | */ |
darcy@1054 | 182 | protected SimpleAnnotationValueVisitor() { |
darcy@1054 | 183 | super(null); |
darcy@1054 | 184 | } |
darcy@1054 | 185 | |
darcy@1054 | 186 | /** |
darcy@1054 | 187 | * Constructor for concrete subclasses; uses the argument for the |
darcy@1054 | 188 | * default value. |
darcy@1054 | 189 | * |
darcy@1054 | 190 | * @param defaultValue the value to assign to {@link #DEFAULT_VALUE} |
darcy@1054 | 191 | */ |
darcy@1054 | 192 | protected SimpleAnnotationValueVisitor(R defaultValue) { |
darcy@1054 | 193 | super(defaultValue); |
darcy@1054 | 194 | } |
darcy@1054 | 195 | } |
darcy@1054 | 196 | |
darcy@1054 | 197 | @SupportedSourceVersion(RELEASE_8) |
darcy@1054 | 198 | public static class SimpleElementVisitor<R, P> extends SimpleElementVisitor8<R, P> { |
darcy@1054 | 199 | /** |
darcy@1054 | 200 | * Constructor for concrete subclasses; uses {@code null} for the |
darcy@1054 | 201 | * default value. |
darcy@1054 | 202 | */ |
darcy@1054 | 203 | protected SimpleElementVisitor(){ |
darcy@1054 | 204 | super(null); |
darcy@1054 | 205 | } |
darcy@1054 | 206 | |
darcy@1054 | 207 | /** |
darcy@1054 | 208 | * Constructor for concrete subclasses; uses the argument for the |
darcy@1054 | 209 | * default value. |
darcy@1054 | 210 | * |
darcy@1054 | 211 | * @param defaultValue the value to assign to {@link #DEFAULT_VALUE} |
darcy@1054 | 212 | */ |
darcy@1054 | 213 | protected SimpleElementVisitor(R defaultValue){ |
darcy@1054 | 214 | super(defaultValue); |
darcy@1054 | 215 | } |
darcy@1054 | 216 | } |
darcy@1054 | 217 | |
darcy@1054 | 218 | @SupportedSourceVersion(RELEASE_8) |
darcy@1054 | 219 | public static class SimpleTypeVisitor<R, P> extends SimpleTypeVisitor8<R, P> { |
darcy@1054 | 220 | /** |
darcy@1054 | 221 | * Constructor for concrete subclasses; uses {@code null} for the |
darcy@1054 | 222 | * default value. |
darcy@1054 | 223 | */ |
darcy@1054 | 224 | protected SimpleTypeVisitor(){ |
darcy@1054 | 225 | super(null); |
darcy@1054 | 226 | } |
darcy@1054 | 227 | |
darcy@1054 | 228 | /** |
darcy@1054 | 229 | * Constructor for concrete subclasses; uses the argument for the |
darcy@1054 | 230 | * default value. |
darcy@1054 | 231 | * |
darcy@1054 | 232 | * @param defaultValue the value to assign to {@link #DEFAULT_VALUE} |
darcy@1054 | 233 | */ |
darcy@1054 | 234 | protected SimpleTypeVisitor(R defaultValue){ |
darcy@1054 | 235 | super(defaultValue); |
darcy@1054 | 236 | } |
darcy@1054 | 237 | } |
darcy@1054 | 238 | |
darcy@1054 | 239 | @SupportedSourceVersion(RELEASE_8) |
darcy@1054 | 240 | public static class TypeKindVisitor<R, P> extends TypeKindVisitor8<R, P> { |
darcy@1054 | 241 | /** |
darcy@1054 | 242 | * Constructor for concrete subclasses to call; uses {@code null} |
darcy@1054 | 243 | * for the default value. |
darcy@1054 | 244 | */ |
darcy@1054 | 245 | protected TypeKindVisitor() { |
darcy@1054 | 246 | super(null); |
darcy@1054 | 247 | } |
darcy@1054 | 248 | |
darcy@1054 | 249 | /** |
darcy@1054 | 250 | * Constructor for concrete subclasses to call; uses the argument |
darcy@1054 | 251 | * for the default value. |
darcy@1054 | 252 | * |
darcy@1054 | 253 | * @param defaultValue the value to assign to {@link #DEFAULT_VALUE} |
darcy@1054 | 254 | */ |
darcy@1054 | 255 | protected TypeKindVisitor(R defaultValue) { |
darcy@1054 | 256 | super(defaultValue); |
darcy@1054 | 257 | } |
darcy@1054 | 258 | } |
darcy@699 | 259 | } |