|
Java example source code file (TestWarnErrorCount.java)
The TestWarnErrorCount.java Java example source code/* * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ /* * @test * @bug 7022337 * @summary repeated warnings about bootclasspath not set * @library /tools/javac/lib * @build JavacTestingAbstractProcessor TestWarnErrorCount * @run main TestWarnErrorCount */ import java.io.*; import java.util.*; import javax.annotation.processing.*; import javax.lang.model.element.*; import javax.tools.*; @SupportedOptions({"errKind", "msgrWarnKind", "javaWarnKind"}) public class TestWarnErrorCount extends JavacTestingAbstractProcessor { public static void main(String... args) throws Exception { new TestWarnErrorCount().run(args); } final int MAX_GEN = 10; final int ERROR_ROUND = MAX_GEN / 2; // when to generate error /** * Type of errors to generate in test case. */ enum ErrorKind { /** No errors. */ NONE, /** Source code errors. */ JAVA, /** Errors reported to Messager. */ MESSAGER, /** Error as a result of using -Werror. */ WERROR, } /** * Frequency of warnings in test case. */ enum WarnKind { /** No warnings. */ NONE { boolean warn(int round) { return false; } int count(int start, int end) { return 0; } }, /** Generate a warning if round count is a multiple of 2. */ EVERY_TWO { boolean warn(int round) { return (round % 2) == 0; } int count(int start, int end) { return (end / 2) - ((start - 1)/ 2); } }, /** Generate a warning if round count is a multiple of 3. */ EVERY_THREE { boolean warn(int round) { return (round % 3) == 0; } int count(int start, int end) { return (end / 3) - ((start - 1)/ 3); } }, /** Generate a warning every round. */ ALL { boolean warn(int round) { return true; } int count(int start, int end) { return (end - start + 1); } }; /** whether to generate a warning in round 'round'. */ abstract boolean warn(int round); /** number of warnings generated in a range of rounds, inclusive. */ abstract int count(int start, int end); } /** * Run test. * @param args provide ability to specify particular test cases for debugging. */ void run(String... args) throws Exception { for (String arg: args) { if (arg.matches("[0-9]+")) { if (testCases == null) testCases = new HashSet<Integer>(); testCases.add(Integer.valueOf(arg)); } else if (arg.equals("-stopOnError")) { stopOnError = true; } else throw new IllegalArgumentException(arg); } run (); if (errors > 0) throw new Exception(errors + " errors found"); } /** * Run test. */ void run() throws Exception { for (ErrorKind ek: ErrorKind.values()) { for (WarnKind mwk: WarnKind.values()) { for (WarnKind jwk: WarnKind.values()) { test(ek, mwk, jwk); if (stopOnError && errors > 0) throw new Exception(errors + " errors found"); } } } } boolean stopOnError; Set<Integer> testCases; int testNum = 0; /** * Run a test case. * @param ek The type of errors to generate * @param mwk The frequency of Messager warnings to generate * @param jwk The frequency of Java warnings to generate */ void test(ErrorKind ek, WarnKind mwk, WarnKind jwk) { testNum++; if (testCases != null && !testCases.contains(testNum)) return; System.err.println("Test " + testNum + ": ek:" + ek + " mwk:" + mwk + " jwk:" + jwk); File testDir = new File("test" + testNum); testDir.mkdirs(); String myName = TestWarnErrorCount.class.getSimpleName(); File testSrc = new File(System.getProperty("test.src")); File file = new File(testSrc, myName + ".java"); List<String> args = new ArrayList Other Java examples (source code examples)Here is a short list of links related to this Java TestWarnErrorCount.java source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.