698N/A/*
931N/A * Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved.
698N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
698N/A *
698N/A * This code is free software; you can redistribute it and/or modify it
698N/A * under the terms of the GNU General Public License version 2 only, as
698N/A * published by the Free Software Foundation.
698N/A *
698N/A * This code is distributed in the hope that it will be useful, but WITHOUT
698N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
698N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
698N/A * version 2 for more details (a copy is included in the LICENSE file that
698N/A * accompanied this code).
698N/A *
698N/A * You should have received a copy of the GNU General Public License version
698N/A * 2 along with this work; if not, write to the Free Software Foundation,
698N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
698N/A *
698N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
698N/A * or visit www.oracle.com if you need additional information or have any
698N/A * questions.
698N/A */
698N/A
698N/Aimport java.util.*;
698N/Aimport javax.annotation.processing.*;
698N/Aimport javax.lang.model.SourceVersion;
698N/Aimport javax.lang.model.util.*;
698N/A
698N/A/**
698N/A * An abstract annotation processor tailored to javac regression testing.
698N/A */
698N/Apublic abstract class JavacTestingAbstractProcessor extends AbstractProcessor {
698N/A private static final Set<String> allAnnotations;
698N/A
698N/A static {
698N/A Set<String> tmp = new HashSet<>();
698N/A tmp.add("*");
698N/A allAnnotations = Collections.unmodifiableSet(tmp);
698N/A }
698N/A
698N/A protected Elements eltUtils;
698N/A protected Elements elements;
698N/A protected Types typeUtils;
698N/A protected Types types;
698N/A protected Filer filer;
698N/A protected Messager messager;
698N/A protected Map<String, String> options;
698N/A
698N/A /**
698N/A * Constructor for subclasses to call.
698N/A */
698N/A protected JavacTestingAbstractProcessor() {
698N/A super();
698N/A }
698N/A
698N/A /**
698N/A * Return the latest source version. Unless this method is
698N/A * overridden, an {@code IllegalStateException} will be thrown if a
698N/A * subclass has a {@code SupportedSourceVersion} annotation.
698N/A */
698N/A @Override
698N/A public SourceVersion getSupportedSourceVersion() {
698N/A SupportedSourceVersion ssv = this.getClass().getAnnotation(SupportedSourceVersion.class);
698N/A if (ssv != null)
698N/A throw new IllegalStateException("SupportedSourceVersion annotation not supported here.");
698N/A
698N/A return SourceVersion.latest();
698N/A }
698N/A
698N/A /**
698N/A * If the processor class is annotated with {@link
698N/A * SupportedAnnotationTypes}, return an unmodifiable set with the
698N/A * same set of strings as the annotation. If the class is not so
698N/A * annotated, a one-element set containing {@code "*"} is returned
698N/A * to indicate all annotations are processed.
698N/A *
698N/A * @return the names of the annotation types supported by this
698N/A * processor, or an empty set if none
698N/A */
698N/A @Override
698N/A public Set<String> getSupportedAnnotationTypes() {
698N/A SupportedAnnotationTypes sat = this.getClass().getAnnotation(SupportedAnnotationTypes.class);
698N/A if (sat != null)
698N/A return super.getSupportedAnnotationTypes();
698N/A else
698N/A return allAnnotations;
698N/A }
698N/A
698N/A @Override
698N/A public void init(ProcessingEnvironment processingEnv) {
698N/A super.init(processingEnv);
698N/A elements = eltUtils = processingEnv.getElementUtils();
698N/A types = typeUtils = processingEnv.getTypeUtils();
698N/A filer = processingEnv.getFiler();
698N/A messager = processingEnv.getMessager();
698N/A options = processingEnv.getOptions();
698N/A }
698N/A}