jdk
1/*
2* Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
3* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*
5* This code is free software; you can redistribute it and/or modify it
6* under the terms of the GNU General Public License version 2 only, as
7* published by the Free Software Foundation.
8*
9* This code is distributed in the hope that it will be useful, but WITHOUT
10* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12* version 2 for more details (a copy is included in the LICENSE file that
13* accompanied this code).
14*
15* You should have received a copy of the GNU General Public License version
16* 2 along with this work; if not, write to the Free Software Foundation,
17* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18*
19* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20* or visit www.oracle.com if you need additional information or have any
21* questions.
22*/
23
24/*
25* @test
26* @bug 8189782 8210555
27* @summary Test for isSupportedOption
28* @modules java.compiler
29* jdk.compiler
30* @run main IsSupportedOptionTest
31*/
32
33import javax.tools.JavaCompiler;34import javax.tools.ToolProvider;35
36/**
37* Tests for JavaCompiler.isSupportedOption method.
38*/
39public class IsSupportedOptionTest {40public static void main(String... args) throws Exception {41new IsSupportedOptionTest().run();42}43
44public void run() throws Exception {45JavaCompiler tool = ToolProvider.getSystemJavaCompiler();46check(tool, "-source", 1);47check(tool, "--source", 1);48check(tool, "-target", 1);49check(tool, "--target", 1);50check(tool, "--add-modules", 1);51check(tool, "-verbose", 0);52check(tool, "-proc:none", 0);53check(tool, "-Xlint", 0);54check(tool, "-Xlint:unchecked", 0);55check(tool, "-Xdoclint", 0);56check(tool, "-Xdoclint:stats", 0);57check(tool, "-Xdoclint/package:foo", 0);58check(tool, "--debug=any", 1);59check(tool, "-g", 0);60check(tool, "-g:vars", 0);61check(tool, "-g:none", 0);62check(tool, "-ZZZ", -1);63check(tool, "-Afoobar", 0);64
65try {66check(tool, null, -1);67throw new AssertionError("null was accepted without exception");68} catch (NullPointerException e) {69}70}71
72private void check(JavaCompiler tool, String option, int numArgs) {73System.err.println("check " + option);74int n = tool.isSupportedOption(option);75if (n != numArgs) {76throw new AssertionError("unexpected result for option: " + option + ": " + n);77}78}79}
80
81