Roberto Lublinerman has uploaded a new change for review.

  https://gwt-review.googlesource.com/2910


Change subject: Chooses a default gwt source level to match the current java runtime.
......................................................................

Chooses a default gwt source level to match the current java runtime.

Change-Id: I69dc0e9b1ac0ecf9a40ee2a08d8d555319d0af6f
---
M dev/core/src/com/google/gwt/dev/util/arg/OptionSource.java
M dev/core/src/com/google/gwt/dev/util/arg/SourceLevel.java
2 files changed, 42 insertions(+), 1 deletion(-)



diff --git a/dev/core/src/com/google/gwt/dev/util/arg/OptionSource.java b/dev/core/src/com/google/gwt/dev/util/arg/OptionSource.java
index 15f238f..da05070 100644
--- a/dev/core/src/com/google/gwt/dev/util/arg/OptionSource.java
+++ b/dev/core/src/com/google/gwt/dev/util/arg/OptionSource.java
@@ -20,7 +20,10 @@
  */
 public interface OptionSource {

-  static final SourceLevel DEFAULT_SOURCE_LEVEL = SourceLevel.JAVA6;
+  /**
+ * The default GWT source level is the one that matches best that of the runtime environment.
+   */
+ static final SourceLevel DEFAULT_SOURCE_LEVEL = SourceLevel.getDefaultSourceLevel();

   SourceLevel getSourceLevel();

diff --git a/dev/core/src/com/google/gwt/dev/util/arg/SourceLevel.java b/dev/core/src/com/google/gwt/dev/util/arg/SourceLevel.java
index 63c2fc2..230f5a60 100644
--- a/dev/core/src/com/google/gwt/dev/util/arg/SourceLevel.java
+++ b/dev/core/src/com/google/gwt/dev/util/arg/SourceLevel.java
@@ -15,6 +15,10 @@
  */
 package com.google.gwt.dev.util.arg;

+import com.google.gwt.thirdparty.guava.common.collect.ImmutableMap;
+
+import java.util.Map;
+
 /**
  * Java source level compatibility constants.
  * Java versions range from 1.0 to 1.7.
@@ -28,10 +32,12 @@

   private final String stringValue;
   private final String altStringValue;
+  private final Double javaLevel;

   SourceLevel(String stringValue, String altStringValue) {
     this.stringValue = stringValue;
     this.altStringValue = altStringValue;
+    this.javaLevel = Double.parseDouble(stringValue);
   }

   /**
@@ -52,4 +58,36 @@
   public String toString() {
     return stringValue;
   }
+
+  /**
+ * Maps from Java source compatibility level to the GWT compiler Java source compatibility levels.
+   */
+  private static final Map<Double, SourceLevel> gwtLevelByJavaLevel;
+
+  static {
+ ImmutableMap.Builder<Double, SourceLevel> builder = ImmutableMap.<Double, SourceLevel>builder();
+    for (SourceLevel sourceLevel : SourceLevel.values()) {
+      builder.put(sourceLevel.javaLevel, sourceLevel);
+    }
+    gwtLevelByJavaLevel = builder.build();
+  }
+
+  /**
+ * Provides a SourceLevel that best matches the runtime environment (to be used as a default).
+   *
+ * @return a SourceLevel that best matches the Java source level of the runtime environment.
+   */
+  static SourceLevel getDefaultSourceLevel() {
+    SourceLevel result = SourceLevel.JAVA6;
+    try {
+ double javaSpecLevel = Double.parseDouble(System.getProperty("java.specification.version"));
+      for (double javaLevel :  gwtLevelByJavaLevel.keySet() ) {
+ if (javaSpecLevel >= javaLevel && javaSpecLevel >result.javaLevel) {
+          result = gwtLevelByJavaLevel.get(javaLevel);
+        }
+      }
+    } catch (NumberFormatException e) {
+    }
+    return result;
+  }
 }

--
To view, visit https://gwt-review.googlesource.com/2910
To unsubscribe, visit https://gwt-review.googlesource.com/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I69dc0e9b1ac0ecf9a40ee2a08d8d555319d0af6f
Gerrit-PatchSet: 1
Gerrit-Project: gwt
Gerrit-Branch: master
Gerrit-Owner: Roberto Lublinerman <rlu...@google.com>

--
http://groups.google.com/group/Google-Web-Toolkit-Contributors
--- You received this message because you are subscribed to the Google Groups "GWT Contributors" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to google-web-toolkit-contributors+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to