src/share/classes/com/sun/tools/javac/file/SymbolArchive.java

Wed, 23 Sep 2009 18:48:13 -0700

author
jjg
date
Wed, 23 Sep 2009 18:48:13 -0700
changeset 415
49359d0e6a9c
parent 400
35e29f51a7c3
child 418
4776a869fdfa
permissions
-rw-r--r--

6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
6747645: ZipFileObject.getName is incorrectly deprecated
6885123: JavaFileObject getName issues
Reviewed-by: mcimadamore

jjg@57 1 /*
jjg@57 2 * Copyright 2005-2008 Sun Microsystems, Inc. All Rights Reserved.
jjg@57 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
jjg@57 4 *
jjg@57 5 * This code is free software; you can redistribute it and/or modify it
jjg@57 6 * under the terms of the GNU General Public License version 2 only, as
jjg@57 7 * published by the Free Software Foundation. Sun designates this
jjg@57 8 * particular file as subject to the "Classpath" exception as provided
jjg@57 9 * by Sun in the LICENSE file that accompanied this code.
jjg@57 10 *
jjg@57 11 * This code is distributed in the hope that it will be useful, but WITHOUT
jjg@57 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
jjg@57 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
jjg@57 14 * version 2 for more details (a copy is included in the LICENSE file that
jjg@57 15 * accompanied this code).
jjg@57 16 *
jjg@57 17 * You should have received a copy of the GNU General Public License version
jjg@57 18 * 2 along with this work; if not, write to the Free Software Foundation,
jjg@57 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
jjg@57 20 *
jjg@57 21 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
jjg@57 22 * CA 95054 USA or visit www.sun.com if you need additional information or
jjg@57 23 * have any questions.
jjg@57 24 */
jjg@57 25
jjg@57 26 package com.sun.tools.javac.file;
jjg@57 27
jjg@57 28 import java.io.File;
jjg@57 29 import java.io.IOException;
jjg@57 30 import java.util.zip.ZipEntry;
jjg@57 31 import java.util.zip.ZipFile;
jjg@57 32 import javax.tools.JavaFileObject;
jjg@57 33
jjg@103 34 import com.sun.tools.javac.file.RelativePath.RelativeDirectory;
jjg@103 35 import com.sun.tools.javac.file.RelativePath.RelativeFile;
jjg@103 36 import com.sun.tools.javac.util.List;
jjg@103 37
jjg@333 38 /**
jjg@333 39 * <p><b>This is NOT part of any API supported by Sun Microsystems.
jjg@333 40 * If you write code that depends on this, you do so at your own risk.
jjg@333 41 * This code and its internal interfaces are subject to change or
jjg@333 42 * deletion without notice.</b>
jjg@333 43 */
jjg@57 44 public class SymbolArchive extends ZipArchive {
jjg@57 45
jjg@57 46 final File origFile;
jjg@103 47 final RelativeDirectory prefix;
jjg@57 48
jjg@103 49 public SymbolArchive(JavacFileManager fileManager, File orig, ZipFile zdir, RelativeDirectory prefix) throws IOException {
jjg@103 50 super(fileManager, zdir, false);
jjg@57 51 this.origFile = orig;
jjg@57 52 this.prefix = prefix;
jjg@103 53 initMap();
jjg@57 54 }
jjg@57 55
jjg@57 56 @Override
jjg@57 57 void addZipEntry(ZipEntry entry) {
jjg@57 58 String name = entry.getName();
jjg@103 59 if (!name.startsWith(prefix.path)) {
jjg@57 60 return;
jjg@57 61 }
jjg@103 62 name = name.substring(prefix.path.length());
jjg@57 63 int i = name.lastIndexOf('/');
jjg@103 64 RelativeDirectory dirname = new RelativeDirectory(name.substring(0, i+1));
jjg@57 65 String basename = name.substring(i + 1);
jjg@57 66 if (basename.length() == 0) {
jjg@57 67 return;
jjg@57 68 }
jjg@57 69 List<String> list = map.get(dirname);
jjg@103 70 if (list == null)
jjg@57 71 list = List.nil();
jjg@57 72 list = list.prepend(basename);
jjg@57 73 map.put(dirname, list);
jjg@57 74 }
jjg@57 75
jjg@400 76 @Override
jjg@103 77 public JavaFileObject getFileObject(RelativeDirectory subdirectory, String file) {
jjg@103 78 RelativeDirectory prefix_subdir = new RelativeDirectory(prefix, subdirectory.path);
jjg@103 79 ZipEntry ze = new RelativeFile(prefix_subdir, file).getZipEntry(zdir);
jjg@103 80 return new SymbolFileObject(this, file, ze);
jjg@57 81 }
jjg@103 82
jjg@400 83 @Override
jjg@103 84 public String toString() {
jjg@103 85 return "SymbolArchive[" + zdir.getName() + "]";
jjg@103 86 }
jjg@103 87
jjg@103 88 /**
jjg@103 89 * A subclass of JavaFileObject representing zip entries in a symbol file.
jjg@103 90 */
jjg@103 91 public static class SymbolFileObject extends ZipFileObject {
jjg@103 92 protected SymbolFileObject(SymbolArchive zarch, String name, ZipEntry entry) {
jjg@103 93 super(zarch, name, entry);
jjg@103 94 }
jjg@103 95
jjg@103 96 @Override
jjg@103 97 protected String inferBinaryName(Iterable<? extends File> path) {
jjg@415 98 String entryName = entry.getName();
jjg@103 99 String prefix = ((SymbolArchive) zarch).prefix.path;
jjg@103 100 if (entryName.startsWith(prefix))
jjg@103 101 entryName = entryName.substring(prefix.length());
jjg@103 102 return removeExtension(entryName).replace('/', '.');
jjg@103 103 }
jjg@103 104 }
jjg@103 105
jjg@103 106
jjg@57 107 }

mercurial