TestSourceVersionWarnings.java revision 3890:05b91c7f6f9e
150276Speter/*
2176187Srafan * Copyright (c) 2006, 2017, Oracle and/or its affiliates. All rights reserved.
350276Speter * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
450276Speter *
550276Speter * This code is free software; you can redistribute it and/or modify it
650276Speter * under the terms of the GNU General Public License version 2 only, as
750276Speter * published by the Free Software Foundation.
850276Speter *
950276Speter * This code is distributed in the hope that it will be useful, but WITHOUT
1050276Speter * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1150276Speter * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
1250276Speter * version 2 for more details (a copy is included in the LICENSE file that
1350276Speter * accompanied this code).
1450276Speter *
1550276Speter * You should have received a copy of the GNU General Public License version
1650276Speter * 2 along with this work; if not, write to the Free Software Foundation,
1750276Speter * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1850276Speter *
1950276Speter * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2050276Speter * or visit www.oracle.com if you need additional information or have any
2150276Speter * questions.
2250276Speter */
2350276Speter
2450276Speter/*
2550276Speter * @test
2650276Speter * @bug 6376083 6376084 6458819 7025784 7025786 7025789
2750276Speter * @summary Test that warnings about source versions are output as expected.
2850276Speter * @author  Joseph D. Darcy
2950276Speter * @modules java.compiler
3050276Speter *          jdk.compiler
3150276Speter * @compile TestSourceVersionWarnings.java
32166124Srafan * @compile/ref=gold_0.out             -XDrawDiagnostics -processor TestSourceVersionWarnings -proc:only                           -source 1.6 -Xlint:-options HelloWorld.java
3350276Speter * @compile/ref=gold_sv_warn_5_6.out   -XDrawDiagnostics -processor TestSourceVersionWarnings -proc:only -ASourceVersion=RELEASE_5 -source 1.6 -Xlint:-options HelloWorld.java
3450276Speter * @compile/ref=gold_sv_none.out       -XDrawDiagnostics -processor TestSourceVersionWarnings -proc:only -ASourceVersion=RELEASE_6 -source 1.6 -Xlint:-options HelloWorld.java
3550276Speter * @compile/ref=gold_unsp_warn.out     -XDrawDiagnostics -processor TestSourceVersionWarnings -proc:only -ASourceVersion=RELEASE_6 -source 1.6 -Xlint:-options -Aunsupported HelloWorld.java
3650276Speter * @compile/ref=gold_sv_none.out       -XDrawDiagnostics -processor TestSourceVersionWarnings -proc:only -ASourceVersion=RELEASE_7 -source 1.7 -Xlint:-options HelloWorld.java
3750276Speter * @compile/ref=gold_sv_none.out       -XDrawDiagnostics -processor TestSourceVersionWarnings -proc:only -ASourceVersion=RELEASE_8 -source 1.8 -Xlint:-options HelloWorld.java
38174993Srafan * @compile/ref=gold_sv_none.out       -XDrawDiagnostics -processor TestSourceVersionWarnings -proc:only -ASourceVersion=RELEASE_9 -source 1.9 -Xlint:-options HelloWorld.java
3950276Speter */
4050276Speter
4150276Speterimport java.util.Set;
4250276Speterimport java.util.HashSet;
4350276Speterimport java.util.Arrays;
4450276Speterimport javax.annotation.processing.*;
45184989Srafanimport javax.lang.model.SourceVersion;
4650276Speterimport static javax.lang.model.SourceVersion.*;
4750276Speterimport javax.lang.model.element.*;
4850276Speterimport javax.lang.model.util.*;
4950276Speterimport static javax.tools.Diagnostic.Kind.*;
5062449Speter
5150276Speter/**
5250276Speter * This processor returns the supported source level as indicated by
5350276Speter * the "SourceLevel" option; therefore, don't use
5462449Speter * JavacTestingAbstractProcessor which returns the latest source
5550276Speter * level.
5650276Speter */
5750276Speter@SupportedAnnotationTypes("*")
5850276Speter@SupportedOptions("SourceVersion")
5950276Speterpublic class TestSourceVersionWarnings extends AbstractProcessor {
6050276Speter
6150276Speter    @Override
6250276Speter    public SourceVersion getSupportedSourceVersion() {
63174993Srafan        String sourceVersion = processingEnv.getOptions().get("SourceVersion");
6450276Speter        if (sourceVersion == null) {
6550276Speter            processingEnv.getMessager().printMessage(WARNING,
6662449Speter                                                     "No SourceVersion option given");
6762449Speter            return SourceVersion.RELEASE_6;
68166124Srafan        } else {
6962449Speter            return SourceVersion.valueOf(sourceVersion);
7062449Speter        }
7162449Speter    }
7250276Speter
7362449Speter    public boolean process(Set<? extends TypeElement> annotations,
7462449Speter                           RoundEnvironment roundEnvironment) {
7550276Speter        return true;
7666963Speter    }
7750276Speter}
7850276Speter