6507179: javadoc -source 1.3 does not work with jdk6
Reviewed-by: mcimadamore
This commit is contained in:
parent
f33c28c7fb
commit
dd0f4f4cc6
langtools
src/share/classes/com/sun/tools/javac
test/tools/javadoc/sourceOption
@ -100,9 +100,12 @@ public class Check {
|
||||
|
||||
boolean verboseDeprecated = lint.isEnabled(LintCategory.DEPRECATION);
|
||||
boolean verboseUnchecked = lint.isEnabled(LintCategory.UNCHECKED);
|
||||
boolean enforceMandatoryWarnings = source.enforceMandatoryWarnings();
|
||||
|
||||
deprecationHandler = new MandatoryWarningHandler(log,verboseDeprecated, "deprecated");
|
||||
uncheckedHandler = new MandatoryWarningHandler(log, verboseUnchecked, "unchecked");
|
||||
deprecationHandler = new MandatoryWarningHandler(log, verboseDeprecated,
|
||||
enforceMandatoryWarnings, "deprecated");
|
||||
uncheckedHandler = new MandatoryWarningHandler(log, verboseUnchecked,
|
||||
enforceMandatoryWarnings, "unchecked");
|
||||
}
|
||||
|
||||
/** Switch: generics enabled?
|
||||
|
@ -34,7 +34,6 @@ import java.util.Set;
|
||||
import javax.tools.DiagnosticListener;
|
||||
import javax.tools.JavaFileObject;
|
||||
|
||||
import com.sun.tools.javac.code.Source;
|
||||
import com.sun.tools.javac.file.JavacFileManager;
|
||||
import com.sun.tools.javac.tree.JCTree;
|
||||
import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
|
||||
@ -86,10 +85,6 @@ public class Log {
|
||||
*/
|
||||
public boolean emitWarnings;
|
||||
|
||||
/** Enforce mandatory warnings.
|
||||
*/
|
||||
private boolean enforceMandatoryWarnings;
|
||||
|
||||
/** Print stack trace on errors?
|
||||
*/
|
||||
public boolean dumpOnError;
|
||||
@ -138,9 +133,6 @@ public class Log {
|
||||
DiagnosticListener<? super JavaFileObject> diagListener =
|
||||
context.get(DiagnosticListener.class);
|
||||
this.diagListener = diagListener;
|
||||
|
||||
Source source = Source.instance(context);
|
||||
this.enforceMandatoryWarnings = source.enforceMandatoryWarnings();
|
||||
}
|
||||
// where
|
||||
private int getIntOption(Options options, String optionName, int defaultValue) {
|
||||
@ -473,10 +465,7 @@ public class Log {
|
||||
* @param args Fields of the warning message.
|
||||
*/
|
||||
public void mandatoryWarning(DiagnosticPosition pos, String key, Object ... args) {
|
||||
if (enforceMandatoryWarnings)
|
||||
report(diags.mandatoryWarning(source, pos, key, args));
|
||||
else
|
||||
report(diags.warning(source, pos, key, args));
|
||||
report(diags.mandatoryWarning(source, pos, key, args));
|
||||
}
|
||||
|
||||
/** Report a warning that cannot be suppressed.
|
||||
@ -513,35 +502,44 @@ public class Log {
|
||||
report(diags.note(source, wrap(pos), key, args));
|
||||
}
|
||||
|
||||
/** Provide a non-fatal notification, unless suppressed by the -nowarn option.
|
||||
* @param file The file to which the note applies.
|
||||
* @param key The key for the localized notification message.
|
||||
* @param args Fields of the notification message.
|
||||
*/
|
||||
public void note(JavaFileObject file, String key, Object ... args) {
|
||||
report(diags.note(wrap(file), null, key, args));
|
||||
}
|
||||
|
||||
/** Provide a non-fatal notification, unless suppressed by the -nowarn option.
|
||||
* @param key The key for the localized notification message.
|
||||
* @param args Fields of the notification message.
|
||||
*/
|
||||
public void mandatoryNote(final JavaFileObject file, String key, Object ... args) {
|
||||
JCDiagnostic.DiagnosticSource wrapper = null;
|
||||
if (file != null) {
|
||||
wrapper = new JCDiagnostic.DiagnosticSource() {
|
||||
public JavaFileObject getFile() {
|
||||
return file;
|
||||
}
|
||||
public CharSequence getName() {
|
||||
return JavacFileManager.getJavacBaseFileName(getFile());
|
||||
}
|
||||
public int getLineNumber(int pos) {
|
||||
return Log.this.getLineNumber(pos);
|
||||
}
|
||||
public int getColumnNumber(int pos) {
|
||||
return Log.this.getColumnNumber(pos);
|
||||
}
|
||||
public Map<JCTree, Integer> getEndPosTable() {
|
||||
return (endPosTables == null ? null : endPosTables.get(file));
|
||||
}
|
||||
};
|
||||
report(diags.mandatoryNote(wrap(file), key, args));
|
||||
}
|
||||
|
||||
private JCDiagnostic.DiagnosticSource wrap(final JavaFileObject file) {
|
||||
if (file == null) {
|
||||
return null;
|
||||
}
|
||||
if (enforceMandatoryWarnings)
|
||||
report(diags.mandatoryNote(wrapper, key, args));
|
||||
else
|
||||
report(diags.note(wrapper, null, key, args));
|
||||
return new JCDiagnostic.DiagnosticSource() {
|
||||
public JavaFileObject getFile() {
|
||||
return file;
|
||||
}
|
||||
public CharSequence getName() {
|
||||
return JavacFileManager.getJavacBaseFileName(getFile());
|
||||
}
|
||||
public int getLineNumber(int pos) {
|
||||
return Log.this.getLineNumber(pos);
|
||||
}
|
||||
public int getColumnNumber(int pos) {
|
||||
return Log.this.getColumnNumber(pos);
|
||||
}
|
||||
public Map<JCTree, Integer> getEndPosTable() {
|
||||
return (endPosTables == null ? null : endPosTables.get(file));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private DiagnosticPosition wrap(int pos) {
|
||||
|
@ -101,13 +101,17 @@ public class MandatoryWarningHandler {
|
||||
* individual instances should be given, or whether an aggregate
|
||||
* message should be generated at the end of the compilation.
|
||||
* Typically set via -Xlint:option.
|
||||
* @param enforceMandatory
|
||||
* True if mandatory warnings and notes are being enforced.
|
||||
* @param prefix A common prefix for the set of message keys for
|
||||
* the messages that may be generated.
|
||||
*/
|
||||
public MandatoryWarningHandler(Log log, boolean verbose, String prefix) {
|
||||
public MandatoryWarningHandler(Log log, boolean verbose,
|
||||
boolean enforceMandatory, String prefix) {
|
||||
this.log = log;
|
||||
this.verbose = verbose;
|
||||
this.prefix = prefix;
|
||||
this.enforceMandatory = enforceMandatory;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -122,7 +126,7 @@ public class MandatoryWarningHandler {
|
||||
|
||||
if (log.nwarnings < log.MaxWarnings) {
|
||||
// generate message and remember the source file
|
||||
log.mandatoryWarning(pos, msg, args);
|
||||
logMandatoryWarning(pos, msg, args);
|
||||
sourcesWithReportedWarnings.add(currentSource);
|
||||
} else if (deferredDiagnosticKind == null) {
|
||||
// set up deferred message
|
||||
@ -163,12 +167,12 @@ public class MandatoryWarningHandler {
|
||||
public void reportDeferredDiagnostic() {
|
||||
if (deferredDiagnosticKind != null) {
|
||||
if (deferredDiagnosticArg == null)
|
||||
log.mandatoryNote(deferredDiagnosticSource, deferredDiagnosticKind.getKey(prefix));
|
||||
logMandatoryNote(deferredDiagnosticSource, deferredDiagnosticKind.getKey(prefix));
|
||||
else
|
||||
log.mandatoryNote(deferredDiagnosticSource, deferredDiagnosticKind.getKey(prefix), deferredDiagnosticArg);
|
||||
logMandatoryNote(deferredDiagnosticSource, deferredDiagnosticKind.getKey(prefix), deferredDiagnosticArg);
|
||||
|
||||
if (!verbose)
|
||||
log.mandatoryNote(deferredDiagnosticSource, prefix + ".recompile");
|
||||
logMandatoryNote(deferredDiagnosticSource, prefix + ".recompile");
|
||||
}
|
||||
}
|
||||
|
||||
@ -224,4 +228,32 @@ public class MandatoryWarningHandler {
|
||||
* deferredDiagnosticKind is updated.
|
||||
*/
|
||||
private Object deferredDiagnosticArg;
|
||||
|
||||
/**
|
||||
* True if mandatory warnings and notes are being enforced.
|
||||
*/
|
||||
private final boolean enforceMandatory;
|
||||
|
||||
/**
|
||||
* Reports a mandatory warning to the log. If mandatory warnings
|
||||
* are not being enforced, treat this as an ordinary warning.
|
||||
*/
|
||||
private void logMandatoryWarning(DiagnosticPosition pos, String msg,
|
||||
Object... args) {
|
||||
if (enforceMandatory)
|
||||
log.mandatoryWarning(pos, msg, args);
|
||||
else
|
||||
log.warning(pos, msg, args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reports a mandatory note to the log. If mandatory notes are
|
||||
* not being enforced, treat this as an ordinary note.
|
||||
*/
|
||||
private void logMandatoryNote(JavaFileObject file, String msg, Object... args) {
|
||||
if (enforceMandatory)
|
||||
log.mandatoryNote(file, msg, args);
|
||||
else
|
||||
log.note(file, msg, args);
|
||||
}
|
||||
}
|
||||
|
47
langtools/test/tools/javadoc/sourceOption/SourceOption.java
Normal file
47
langtools/test/tools/javadoc/sourceOption/SourceOption.java
Normal file
@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright 2006 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 6507179
|
||||
* @summary Ensure that "-source" option isn't ignored.
|
||||
* @author Scott Seligman
|
||||
*/
|
||||
|
||||
import com.sun.javadoc.*;
|
||||
|
||||
public class SourceOption extends Doclet {
|
||||
|
||||
public static void main(String[] args) {
|
||||
if (com.sun.tools.javadoc.Main.execute(
|
||||
"javadoc",
|
||||
"SourceOption",
|
||||
new String[] {"-source", "1.3", "p"}) != 0)
|
||||
throw new Error("Javadoc encountered warnings or errors.");
|
||||
}
|
||||
|
||||
public static boolean start(RootDoc root) {
|
||||
root.classes(); // force parser into action
|
||||
return true;
|
||||
}
|
||||
}
|
29
langtools/test/tools/javadoc/sourceOption/p/A.java
Normal file
29
langtools/test/tools/javadoc/sourceOption/p/A.java
Normal file
@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright 2004 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.
|
||||
*/
|
||||
|
||||
package p;
|
||||
|
||||
public class A {
|
||||
boolean assert; // illegal since 1.4
|
||||
boolean enum; // illegal since 5
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user