Mercurial > hg > release > icedtea7-forest-2.2 > langtools
changeset 193:d0b33fe8e710
6794959: add new switch -XDexpectKeys=key,key....
Reviewed-by: mcimadamore
author | jjg |
---|---|
date | Mon, 19 Jan 2009 19:36:14 -0800 |
parents | 18c433be7aa7 |
children | 83c59a9d4b94 |
files | src/share/classes/com/sun/tools/javac/main/Main.java src/share/classes/com/sun/tools/javac/util/Log.java test/tools/javac/T6794959.java |
diffstat | 3 files changed, 69 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/src/share/classes/com/sun/tools/javac/main/Main.java Fri Jan 16 14:05:55 2009 -0800 +++ b/src/share/classes/com/sun/tools/javac/main/Main.java Mon Jan 19 19:36:14 2009 -0800 @@ -338,13 +338,13 @@ 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 @@ 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 @@ 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;
--- a/src/share/classes/com/sun/tools/javac/util/Log.java Fri Jan 16 14:05:55 2009 -0800 +++ b/src/share/classes/com/sun/tools/javac/util/Log.java Mon Jan 19 19:36:14 2009 -0800 @@ -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; @@ -97,6 +98,11 @@ private DiagnosticFormatter<JCDiagnostic> diagFormatter; /** + * Keys for expected diagnostics + */ + public Set<String> expectDiagKeys; + + /** * JavacMessages object used for localization */ private JavacMessages messages; @@ -123,9 +129,13 @@ 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 @@ * 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();
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/T6794959.java Mon Jan 19 19:36:14 2009 -0800 @@ -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; +}