6794959: add new switch -XDexpectKeys=key,key...
Reviewed-by: mcimadamore
This commit is contained in:
parent
6644396543
commit
a1f31b73db
@ -338,13 +338,13 @@ public class Main {
|
||||
return EXIT_CMDERR;
|
||||
}
|
||||
|
||||
List<File> filenames;
|
||||
List<File> files;
|
||||
try {
|
||||
filenames = processArgs(CommandLine.parse(args));
|
||||
if (filenames == null) {
|
||||
files = processArgs(CommandLine.parse(args));
|
||||
if (files == null) {
|
||||
// null signals an error in options, abort
|
||||
return EXIT_CMDERR;
|
||||
} else if (filenames.isEmpty() && fileObjects.isEmpty() && classnames.isEmpty()) {
|
||||
} else if (files.isEmpty() && fileObjects.isEmpty() && classnames.isEmpty()) {
|
||||
// it is allowed to compile nothing if just asking for help or version info
|
||||
if (options.get("-help") != null
|
||||
|| options.get("-X") != null
|
||||
@ -380,12 +380,14 @@ public class Main {
|
||||
comp = JavaCompiler.instance(context);
|
||||
if (comp == null) return EXIT_SYSERR;
|
||||
|
||||
if (!filenames.isEmpty()) {
|
||||
Log log = Log.instance(context);
|
||||
|
||||
if (!files.isEmpty()) {
|
||||
// add filenames to fileObjects
|
||||
comp = JavaCompiler.instance(context);
|
||||
List<JavaFileObject> otherFiles = List.nil();
|
||||
JavacFileManager dfm = (JavacFileManager)fileManager;
|
||||
for (JavaFileObject fo : dfm.getJavaFileObjectsFromFiles(filenames))
|
||||
for (JavaFileObject fo : dfm.getJavaFileObjectsFromFiles(files))
|
||||
otherFiles = otherFiles.prepend(fo);
|
||||
for (JavaFileObject fo : otherFiles)
|
||||
fileObjects = fileObjects.prepend(fo);
|
||||
@ -394,6 +396,16 @@ public class Main {
|
||||
classnames.toList(),
|
||||
processors);
|
||||
|
||||
if (log.expectDiagKeys != null) {
|
||||
if (log.expectDiagKeys.size() == 0) {
|
||||
Log.printLines(log.noticeWriter, "all expected diagnostics found");
|
||||
return EXIT_OK;
|
||||
} else {
|
||||
Log.printLines(log.noticeWriter, "expected diagnostic keys not found: " + log.expectDiagKeys);
|
||||
return EXIT_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
if (comp.errorCount() != 0 ||
|
||||
options.get("-Werror") != null && comp.warningCount() != 0)
|
||||
return EXIT_ERROR;
|
||||
|
@ -26,6 +26,7 @@
|
||||
package com.sun.tools.javac.util;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
@ -96,6 +97,11 @@ public class Log extends AbstractLog {
|
||||
*/
|
||||
private DiagnosticFormatter<JCDiagnostic> diagFormatter;
|
||||
|
||||
/**
|
||||
* Keys for expected diagnostics
|
||||
*/
|
||||
public Set<String> expectDiagKeys;
|
||||
|
||||
/**
|
||||
* JavacMessages object used for localization
|
||||
*/
|
||||
@ -123,9 +129,13 @@ public class Log extends AbstractLog {
|
||||
this.diagFormatter = rawDiagnostics ? new RawDiagnosticFormatter(options) :
|
||||
new BasicDiagnosticFormatter(options, messages);
|
||||
@SuppressWarnings("unchecked") // FIXME
|
||||
DiagnosticListener<? super JavaFileObject> diagListener =
|
||||
DiagnosticListener<? super JavaFileObject> dl =
|
||||
context.get(DiagnosticListener.class);
|
||||
this.diagListener = diagListener;
|
||||
this.diagListener = dl;
|
||||
|
||||
String ek = options.get("expectKeys");
|
||||
if (ek != null)
|
||||
expectDiagKeys = new HashSet<String>(Arrays.asList(ek.split(", *")));
|
||||
}
|
||||
// where
|
||||
private int getIntOption(Options options, String optionName, int defaultValue) {
|
||||
@ -291,6 +301,9 @@ public class Log extends AbstractLog {
|
||||
* reported so far, the diagnostic may be handed off to writeDiagnostic.
|
||||
*/
|
||||
public void report(JCDiagnostic diagnostic) {
|
||||
if (expectDiagKeys != null)
|
||||
expectDiagKeys.remove(diagnostic.getCode());
|
||||
|
||||
switch (diagnostic.getType()) {
|
||||
case FRAGMENT:
|
||||
throw new IllegalArgumentException();
|
||||
|
36
langtools/test/tools/javac/T6794959.java
Normal file
36
langtools/test/tools/javac/T6794959.java
Normal file
@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright 2009 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
||||
* CA 95054 USA or visit www.sun.com if you need additional information or
|
||||
* have any questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 6794959
|
||||
* @summary add new switch -XDexpectKeys=key,key,...
|
||||
* @compile T6794959.java
|
||||
* @compile/fail -XDfailcomplete=java.lang.String T6794959.java
|
||||
* @compile -XDfailcomplete=java.lang.String -XDexpectKeys=compiler.err.cant.resolve.location T6794959.java
|
||||
* @compile/fail -XDexpectKeys=compiler.err.cant.resolve.location T6794959.java
|
||||
*/
|
||||
|
||||
class T6794959 {
|
||||
String s;
|
||||
}
|
Loading…
Reference in New Issue
Block a user