changeset 1960:58da1296c6b3

8011043: Warn about use of 1.5 and earlier source and target values Reviewed-by: jjg
author darcy
date Tue, 20 Aug 2013 12:15:19 -0700
parents e811fb09a1dc
children 0f88e3d3d250
files src/share/classes/com/sun/tools/javac/main/JavaCompiler.java src/share/classes/com/sun/tools/javac/resources/compiler.properties src/share/classes/com/sun/tools/javadoc/Start.java test/tools/javac/diags/examples/ObsoleteSourceAndTarget.java
diffstat 4 files changed, 68 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/com/sun/tools/javac/main/JavaCompiler.java	Tue Aug 20 17:21:47 2013 +0200
+++ b/src/share/classes/com/sun/tools/javac/main/JavaCompiler.java	Tue Aug 20 12:15:19 2013 -0700
@@ -363,6 +363,7 @@
                 throw new Abort();
         }
         source = Source.instance(context);
+        Target target = Target.instance(context);
         attr = Attr.instance(context);
         chk = Check.instance(context);
         gen = Gen.instance(context);
@@ -403,6 +404,8 @@
             }
         }
 
+        checkForObsoleteOptions(target);
+
         verboseCompilePolicy = options.isSet("verboseCompilePolicy");
 
         if (attrParseOnly)
@@ -432,6 +435,26 @@
             log.setDiagnosticFormatter(RichDiagnosticFormatter.instance(context));
     }
 
+    private void checkForObsoleteOptions(Target target) {
+        // Unless lint checking on options is disabled, check for
+        // obsolete source and target options.
+        boolean obsoleteOptionFound = false;
+        if (options.isUnset(XLINT_CUSTOM, "-" + LintCategory.OPTIONS.option)) {
+            if (source.compareTo(Source.JDK1_5) <= 0) {
+                log.warning(LintCategory.OPTIONS, "option.obsolete.source", source.name);
+                obsoleteOptionFound = true;
+            }
+
+            if (target.compareTo(Target.JDK1_5) <= 0) {
+                log.warning(LintCategory.OPTIONS, "option.obsolete.target", source.name);
+                obsoleteOptionFound = true;
+            }
+
+            if (obsoleteOptionFound)
+                log.warning(LintCategory.OPTIONS, "option.obsolete.suppression");
+        }
+    }
+
     /* Switches:
      */
 
--- a/src/share/classes/com/sun/tools/javac/resources/compiler.properties	Tue Aug 20 17:21:47 2013 +0200
+++ b/src/share/classes/com/sun/tools/javac/resources/compiler.properties	Tue Aug 20 12:15:19 2013 -0700
@@ -1440,6 +1440,17 @@
 compiler.warn.source.no.bootclasspath=\
     bootstrap class path not set in conjunction with -source {0}
 
+# 0: string
+compiler.warn.option.obsolete.source=\
+    source value {0} is obsolete and will be removed in a future release
+
+# 0: string
+compiler.warn.option.obsolete.target=\
+    target value {0} is obsolete and will be removed in a future release
+
+compiler.warn.option.obsolete.suppression=\
+    To suppress warnings about obsolete options, use -Xlint:-options.
+
 # 0: name, 1: number, 2: number, 3: number, 4: number
 compiler.warn.future.attr=\
     {0} attribute introduced in version {1}.{2} class files is ignored in version {3}.{4} class files
--- a/src/share/classes/com/sun/tools/javadoc/Start.java	Tue Aug 20 17:21:47 2013 +0200
+++ b/src/share/classes/com/sun/tools/javadoc/Start.java	Tue Aug 20 12:15:19 2013 -0700
@@ -269,6 +269,8 @@
         setDocletInvoker(docletClass, fileManager, argv);
 
         compOpts = Options.instance(context);
+        // Make sure no obsolete source/target messages are reported
+        compOpts.put("-Xlint:-options", "-Xlint:-options");
 
         // Parse arguments
         for (int i = 0 ; i < argv.length ; i++) {
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/diags/examples/ObsoleteSourceAndTarget.java	Tue Aug 20 12:15:19 2013 -0700
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2013, 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.
+ */
+
+// key: compiler.warn.option.obsolete.source
+// key: compiler.warn.option.obsolete.target
+// key: compiler.warn.option.obsolete.suppression
+// key: compiler.warn.source.no.bootclasspath
+// options: -source 1.5 -target 1.5
+
+class ObsoleteSourceAndTarget {
+    public static void foo() {;}
+}