]> Savannah Git Hosting - gnulib.git/commitdiff
javacomp: Add support for Java 7, 8, 9.
authorBruno Haible <bruno@clisp.org>
Mon, 19 Mar 2018 23:39:01 +0000 (00:39 +0100)
committerBruno Haible <bruno@clisp.org>
Mon, 19 Mar 2018 23:39:01 +0000 (00:39 +0100)
* lib/javacomp.c (default_target_version, SOURCE_VERSION_BOUND,
source_version_index, get_goodcode_snippet, get_failcode_snippet,
corresponding_classfile_version): Accept source_version 1,7, 1.8, 1.9
and target_version 1,7, 1.8, 1.9.
* lib/javacomp.h: Update comments accordingly.

ChangeLog
lib/javacomp.c
lib/javacomp.h

index a1a286faac344b8d2459be711384fc181873a5bb..3bbe99989ebef37c6b1e743a3316a61a7596d424 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2018-03-19  Bruno Haible  <bruno@clisp.org>
+
+       javacomp: Add support for Java 7, 8, 9.
+       * lib/javacomp.c (default_target_version, SOURCE_VERSION_BOUND,
+       source_version_index, get_goodcode_snippet, get_failcode_snippet,
+       corresponding_classfile_version): Accept source_version 1,7, 1.8, 1.9
+       and target_version 1,7, 1.8, 1.9.
+       * lib/javacomp.h: Update comments accordingly.
+
 2018-03-19  Bruno Haible  <bruno@clisp.org>
 
        javacomp-script: Add support for Java 9.
index dd9fe7bb9d423a24976e3ca912b888a54906a60e..f9e7292d0c7d32b2460fd3760d2f2250ca5c0aac 100644 (file)
@@ -100,7 +100,7 @@ default_target_version (void)
       java_version_cache = javaexec_version ();
       if (java_version_cache == NULL
           || !(java_version_cache[0] == '1' && java_version_cache[1] == '.'
-               && (java_version_cache[2] >= '1' && java_version_cache[2] <= '6')
+               && (java_version_cache[2] >= '1' && java_version_cache[2] <= '9')
                && java_version_cache[3] == '\0'))
         java_version_cache = "1.1";
     }
@@ -110,14 +110,19 @@ default_target_version (void)
 /* ======================= Source version dependent ======================= */
 
 /* Convert a source version to an index.  */
-#define SOURCE_VERSION_BOUND 3 /* exclusive upper bound */
+#define SOURCE_VERSION_BOUND 6 /* exclusive upper bound */
 static unsigned int
 source_version_index (const char *source_version)
 {
-  if (source_version[0] == '1' && source_version[1] == '.'
-      && (source_version[2] >= '3' && source_version[2] <= '5')
-      && source_version[3] == '\0')
-    return source_version[2] - '3';
+  if (source_version[0] == '1' && source_version[1] == '.')
+    {
+      if ((source_version[2] >= '3' && source_version[2] <= '5')
+          && source_version[3] == '\0')
+        return source_version[2] - '3';
+      if ((source_version[2] >= '7' && source_version[2] <= '9')
+          && source_version[3] == '\0')
+        return source_version[2] - '4';
+    }
   error (EXIT_FAILURE, 0, _("invalid source_version argument to compile_java_class"));
   return 0;
 }
@@ -132,6 +137,12 @@ get_goodcode_snippet (const char *source_version)
     return "class conftest { static { assert(true); } }\n";
   if (strcmp (source_version, "1.5") == 0)
     return "class conftest<T> { T foo() { return null; } }\n";
+  if (strcmp (source_version, "1.7") == 0)
+    return "class conftest { void foo () { switch (\"A\") {} } }\n";
+  if (strcmp (source_version, "1.8") == 0)
+    return "class conftest { void foo () { Runnable r = () -> {}; } }\n";
+  if (strcmp (source_version, "1.9") == 0)
+    return "interface conftest { private void foo () {} }\n";
   error (EXIT_FAILURE, 0, _("invalid source_version argument to compile_java_class"));
   return NULL;
 }
@@ -147,6 +158,12 @@ get_failcode_snippet (const char *source_version)
   if (strcmp (source_version, "1.4") == 0)
     return "class conftestfail<T> { T foo() { return null; } }\n";
   if (strcmp (source_version, "1.5") == 0)
+    return "class conftestfail { void foo () { switch (\"A\") {} } }\n";
+  if (strcmp (source_version, "1.7") == 0)
+    return "class conftestfail { void foo () { Runnable r = () -> {}; } }\n";
+  if (strcmp (source_version, "1.8") == 0)
+    return "interface conftestfail { private void foo () {} }\n";
+  if (strcmp (source_version, "1.9") == 0)
     return NULL;
   error (EXIT_FAILURE, 0, _("invalid source_version argument to compile_java_class"));
   return NULL;
@@ -184,6 +201,12 @@ corresponding_classfile_version (const char *target_version)
     return 49;
   if (strcmp (target_version, "1.6") == 0)
     return 50;
+  if (strcmp (target_version, "1.7") == 0)
+    return 51;
+  if (strcmp (target_version, "1.8") == 0)
+    return 52;
+  if (strcmp (target_version, "1.9") == 0)
+    return 53;
   error (EXIT_FAILURE, 0, _("invalid target_version argument to compile_java_class"));
   return 0;
 }
index f7e977df70135f70080ecb47ad54a3d37c43fea0..3d0a02d615420777587dfa6c3691b6677706af78 100644 (file)
              1.3             inner classes
              1.4             assert keyword
              1.5             generic classes and methods
-             1.6             (not yet supported)
+             1.6             (not supported)
+             1.7             switch(string)
+             1.8             lambdas
+             1.9             private interface methods
    target_version can be:  classfile version:
              1.1                 45.3
              1.2                 46.0
@@ -36,6 +39,9 @@
              1.4                 48.0
              1.5                 49.0
              1.6                 50.0
+             1.7                 51.0
+             1.8                 52.0
+             1.9                 53.0
    target_version can also be given as NULL. In this case, the required
    target_version is determined from the found JVM (see javaversion.h).
    Specifying target_version is useful when building a library (.jar) that is
    It is unreasonable to ask for:
      - target_version < 1.4 with source_version >= 1.4, or
      - target_version < 1.5 with source_version >= 1.5, or
-     - target_version < 1.6 with source_version >= 1.6,
-   because even Sun's javac doesn't support these combinations.
+     - target_version < 1.6 with source_version >= 1.6, or
+     - target_version < 1.7 with source_version >= 1.7, or
+     - target_version < 1.8 with source_version >= 1.8, or
+     - target_version < 1.9 with source_version >= 1.9,
+   because even Sun's/Oracle's javac doesn't support these combinations.
    It is redundant to ask for a target_version > source_version, since the
    smaller target_version = source_version will also always work and newer JVMs
    support the older target_versions too. Except for the case