8011043: Warn about use of 1.5 and earlier source and target values
authordarcy
Tue, 20 Aug 2013 12:15:19 -0700
changeset 19508 e2cd0ed6c9b0
parent 19507 323f001d6be1
child 19509 fb622612d5df
8011043: Warn about use of 1.5 and earlier source and target values Reviewed-by: jjg
langtools/src/share/classes/com/sun/tools/javac/main/JavaCompiler.java
langtools/src/share/classes/com/sun/tools/javac/resources/compiler.properties
langtools/src/share/classes/com/sun/tools/javadoc/Start.java
langtools/test/tools/javac/diags/examples/ObsoleteSourceAndTarget.java
--- a/langtools/src/share/classes/com/sun/tools/javac/main/JavaCompiler.java	Tue Aug 20 17:21:47 2013 +0200
+++ b/langtools/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/langtools/src/share/classes/com/sun/tools/javac/resources/compiler.properties	Tue Aug 20 17:21:47 2013 +0200
+++ b/langtools/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/langtools/src/share/classes/com/sun/tools/javadoc/Start.java	Tue Aug 20 17:21:47 2013 +0200
+++ b/langtools/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/langtools/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() {;}
+}