Reviewers: tobyr,

Message:
Remember when you did this for the web mode compiler?  I want to do this
for JdtCompiler as well.



Please review this at http://gwt-code-reviews.appspot.com/1318802/show

Affected files:
  M dev/core/src/com/google/gwt/dev/javac/JdtCompiler.java


Index: dev/core/src/com/google/gwt/dev/javac/JdtCompiler.java
diff --git a/dev/core/src/com/google/gwt/dev/javac/JdtCompiler.java b/dev/core/src/com/google/gwt/dev/javac/JdtCompiler.java index d3b0bc5befd92fc9249e3a536a04cd42f1cd937e..3fee570b4751e593eb585a13ee70764d8df85a83 100644
--- a/dev/core/src/com/google/gwt/dev/javac/JdtCompiler.java
+++ b/dev/core/src/com/google/gwt/dev/javac/JdtCompiler.java
@@ -16,6 +16,7 @@
 package com.google.gwt.dev.javac;

 import com.google.gwt.dev.jdt.TypeRefVisitor;
+import com.google.gwt.dev.jjs.InternalCompilerException;
 import com.google.gwt.dev.util.Name.BinaryName;
 import com.google.gwt.dev.util.collect.Lists;
 import com.google.gwt.dev.util.log.speedtracer.CompilerEventType;
@@ -60,10 +61,12 @@ import org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory;

 import java.io.IOException;
 import java.io.InputStream;
+import java.net.JarURLConnection;
 import java.net.URL;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
+import java.util.Enumeration;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.LinkedHashMap;
@@ -71,6 +74,8 @@ import java.util.List;
 import java.util.Locale;
 import java.util.Map;
 import java.util.Set;
+import java.util.jar.JarEntry;
+import java.util.jar.JarFile;

 /**
  * Manages the process of compiling {@link CompilationUnit}s.
@@ -130,6 +135,48 @@ public class JdtCompiler {
     void process(CompilationUnitBuilder builder,
CompilationUnitDeclaration cud, List<CompiledClass> compiledClasses);
   }
+
+  static class JreIndex {
+    private static Set<String> packages = readPackages();
+
+    public static boolean contains(String name) {
+      return packages.contains(name);
+    }
+
+ private static void addPackageRecursively(Set<String> packages, String pkg) {
+      if (!packages.add(pkg)) {
+        return;
+      }
+
+      int i = pkg.lastIndexOf('/');
+      if (i != -1) {
+        addPackageRecursively(packages, pkg.substring(0, i));
+      }
+    }
+
+    private static Set<String> readPackages() {
+      HashSet<String> pkgs = new HashSet<String>();
+      String klass = "java/lang/Object.class";
+      URL url = ClassLoader.getSystemClassLoader().getResource(klass);
+      try {
+ JarURLConnection connection = (JarURLConnection) url.openConnection();
+        JarFile f = connection.getJarFile();
+        Enumeration<JarEntry> entries = f.entries();
+        while (entries.hasMoreElements()) {
+          JarEntry e = entries.nextElement();
+          String name = e.getName();
+          if (name.endsWith(".class")) {
+            String pkg = Shared.getSlashedPackageFrom(name);
+            addPackageRecursively(pkgs, pkg);
+          }
+        }
+        return pkgs;
+      } catch (IOException e) {
+        throw new InternalCompilerException("Unable to find JRE", e);
+      }
+    }
+  }
+
   /**
    * Adapts a {@link CompilationUnit} for a JDT compile.
    */
@@ -282,7 +329,11 @@ public class JdtCompiler {
     }

     private boolean isPackage(String slashedPackageName) {
-      // Include class loader check for binary-only annotations.
+      // Test the JRE explicitly first, because the following method does
+      // not work for JRE classes.
+      if (JreIndex.contains(slashedPackageName)) {
+        return true;
+      }
       if (packages.contains(slashedPackageName)) {
         return true;
       }


--
http://groups.google.com/group/Google-Web-Toolkit-Contributors

Reply via email to