Sun, 31 Aug 2008 12:00:43 -0700
Merge
1.1 --- a/src/share/classes/com/sun/tools/javac/Server.java Fri Aug 29 12:42:27 2008 -0700 1.2 +++ b/src/share/classes/com/sun/tools/javac/Server.java Sun Aug 31 12:00:43 2008 -0700 1.3 @@ -25,9 +25,6 @@ 1.4 1.5 package com.sun.tools.javac; 1.6 1.7 -import com.sun.tools.javac.main.JavacOption.Option; 1.8 -import com.sun.tools.javac.main.RecognizedOptions.GrumpyHelper; 1.9 -import com.sun.tools.javac.main.RecognizedOptions; 1.10 import java.io.*; 1.11 import java.net.*; 1.12 import java.util.*;
2.1 --- a/src/share/classes/com/sun/tools/javac/api/JavacScope.java Fri Aug 29 12:42:27 2008 -0700 2.2 +++ b/src/share/classes/com/sun/tools/javac/api/JavacScope.java Sun Aug 31 12:00:43 2008 -0700 2.3 @@ -25,41 +25,14 @@ 2.4 2.5 package com.sun.tools.javac.api; 2.6 2.7 -import java.io.IOException; 2.8 -import java.lang.ref.SoftReference; 2.9 -import java.util.Iterator; 2.10 2.11 import javax.lang.model.element.Element; 2.12 import javax.lang.model.element.ExecutableElement; 2.13 import javax.lang.model.element.TypeElement; 2.14 -import javax.tools.JavaFileObject; 2.15 2.16 -import com.sun.source.tree.Tree; 2.17 -import com.sun.source.util.SourcePositions; 2.18 -import com.sun.source.util.TreePath; 2.19 -import com.sun.source.util.Trees; 2.20 -import com.sun.tools.javac.code.Scope; 2.21 -import com.sun.tools.javac.code.Symbol.ClassSymbol; 2.22 -import com.sun.tools.javac.comp.Attr; 2.23 import com.sun.tools.javac.comp.AttrContext; 2.24 -import com.sun.tools.javac.comp.Enter; 2.25 import com.sun.tools.javac.comp.Env; 2.26 -import com.sun.tools.javac.comp.MemberEnter; 2.27 -import com.sun.tools.javac.comp.Resolve; 2.28 -import com.sun.tools.javac.tree.JCTree.JCClassDecl; 2.29 -import com.sun.tools.javac.tree.JCTree.JCCompilationUnit; 2.30 -import com.sun.tools.javac.tree.JCTree.JCExpression; 2.31 -import com.sun.tools.javac.tree.JCTree.JCMethodDecl; 2.32 -import com.sun.tools.javac.tree.JCTree.JCVariableDecl; 2.33 -import com.sun.tools.javac.tree.JCTree; 2.34 -import com.sun.tools.javac.tree.TreeCopier; 2.35 -import com.sun.tools.javac.tree.TreeInfo; 2.36 -import com.sun.tools.javac.tree.TreeMaker; 2.37 -import com.sun.tools.javac.util.Context; 2.38 -import com.sun.tools.javac.util.List; 2.39 -import com.sun.tools.javac.util.Log; 2.40 2.41 -import static com.sun.source.tree.Tree.Kind.*; 2.42 2.43 2.44 /**
3.1 --- a/src/share/classes/com/sun/tools/javac/api/WrappingJavaFileManager.java Fri Aug 29 12:42:27 2008 -0700 3.2 +++ b/src/share/classes/com/sun/tools/javac/api/WrappingJavaFileManager.java Sun Aug 31 12:00:43 2008 -0700 3.3 @@ -29,7 +29,6 @@ 3.4 import java.net.URI; 3.5 import java.util.ArrayList; 3.6 import java.util.Collections; 3.7 -import java.util.Iterator; 3.8 import java.util.List; 3.9 import java.util.Set; 3.10 import javax.tools.JavaFileObject.Kind;
4.1 --- a/src/share/classes/com/sun/tools/javac/code/Attribute.java Fri Aug 29 12:42:27 2008 -0700 4.2 +++ b/src/share/classes/com/sun/tools/javac/code/Attribute.java Sun Aug 31 12:00:43 2008 -0700 4.3 @@ -30,7 +30,6 @@ 4.4 import javax.lang.model.element.AnnotationMirror; 4.5 import javax.lang.model.element.AnnotationValue; 4.6 import javax.lang.model.element.AnnotationValueVisitor; 4.7 -import javax.lang.model.element.ExecutableElement; 4.8 import javax.lang.model.type.DeclaredType; 4.9 import com.sun.tools.javac.code.Symbol.*; 4.10 import com.sun.tools.javac.util.*;
5.1 --- a/src/share/classes/com/sun/tools/javac/code/Type.java Fri Aug 29 12:42:27 2008 -0700 5.2 +++ b/src/share/classes/com/sun/tools/javac/code/Type.java Sun Aug 31 12:00:43 2008 -0700 5.3 @@ -25,11 +25,8 @@ 5.4 5.5 package com.sun.tools.javac.code; 5.6 5.7 -import javax.lang.model.element.Element; 5.8 -import javax.lang.model.type.*; 5.9 import com.sun.tools.javac.util.*; 5.10 import com.sun.tools.javac.code.Symbol.*; 5.11 -import javax.lang.model.element.Element; 5.12 5.13 import javax.lang.model.type.*; 5.14
6.1 --- a/src/share/classes/com/sun/tools/javac/code/Types.java Fri Aug 29 12:42:27 2008 -0700 6.2 +++ b/src/share/classes/com/sun/tools/javac/code/Types.java Sun Aug 31 12:00:43 2008 -0700 6.3 @@ -31,7 +31,6 @@ 6.4 import com.sun.tools.javac.util.List; 6.5 6.6 import com.sun.tools.javac.jvm.ClassReader; 6.7 -import com.sun.tools.javac.comp.Infer; 6.8 import com.sun.tools.javac.comp.Check; 6.9 6.10 import static com.sun.tools.javac.code.Type.*;
7.1 --- a/src/share/classes/com/sun/tools/javac/comp/Enter.java Fri Aug 29 12:42:27 2008 -0700 7.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Enter.java Sun Aug 31 12:00:43 2008 -0700 7.3 @@ -26,7 +26,6 @@ 7.4 package com.sun.tools.javac.comp; 7.5 7.6 import java.util.*; 7.7 -import java.util.Set; 7.8 import javax.tools.JavaFileObject; 7.9 import javax.tools.JavaFileManager; 7.10 7.11 @@ -43,7 +42,6 @@ 7.12 7.13 import static com.sun.tools.javac.code.Flags.*; 7.14 import static com.sun.tools.javac.code.Kinds.*; 7.15 -import static com.sun.tools.javac.code.TypeTags.*; 7.16 7.17 /** This class enters symbols for all encountered definitions into 7.18 * the symbol table. The pass consists of two phases, organized as
8.1 --- a/src/share/classes/com/sun/tools/javac/comp/Env.java Fri Aug 29 12:42:27 2008 -0700 8.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Env.java Sun Aug 31 12:00:43 2008 -0700 8.3 @@ -25,7 +25,6 @@ 8.4 8.5 package com.sun.tools.javac.comp; 8.6 8.7 -import com.sun.tools.javac.util.*; 8.8 import com.sun.tools.javac.tree.*; 8.9 import java.util.Iterator; 8.10 import java.util.NoSuchElementException;
9.1 --- a/src/share/classes/com/sun/tools/javac/comp/Infer.java Fri Aug 29 12:42:27 2008 -0700 9.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Infer.java Sun Aug 31 12:00:43 2008 -0700 9.3 @@ -31,8 +31,6 @@ 9.4 import com.sun.tools.javac.code.Type.*; 9.5 import com.sun.tools.javac.util.JCDiagnostic; 9.6 9.7 -import static com.sun.tools.javac.code.Flags.*; 9.8 -import static com.sun.tools.javac.code.Kinds.*; 9.9 import static com.sun.tools.javac.code.TypeTags.*; 9.10 9.11 /** Helper class for type parameter inference, used by the attribution phase.
10.1 --- a/src/share/classes/com/sun/tools/javac/file/JavacFileManager.java Fri Aug 29 12:42:27 2008 -0700 10.2 +++ b/src/share/classes/com/sun/tools/javac/file/JavacFileManager.java Sun Aug 31 12:00:43 2008 -0700 10.3 @@ -65,6 +65,8 @@ 10.4 import javax.tools.StandardJavaFileManager; 10.5 10.6 import com.sun.tools.javac.code.Source; 10.7 +import com.sun.tools.javac.file.RelativePath.RelativeFile; 10.8 +import com.sun.tools.javac.file.RelativePath.RelativeDirectory; 10.9 import com.sun.tools.javac.main.JavacOption; 10.10 import com.sun.tools.javac.main.OptionName; 10.11 import com.sun.tools.javac.main.RecognizedOptions; 10.12 @@ -75,8 +77,8 @@ 10.13 import com.sun.tools.javac.util.Log; 10.14 import com.sun.tools.javac.util.Options; 10.15 10.16 +import static javax.tools.StandardLocation.*; 10.17 import static com.sun.tools.javac.main.OptionName.*; 10.18 -import static javax.tools.StandardLocation.*; 10.19 10.20 /** 10.21 * This class provides access to the source, class and other files 10.22 @@ -84,9 +86,6 @@ 10.23 */ 10.24 public class JavacFileManager implements StandardJavaFileManager { 10.25 10.26 - private static final String[] symbolFileLocation = { "lib", "ct.sym" }; 10.27 - private static final String symbolFilePrefix = "META-INF/sym/rt.jar/"; 10.28 - 10.29 boolean useZipFileIndex; 10.30 10.31 private static boolean CHECK_ZIP_TIMESTAMP = false; 10.32 @@ -267,6 +266,7 @@ 10.33 printAscii("Invalid class name: \"%s\"", name); 10.34 } 10.35 } 10.36 + 10.37 private static void printAscii(String format, Object... args) { 10.38 String message; 10.39 try { 10.40 @@ -278,27 +278,12 @@ 10.41 System.out.println(message); 10.42 } 10.43 10.44 - /** Return external representation of name, 10.45 - * converting '.' to File.separatorChar. 10.46 - */ 10.47 - private static String externalizeFileName(CharSequence name) { 10.48 - return name.toString().replace('.', File.separatorChar); 10.49 - } 10.50 - 10.51 - private static String externalizeFileName(CharSequence n, JavaFileObject.Kind kind) { 10.52 - return externalizeFileName(n) + kind.extension; 10.53 - } 10.54 - 10.55 - private static String baseName(String fileName) { 10.56 - return fileName.substring(fileName.lastIndexOf(File.separatorChar) + 1); 10.57 - } 10.58 - 10.59 /** 10.60 * Insert all files in subdirectory `subdirectory' of `directory' which end 10.61 * in one of the extensions in `extensions' into packageSym. 10.62 */ 10.63 private void listDirectory(File directory, 10.64 - String subdirectory, 10.65 + RelativeDirectory subdirectory, 10.66 Set<JavaFileObject.Kind> fileKinds, 10.67 boolean recurse, 10.68 ListBuffer<JavaFileObject> l) { 10.69 @@ -329,22 +314,6 @@ 10.70 return; 10.71 } 10.72 } 10.73 - if (subdirectory.length() != 0) { 10.74 - if (!useZipFileIndex) { 10.75 - subdirectory = subdirectory.replace('\\', '/'); 10.76 - if (!subdirectory.endsWith("/")) subdirectory = subdirectory + "/"; 10.77 - } 10.78 - else { 10.79 - if (File.separatorChar == '/') { 10.80 - subdirectory = subdirectory.replace('\\', '/'); 10.81 - } 10.82 - else { 10.83 - subdirectory = subdirectory.replace('/', '\\'); 10.84 - } 10.85 - 10.86 - if (!subdirectory.endsWith(File.separator)) subdirectory = subdirectory + File.separator; 10.87 - } 10.88 - } 10.89 10.90 List<String> files = archive.getFiles(subdirectory); 10.91 if (files != null) { 10.92 @@ -356,8 +325,8 @@ 10.93 } 10.94 } 10.95 if (recurse) { 10.96 - for (String s: archive.getSubdirectories()) { 10.97 - if (s.startsWith(subdirectory) && !s.equals(subdirectory)) { 10.98 + for (RelativeDirectory s: archive.getSubdirectories()) { 10.99 + if (subdirectory.contains(s)) { 10.100 // Because the archive map is a flat list of directories, 10.101 // the enclosing loop will pick up all child subdirectories. 10.102 // Therefore, there is no need to recurse deeper. 10.103 @@ -366,9 +335,7 @@ 10.104 } 10.105 } 10.106 } else { 10.107 - File d = subdirectory.length() != 0 10.108 - ? new File(directory, subdirectory) 10.109 - : directory; 10.110 + File d = subdirectory.getFile(directory); 10.111 if (!caseMapCheck(d, subdirectory)) 10.112 return; 10.113 10.114 @@ -381,7 +348,7 @@ 10.115 if (f.isDirectory()) { 10.116 if (recurse && SourceVersion.isIdentifier(fname)) { 10.117 listDirectory(directory, 10.118 - subdirectory + File.separator + fname, 10.119 + new RelativeDirectory(subdirectory, fname), 10.120 fileKinds, 10.121 recurse, 10.122 l); 10.123 @@ -411,7 +378,7 @@ 10.124 * ends in a string of characters with the same case as given name. 10.125 * Ignore file separators in both path and name. 10.126 */ 10.127 - private boolean caseMapCheck(File f, String name) { 10.128 + private boolean caseMapCheck(File f, RelativePath name) { 10.129 if (fileSystemIsCaseSensitive) return true; 10.130 // Note that getCanonicalPath() returns the case-sensitive 10.131 // spelled file name. 10.132 @@ -422,12 +389,12 @@ 10.133 return false; 10.134 } 10.135 char[] pcs = path.toCharArray(); 10.136 - char[] ncs = name.toCharArray(); 10.137 + char[] ncs = name.path.toCharArray(); 10.138 int i = pcs.length - 1; 10.139 int j = ncs.length - 1; 10.140 while (i >= 0 && j >= 0) { 10.141 while (i >= 0 && pcs[i] == File.separatorChar) i--; 10.142 - while (j >= 0 && ncs[j] == File.separatorChar) j--; 10.143 + while (j >= 0 && ncs[j] == '/') j--; 10.144 if (i >= 0 && j >= 0) { 10.145 if (pcs[i] != ncs[j]) return false; 10.146 i--; 10.147 @@ -444,13 +411,13 @@ 10.148 public interface Archive { 10.149 void close() throws IOException; 10.150 10.151 - boolean contains(String name); 10.152 + boolean contains(RelativePath name); 10.153 10.154 - JavaFileObject getFileObject(String subdirectory, String file); 10.155 + JavaFileObject getFileObject(RelativeDirectory subdirectory, String file); 10.156 10.157 - List<String> getFiles(String subdirectory); 10.158 + List<String> getFiles(RelativeDirectory subdirectory); 10.159 10.160 - Set<String> getSubdirectories(); 10.161 + Set<RelativeDirectory> getSubdirectories(); 10.162 } 10.163 10.164 public class MissingArchive implements Archive { 10.165 @@ -458,30 +425,38 @@ 10.166 public MissingArchive(File name) { 10.167 zipFileName = name; 10.168 } 10.169 - public boolean contains(String name) { 10.170 + public boolean contains(RelativePath name) { 10.171 return false; 10.172 } 10.173 10.174 public void close() { 10.175 } 10.176 10.177 - public JavaFileObject getFileObject(String subdirectory, String file) { 10.178 + public JavaFileObject getFileObject(RelativeDirectory subdirectory, String file) { 10.179 return null; 10.180 } 10.181 10.182 - public List<String> getFiles(String subdirectory) { 10.183 + public List<String> getFiles(RelativeDirectory subdirectory) { 10.184 return List.nil(); 10.185 } 10.186 10.187 - public Set<String> getSubdirectories() { 10.188 + public Set<RelativeDirectory> getSubdirectories() { 10.189 return Collections.emptySet(); 10.190 } 10.191 + 10.192 + public String toString() { 10.193 + return "MissingArchive[" + zipFileName + "]"; 10.194 + } 10.195 } 10.196 10.197 /** A directory of zip files already opened. 10.198 */ 10.199 Map<File, Archive> archives = new HashMap<File,Archive>(); 10.200 10.201 + private static final String[] symbolFileLocation = { "lib", "ct.sym" }; 10.202 + private static final RelativeDirectory symbolFilePrefix 10.203 + = new RelativeDirectory("META-INF/sym/rt.jar/"); 10.204 + 10.205 /** Open a new zip file directory. 10.206 */ 10.207 protected Archive openArchive(File zipFileName) throws IOException { 10.208 @@ -540,8 +515,12 @@ 10.209 if (!useZipFileIndex) { 10.210 archive = new ZipArchive(this, zdir); 10.211 } else { 10.212 - archive = new ZipFileIndexArchive(this, ZipFileIndex.getZipFileIndex(zipFileName, null, 10.213 - usePreindexedCache, preindexCacheLocation, options.get("writezipindexfiles") != null)); 10.214 + archive = new ZipFileIndexArchive(this, 10.215 + ZipFileIndex.getZipFileIndex(zipFileName, 10.216 + null, 10.217 + usePreindexedCache, 10.218 + preindexCacheLocation, 10.219 + options.get("writezipindexfiles") != null)); 10.220 } 10.221 } 10.222 else { 10.223 @@ -551,10 +530,10 @@ 10.224 else { 10.225 archive = new ZipFileIndexArchive(this, 10.226 ZipFileIndex.getZipFileIndex(zipFileName, 10.227 - symbolFilePrefix, 10.228 - usePreindexedCache, 10.229 - preindexCacheLocation, 10.230 - options.get("writezipindexfiles") != null)); 10.231 + symbolFilePrefix, 10.232 + usePreindexedCache, 10.233 + preindexCacheLocation, 10.234 + options.get("writezipindexfiles") != null)); 10.235 } 10.236 } 10.237 } catch (FileNotFoundException ex) { 10.238 @@ -796,7 +775,7 @@ 10.239 Iterable<? extends File> path = getLocation(location); 10.240 if (path == null) 10.241 return List.nil(); 10.242 - String subdirectory = externalizeFileName(packageName); 10.243 + RelativeDirectory subdirectory = RelativeDirectory.forPackage(packageName); 10.244 ListBuffer<JavaFileObject> results = new ListBuffer<JavaFileObject>(); 10.245 10.246 for (File directory : path) 10.247 @@ -877,7 +856,7 @@ 10.248 nullCheck(kind); 10.249 if (!sourceOrClass.contains(kind)) 10.250 throw new IllegalArgumentException("Invalid kind " + kind); 10.251 - return getFileForInput(location, externalizeFileName(className, kind)); 10.252 + return getFileForInput(location, RelativeFile.forClass(className, kind)); 10.253 } 10.254 10.255 public FileObject getFileForInput(Location location, 10.256 @@ -890,35 +869,32 @@ 10.257 nullCheck(packageName); 10.258 if (!isRelativeUri(URI.create(relativeName))) // FIXME 6419701 10.259 throw new IllegalArgumentException("Invalid relative name: " + relativeName); 10.260 - String name = packageName.length() == 0 10.261 - ? relativeName 10.262 - : new File(externalizeFileName(packageName), relativeName).getPath(); 10.263 + RelativeFile name = packageName.length() == 0 10.264 + ? new RelativeFile(relativeName) 10.265 + : new RelativeFile(RelativeDirectory.forPackage(packageName), relativeName); 10.266 return getFileForInput(location, name); 10.267 } 10.268 10.269 - private JavaFileObject getFileForInput(Location location, String name) throws IOException { 10.270 + private JavaFileObject getFileForInput(Location location, RelativeFile name) throws IOException { 10.271 Iterable<? extends File> path = getLocation(location); 10.272 if (path == null) 10.273 return null; 10.274 10.275 for (File dir: path) { 10.276 if (dir.isDirectory()) { 10.277 - File f = new File(dir, name.replace('/', File.separatorChar)); 10.278 + File f = name.getFile(dir); 10.279 if (f.exists()) 10.280 return new RegularFileObject(this, f); 10.281 } else { 10.282 Archive a = openArchive(dir); 10.283 if (a.contains(name)) { 10.284 - int i = name.lastIndexOf('/'); 10.285 - String dirname = name.substring(0, i+1); 10.286 - String basename = name.substring(i+1); 10.287 - return a.getFileObject(dirname, basename); 10.288 + return a.getFileObject(name.dirname(), name.basename()); 10.289 } 10.290 10.291 } 10.292 } 10.293 + 10.294 return null; 10.295 - 10.296 } 10.297 10.298 public JavaFileObject getJavaFileForOutput(Location location, 10.299 @@ -933,7 +909,7 @@ 10.300 nullCheck(kind); 10.301 if (!sourceOrClass.contains(kind)) 10.302 throw new IllegalArgumentException("Invalid kind " + kind); 10.303 - return getFileForOutput(location, externalizeFileName(className, kind), sibling); 10.304 + return getFileForOutput(location, RelativeFile.forClass(className, kind), sibling); 10.305 } 10.306 10.307 public FileObject getFileForOutput(Location location, 10.308 @@ -947,14 +923,14 @@ 10.309 nullCheck(packageName); 10.310 if (!isRelativeUri(URI.create(relativeName))) // FIXME 6419701 10.311 throw new IllegalArgumentException("relativeName is invalid"); 10.312 - String name = packageName.length() == 0 10.313 - ? relativeName 10.314 - : new File(externalizeFileName(packageName), relativeName).getPath(); 10.315 + RelativeFile name = packageName.length() == 0 10.316 + ? new RelativeFile(relativeName) 10.317 + : new RelativeFile(RelativeDirectory.forPackage(packageName), relativeName); 10.318 return getFileForOutput(location, name, sibling); 10.319 } 10.320 10.321 private JavaFileObject getFileForOutput(Location location, 10.322 - String fileName, 10.323 + RelativeFile fileName, 10.324 FileObject sibling) 10.325 throws IOException 10.326 { 10.327 @@ -967,7 +943,7 @@ 10.328 if (sibling != null && sibling instanceof RegularFileObject) { 10.329 siblingDir = ((RegularFileObject)sibling).f.getParentFile(); 10.330 } 10.331 - return new RegularFileObject(this, new File(siblingDir, baseName(fileName))); 10.332 + return new RegularFileObject(this, new File(siblingDir, fileName.basename())); 10.333 } 10.334 } else if (location == SOURCE_OUTPUT) { 10.335 dir = (getSourceOutDir() != null ? getSourceOutDir() : getClassOutDir()); 10.336 @@ -980,7 +956,7 @@ 10.337 } 10.338 } 10.339 10.340 - File file = (dir == null ? new File(fileName) : new File(dir, fileName)); 10.341 + File file = fileName.getFile(dir); // null-safe 10.342 return new RegularFileObject(this, file); 10.343 10.344 }
11.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 11.2 +++ b/src/share/classes/com/sun/tools/javac/file/RelativePath.java Sun Aug 31 12:00:43 2008 -0700 11.3 @@ -0,0 +1,191 @@ 11.4 +/* 11.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. 11.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 11.7 + * 11.8 + * This code is free software; you can redistribute it and/or modify it 11.9 + * under the terms of the GNU General Public License version 2 only, as 11.10 + * published by the Free Software Foundation. Sun designates this 11.11 + * particular file as subject to the "Classpath" exception as provided 11.12 + * by Sun in the LICENSE file that accompanied this code. 11.13 + * 11.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 11.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 11.17 + * version 2 for more details (a copy is included in the LICENSE file that 11.18 + * accompanied this code). 11.19 + * 11.20 + * You should have received a copy of the GNU General Public License version 11.21 + * 2 along with this work; if not, write to the Free Software Foundation, 11.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 11.23 + * 11.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 11.25 + * CA 95054 USA or visit www.sun.com if you need additional information or 11.26 + * have any questions. 11.27 + */ 11.28 + 11.29 +package com.sun.tools.javac.file; 11.30 + 11.31 +import java.io.File; 11.32 +import java.util.zip.ZipEntry; 11.33 +import java.util.zip.ZipFile; 11.34 +import javax.tools.JavaFileObject; 11.35 + 11.36 +/** 11.37 + * Used to represent a platform-neutral path within a platform-specific 11.38 + * container, such as a directory or zip file. 11.39 + * Internally, the file separator is always '/'. 11.40 + */ 11.41 +public abstract class RelativePath implements Comparable<RelativePath> { 11.42 + /** 11.43 + * @param p must use '/' as an internal separator 11.44 + */ 11.45 + protected RelativePath(String p) { 11.46 + path = p; 11.47 + } 11.48 + 11.49 + public abstract RelativeDirectory dirname(); 11.50 + 11.51 + public abstract String basename(); 11.52 + 11.53 + public File getFile(File directory) { 11.54 + if (path.length() == 0) 11.55 + return directory; 11.56 + return new File(directory, path.replace('/', File.separatorChar)); 11.57 + } 11.58 + 11.59 + public int compareTo(RelativePath other) { 11.60 + return path.compareTo(other.path); 11.61 + } 11.62 + 11.63 + @Override 11.64 + public boolean equals(Object other) { 11.65 + if (!(other instanceof RelativePath)) 11.66 + return false; 11.67 + return path.equals(((RelativePath) other).path); 11.68 + } 11.69 + 11.70 + @Override 11.71 + public int hashCode() { 11.72 + return path.hashCode(); 11.73 + } 11.74 + 11.75 + @Override 11.76 + public String toString() { 11.77 + return "RelPath[" + path + "]"; 11.78 + } 11.79 + 11.80 + public String getPath() { 11.81 + return path; 11.82 + } 11.83 + 11.84 + protected final String path; 11.85 + 11.86 + /** 11.87 + * Used to represent a platform-neutral subdirectory within a platform-specific 11.88 + * container, such as a directory or zip file. 11.89 + * Internally, the file separator is always '/', and if the path is not empty, 11.90 + * it always ends in a '/' as well. 11.91 + */ 11.92 + public static class RelativeDirectory extends RelativePath { 11.93 + 11.94 + static RelativeDirectory forPackage(CharSequence packageName) { 11.95 + return new RelativeDirectory(packageName.toString().replace('.', '/')); 11.96 + } 11.97 + 11.98 + /** 11.99 + * @param p must use '/' as an internal separator 11.100 + */ 11.101 + public RelativeDirectory(String p) { 11.102 + super(p.length() == 0 || p.endsWith("/") ? p : p + "/"); 11.103 + } 11.104 + 11.105 + /** 11.106 + * @param p must use '/' as an internal separator 11.107 + */ 11.108 + public RelativeDirectory(RelativeDirectory d, String p) { 11.109 + this(d.path + p); 11.110 + } 11.111 + 11.112 + @Override 11.113 + public RelativeDirectory dirname() { 11.114 + int l = path.length(); 11.115 + if (l == 0) 11.116 + return this; 11.117 + int sep = path.lastIndexOf('/', l - 2); 11.118 + return new RelativeDirectory(path.substring(0, sep + 1)); 11.119 + } 11.120 + 11.121 + @Override 11.122 + public String basename() { 11.123 + int l = path.length(); 11.124 + if (l == 0) 11.125 + return path; 11.126 + int sep = path.lastIndexOf('/', l - 2); 11.127 + return path.substring(sep + 1, l - 1); 11.128 + } 11.129 + 11.130 + /** 11.131 + * Return true if this subdirectory "contains" the other path. 11.132 + * A subdirectory path does not contain itself. 11.133 + **/ 11.134 + boolean contains(RelativePath other) { 11.135 + return other.path.length() > path.length() && other.path.startsWith(path); 11.136 + } 11.137 + 11.138 + @Override 11.139 + public String toString() { 11.140 + return "RelativeDirectory[" + path + "]"; 11.141 + } 11.142 + } 11.143 + 11.144 + /** 11.145 + * Used to represent a platform-neutral file within a platform-specific 11.146 + * container, such as a directory or zip file. 11.147 + * Internally, the file separator is always '/'. It never ends in '/'. 11.148 + */ 11.149 + public static class RelativeFile extends RelativePath { 11.150 + static RelativeFile forClass(CharSequence className, JavaFileObject.Kind kind) { 11.151 + return new RelativeFile(className.toString().replace('.', '/') + kind.extension); 11.152 + } 11.153 + 11.154 + public RelativeFile(String p) { 11.155 + super(p); 11.156 + if (p.endsWith("/")) 11.157 + throw new IllegalArgumentException(p); 11.158 + } 11.159 + 11.160 + /** 11.161 + * @param p must use '/' as an internal separator 11.162 + */ 11.163 + public RelativeFile(RelativeDirectory d, String p) { 11.164 + this(d.path + p); 11.165 + } 11.166 + 11.167 + RelativeFile(RelativeDirectory d, RelativePath p) { 11.168 + this(d, p.path); 11.169 + } 11.170 + 11.171 + @Override 11.172 + public RelativeDirectory dirname() { 11.173 + int sep = path.lastIndexOf('/'); 11.174 + return new RelativeDirectory(path.substring(0, sep + 1)); 11.175 + } 11.176 + 11.177 + @Override 11.178 + public String basename() { 11.179 + int sep = path.lastIndexOf('/'); 11.180 + return path.substring(sep + 1); 11.181 + } 11.182 + 11.183 + ZipEntry getZipEntry(ZipFile zip) { 11.184 + return zip.getEntry(path); 11.185 + } 11.186 + 11.187 + @Override 11.188 + public String toString() { 11.189 + return "RelativeFile[" + path + "]"; 11.190 + } 11.191 + 11.192 + } 11.193 + 11.194 +}
12.1 --- a/src/share/classes/com/sun/tools/javac/file/SymbolArchive.java Fri Aug 29 12:42:27 2008 -0700 12.2 +++ b/src/share/classes/com/sun/tools/javac/file/SymbolArchive.java Sun Aug 31 12:00:43 2008 -0700 12.3 @@ -25,47 +25,75 @@ 12.4 12.5 package com.sun.tools.javac.file; 12.6 12.7 -import com.sun.tools.javac.util.List; 12.8 import java.io.File; 12.9 import java.io.IOException; 12.10 import java.util.zip.ZipEntry; 12.11 import java.util.zip.ZipFile; 12.12 import javax.tools.JavaFileObject; 12.13 12.14 +import com.sun.tools.javac.file.RelativePath.RelativeDirectory; 12.15 +import com.sun.tools.javac.file.RelativePath.RelativeFile; 12.16 +import com.sun.tools.javac.util.List; 12.17 + 12.18 public class SymbolArchive extends ZipArchive { 12.19 12.20 final File origFile; 12.21 - final String prefix; 12.22 + final RelativeDirectory prefix; 12.23 12.24 - public SymbolArchive(JavacFileManager fileManager, File orig, ZipFile zdir, String prefix) throws IOException { 12.25 - super(fileManager, zdir); 12.26 + public SymbolArchive(JavacFileManager fileManager, File orig, ZipFile zdir, RelativeDirectory prefix) throws IOException { 12.27 + super(fileManager, zdir, false); 12.28 this.origFile = orig; 12.29 this.prefix = prefix; 12.30 + initMap(); 12.31 } 12.32 12.33 @Override 12.34 void addZipEntry(ZipEntry entry) { 12.35 String name = entry.getName(); 12.36 - if (!name.startsWith(prefix)) { 12.37 + if (!name.startsWith(prefix.path)) { 12.38 return; 12.39 } 12.40 - name = name.substring(prefix.length()); 12.41 + name = name.substring(prefix.path.length()); 12.42 int i = name.lastIndexOf('/'); 12.43 - String dirname = name.substring(0, i + 1); 12.44 + RelativeDirectory dirname = new RelativeDirectory(name.substring(0, i+1)); 12.45 String basename = name.substring(i + 1); 12.46 if (basename.length() == 0) { 12.47 return; 12.48 } 12.49 List<String> list = map.get(dirname); 12.50 - if (list == null) { 12.51 + if (list == null) 12.52 list = List.nil(); 12.53 - } 12.54 list = list.prepend(basename); 12.55 map.put(dirname, list); 12.56 } 12.57 12.58 - @Override 12.59 - public JavaFileObject getFileObject(String subdirectory, String file) { 12.60 - return super.getFileObject(prefix + subdirectory, file); 12.61 + public JavaFileObject getFileObject(RelativeDirectory subdirectory, String file) { 12.62 + RelativeDirectory prefix_subdir = new RelativeDirectory(prefix, subdirectory.path); 12.63 + ZipEntry ze = new RelativeFile(prefix_subdir, file).getZipEntry(zdir); 12.64 + return new SymbolFileObject(this, file, ze); 12.65 } 12.66 + 12.67 + public String toString() { 12.68 + return "SymbolArchive[" + zdir.getName() + "]"; 12.69 + } 12.70 + 12.71 + /** 12.72 + * A subclass of JavaFileObject representing zip entries in a symbol file. 12.73 + */ 12.74 + public static class SymbolFileObject extends ZipFileObject { 12.75 + protected SymbolFileObject(SymbolArchive zarch, String name, ZipEntry entry) { 12.76 + super(zarch, name, entry); 12.77 + } 12.78 + 12.79 + @Override 12.80 + protected String inferBinaryName(Iterable<? extends File> path) { 12.81 + String entryName = getZipEntryName(); 12.82 + String prefix = ((SymbolArchive) zarch).prefix.path; 12.83 + if (entryName.startsWith(prefix)) 12.84 + entryName = entryName.substring(prefix.length()); 12.85 + return removeExtension(entryName).replace('/', '.'); 12.86 + } 12.87 + } 12.88 + 12.89 + 12.90 }
13.1 --- a/src/share/classes/com/sun/tools/javac/file/ZipArchive.java Fri Aug 29 12:42:27 2008 -0700 13.2 +++ b/src/share/classes/com/sun/tools/javac/file/ZipArchive.java Sun Aug 31 12:00:43 2008 -0700 13.3 @@ -25,18 +25,8 @@ 13.4 13.5 package com.sun.tools.javac.file; 13.6 13.7 +import java.io.File; 13.8 import java.io.IOException; 13.9 -import java.util.Enumeration; 13.10 -import java.util.HashMap; 13.11 -import java.util.Map; 13.12 -import java.util.Set; 13.13 -import java.util.zip.ZipEntry; 13.14 -import java.util.zip.ZipFile; 13.15 -import javax.tools.JavaFileObject; 13.16 - 13.17 -import com.sun.tools.javac.file.JavacFileManager.Archive; 13.18 -import com.sun.tools.javac.util.List; 13.19 -import java.io.File; 13.20 import java.io.InputStream; 13.21 import java.io.OutputStream; 13.22 import java.io.Writer; 13.23 @@ -44,13 +34,35 @@ 13.24 import java.nio.ByteBuffer; 13.25 import java.nio.CharBuffer; 13.26 import java.nio.charset.CharsetDecoder; 13.27 +import java.util.Enumeration; 13.28 +import java.util.HashMap; 13.29 +import java.util.Map; 13.30 +import java.util.Set; 13.31 +import java.util.zip.ZipEntry; 13.32 +import java.util.zip.ZipFile; 13.33 + 13.34 +import javax.tools.JavaFileObject; 13.35 + 13.36 +import com.sun.tools.javac.file.JavacFileManager.Archive; 13.37 +import com.sun.tools.javac.file.RelativePath.RelativeDirectory; 13.38 +import com.sun.tools.javac.file.RelativePath.RelativeFile; 13.39 +import com.sun.tools.javac.util.List; 13.40 13.41 public class ZipArchive implements Archive { 13.42 13.43 public ZipArchive(JavacFileManager fm, ZipFile zdir) throws IOException { 13.44 + this(fm, zdir, true); 13.45 + } 13.46 + 13.47 + protected ZipArchive(JavacFileManager fm, ZipFile zdir, boolean initMap) throws IOException { 13.48 this.fileManager = fm; 13.49 this.zdir = zdir; 13.50 - this.map = new HashMap<String,List<String>>(); 13.51 + this.map = new HashMap<RelativeDirectory,List<String>>(); 13.52 + if (initMap) 13.53 + initMap(); 13.54 + } 13.55 + 13.56 + protected void initMap() throws IOException { 13.57 for (Enumeration<? extends ZipEntry> e = zdir.entries(); e.hasMoreElements(); ) { 13.58 ZipEntry entry; 13.59 try { 13.60 @@ -67,7 +79,7 @@ 13.61 void addZipEntry(ZipEntry entry) { 13.62 String name = entry.getName(); 13.63 int i = name.lastIndexOf('/'); 13.64 - String dirname = name.substring(0, i+1); 13.65 + RelativeDirectory dirname = new RelativeDirectory(name.substring(0, i+1)); 13.66 String basename = name.substring(i+1); 13.67 if (basename.length() == 0) 13.68 return; 13.69 @@ -78,26 +90,25 @@ 13.70 map.put(dirname, list); 13.71 } 13.72 13.73 - public boolean contains(String name) { 13.74 - int i = name.lastIndexOf('/'); 13.75 - String dirname = name.substring(0, i+1); 13.76 - String basename = name.substring(i+1); 13.77 + public boolean contains(RelativePath name) { 13.78 + RelativeDirectory dirname = name.dirname(); 13.79 + String basename = name.basename(); 13.80 if (basename.length() == 0) 13.81 return false; 13.82 List<String> list = map.get(dirname); 13.83 return (list != null && list.contains(basename)); 13.84 } 13.85 13.86 - public List<String> getFiles(String subdirectory) { 13.87 + public List<String> getFiles(RelativeDirectory subdirectory) { 13.88 return map.get(subdirectory); 13.89 } 13.90 13.91 - public JavaFileObject getFileObject(String subdirectory, String file) { 13.92 - ZipEntry ze = zdir.getEntry(subdirectory + file); 13.93 + public JavaFileObject getFileObject(RelativeDirectory subdirectory, String file) { 13.94 + ZipEntry ze = new RelativeFile(subdirectory, file).getZipEntry(zdir); 13.95 return new ZipFileObject(this, file, ze); 13.96 } 13.97 13.98 - public Set<String> getSubdirectories() { 13.99 + public Set<RelativeDirectory> getSubdirectories() { 13.100 return map.keySet(); 13.101 } 13.102 13.103 @@ -105,8 +116,12 @@ 13.104 zdir.close(); 13.105 } 13.106 13.107 + public String toString() { 13.108 + return "ZipArchive[" + zdir.getName() + "]"; 13.109 + } 13.110 + 13.111 protected JavacFileManager fileManager; 13.112 - protected final Map<String,List<String>> map; 13.113 + protected final Map<RelativeDirectory,List<String>> map; 13.114 protected final ZipFile zdir; 13.115 13.116 /** 13.117 @@ -118,7 +133,7 @@ 13.118 ZipArchive zarch; 13.119 ZipEntry entry; 13.120 13.121 - public ZipFileObject(ZipArchive zarch, String name, ZipEntry entry) { 13.122 + protected ZipFileObject(ZipArchive zarch, String name, ZipEntry entry) { 13.123 super(zarch.fileManager); 13.124 this.zarch = zarch; 13.125 this.name = name; 13.126 @@ -222,11 +237,6 @@ 13.127 @Override 13.128 protected String inferBinaryName(Iterable<? extends File> path) { 13.129 String entryName = getZipEntryName(); 13.130 - if (zarch instanceof SymbolArchive) { 13.131 - String prefix = ((SymbolArchive) zarch).prefix; 13.132 - if (entryName.startsWith(prefix)) 13.133 - entryName = entryName.substring(prefix.length()); 13.134 - } 13.135 return removeExtension(entryName).replace('/', '.'); 13.136 } 13.137 }
14.1 --- a/src/share/classes/com/sun/tools/javac/file/ZipFileIndex.java Fri Aug 29 12:42:27 2008 -0700 14.2 +++ b/src/share/classes/com/sun/tools/javac/file/ZipFileIndex.java Sun Aug 31 12:00:43 2008 -0700 14.3 @@ -25,11 +25,12 @@ 14.4 14.5 package com.sun.tools.javac.file; 14.6 14.7 + 14.8 import java.io.File; 14.9 import java.io.FileNotFoundException; 14.10 import java.io.IOException; 14.11 import java.io.RandomAccessFile; 14.12 -import java.text.MessageFormat; 14.13 +import java.lang.ref.SoftReference; 14.14 import java.util.ArrayList; 14.15 import java.util.Arrays; 14.16 import java.util.Calendar; 14.17 @@ -45,6 +46,9 @@ 14.18 import java.util.zip.Inflater; 14.19 import java.util.zip.ZipException; 14.20 14.21 +import com.sun.tools.javac.file.RelativePath.RelativeDirectory; 14.22 +import com.sun.tools.javac.file.RelativePath.RelativeFile; 14.23 + 14.24 /** This class implements building of index of a zip archive and access to it's context. 14.25 * It also uses prebuild index if available. It supports invocations where it will 14.26 * serialize an optimized zip index file to disk. 14.27 @@ -75,8 +79,8 @@ 14.28 14.29 private static boolean NON_BATCH_MODE = System.getProperty("nonBatchMode") != null;// TODO: Use -XD compiler switch for this. 14.30 14.31 - private Map<String, DirectoryEntry> directories = Collections.<String, DirectoryEntry>emptyMap(); 14.32 - private Set<String> allDirs = Collections.<String>emptySet(); 14.33 + private Map<RelativeDirectory, DirectoryEntry> directories = Collections.<RelativeDirectory, DirectoryEntry>emptyMap(); 14.34 + private Set<RelativeDirectory> allDirs = Collections.<RelativeDirectory>emptySet(); 14.35 14.36 // ZipFileIndex data entries 14.37 private File zipFile; 14.38 @@ -87,7 +91,7 @@ 14.39 private boolean readFromIndex = false; 14.40 private File zipIndexFile = null; 14.41 private boolean triedToReadIndex = false; 14.42 - final String symbolFilePrefix; 14.43 + final RelativeDirectory symbolFilePrefix; 14.44 private int symbolFilePrefixLength = 0; 14.45 private boolean hasPopulatedData = false; 14.46 private long lastReferenceTimeStamp = NOT_MODIFIED; 14.47 @@ -97,6 +101,9 @@ 14.48 14.49 private boolean writeIndex = false; 14.50 14.51 + private Map <String, SoftReference<RelativeDirectory>> relativeDirectoryCache = 14.52 + new HashMap<String, SoftReference<RelativeDirectory>>(); 14.53 + 14.54 /** 14.55 * Returns a list of all ZipFileIndex entries 14.56 * 14.57 @@ -143,7 +150,10 @@ 14.58 } 14.59 } 14.60 14.61 - public static ZipFileIndex getZipFileIndex(File zipFile, String symbolFilePrefix, boolean useCache, String cacheLocation, boolean writeIndex) throws IOException { 14.62 + public static ZipFileIndex getZipFileIndex(File zipFile, 14.63 + RelativeDirectory symbolFilePrefix, 14.64 + boolean useCache, String cacheLocation, 14.65 + boolean writeIndex) throws IOException { 14.66 ZipFileIndex zi = null; 14.67 lock.lock(); 14.68 try { 14.69 @@ -231,12 +241,12 @@ 14.70 } 14.71 } 14.72 14.73 - private ZipFileIndex(File zipFile, String symbolFilePrefix, boolean writeIndex, 14.74 + private ZipFileIndex(File zipFile, RelativeDirectory symbolFilePrefix, boolean writeIndex, 14.75 boolean useCache, String cacheLocation) throws IOException { 14.76 this.zipFile = zipFile; 14.77 this.symbolFilePrefix = symbolFilePrefix; 14.78 this.symbolFilePrefixLength = (symbolFilePrefix == null ? 0 : 14.79 - symbolFilePrefix.getBytes("UTF-8").length); 14.80 + symbolFilePrefix.getPath().getBytes("UTF-8").length); 14.81 this.writeIndex = writeIndex; 14.82 this.usePreindexedCache = useCache; 14.83 this.preindexedCacheLocation = cacheLocation; 14.84 @@ -250,7 +260,7 @@ 14.85 } 14.86 14.87 public String toString() { 14.88 - return "ZipFileIndex of file:(" + zipFile + ")"; 14.89 + return "ZipFileIndex[" + zipFile + "]"; 14.90 } 14.91 14.92 // Just in case... 14.93 @@ -291,8 +301,8 @@ 14.94 return; 14.95 } 14.96 14.97 - directories = Collections.<String, DirectoryEntry>emptyMap(); 14.98 - allDirs = Collections.<String>emptySet(); 14.99 + directories = Collections.<RelativeDirectory, DirectoryEntry>emptyMap(); 14.100 + allDirs = Collections.<RelativeDirectory>emptySet(); 14.101 14.102 try { 14.103 openFile(); 14.104 @@ -317,9 +327,9 @@ 14.105 private void cleanupState() { 14.106 // Make sure there is a valid but empty index if the file doesn't exist 14.107 entries = Entry.EMPTY_ARRAY; 14.108 - directories = Collections.<String, DirectoryEntry>emptyMap(); 14.109 + directories = Collections.<RelativeDirectory, DirectoryEntry>emptyMap(); 14.110 zipFileLastModified = NOT_MODIFIED; 14.111 - allDirs = Collections.<String>emptySet(); 14.112 + allDirs = Collections.<RelativeDirectory>emptySet(); 14.113 } 14.114 14.115 public void close() { 14.116 @@ -346,24 +356,12 @@ 14.117 /** 14.118 * Returns the ZipFileIndexEntry for an absolute path, if there is one. 14.119 */ 14.120 - Entry getZipIndexEntry(String path) { 14.121 - if (File.separatorChar != '/') { 14.122 - path = path.replace('/', File.separatorChar); 14.123 - } 14.124 + Entry getZipIndexEntry(RelativePath path) { 14.125 lock.lock(); 14.126 try { 14.127 checkIndex(); 14.128 - String lookFor = ""; 14.129 - int lastSepIndex = path.lastIndexOf(File.separatorChar); 14.130 - boolean noSeparator = false; 14.131 - if (lastSepIndex == -1) { 14.132 - noSeparator = true; 14.133 - } 14.134 - 14.135 - DirectoryEntry de = directories.get(noSeparator ? "" : path.substring(0, lastSepIndex)); 14.136 - 14.137 - lookFor = path.substring(noSeparator ? 0 : lastSepIndex + 1); 14.138 - 14.139 + DirectoryEntry de = directories.get(path.dirname()); 14.140 + String lookFor = path.basename(); 14.141 return de == null ? null : de.getEntry(lookFor); 14.142 } 14.143 catch (IOException e) { 14.144 @@ -377,11 +375,7 @@ 14.145 /** 14.146 * Returns a javac List of filenames within an absolute path in the ZipFileIndex. 14.147 */ 14.148 - public com.sun.tools.javac.util.List<String> getFiles(String path) { 14.149 - if (File.separatorChar != '/') { 14.150 - path = path.replace('/', File.separatorChar); 14.151 - } 14.152 - 14.153 + public com.sun.tools.javac.util.List<String> getFiles(RelativeDirectory path) { 14.154 lock.lock(); 14.155 try { 14.156 checkIndex(); 14.157 @@ -402,16 +396,10 @@ 14.158 } 14.159 } 14.160 14.161 - public List<String> getAllDirectories(String path) { 14.162 - 14.163 - if (File.separatorChar != '/') { 14.164 - path = path.replace('/', File.separatorChar); 14.165 - } 14.166 - 14.167 + public List<String> getDirectories(RelativeDirectory path) { 14.168 lock.lock(); 14.169 try { 14.170 checkIndex(); 14.171 - path = path.intern(); 14.172 14.173 DirectoryEntry de = directories.get(path); 14.174 com.sun.tools.javac.util.List<String> ret = de == null ? null : de.getDirectories(); 14.175 @@ -430,24 +418,18 @@ 14.176 } 14.177 } 14.178 14.179 - public Set<String> getAllDirectories() { 14.180 + public Set<RelativeDirectory> getAllDirectories() { 14.181 lock.lock(); 14.182 try { 14.183 checkIndex(); 14.184 if (allDirs == Collections.EMPTY_SET) { 14.185 - Set<String> alldirs = new HashSet<String>(); 14.186 - Iterator<String> dirsIter = directories.keySet().iterator(); 14.187 - while (dirsIter.hasNext()) { 14.188 - alldirs.add(new String(dirsIter.next())); 14.189 - } 14.190 - 14.191 - allDirs = alldirs; 14.192 + allDirs = new HashSet<RelativeDirectory>(directories.keySet()); 14.193 } 14.194 14.195 return allDirs; 14.196 } 14.197 catch (IOException e) { 14.198 - return Collections.<String>emptySet(); 14.199 + return Collections.<RelativeDirectory>emptySet(); 14.200 } 14.201 finally { 14.202 lock.unlock(); 14.203 @@ -461,7 +443,7 @@ 14.204 * @param path A path within the zip. 14.205 * @return True if the path is a file or dir, false otherwise. 14.206 */ 14.207 - public boolean contains(String path) { 14.208 + public boolean contains(RelativePath path) { 14.209 lock.lock(); 14.210 try { 14.211 checkIndex(); 14.212 @@ -475,17 +457,15 @@ 14.213 } 14.214 } 14.215 14.216 - public boolean isDirectory(String path) throws IOException { 14.217 + public boolean isDirectory(RelativePath path) throws IOException { 14.218 lock.lock(); 14.219 try { 14.220 // The top level in a zip file is always a directory. 14.221 - if (path.length() == 0) { 14.222 + if (path.getPath().length() == 0) { 14.223 lastReferenceTimeStamp = System.currentTimeMillis(); 14.224 return true; 14.225 } 14.226 14.227 - if (File.separatorChar != '/') 14.228 - path = path.replace('/', File.separatorChar); 14.229 checkIndex(); 14.230 return directories.get(path) != null; 14.231 } 14.232 @@ -494,7 +474,7 @@ 14.233 } 14.234 } 14.235 14.236 - public long getLastModified(String path) throws IOException { 14.237 + public long getLastModified(RelativeFile path) throws IOException { 14.238 lock.lock(); 14.239 try { 14.240 Entry entry = getZipIndexEntry(path); 14.241 @@ -507,7 +487,7 @@ 14.242 } 14.243 } 14.244 14.245 - public int length(String path) throws IOException { 14.246 + public int length(RelativeFile path) throws IOException { 14.247 lock.lock(); 14.248 try { 14.249 Entry entry = getZipIndexEntry(path); 14.250 @@ -531,12 +511,12 @@ 14.251 } 14.252 } 14.253 14.254 - public byte[] read(String path) throws IOException { 14.255 + public byte[] read(RelativeFile path) throws IOException { 14.256 lock.lock(); 14.257 try { 14.258 Entry entry = getZipIndexEntry(path); 14.259 if (entry == null) 14.260 - throw new FileNotFoundException(MessageFormat.format("Path not found in ZIP: {0}", path)); 14.261 + throw new FileNotFoundException("Path not found in ZIP: " + path.path); 14.262 return read(entry); 14.263 } 14.264 finally { 14.265 @@ -557,7 +537,7 @@ 14.266 } 14.267 } 14.268 14.269 - public int read(String path, byte[] buffer) throws IOException { 14.270 + public int read(RelativeFile path, byte[] buffer) throws IOException { 14.271 lock.lock(); 14.272 try { 14.273 Entry entry = getZipIndexEntry(path); 14.274 @@ -690,7 +670,7 @@ 14.275 * ----------------------------------------------------------------------------*/ 14.276 14.277 private class ZipDirectory { 14.278 - private String lastDir; 14.279 + private RelativeDirectory lastDir; 14.280 private int lastStart; 14.281 private int lastLen; 14.282 14.283 @@ -747,13 +727,13 @@ 14.284 } 14.285 throw new ZipException("cannot read zip file"); 14.286 } 14.287 + 14.288 private void buildIndex() throws IOException { 14.289 int entryCount = get2ByteLittleEndian(zipDir, 0); 14.290 14.291 - entries = new Entry[entryCount]; 14.292 // Add each of the files 14.293 if (entryCount > 0) { 14.294 - directories = new HashMap<String, DirectoryEntry>(); 14.295 + directories = new HashMap<RelativeDirectory, DirectoryEntry>(); 14.296 ArrayList<Entry> entryList = new ArrayList<Entry>(); 14.297 int pos = 2; 14.298 for (int i = 0; i < entryCount; i++) { 14.299 @@ -761,9 +741,11 @@ 14.300 } 14.301 14.302 // Add the accumulated dirs into the same list 14.303 - Iterator i = directories.keySet().iterator(); 14.304 - while (i.hasNext()) { 14.305 - Entry zipFileIndexEntry = new Entry( (String) i.next()); 14.306 + for (RelativeDirectory d: directories.keySet()) { 14.307 + // use shared RelativeDirectory objects for parent dirs 14.308 + RelativeDirectory parent = getRelativeDirectory(d.dirname().getPath()); 14.309 + String file = d.basename(); 14.310 + Entry zipFileIndexEntry = new Entry(parent, file); 14.311 zipFileIndexEntry.isDir = true; 14.312 entryList.add(zipFileIndexEntry); 14.313 } 14.314 @@ -776,7 +758,7 @@ 14.315 } 14.316 14.317 private int readEntry(int pos, List<Entry> entryList, 14.318 - Map<String, DirectoryEntry> directories) throws IOException { 14.319 + Map<RelativeDirectory, DirectoryEntry> directories) throws IOException { 14.320 if (get4ByteLittleEndian(zipDir, pos) != 0x02014b50) { 14.321 throw new ZipException("cannot read zip file entry"); 14.322 } 14.323 @@ -790,19 +772,20 @@ 14.324 dirStart += zipFileIndex.symbolFilePrefixLength; 14.325 fileStart += zipFileIndex.symbolFilePrefixLength; 14.326 } 14.327 - 14.328 - // Use the OS's path separator. Keep the position of the last one. 14.329 + // Force any '\' to '/'. Keep the position of the last separator. 14.330 for (int index = fileStart; index < fileEnd; index++) { 14.331 byte nextByte = zipDir[index]; 14.332 - if (nextByte == (byte)'\\' || nextByte == (byte)'/') { 14.333 - zipDir[index] = (byte)File.separatorChar; 14.334 + if (nextByte == (byte)'\\') { 14.335 + zipDir[index] = (byte)'/'; 14.336 + fileStart = index + 1; 14.337 + } else if (nextByte == (byte)'/') { 14.338 fileStart = index + 1; 14.339 } 14.340 } 14.341 14.342 - String directory = null; 14.343 + RelativeDirectory directory = null; 14.344 if (fileStart == dirStart) 14.345 - directory = ""; 14.346 + directory = getRelativeDirectory(""); 14.347 else if (lastDir != null && lastLen == fileStart - dirStart - 1) { 14.348 int index = lastLen - 1; 14.349 while (zipDir[lastStart + index] == zipDir[dirStart + index]) { 14.350 @@ -819,22 +802,23 @@ 14.351 lastStart = dirStart; 14.352 lastLen = fileStart - dirStart - 1; 14.353 14.354 - directory = new String(zipDir, dirStart, lastLen, "UTF-8").intern(); 14.355 + directory = getRelativeDirectory(new String(zipDir, dirStart, lastLen, "UTF-8")); 14.356 lastDir = directory; 14.357 14.358 // Enter also all the parent directories 14.359 - String tempDirectory = directory; 14.360 + RelativeDirectory tempDirectory = directory; 14.361 14.362 while (directories.get(tempDirectory) == null) { 14.363 directories.put(tempDirectory, new DirectoryEntry(tempDirectory, zipFileIndex)); 14.364 - int separator = tempDirectory.lastIndexOf(File.separatorChar); 14.365 - if (separator == -1) 14.366 + if (tempDirectory.path.indexOf("/") == tempDirectory.path.length() - 1) 14.367 break; 14.368 - tempDirectory = tempDirectory.substring(0, separator); 14.369 + else { 14.370 + // use shared RelativeDirectory objects for parent dirs 14.371 + tempDirectory = getRelativeDirectory(tempDirectory.dirname().getPath()); 14.372 + } 14.373 } 14.374 } 14.375 else { 14.376 - directory = directory.intern(); 14.377 if (directories.get(directory) == null) { 14.378 directories.put(directory, new DirectoryEntry(directory, zipFileIndex)); 14.379 } 14.380 @@ -886,7 +870,7 @@ 14.381 14.382 private long writtenOffsetOffset = 0; 14.383 14.384 - private String dirName; 14.385 + private RelativeDirectory dirName; 14.386 14.387 private com.sun.tools.javac.util.List<String> zipFileEntriesFiles = com.sun.tools.javac.util.List.<String>nil(); 14.388 private com.sun.tools.javac.util.List<String> zipFileEntriesDirectories = com.sun.tools.javac.util.List.<String>nil(); 14.389 @@ -898,70 +882,50 @@ 14.390 14.391 private int numEntries; 14.392 14.393 - DirectoryEntry(String dirName, ZipFileIndex index) { 14.394 - filesInited = false; 14.395 + DirectoryEntry(RelativeDirectory dirName, ZipFileIndex index) { 14.396 + filesInited = false; 14.397 directoriesInited = false; 14.398 entriesInited = false; 14.399 14.400 - if (File.separatorChar == '/') { 14.401 - dirName.replace('\\', '/'); 14.402 - } 14.403 - else { 14.404 - dirName.replace('/', '\\'); 14.405 - } 14.406 - 14.407 - this.dirName = dirName.intern(); 14.408 + this.dirName = dirName; 14.409 this.zipFileIndex = index; 14.410 } 14.411 14.412 private com.sun.tools.javac.util.List<String> getFiles() { 14.413 - if (filesInited) { 14.414 - return zipFileEntriesFiles; 14.415 + if (!filesInited) { 14.416 + initEntries(); 14.417 + for (Entry e : entries) { 14.418 + if (!e.isDir) { 14.419 + zipFileEntriesFiles = zipFileEntriesFiles.append(e.name); 14.420 + } 14.421 + } 14.422 + filesInited = true; 14.423 } 14.424 - 14.425 - initEntries(); 14.426 - 14.427 - for (Entry e : entries) { 14.428 - if (!e.isDir) { 14.429 - zipFileEntriesFiles = zipFileEntriesFiles.append(e.name); 14.430 - } 14.431 - } 14.432 - filesInited = true; 14.433 return zipFileEntriesFiles; 14.434 } 14.435 14.436 private com.sun.tools.javac.util.List<String> getDirectories() { 14.437 - if (directoriesInited) { 14.438 - return zipFileEntriesFiles; 14.439 + if (!directoriesInited) { 14.440 + initEntries(); 14.441 + for (Entry e : entries) { 14.442 + if (e.isDir) { 14.443 + zipFileEntriesDirectories = zipFileEntriesDirectories.append(e.name); 14.444 + } 14.445 + } 14.446 + directoriesInited = true; 14.447 } 14.448 - 14.449 - initEntries(); 14.450 - 14.451 - for (Entry e : entries) { 14.452 - if (e.isDir) { 14.453 - zipFileEntriesDirectories = zipFileEntriesDirectories.append(e.name); 14.454 - } 14.455 - } 14.456 - 14.457 - directoriesInited = true; 14.458 - 14.459 return zipFileEntriesDirectories; 14.460 } 14.461 14.462 private com.sun.tools.javac.util.List<Entry> getEntries() { 14.463 - if (zipFileEntriesInited) { 14.464 - return zipFileEntries; 14.465 + if (!zipFileEntriesInited) { 14.466 + initEntries(); 14.467 + zipFileEntries = com.sun.tools.javac.util.List.nil(); 14.468 + for (Entry zfie : entries) { 14.469 + zipFileEntries = zipFileEntries.append(zfie); 14.470 + } 14.471 + zipFileEntriesInited = true; 14.472 } 14.473 - 14.474 - initEntries(); 14.475 - 14.476 - zipFileEntries = com.sun.tools.javac.util.List.nil(); 14.477 - for (Entry zfie : entries) { 14.478 - zipFileEntries = zipFileEntries.append(zfie); 14.479 - } 14.480 - 14.481 - zipFileEntriesInited = true; 14.482 - 14.483 return zipFileEntries; 14.484 } 14.485 14.486 @@ -986,8 +950,6 @@ 14.487 int to = -Arrays.binarySearch(zipFileIndex.entries, 14.488 new Entry(dirName, MAX_CHAR)) - 1; 14.489 14.490 - boolean emptyList = false; 14.491 - 14.492 for (int i = from; i < to; i++) { 14.493 entries.add(zipFileIndex.entries[i]); 14.494 } 14.495 @@ -1071,14 +1033,14 @@ 14.496 if (zipFile.lastModified() != fileStamp) { 14.497 ret = false; 14.498 } else { 14.499 - directories = new HashMap<String, DirectoryEntry>(); 14.500 + directories = new HashMap<RelativeDirectory, DirectoryEntry>(); 14.501 int numDirs = raf.readInt(); 14.502 for (int nDirs = 0; nDirs < numDirs; nDirs++) { 14.503 int dirNameBytesLen = raf.readInt(); 14.504 byte [] dirNameBytes = new byte[dirNameBytesLen]; 14.505 raf.read(dirNameBytes); 14.506 14.507 - String dirNameStr = new String(dirNameBytes, "UTF-8"); 14.508 + RelativeDirectory dirNameStr = getRelativeDirectory(new String(dirNameBytes, "UTF-8")); 14.509 DirectoryEntry de = new DirectoryEntry(dirNameStr, this); 14.510 de.numEntries = raf.readInt(); 14.511 de.writtenOffsetOffset = raf.readLong(); 14.512 @@ -1132,21 +1094,18 @@ 14.513 raf.writeLong(zipFileLastModified); 14.514 writtenSoFar += 8; 14.515 14.516 - 14.517 - Iterator<String> iterDirName = directories.keySet().iterator(); 14.518 List<DirectoryEntry> directoriesToWrite = new ArrayList<DirectoryEntry>(); 14.519 - Map<String, Long> offsets = new HashMap<String, Long>(); 14.520 + Map<RelativeDirectory, Long> offsets = new HashMap<RelativeDirectory, Long>(); 14.521 raf.writeInt(directories.keySet().size()); 14.522 writtenSoFar += 4; 14.523 14.524 - while(iterDirName.hasNext()) { 14.525 - String dirName = iterDirName.next(); 14.526 + for (RelativeDirectory dirName: directories.keySet()) { 14.527 DirectoryEntry dirEntry = directories.get(dirName); 14.528 14.529 directoriesToWrite.add(dirEntry); 14.530 14.531 // Write the dir name bytes 14.532 - byte [] dirNameBytes = dirName.getBytes("UTF-8"); 14.533 + byte [] dirNameBytes = dirName.getPath().getBytes("UTF-8"); 14.534 int dirNameBytesLen = dirNameBytes.length; 14.535 raf.writeInt(dirNameBytesLen); 14.536 writtenSoFar += 4; 14.537 @@ -1251,12 +1210,24 @@ 14.538 return zipFile; 14.539 } 14.540 14.541 + private RelativeDirectory getRelativeDirectory(String path) { 14.542 + RelativeDirectory rd; 14.543 + SoftReference<RelativeDirectory> ref = relativeDirectoryCache.get(path); 14.544 + if (ref != null) { 14.545 + rd = ref.get(); 14.546 + if (rd != null) 14.547 + return rd; 14.548 + } 14.549 + rd = new RelativeDirectory(path); 14.550 + relativeDirectoryCache.put(path, new SoftReference<RelativeDirectory>(rd)); 14.551 + return rd; 14.552 + } 14.553 14.554 static class Entry implements Comparable<Entry> { 14.555 public static final Entry[] EMPTY_ARRAY = {}; 14.556 14.557 // Directory related 14.558 - String dir; 14.559 + RelativeDirectory dir; 14.560 boolean isDir; 14.561 14.562 // File related 14.563 @@ -1269,32 +1240,17 @@ 14.564 14.565 private int nativetime; 14.566 14.567 - public Entry(String path) { 14.568 - int separator = path.lastIndexOf(File.separatorChar); 14.569 - if (separator == -1) { 14.570 - dir = "".intern(); 14.571 - name = path; 14.572 - } else { 14.573 - dir = path.substring(0, separator).intern(); 14.574 - name = path.substring(separator + 1); 14.575 - } 14.576 + public Entry(RelativePath path) { 14.577 + this(path.dirname(), path.basename()); 14.578 } 14.579 14.580 - public Entry(String directory, String name) { 14.581 - this.dir = directory.intern(); 14.582 + public Entry(RelativeDirectory directory, String name) { 14.583 + this.dir = directory; 14.584 this.name = name; 14.585 } 14.586 14.587 public String getName() { 14.588 - if (dir == null || dir.length() == 0) { 14.589 - return name; 14.590 - } 14.591 - 14.592 - StringBuilder sb = new StringBuilder(); 14.593 - sb.append(dir); 14.594 - sb.append(File.separatorChar); 14.595 - sb.append(name); 14.596 - return sb.toString(); 14.597 + return new RelativeFile(dir, name).getPath(); 14.598 } 14.599 14.600 public String getFileName() { 14.601 @@ -1331,7 +1287,7 @@ 14.602 } 14.603 14.604 public int compareTo(Entry other) { 14.605 - String otherD = other.dir; 14.606 + RelativeDirectory otherD = other.dir; 14.607 if (dir != otherD) { 14.608 int c = dir.compareTo(otherD); 14.609 if (c != 0) 14.610 @@ -1340,6 +1296,22 @@ 14.611 return name.compareTo(other.name); 14.612 } 14.613 14.614 + @Override 14.615 + public boolean equals(Object o) { 14.616 + if (!(o instanceof Entry)) 14.617 + return false; 14.618 + Entry other = (Entry) o; 14.619 + return dir.equals(other.dir) && name.equals(other.name); 14.620 + } 14.621 + 14.622 + @Override 14.623 + public int hashCode() { 14.624 + int hash = 7; 14.625 + hash = 97 * hash + (this.dir != null ? this.dir.hashCode() : 0); 14.626 + hash = 97 * hash + (this.name != null ? this.name.hashCode() : 0); 14.627 + return hash; 14.628 + } 14.629 + 14.630 14.631 public String toString() { 14.632 return isDir ? ("Dir:" + dir + " : " + name) :
15.1 --- a/src/share/classes/com/sun/tools/javac/file/ZipFileIndexArchive.java Fri Aug 29 12:42:27 2008 -0700 15.2 +++ b/src/share/classes/com/sun/tools/javac/file/ZipFileIndexArchive.java Sun Aug 31 12:00:43 2008 -0700 15.3 @@ -29,11 +29,8 @@ 15.4 import java.util.Set; 15.5 import javax.tools.JavaFileObject; 15.6 15.7 -import com.sun.tools.javac.file.JavacFileManager.Archive; 15.8 -import com.sun.tools.javac.util.List; 15.9 import java.io.ByteArrayInputStream; 15.10 import java.io.File; 15.11 -import java.io.FileNotFoundException; 15.12 import java.io.InputStream; 15.13 import java.io.OutputStream; 15.14 import java.io.Writer; 15.15 @@ -42,6 +39,11 @@ 15.16 import java.nio.CharBuffer; 15.17 import java.nio.charset.CharsetDecoder; 15.18 15.19 +import com.sun.tools.javac.file.JavacFileManager.Archive; 15.20 +import com.sun.tools.javac.file.RelativePath.RelativeDirectory; 15.21 +import com.sun.tools.javac.file.RelativePath.RelativeFile; 15.22 +import com.sun.tools.javac.util.List; 15.23 + 15.24 public class ZipFileIndexArchive implements Archive { 15.25 15.26 private final ZipFileIndex zfIndex; 15.27 @@ -53,22 +55,22 @@ 15.28 this.zfIndex = zdir; 15.29 } 15.30 15.31 - public boolean contains(String name) { 15.32 + public boolean contains(RelativePath name) { 15.33 return zfIndex.contains(name); 15.34 } 15.35 15.36 - public List<String> getFiles(String subdirectory) { 15.37 - return zfIndex.getFiles((subdirectory.endsWith("/") || subdirectory.endsWith("\\")) ? subdirectory.substring(0, subdirectory.length() - 1) : subdirectory); 15.38 + public List<String> getFiles(RelativeDirectory subdirectory) { 15.39 + return zfIndex.getFiles(subdirectory); 15.40 } 15.41 15.42 - public JavaFileObject getFileObject(String subdirectory, String file) { 15.43 - String fullZipFileName = subdirectory + file; 15.44 + public JavaFileObject getFileObject(RelativeDirectory subdirectory, String file) { 15.45 + RelativeFile fullZipFileName = new RelativeFile(subdirectory, file); 15.46 ZipFileIndex.Entry entry = zfIndex.getZipIndexEntry(fullZipFileName); 15.47 JavaFileObject ret = new ZipFileIndexFileObject(fileManager, zfIndex, entry, zfIndex.getZipFile().getPath()); 15.48 return ret; 15.49 } 15.50 15.51 - public Set<String> getSubdirectories() { 15.52 + public Set<RelativeDirectory> getSubdirectories() { 15.53 return zfIndex.getAllDirectories(); 15.54 } 15.55 15.56 @@ -76,6 +78,10 @@ 15.57 zfIndex.close(); 15.58 } 15.59 15.60 + public String toString() { 15.61 + return "ZipFileIndexArchive[" + zfIndex + "]"; 15.62 + } 15.63 + 15.64 /** 15.65 * A subclass of JavaFileObject representing zip entries using the com.sun.tools.javac.file.ZipFileIndex implementation. 15.66 */ 15.67 @@ -181,18 +187,11 @@ 15.68 public URI toUri() { 15.69 String zipName = new File(getZipName()).toURI().normalize().getPath(); 15.70 String entryName = getZipEntryName(); 15.71 - if (File.separatorChar != '/') { 15.72 - entryName = entryName.replace(File.separatorChar, '/'); 15.73 - } 15.74 return URI.create("jar:" + zipName + "!" + entryName); 15.75 } 15.76 15.77 private byte[] read() throws IOException { 15.78 - if (entry == null) { 15.79 - entry = zfIndex.getZipIndexEntry(name); 15.80 - if (entry == null) 15.81 - throw new FileNotFoundException(); 15.82 - } 15.83 + assert entry != null; // see constructor 15.84 return zfIndex.read(entry); 15.85 } 15.86 15.87 @@ -222,11 +221,11 @@ 15.88 protected String inferBinaryName(Iterable<? extends File> path) { 15.89 String entryName = getZipEntryName(); 15.90 if (zfIndex.symbolFilePrefix != null) { 15.91 - String prefix = zfIndex.symbolFilePrefix; 15.92 + String prefix = zfIndex.symbolFilePrefix.path; 15.93 if (entryName.startsWith(prefix)) 15.94 entryName = entryName.substring(prefix.length()); 15.95 } 15.96 - return removeExtension(entryName).replace(File.separatorChar, '.'); 15.97 + return removeExtension(entryName).replace('/', '.'); 15.98 } 15.99 } 15.100
16.1 --- a/src/share/classes/com/sun/tools/javac/jvm/Items.java Fri Aug 29 12:42:27 2008 -0700 16.2 +++ b/src/share/classes/com/sun/tools/javac/jvm/Items.java Sun Aug 31 12:00:43 2008 -0700 16.3 @@ -25,7 +25,6 @@ 16.4 16.5 package com.sun.tools.javac.jvm; 16.6 16.7 -import com.sun.tools.javac.util.*; 16.8 import com.sun.tools.javac.code.*; 16.9 16.10 import com.sun.tools.javac.code.Symbol.*; 16.11 @@ -33,7 +32,6 @@ 16.12 import com.sun.tools.javac.jvm.Code.*; 16.13 import com.sun.tools.javac.tree.JCTree; 16.14 16.15 -import static com.sun.tools.javac.code.TypeTags.*; 16.16 import static com.sun.tools.javac.jvm.ByteCodes.*; 16.17 16.18 /** A helper class for code generation. Items are objects 16.19 @@ -449,9 +447,7 @@ 16.20 16.21 Item invoke() { 16.22 MethodType mtype = (MethodType)member.erasure(types); 16.23 - int argsize = Code.width(mtype.argtypes); 16.24 int rescode = Code.typecode(mtype.restype); 16.25 - int sdiff = Code.width(rescode) - argsize; 16.26 code.emitInvokestatic(pool.put(member), mtype); 16.27 return stackItem[rescode]; 16.28 }
17.1 --- a/src/share/classes/com/sun/tools/javac/jvm/Pool.java Fri Aug 29 12:42:27 2008 -0700 17.2 +++ b/src/share/classes/com/sun/tools/javac/jvm/Pool.java Sun Aug 31 12:00:43 2008 -0700 17.3 @@ -27,9 +27,7 @@ 17.4 17.5 import java.util.*; 17.6 17.7 -import com.sun.tools.javac.util.*; 17.8 import com.sun.tools.javac.code.Symbol.*; 17.9 -import com.sun.tools.javac.code.Type; 17.10 17.11 /** An internal structure that corresponds to the constant pool of a classfile. 17.12 *
18.1 --- a/src/share/classes/com/sun/tools/javac/main/RecognizedOptions.java Fri Aug 29 12:42:27 2008 -0700 18.2 +++ b/src/share/classes/com/sun/tools/javac/main/RecognizedOptions.java Sun Aug 31 12:00:43 2008 -0700 18.3 @@ -38,12 +38,10 @@ 18.4 import java.io.File; 18.5 import java.io.FileWriter; 18.6 import java.io.PrintWriter; 18.7 -import java.util.Arrays; 18.8 import java.util.Collection; 18.9 import java.util.EnumSet; 18.10 import java.util.LinkedHashSet; 18.11 import java.util.Set; 18.12 -import java.util.StringTokenizer; 18.13 import javax.lang.model.SourceVersion; 18.14 18.15 import static com.sun.tools.javac.main.OptionName.*;
19.1 --- a/src/share/classes/com/sun/tools/javac/model/FilteredMemberList.java Fri Aug 29 12:42:27 2008 -0700 19.2 +++ b/src/share/classes/com/sun/tools/javac/model/FilteredMemberList.java Sun Aug 31 12:00:43 2008 -0700 19.3 @@ -25,7 +25,6 @@ 19.4 19.5 package com.sun.tools.javac.model; 19.6 19.7 -import com.sun.tools.javac.util.*; 19.8 import java.util.AbstractList; 19.9 import java.util.Iterator; 19.10 import java.util.NoSuchElementException;
20.1 --- a/src/share/classes/com/sun/tools/javac/parser/DocCommentScanner.java Fri Aug 29 12:42:27 2008 -0700 20.2 +++ b/src/share/classes/com/sun/tools/javac/parser/DocCommentScanner.java Sun Aug 31 12:00:43 2008 -0700 20.3 @@ -25,7 +25,6 @@ 20.4 20.5 package com.sun.tools.javac.parser; 20.6 20.7 -import java.io.*; 20.8 import java.nio.*; 20.9 20.10 import com.sun.tools.javac.util.*;
21.1 --- a/src/share/classes/com/sun/tools/javac/parser/EndPosParser.java Fri Aug 29 12:42:27 2008 -0700 21.2 +++ b/src/share/classes/com/sun/tools/javac/parser/EndPosParser.java Sun Aug 31 12:00:43 2008 -0700 21.3 @@ -29,8 +29,6 @@ 21.4 import java.util.HashMap; 21.5 import com.sun.tools.javac.tree.JCTree; 21.6 import com.sun.tools.javac.tree.TreeInfo; 21.7 -import com.sun.tools.javac.util.Position; 21.8 -import com.sun.tools.javac.util.List; 21.9 21.10 import static com.sun.tools.javac.tree.JCTree.*; 21.11
22.1 --- a/src/share/classes/com/sun/tools/javac/processing/JavacFiler.java Fri Aug 29 12:42:27 2008 -0700 22.2 +++ b/src/share/classes/com/sun/tools/javac/processing/JavacFiler.java Sun Aug 31 12:00:43 2008 -0700 22.3 @@ -34,18 +34,14 @@ 22.4 import java.util.*; 22.5 22.6 import java.io.Closeable; 22.7 -import java.io.File; 22.8 import java.io.InputStream; 22.9 import java.io.OutputStream; 22.10 -import java.io.OutputStreamWriter; 22.11 import java.io.FilterOutputStream; 22.12 import java.io.Reader; 22.13 import java.io.Writer; 22.14 import java.io.FilterWriter; 22.15 import java.io.PrintWriter; 22.16 import java.io.IOException; 22.17 -import java.net.URI; 22.18 -import javax.tools.FileObject; 22.19 22.20 import javax.tools.*; 22.21 import static java.util.Collections.*;
23.1 --- a/src/share/classes/com/sun/tools/javac/processing/JavacMessager.java Fri Aug 29 12:42:27 2008 -0700 23.2 +++ b/src/share/classes/com/sun/tools/javac/processing/JavacMessager.java Sun Aug 31 12:00:43 2008 -0700 23.3 @@ -27,15 +27,12 @@ 23.4 23.5 import com.sun.tools.javac.model.JavacElements; 23.6 import com.sun.tools.javac.util.*; 23.7 -import com.sun.tools.javac.comp.*; 23.8 import com.sun.tools.javac.tree.JCTree; 23.9 import com.sun.tools.javac.tree.JCTree.*; 23.10 -import com.sun.tools.javac.util.Position; 23.11 import javax.lang.model.element.*; 23.12 import javax.tools.JavaFileObject; 23.13 import javax.tools.Diagnostic; 23.14 import javax.annotation.processing.*; 23.15 -import java.util.*; 23.16 23.17 /** 23.18 * An implementation of the Messager built on top of log.
24.1 --- a/src/share/classes/com/sun/tools/javac/processing/JavacRoundEnvironment.java Fri Aug 29 12:42:27 2008 -0700 24.2 +++ b/src/share/classes/com/sun/tools/javac/processing/JavacRoundEnvironment.java Sun Aug 31 12:00:43 2008 -0700 24.3 @@ -26,8 +26,6 @@ 24.4 package com.sun.tools.javac.processing; 24.5 24.6 import java.lang.annotation.Annotation; 24.7 -import com.sun.tools.javac.util.*; 24.8 -import com.sun.tools.javac.comp.*; 24.9 import com.sun.tools.javac.tree.JCTree.*; 24.10 import javax.annotation.processing.*; 24.11 import javax.lang.model.element.*;
25.1 --- a/src/share/classes/com/sun/tools/javac/processing/PrintingProcessor.java Fri Aug 29 12:42:27 2008 -0700 25.2 +++ b/src/share/classes/com/sun/tools/javac/processing/PrintingProcessor.java Sun Aug 31 12:00:43 2008 -0700 25.3 @@ -32,7 +32,6 @@ 25.4 import static javax.lang.model.element.NestingKind.*; 25.5 import javax.lang.model.type.*; 25.6 import javax.lang.model.util.*; 25.7 -import static javax.lang.model.util.ElementFilter.*; 25.8 25.9 import java.io.PrintWriter; 25.10 import java.io.Writer;
26.1 --- a/src/share/classes/com/sun/tools/javac/processing/ServiceProxy.java Fri Aug 29 12:42:27 2008 -0700 26.2 +++ b/src/share/classes/com/sun/tools/javac/processing/ServiceProxy.java Sun Aug 31 12:00:43 2008 -0700 26.3 @@ -32,10 +32,6 @@ 26.4 import java.io.InputStreamReader; 26.5 import java.net.MalformedURLException; 26.6 import java.net.URL; 26.7 -import java.util.ArrayList; 26.8 -import java.util.Iterator; 26.9 -import java.util.List; 26.10 -import java.util.Set; 26.11 26.12 /** 26.13 * Utility class to determine if a service can be found on the
27.1 --- a/src/share/classes/com/sun/tools/javac/sym/CreateSymbols.java Fri Aug 29 12:42:27 2008 -0700 27.2 +++ b/src/share/classes/com/sun/tools/javac/sym/CreateSymbols.java Sun Aug 31 12:00:43 2008 -0700 27.3 @@ -39,7 +39,6 @@ 27.4 import com.sun.tools.javac.processing.JavacProcessingEnvironment; 27.5 import com.sun.tools.javac.util.List; 27.6 import com.sun.tools.javac.util.Pair; 27.7 -import com.sun.tools.javac.util.Name; 27.8 27.9 import java.io.File; 27.10 import java.io.IOException; 27.11 @@ -47,7 +46,6 @@ 27.12 import java.util.EnumSet; 27.13 import java.util.Enumeration; 27.14 import java.util.HashSet; 27.15 -import java.util.Properties; 27.16 import java.util.ResourceBundle; 27.17 import java.util.Set; 27.18
28.1 --- a/src/share/classes/com/sun/tools/javac/tree/JCTree.java Fri Aug 29 12:42:27 2008 -0700 28.2 +++ b/src/share/classes/com/sun/tools/javac/tree/JCTree.java Sun Aug 31 12:00:43 2008 -0700 28.3 @@ -27,9 +27,7 @@ 28.4 28.5 import java.util.*; 28.6 28.7 -import java.io.File; 28.8 import java.io.IOException; 28.9 -import java.io.PrintWriter; 28.10 import java.io.StringWriter; 28.11 import javax.lang.model.element.Modifier; 28.12 import javax.lang.model.type.TypeKind; 28.13 @@ -41,7 +39,6 @@ 28.14 import com.sun.tools.javac.code.*; 28.15 import com.sun.tools.javac.code.Scope; 28.16 import com.sun.tools.javac.code.Symbol.*; 28.17 -import com.sun.source.tree.Tree; 28.18 import com.sun.source.tree.*; 28.19 28.20 import static com.sun.tools.javac.code.BoundKind.*;
29.1 --- a/src/share/classes/com/sun/tools/javac/tree/TreeCopier.java Fri Aug 29 12:42:27 2008 -0700 29.2 +++ b/src/share/classes/com/sun/tools/javac/tree/TreeCopier.java Sun Aug 31 12:00:43 2008 -0700 29.3 @@ -25,12 +25,10 @@ 29.4 29.5 package com.sun.tools.javac.tree; 29.6 29.7 -import com.sun.source.tree.Tree; 29.8 import com.sun.source.tree.*; 29.9 import com.sun.tools.javac.tree.JCTree.*; 29.10 import com.sun.tools.javac.util.List; 29.11 import com.sun.tools.javac.util.ListBuffer; 29.12 -import java.util.Map; 29.13 29.14 /** 29.15 * Creates a copy of a tree, using a given TreeMaker.
30.1 --- a/src/share/classes/com/sun/tools/javac/tree/TreeInfo.java Fri Aug 29 12:42:27 2008 -0700 30.2 +++ b/src/share/classes/com/sun/tools/javac/tree/TreeInfo.java Sun Aug 31 12:00:43 2008 -0700 30.3 @@ -35,7 +35,6 @@ 30.4 import com.sun.tools.javac.tree.JCTree.*; 30.5 30.6 import static com.sun.tools.javac.code.Flags.*; 30.7 -import com.sun.tools.javac.util.JCDiagnostic.SimpleDiagnosticPosition; 30.8 30.9 /** Utility class containing inspector methods for trees. 30.10 *
31.1 --- a/src/share/classes/com/sun/tools/javac/util/Context.java Fri Aug 29 12:42:27 2008 -0700 31.2 +++ b/src/share/classes/com/sun/tools/javac/util/Context.java Sun Aug 31 12:00:43 2008 -0700 31.3 @@ -25,7 +25,6 @@ 31.4 31.5 package com.sun.tools.javac.util; 31.6 31.7 -import com.sun.tools.javac.Main; 31.8 import java.util.*; 31.9 31.10 /**
32.1 --- a/src/share/classes/com/sun/tools/javadoc/DocletInvoker.java Fri Aug 29 12:42:27 2008 -0700 32.2 +++ b/src/share/classes/com/sun/tools/javadoc/DocletInvoker.java Sun Aug 31 12:00:43 2008 -0700 32.3 @@ -82,6 +82,7 @@ 32.4 cpString = appendPath(System.getProperty("java.class.path"), cpString); 32.5 cpString = appendPath(docletPath, cpString); 32.6 URL[] urls = pathToURLs(cpString); 32.7 + System.err.println("DocletInvoker urls=" + urls); 32.8 appClassLoader = new URLClassLoader(urls); 32.9 32.10 // attempt to find doclet
33.1 --- a/src/share/classes/javax/tools/StandardLocation.java Fri Aug 29 12:42:27 2008 -0700 33.2 +++ b/src/share/classes/javax/tools/StandardLocation.java Sun Aug 31 12:00:43 2008 -0700 33.3 @@ -27,8 +27,6 @@ 33.4 33.5 import javax.tools.JavaFileManager.Location; 33.6 33.7 -import java.io.File; 33.8 -import java.util.*; 33.9 import java.util.concurrent.*; 33.10 33.11 /**
34.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 34.2 +++ b/test/tools/javac/6508981/TestInferBinaryName.java Sun Aug 31 12:00:43 2008 -0700 34.3 @@ -0,0 +1,177 @@ 34.4 +/* 34.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. 34.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 34.7 + * 34.8 + * This code is free software; you can redistribute it and/or modify it 34.9 + * under the terms of the GNU General Public License version 2 only, as 34.10 + * published by the Free Software Foundation. 34.11 + * 34.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 34.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 34.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 34.15 + * version 2 for more details (a copy is included in the LICENSE file that 34.16 + * accompanied this code). 34.17 + * 34.18 + * You should have received a copy of the GNU General Public License version 34.19 + * 2 along with this work; if not, write to the Free Software Foundation, 34.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 34.21 + * 34.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 34.23 + * CA 95054 USA or visit www.sun.com if you need additional information or 34.24 + * have any questions. 34.25 + */ 34.26 + 34.27 +/* 34.28 + * @test 34.29 + * @bug 6508981 34.30 + * @summary cleanup file separator handling in JavacFileManager 34.31 + * (This test is specifically to test the new impl of inferBinaryName) 34.32 + * @build p.A 34.33 + * @run main TestInferBinaryName 34.34 + */ 34.35 + 34.36 +import java.io.*; 34.37 +import java.util.*; 34.38 +import javax.tools.*; 34.39 + 34.40 +import com.sun.tools.javac.file.JavacFileManager; 34.41 +import com.sun.tools.javac.util.Context; 34.42 +import com.sun.tools.javac.util.Options; 34.43 + 34.44 +import static javax.tools.JavaFileObject.Kind.*; 34.45 +import static javax.tools.StandardLocation.*; 34.46 + 34.47 + 34.48 +/** 34.49 + * Verify the various implementations of inferBinaryName, but configuring 34.50 + * different instances of a file manager, getting a file object, and checking 34.51 + * the impl of inferBinaryName for that file object. 34.52 + */ 34.53 +public class TestInferBinaryName { 34.54 + static final boolean IGNORE_SYMBOL_FILE = false; 34.55 + static final boolean USE_SYMBOL_FILE = true; 34.56 + static final boolean DONT_USE_ZIP_FILE_INDEX = false; 34.57 + static final boolean USE_ZIP_FILE_INDEX = true; 34.58 + 34.59 + public static void main(String... args) throws Exception { 34.60 + new TestInferBinaryName().run(); 34.61 + } 34.62 + 34.63 + void run() throws Exception { 34.64 + //System.err.println(System.getProperties()); 34.65 + testDirectory(); 34.66 + testSymbolArchive(); 34.67 + testZipArchive(); 34.68 + testZipFileIndexArchive(); 34.69 + testZipFileIndexArchive2(); 34.70 + if (errors > 0) 34.71 + throw new Exception(errors + " error found"); 34.72 + } 34.73 + 34.74 + void testDirectory() throws IOException { 34.75 + String testClassName = "p.A"; 34.76 + JavaFileManager fm = 34.77 + getFileManager("test.classes", USE_SYMBOL_FILE, USE_ZIP_FILE_INDEX); 34.78 + test("testDirectory", 34.79 + fm, testClassName, "com.sun.tools.javac.file.RegularFileObject"); 34.80 + } 34.81 + 34.82 + void testSymbolArchive() throws IOException { 34.83 + String testClassName = "java.lang.String"; 34.84 + JavaFileManager fm = 34.85 + getFileManager("sun.boot.class.path", USE_SYMBOL_FILE, DONT_USE_ZIP_FILE_INDEX); 34.86 + test("testSymbolArchive", 34.87 + fm, testClassName, "com.sun.tools.javac.file.SymbolArchive$SymbolFileObject"); 34.88 + } 34.89 + 34.90 + void testZipArchive() throws IOException { 34.91 + String testClassName = "java.lang.String"; 34.92 + JavaFileManager fm = 34.93 + getFileManager("sun.boot.class.path", IGNORE_SYMBOL_FILE, DONT_USE_ZIP_FILE_INDEX); 34.94 + test("testZipArchive", 34.95 + fm, testClassName, "com.sun.tools.javac.file.ZipArchive$ZipFileObject"); 34.96 + } 34.97 + 34.98 + void testZipFileIndexArchive() throws IOException { 34.99 + String testClassName = "java.lang.String"; 34.100 + JavaFileManager fm = 34.101 + getFileManager("sun.boot.class.path", USE_SYMBOL_FILE, USE_ZIP_FILE_INDEX); 34.102 + test("testZipFileIndexArchive", 34.103 + fm, testClassName, "com.sun.tools.javac.file.ZipFileIndexArchive$ZipFileIndexFileObject"); 34.104 + } 34.105 + 34.106 + void testZipFileIndexArchive2() throws IOException { 34.107 + String testClassName = "java.lang.String"; 34.108 + JavaFileManager fm = 34.109 + getFileManager("sun.boot.class.path", IGNORE_SYMBOL_FILE, USE_ZIP_FILE_INDEX); 34.110 + test("testZipFileIndexArchive2", 34.111 + fm, testClassName, "com.sun.tools.javac.file.ZipFileIndexArchive$ZipFileIndexFileObject"); 34.112 + } 34.113 + 34.114 + /** 34.115 + * @param testName for debugging 34.116 + * @param fm suitably configured file manager 34.117 + * @param testClassName the classname to test 34.118 + * @param implClassName the expected classname of the JavaFileObject impl, 34.119 + * used for checking that we are checking the expected impl of 34.120 + * inferBinaryName 34.121 + */ 34.122 + void test(String testName, 34.123 + JavaFileManager fm, String testClassName, String implClassName) throws IOException { 34.124 + JavaFileObject fo = fm.getJavaFileForInput(CLASS_PATH, testClassName, CLASS); 34.125 + if (fo == null) { 34.126 + System.err.println("Can't find " + testClassName); 34.127 + errors++; 34.128 + return; 34.129 + } 34.130 + 34.131 + String cn = fo.getClass().getName(); 34.132 + String bn = fm.inferBinaryName(CLASS_PATH, fo); 34.133 + System.err.println(testName + " " + cn + " " + bn); 34.134 + check(cn, implClassName); 34.135 + check(bn, testClassName); 34.136 + System.err.println("OK"); 34.137 + } 34.138 + 34.139 + JavaFileManager getFileManager(String classpathProperty, 34.140 + boolean symFileKind, 34.141 + boolean zipFileIndexKind) 34.142 + throws IOException { 34.143 + Context ctx = new Context(); 34.144 + // uugh, ugly back door, should be cleaned up, someday 34.145 + if (zipFileIndexKind == USE_ZIP_FILE_INDEX) 34.146 + System.clearProperty("useJavaUtilZip"); 34.147 + else 34.148 + System.setProperty("useJavaUtilZip", "true"); 34.149 + Options options = Options.instance(ctx); 34.150 + if (symFileKind == IGNORE_SYMBOL_FILE) 34.151 + options.put("ignore.symbol.file", "true"); 34.152 + JavacFileManager fm = new JavacFileManager(ctx, false, null); 34.153 + List<File> path = getPath(System.getProperty(classpathProperty)); 34.154 + fm.setLocation(CLASS_PATH, path); 34.155 + return fm; 34.156 + } 34.157 + 34.158 + List<File> getPath(String s) { 34.159 + List<File> path = new ArrayList<File>(); 34.160 + for (String f: s.split(File.pathSeparator)) { 34.161 + if (f.length() > 0) 34.162 + path.add(new File(f)); 34.163 + } 34.164 + //System.err.println("path: " + path); 34.165 + return path; 34.166 + } 34.167 + 34.168 + void check(String found, String expect) { 34.169 + if (!found.equals(expect)) { 34.170 + System.err.println("Expected: " + expect); 34.171 + System.err.println(" Found: " + found); 34.172 + errors++; 34.173 + } 34.174 + } 34.175 + 34.176 + private int errors; 34.177 +} 34.178 + 34.179 +class A { } 34.180 +
35.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 35.2 +++ b/test/tools/javac/6508981/p/A.java Sun Aug 31 12:00:43 2008 -0700 35.3 @@ -0,0 +1,24 @@ 35.4 +/* 35.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. 35.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 35.7 + * 35.8 + * This code is free software; you can redistribute it and/or modify it 35.9 + * under the terms of the GNU General Public License version 2 only, as 35.10 + * published by the Free Software Foundation. 35.11 + * 35.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 35.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 35.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 35.15 + * version 2 for more details (a copy is included in the LICENSE file that 35.16 + * accompanied this code). 35.17 + * 35.18 + * You should have received a copy of the GNU General Public License version 35.19 + * 2 along with this work; if not, write to the Free Software Foundation, 35.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 35.21 + * 35.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 35.23 + * CA 95054 USA or visit www.sun.com if you need additional information or 35.24 + * have any questions. 35.25 + */ 35.26 +package p; 35.27 +class A { }
36.1 --- a/test/tools/javac/T6725036.java Fri Aug 29 12:42:27 2008 -0700 36.2 +++ b/test/tools/javac/T6725036.java Sun Aug 31 12:00:43 2008 -0700 36.3 @@ -35,6 +35,7 @@ 36.4 import javax.tools.JavaFileObject; 36.5 36.6 import com.sun.tools.javac.file.JavacFileManager; 36.7 +import com.sun.tools.javac.file.RelativePath.RelativeFile; 36.8 import com.sun.tools.javac.file.ZipFileIndex; 36.9 import com.sun.tools.javac.file.ZipFileIndexArchive; 36.10 import com.sun.tools.javac.util.Context; 36.11 @@ -45,7 +46,7 @@ 36.12 } 36.13 36.14 void run() throws Exception { 36.15 - String TEST_ENTRY_NAME = "java/lang/String.class"; 36.16 + RelativeFile TEST_ENTRY_NAME = new RelativeFile("java/lang/String.class"); 36.17 36.18 File f = new File(System.getProperty("java.home")); 36.19 if (!f.getName().equals("jre")) 36.20 @@ -53,22 +54,21 @@ 36.21 File rt_jar = new File(new File(f, "lib"), "rt.jar"); 36.22 36.23 JarFile j = new JarFile(rt_jar); 36.24 - JarEntry je = j.getJarEntry(TEST_ENTRY_NAME); 36.25 + JarEntry je = j.getJarEntry(TEST_ENTRY_NAME.getPath()); 36.26 long jarEntryTime = je.getTime(); 36.27 36.28 ZipFileIndex zfi = 36.29 ZipFileIndex.getZipFileIndex(rt_jar, null, false, null, false); 36.30 long zfiTime = zfi.getLastModified(TEST_ENTRY_NAME); 36.31 36.32 - check(je, jarEntryTime, zfi + ":" + TEST_ENTRY_NAME, zfiTime); 36.33 + check(je, jarEntryTime, zfi + ":" + TEST_ENTRY_NAME.getPath(), zfiTime); 36.34 36.35 Context context = new Context(); 36.36 JavacFileManager fm = new JavacFileManager(context, false, null); 36.37 ZipFileIndexArchive zfia = new ZipFileIndexArchive(fm, zfi); 36.38 - int sep = TEST_ENTRY_NAME.lastIndexOf("/"); 36.39 JavaFileObject jfo = 36.40 - zfia.getFileObject(TEST_ENTRY_NAME.substring(0, sep + 1), 36.41 - TEST_ENTRY_NAME.substring(sep + 1)); 36.42 + zfia.getFileObject(TEST_ENTRY_NAME.dirname(), 36.43 + TEST_ENTRY_NAME.basename()); 36.44 long jfoTime = jfo.getLastModified(); 36.45 36.46 check(je, jarEntryTime, jfo, jfoTime);