test/tools/javac/lib/JavacTestingAbstractProcessor.java

Tue, 15 Mar 2011 11:41:21 -0700

author
jjg
date
Tue, 15 Mar 2011 11:41:21 -0700
changeset 932
edf03ca74991
parent 699
d2aaaec153e8
child 1054
111bbf1ad913
permissions
-rw-r--r--

6987384: -XprintProcessorRoundsInfo message printed with different timing than previous
Reviewed-by: darcy

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@699 28
darcy@699 29 /**
darcy@699 30 * An abstract annotation processor tailored to javac regression testing.
darcy@699 31 */
darcy@699 32 public abstract class JavacTestingAbstractProcessor extends AbstractProcessor {
darcy@699 33 private static final Set<String> allAnnotations;
darcy@699 34
darcy@699 35 static {
darcy@699 36 Set<String> tmp = new HashSet<>();
darcy@699 37 tmp.add("*");
darcy@699 38 allAnnotations = Collections.unmodifiableSet(tmp);
darcy@699 39 }
darcy@699 40
darcy@699 41 protected Elements eltUtils;
darcy@699 42 protected Elements elements;
darcy@699 43 protected Types typeUtils;
darcy@699 44 protected Types types;
darcy@699 45 protected Filer filer;
darcy@699 46 protected Messager messager;
darcy@699 47 protected Map<String, String> options;
darcy@699 48
darcy@699 49 /**
darcy@699 50 * Constructor for subclasses to call.
darcy@699 51 */
darcy@699 52 protected JavacTestingAbstractProcessor() {
darcy@699 53 super();
darcy@699 54 }
darcy@699 55
darcy@699 56 /**
darcy@699 57 * Return the latest source version. Unless this method is
darcy@699 58 * overridden, an {@code IllegalStateException} will be thrown if a
darcy@699 59 * subclass has a {@code SupportedSourceVersion} annotation.
darcy@699 60 */
darcy@699 61 @Override
darcy@699 62 public SourceVersion getSupportedSourceVersion() {
darcy@699 63 SupportedSourceVersion ssv = this.getClass().getAnnotation(SupportedSourceVersion.class);
darcy@699 64 if (ssv != null)
darcy@699 65 throw new IllegalStateException("SupportedSourceVersion annotation not supported here.");
darcy@699 66
darcy@699 67 return SourceVersion.latest();
darcy@699 68 }
darcy@699 69
darcy@699 70 /**
darcy@699 71 * If the processor class is annotated with {@link
darcy@699 72 * SupportedAnnotationTypes}, return an unmodifiable set with the
darcy@699 73 * same set of strings as the annotation. If the class is not so
darcy@699 74 * annotated, a one-element set containing {@code "*"} is returned
darcy@699 75 * to indicate all annotations are processed.
darcy@699 76 *
darcy@699 77 * @return the names of the annotation types supported by this
darcy@699 78 * processor, or an empty set if none
darcy@699 79 */
darcy@699 80 @Override
darcy@699 81 public Set<String> getSupportedAnnotationTypes() {
darcy@699 82 SupportedAnnotationTypes sat = this.getClass().getAnnotation(SupportedAnnotationTypes.class);
darcy@699 83 if (sat != null)
darcy@699 84 return super.getSupportedAnnotationTypes();
darcy@699 85 else
darcy@699 86 return allAnnotations;
darcy@699 87 }
darcy@699 88
darcy@699 89 @Override
darcy@699 90 public void init(ProcessingEnvironment processingEnv) {
darcy@699 91 super.init(processingEnv);
darcy@699 92 elements = eltUtils = processingEnv.getElementUtils();
darcy@699 93 types = typeUtils = processingEnv.getTypeUtils();
darcy@699 94 filer = processingEnv.getFiler();
darcy@699 95 messager = processingEnv.getMessager();
darcy@699 96 options = processingEnv.getOptions();
darcy@699 97 }
darcy@699 98 }

mercurial