TestSourceVersionWarnings.java revision 2221:f52909109e6d
1139826Simp/* 253541Sshin * Copyright (c) 2006, 2013, Oracle and/or its affiliates. All rights reserved. 353541Sshin * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 453541Sshin * 553541Sshin * This code is free software; you can redistribute it and/or modify it 653541Sshin * under the terms of the GNU General Public License version 2 only, as 753541Sshin * published by the Free Software Foundation. 853541Sshin * 953541Sshin * This code is distributed in the hope that it will be useful, but WITHOUT 1053541Sshin * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1153541Sshin * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1253541Sshin * version 2 for more details (a copy is included in the LICENSE file that 1353541Sshin * accompanied this code). 1453541Sshin * 1553541Sshin * You should have received a copy of the GNU General Public License version 1653541Sshin * 2 along with this work; if not, write to the Free Software Foundation, 1753541Sshin * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1853541Sshin * 1953541Sshin * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2053541Sshin * or visit www.oracle.com if you need additional information or have any 2153541Sshin * questions. 2253541Sshin */ 2353541Sshin 2453541Sshin/* 2553541Sshin * @test 2653541Sshin * @bug 6376083 6376084 6458819 7025784 7025786 7025789 2753541Sshin * @summary Test that warnings about source versions are output as expected. 28174510Sobrien * @author Joseph D. Darcy 29174510Sobrien * @compile TestSourceVersionWarnings.java 30174510Sobrien * @compile/ref=gold_0.out -XDrawDiagnostics -processor TestSourceVersionWarnings -proc:only -source 1.5 -Xlint:-options HelloWorld.java 3153541Sshin * @compile/ref=gold_sv_warn_0_2.out -XDrawDiagnostics -processor TestSourceVersionWarnings -proc:only -ASourceVersion=RELEASE_0 -source 1.2 -Xlint:-options HelloWorld.java 3253541Sshin * @compile/ref=gold_sv_none.out -XDrawDiagnostics -processor TestSourceVersionWarnings -proc:only -ASourceVersion=RELEASE_2 -source 1.2 -Xlint:-options HelloWorld.java 3353541Sshin * @compile/ref=gold_sv_warn_2_3.out -XDrawDiagnostics -processor TestSourceVersionWarnings -proc:only -ASourceVersion=RELEASE_2 -source 1.3 -Xlint:-options HelloWorld.java 3462587Sitojun * @compile/ref=gold_sv_none.out -XDrawDiagnostics -processor TestSourceVersionWarnings -proc:only -ASourceVersion=RELEASE_5 -source 1.5 -Xlint:-options HelloWorld.java 3553541Sshin * @compile/ref=gold_sv_warn_5_6.out -XDrawDiagnostics -processor TestSourceVersionWarnings -proc:only -ASourceVersion=RELEASE_5 -source 1.6 -Xlint:-options HelloWorld.java 3662587Sitojun * @compile/ref=gold_sv_none.out -XDrawDiagnostics -processor TestSourceVersionWarnings -proc:only -ASourceVersion=RELEASE_6 -source 1.6 -Xlint:-options HelloWorld.java 3762587Sitojun * @compile/ref=gold_unsp_warn.out -XDrawDiagnostics -processor TestSourceVersionWarnings -proc:only -ASourceVersion=RELEASE_6 -source 1.6 -Xlint:-options -Aunsupported HelloWorld.java 3862587Sitojun * @compile/ref=gold_sv_none.out -XDrawDiagnostics -processor TestSourceVersionWarnings -proc:only -ASourceVersion=RELEASE_7 -source 1.7 -Xlint:-options HelloWorld.java 3962587Sitojun * @compile/ref=gold_sv_none.out -XDrawDiagnostics -processor TestSourceVersionWarnings -proc:only -ASourceVersion=RELEASE_8 -source 1.8 -Xlint:-options HelloWorld.java 4062587Sitojun */ 4153541Sshin 4278064Sumeimport java.util.Set; 4353541Sshinimport java.util.HashSet; 44186119Sqingliimport java.util.Arrays; 45151539Ssuzimport javax.annotation.processing.*; 4662587Sitojunimport javax.lang.model.SourceVersion; 4778064Sumeimport static javax.lang.model.SourceVersion.*; 4878064Sumeimport javax.lang.model.element.*; 4978064Sumeimport javax.lang.model.util.*; 5078064Sumeimport static javax.tools.Diagnostic.Kind.*; 5178064Sume 5278064Sume/** 5378064Sume * This processor returns the supported source level as indicated by 5478064Sume * the "SourceLevel" option; therefore, don't use 5562587Sitojun * JavacTestingAbstractProcessor which returns the latest source 5662587Sitojun * level. 5762587Sitojun */ 5862587Sitojun@SupportedAnnotationTypes("*") 5962587Sitojun@SupportedOptions("SourceVersion") 6053541Sshinpublic class TestSourceVersionWarnings extends AbstractProcessor { 6162587Sitojun 62186119Sqingli @Override 6362587Sitojun public SourceVersion getSupportedSourceVersion() { 6453541Sshin String sourceVersion = processingEnv.getOptions().get("SourceVersion"); 6562587Sitojun if (sourceVersion == null) { 6662587Sitojun processingEnv.getMessager().printMessage(WARNING, 6762587Sitojun "No SourceVersion option given"); 6862587Sitojun return SourceVersion.RELEASE_6; 6962587Sitojun } else { 7062587Sitojun return SourceVersion.valueOf(sourceVersion); 7162587Sitojun } 7262587Sitojun } 73121161Sume 7495023Ssuz public boolean process(Set<? extends TypeElement> annotations, 7578064Sume RoundEnvironment roundEnvironment) { 7678064Sume return true; 7778064Sume } 7853541Sshin} 7953541Sshin