8220632: Suggest recompiling with a larger value of -Xmaxerrs/-Xmaxwarns if diagnostics were suppressed
Reviewed-by: jjg
This commit is contained in:
parent
793c71bf92
commit
b0f6b1086a
src/jdk.compiler/share/classes/com/sun/tools/javac
test/langtools/tools/javac
@ -990,6 +990,8 @@ public class JavaCompiler {
|
||||
if (!log.hasDiagnosticListener()) {
|
||||
printCount("error", errorCount());
|
||||
printCount("warn", warningCount());
|
||||
printSuppressedCount(errorCount(), log.nsuppressederrors, "count.error.recompile");
|
||||
printSuppressedCount(warningCount(), log.nsuppressedwarns, "count.warn.recompile");
|
||||
}
|
||||
if (!taskListener.isEmpty()) {
|
||||
taskListener.finished(new TaskEvent(TaskEvent.Kind.COMPILATION));
|
||||
@ -1845,6 +1847,15 @@ public class JavaCompiler {
|
||||
}
|
||||
}
|
||||
|
||||
private void printSuppressedCount(int shown, int suppressed, String diagKey) {
|
||||
if (suppressed > 0) {
|
||||
int total = shown + suppressed;
|
||||
log.printLines(WriterKind.ERROR, diagKey,
|
||||
String.valueOf(shown), String.valueOf(total));
|
||||
log.flush(Log.WriterKind.ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
private static long now() {
|
||||
return System.currentTimeMillis();
|
||||
}
|
||||
|
@ -1636,6 +1636,14 @@ compiler.misc.count.error=\
|
||||
compiler.misc.count.error.plural=\
|
||||
{0} errors
|
||||
|
||||
# 0: number, 1: number
|
||||
compiler.misc.count.error.recompile=\
|
||||
only showing the first {0} errors, of {1} total; use -Xmaxerrs if you would like to see more
|
||||
|
||||
# 0: number, 1: number
|
||||
compiler.misc.count.warn.recompile=\
|
||||
only showing the first {0} warnings, of {1} total; use -Xmaxwarns if you would like to see more
|
||||
|
||||
# 0: number
|
||||
compiler.misc.count.warn=\
|
||||
{0} warning
|
||||
|
@ -419,6 +419,14 @@ public class Log extends AbstractLog {
|
||||
*/
|
||||
public int nwarnings = 0;
|
||||
|
||||
/** The number of errors encountered after MaxErrors was reached.
|
||||
*/
|
||||
public int nsuppressederrors = 0;
|
||||
|
||||
/** The number of warnings encountered after MaxWarnings was reached.
|
||||
*/
|
||||
public int nsuppressedwarns = 0;
|
||||
|
||||
/** A set of all errors generated so far. This is used to avoid printing an
|
||||
* error message more than once. For each error, a pair consisting of the
|
||||
* source file name and source code position of the error is added to the set.
|
||||
@ -708,16 +716,21 @@ public class Log extends AbstractLog {
|
||||
if (nwarnings < MaxWarnings) {
|
||||
writeDiagnostic(diagnostic);
|
||||
nwarnings++;
|
||||
} else {
|
||||
nsuppressedwarns++;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case ERROR:
|
||||
if (nerrors < MaxErrors &&
|
||||
(diagnostic.isFlagSet(DiagnosticFlag.API) ||
|
||||
shouldReport(diagnostic))) {
|
||||
writeDiagnostic(diagnostic);
|
||||
nerrors++;
|
||||
if (diagnostic.isFlagSet(DiagnosticFlag.API) ||
|
||||
shouldReport(diagnostic)) {
|
||||
if (nerrors < MaxErrors) {
|
||||
writeDiagnostic(diagnostic);
|
||||
nerrors++;
|
||||
} else {
|
||||
nsuppressederrors++;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -844,6 +857,8 @@ public class Log extends AbstractLog {
|
||||
printRawDiag(errWriter, "error: ", pos, msg);
|
||||
prompt();
|
||||
nerrors++;
|
||||
} else {
|
||||
nsuppressederrors++;
|
||||
}
|
||||
errWriter.flush();
|
||||
}
|
||||
@ -852,8 +867,12 @@ public class Log extends AbstractLog {
|
||||
*/
|
||||
public void rawWarning(int pos, String msg) {
|
||||
PrintWriter warnWriter = writers.get(WriterKind.ERROR);
|
||||
if (nwarnings < MaxWarnings && emitWarnings) {
|
||||
printRawDiag(warnWriter, "warning: ", pos, msg);
|
||||
if (emitWarnings) {
|
||||
if (nwarnings < MaxWarnings) {
|
||||
printRawDiag(warnWriter, "warning: ", pos, msg);
|
||||
} else {
|
||||
nsuppressedwarns++;
|
||||
}
|
||||
}
|
||||
prompt();
|
||||
nwarnings++;
|
||||
|
@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright (c) 2019, Google LLC. 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.
|
||||
*/
|
||||
|
||||
// key: compiler.err.cant.resolve.location
|
||||
// key: compiler.misc.count.error.recompile
|
||||
// key: compiler.err.error
|
||||
// key: compiler.misc.count.error
|
||||
// key: compiler.misc.kindname.class
|
||||
// key: compiler.misc.location
|
||||
// options: -Xmaxerrs 1
|
||||
// run: backdoor
|
||||
|
||||
class CountErrorRecompile {
|
||||
|
||||
NoSuchSymbol1 f1;
|
||||
NoSuchSymbol2 f2;
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright (c) 2019, Google LLC. 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.
|
||||
*/
|
||||
|
||||
// key: compiler.warn.raw.class.use
|
||||
// key: compiler.misc.count.warn
|
||||
// key: compiler.misc.kindname.interface
|
||||
// key: compiler.misc.where.description.typevar
|
||||
// key: compiler.misc.where.typevar
|
||||
// key: compiler.warn.lintOption
|
||||
// key: compiler.warn.warning
|
||||
// key: compiler.misc.count.warn.recompile
|
||||
// options: -Xlint:all -Xmaxwarns 1
|
||||
// run: backdoor
|
||||
|
||||
import java.util.List;
|
||||
|
||||
class CountWarnRecompile {
|
||||
|
||||
List x1;
|
||||
List x2;
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
MaxDiagsRecompile.java:28:3: compiler.err.cant.resolve.location: kindname.class, NoSuchSymbol1, , , (compiler.misc.location: kindname.class, MaxDiagsRecompile, null)
|
||||
MaxDiagsRecompile.java:29:3: compiler.err.cant.resolve.location: kindname.class, NoSuchSymbol2, , , (compiler.misc.location: kindname.class, MaxDiagsRecompile, null)
|
||||
MaxDiagsRecompile.java:30:3: compiler.err.cant.resolve.location: kindname.class, NoSuchSymbol3, , , (compiler.misc.location: kindname.class, MaxDiagsRecompile, null)
|
||||
MaxDiagsRecompile.java:31:3: compiler.err.cant.resolve.location: kindname.class, NoSuchSymbol4, , , (compiler.misc.location: kindname.class, MaxDiagsRecompile, null)
|
||||
4 errors
|
32
test/langtools/tools/javac/warnings/MaxDiagsRecompile.java
Normal file
32
test/langtools/tools/javac/warnings/MaxDiagsRecompile.java
Normal file
@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright (c) 2019, Google LLC. 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @summary suggest recompiling with -Xmaxerrs
|
||||
* @compile/fail/ref=MaxDiagsRecompile.max1.out -XDrawDiagnostics -Xmaxerrs 1 MaxDiagsRecompile.java
|
||||
* @compile/fail/ref=MaxDiagsRecompile.all.out -XDrawDiagnostics -Xmaxerrs 4 MaxDiagsRecompile.java
|
||||
*/
|
||||
public class MaxDiagsRecompile {
|
||||
|
||||
NoSuchSymbol1 f1;
|
||||
NoSuchSymbol2 f2;
|
||||
NoSuchSymbol3 f3;
|
||||
NoSuchSymbol4 f4;
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
MaxDiagsRecompile.java:28:3: compiler.err.cant.resolve.location: kindname.class, NoSuchSymbol1, , , (compiler.misc.location: kindname.class, MaxDiagsRecompile, null)
|
||||
1 error
|
||||
only showing the first 1 errors, of 4 total; use -Xmaxerrs if you would like to see more
|
@ -0,0 +1,5 @@
|
||||
MaxWarnsRecompile.java:30:3: compiler.warn.raw.class.use: java.util.List, java.util.List<E>
|
||||
MaxWarnsRecompile.java:31:3: compiler.warn.raw.class.use: java.util.List, java.util.List<E>
|
||||
MaxWarnsRecompile.java:32:3: compiler.warn.raw.class.use: java.util.List, java.util.List<E>
|
||||
MaxWarnsRecompile.java:33:3: compiler.warn.raw.class.use: java.util.List, java.util.List<E>
|
||||
4 warnings
|
34
test/langtools/tools/javac/warnings/MaxWarnsRecompile.java
Normal file
34
test/langtools/tools/javac/warnings/MaxWarnsRecompile.java
Normal file
@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright (c) 2019, Google LLC. 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.
|
||||
*/
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @summary suggest recompiling with -Xmaxwarns
|
||||
* @compile/ref=MaxWarnsRecompile.max1.out -XDrawDiagnostics -Xlint:all -Xmaxwarns 1 MaxWarnsRecompile.java
|
||||
* @compile/ref=MaxWarnsRecompile.all.out -XDrawDiagnostics -Xlint:all -Xmaxwarns 4 MaxWarnsRecompile.java
|
||||
*/
|
||||
public class MaxWarnsRecompile {
|
||||
|
||||
List x1;
|
||||
List x2;
|
||||
List x3;
|
||||
List x4;
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
MaxWarnsRecompile.java:30:3: compiler.warn.raw.class.use: java.util.List, java.util.List<E>
|
||||
1 warning
|
||||
only showing the first 1 warnings, of 4 total; use -Xmaxwarns if you would like to see more
|
Loading…
x
Reference in New Issue
Block a user