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