changeset 51701:e0bce2635ec5

8207055: Make javac -help output for -source and -target more informative Reviewed-by: jjg
author darcy
date Wed, 11 Jul 2018 16:12:18 -0700
parents ae39e5a991ed
children 5c3c53703b8b
files src/jdk.compiler/share/classes/com/sun/tools/javac/code/Source.java src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/Target.java src/jdk.compiler/share/classes/com/sun/tools/javac/main/Option.java src/jdk.compiler/share/classes/com/sun/tools/javac/resources/javac.properties test/langtools/jdk/javadoc/tool/modules/ReleaseOptions.java test/langtools/tools/javac/modules/AddLimitMods.java
diffstat 6 files changed, 47 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Source.java	Wed Jul 11 14:32:42 2018 -0700
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Source.java	Wed Jul 11 16:12:18 2018 -0700
@@ -131,6 +131,10 @@
         return tab.get(name);
     }
 
+    public boolean isSupported() {
+        return this.compareTo(MIN) >= 0;
+    }
+
     public Target requiredTarget() {
         if (this.compareTo(JDK12) >= 0) return Target.JDK1_12;
         if (this.compareTo(JDK11) >= 0) return Target.JDK1_11;
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/Target.java	Wed Jul 11 14:32:42 2018 -0700
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/Target.java	Wed Jul 11 16:12:18 2018 -0700
@@ -49,22 +49,22 @@
     JDK1_4("1.4", 48, 0),
 
     /** JDK 5, codename Tiger. */
-    JDK1_5("1.5", 49, 0),
+    JDK1_5("5", 49, 0),
 
     /** JDK 6. */
-    JDK1_6("1.6", 50, 0),
+    JDK1_6("6", 50, 0),
 
     /** JDK 7. */
-    JDK1_7("1.7", 51, 0),
+    JDK1_7("7", 51, 0),
 
     /** JDK 8. */
-    JDK1_8("1.8", 52, 0),
+    JDK1_8("8", 52, 0),
 
     /** JDK 9. */
-    JDK1_9("1.9", 53, 0),
+    JDK1_9("9", 53, 0),
 
     /** JDK 10. */
-    JDK1_10("1.10", 54, 0),
+    JDK1_10("10", 54, 0),
 
     /** JDK 11. */
     JDK1_11("11", 55, 0),
@@ -95,14 +95,12 @@
         for (Target t : values()) {
             tab.put(t.name, t);
         }
-        tab.put("5", JDK1_5);
-        tab.put("6", JDK1_6);
-        tab.put("7", JDK1_7);
-        tab.put("8", JDK1_8);
-        tab.put("9", JDK1_9);
-        tab.put("10", JDK1_10);
-        tab.put("11", JDK1_11);
-        tab.put("12", JDK1_12);
+        tab.put("1.5", JDK1_5);
+        tab.put("1.6", JDK1_6);
+        tab.put("1.7", JDK1_7);
+        tab.put("1.8", JDK1_8);
+        tab.put("1.9", JDK1_9);
+        tab.put("1.10", JDK1_10);
     }
 
     public final String name;
@@ -120,6 +118,10 @@
         return tab.get(name);
     }
 
+    public boolean isSupported() {
+        return this.compareTo(MIN) >= 0;
+    }
+
     /** Return the character to be used in constructing synthetic
      *  identifiers, where not specified by the JLS.
      */
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/main/Option.java	Wed Jul 11 14:32:42 2018 -0700
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/main/Option.java	Wed Jul 11 16:12:18 2018 -0700
@@ -41,6 +41,7 @@
 import java.util.Locale;
 import java.util.ServiceLoader;
 import java.util.Set;
+import java.util.StringJoiner;
 import java.util.TreeSet;
 import java.util.regex.Pattern;
 import java.util.stream.Collectors;
@@ -295,6 +296,16 @@
             }
             super.process(helper, option, operand);
         }
+
+        @Override
+        protected void help(Log log) {
+            StringJoiner sj = new StringJoiner(", ");
+            for(Source source :  Source.values()) {
+                if (source.isSupported())
+                    sj.add(source.name);
+            }
+            super.help(log, log.localize(PrefixKind.JAVAC, descrKey, sj.toString()));
+        }
     },
 
     TARGET("-target", "opt.arg.release", "opt.target", STANDARD, BASIC) {
@@ -306,6 +317,16 @@
             }
             super.process(helper, option, operand);
         }
+
+        @Override
+        protected void help(Log log) {
+            StringJoiner sj = new StringJoiner(", ");
+            for(Target target :  Target.values()) {
+                if (target.isSupported())
+                    sj.add(target.name);
+            }
+            super.help(log, log.localize(PrefixKind.JAVAC, descrKey, sj.toString()));
+        }
     },
 
     RELEASE("--release", "opt.arg.release", "opt.release", STANDARD, BASIC) {
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/javac.properties	Wed Jul 11 14:32:42 2018 -0700
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/javac.properties	Wed Jul 11 16:12:18 2018 -0700
@@ -80,11 +80,11 @@
 javac.opt.profile=\
     Check that API used is available in the specified profile
 javac.opt.target=\
-    Generate class files for specific VM version
+    Generate class files for specific VM version. Supported versions: {0}
 javac.opt.release=\
-    Compile for a specific VM version. Supported targets: {0}
+    Compile for a specific release. Supported releases: {0}
 javac.opt.source=\
-    Provide source compatibility with specified release
+    Provide source compatibility with specified release. Supported releases: {0}
 javac.opt.Werror=\
     Terminate compilation if warnings occur
 javac.opt.A=\
--- a/test/langtools/jdk/javadoc/tool/modules/ReleaseOptions.java	Wed Jul 11 14:32:42 2018 -0700
+++ b/test/langtools/jdk/javadoc/tool/modules/ReleaseOptions.java	Wed Jul 11 16:12:18 2018 -0700
@@ -58,7 +58,7 @@
         Task.Result result = execNegativeTask("--release", "8",
                 "--patch-module", "m=" + mpath.toString(),
                 "p");
-        assertMessagePresent(".*not allowed with target 1.8.*");
+        assertMessagePresent(".*not allowed with target 8.*");
         assertMessageNotPresent(".*Exception*");
         assertMessageNotPresent(".java.lang.AssertionError.*");
     }
@@ -92,7 +92,7 @@
         Task.Result result = execNegativeTask("--release", "8",
                 "--module-source-path", src.toString(),
                 "--module", "m");
-        assertMessagePresent(".*not allowed with target 1.8.*");
+        assertMessagePresent(".*not allowed with target 8.*");
         assertMessageNotPresent(".*Exception*");
         assertMessageNotPresent(".java.lang.AssertionError.*");
     }
--- a/test/langtools/tools/javac/modules/AddLimitMods.java	Wed Jul 11 14:32:42 2018 -0700
+++ b/test/langtools/tools/javac/modules/AddLimitMods.java	Wed Jul 11 16:12:18 2018 -0700
@@ -264,7 +264,7 @@
                    .writeAll()
                    .getOutputLines(Task.OutputKind.DIRECT);
 
-        if (!actual.contains("- compiler.err.option.not.allowed.with.target: --add-modules, 1.8")) {
+        if (!actual.contains("- compiler.err.option.not.allowed.with.target: --add-modules, 8")) {
             throw new IllegalStateException("incorrect errors; actual=" + actual);
         }