author | mchung |
Fri, 20 Jun 2014 13:36:10 -0700 | |
changeset 25303 | 5f9e68207588 |
parent 5847 | 1908176fd6e3 |
permissions | -rw-r--r-- |
810
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
1 |
/* |
5520 | 2 |
* Copyright (c) 2005, 2009, Oracle and/or its affiliates. All rights reserved. |
810
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
4 |
* |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
5520 | 7 |
* published by the Free Software Foundation. Oracle designates this |
810
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
8 |
* particular file as subject to the "Classpath" exception as provided |
5520 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
810
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
10 |
* |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
15 |
* accompanied this code). |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
16 |
* |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
17 |
* You should have received a copy of the GNU General Public License version |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
20 |
* |
5520 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
810
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
24 |
*/ |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
25 |
|
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
26 |
package com.sun.tools.javac.file; |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
27 |
|
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
28 |
import java.io.File; |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
29 |
import java.io.IOException; |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
30 |
import java.util.zip.ZipEntry; |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
31 |
import java.util.zip.ZipFile; |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
32 |
import javax.tools.JavaFileObject; |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
33 |
|
1205
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
810
diff
changeset
|
34 |
import com.sun.tools.javac.file.RelativePath.RelativeDirectory; |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
810
diff
changeset
|
35 |
import com.sun.tools.javac.file.RelativePath.RelativeFile; |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
810
diff
changeset
|
36 |
import com.sun.tools.javac.util.List; |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
810
diff
changeset
|
37 |
|
3380
a6c2bcab0fec
6865399: some javac files are missing Sun internal API comment
jjg
parents:
1205
diff
changeset
|
38 |
/** |
5847
1908176fd6e3
6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents:
5520
diff
changeset
|
39 |
* <p><b>This is NOT part of any supported API. |
3380
a6c2bcab0fec
6865399: some javac files are missing Sun internal API comment
jjg
parents:
1205
diff
changeset
|
40 |
* If you write code that depends on this, you do so at your own risk. |
a6c2bcab0fec
6865399: some javac files are missing Sun internal API comment
jjg
parents:
1205
diff
changeset
|
41 |
* This code and its internal interfaces are subject to change or |
a6c2bcab0fec
6865399: some javac files are missing Sun internal API comment
jjg
parents:
1205
diff
changeset
|
42 |
* deletion without notice.</b> |
a6c2bcab0fec
6865399: some javac files are missing Sun internal API comment
jjg
parents:
1205
diff
changeset
|
43 |
*/ |
810
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
44 |
public class SymbolArchive extends ZipArchive { |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
45 |
|
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
46 |
final File origFile; |
1205
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
810
diff
changeset
|
47 |
final RelativeDirectory prefix; |
810
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
48 |
|
1205
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
810
diff
changeset
|
49 |
public SymbolArchive(JavacFileManager fileManager, File orig, ZipFile zdir, RelativeDirectory prefix) throws IOException { |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
810
diff
changeset
|
50 |
super(fileManager, zdir, false); |
810
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
51 |
this.origFile = orig; |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
52 |
this.prefix = prefix; |
1205
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
810
diff
changeset
|
53 |
initMap(); |
810
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
54 |
} |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
55 |
|
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
56 |
@Override |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
57 |
void addZipEntry(ZipEntry entry) { |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
58 |
String name = entry.getName(); |
1205
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
810
diff
changeset
|
59 |
if (!name.startsWith(prefix.path)) { |
810
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
60 |
return; |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
61 |
} |
1205
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
810
diff
changeset
|
62 |
name = name.substring(prefix.path.length()); |
810
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
63 |
int i = name.lastIndexOf('/'); |
1205
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
810
diff
changeset
|
64 |
RelativeDirectory dirname = new RelativeDirectory(name.substring(0, i+1)); |
810
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
65 |
String basename = name.substring(i + 1); |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
66 |
if (basename.length() == 0) { |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
67 |
return; |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
68 |
} |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
69 |
List<String> list = map.get(dirname); |
1205
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
810
diff
changeset
|
70 |
if (list == null) |
810
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
71 |
list = List.nil(); |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
72 |
list = list.prepend(basename); |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
73 |
map.put(dirname, list); |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
74 |
} |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
75 |
|
3782 | 76 |
@Override |
1205
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
810
diff
changeset
|
77 |
public JavaFileObject getFileObject(RelativeDirectory subdirectory, String file) { |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
810
diff
changeset
|
78 |
RelativeDirectory prefix_subdir = new RelativeDirectory(prefix, subdirectory.path); |
4073
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
3998
diff
changeset
|
79 |
ZipEntry ze = new RelativeFile(prefix_subdir, file).getZipEntry(zfile); |
1205
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
810
diff
changeset
|
80 |
return new SymbolFileObject(this, file, ze); |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
810
diff
changeset
|
81 |
} |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
810
diff
changeset
|
82 |
|
3782 | 83 |
@Override |
1205
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
810
diff
changeset
|
84 |
public String toString() { |
4073
9788f4549740
6838467: JSR199 FileObjects don't obey general contract of equals.
jjg
parents:
3998
diff
changeset
|
85 |
return "SymbolArchive[" + zfile.getName() + "]"; |
810
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
86 |
} |
1205
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
810
diff
changeset
|
87 |
|
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
810
diff
changeset
|
88 |
/** |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
810
diff
changeset
|
89 |
* A subclass of JavaFileObject representing zip entries in a symbol file. |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
810
diff
changeset
|
90 |
*/ |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
810
diff
changeset
|
91 |
public static class SymbolFileObject extends ZipFileObject { |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
810
diff
changeset
|
92 |
protected SymbolFileObject(SymbolArchive zarch, String name, ZipEntry entry) { |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
810
diff
changeset
|
93 |
super(zarch, name, entry); |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
810
diff
changeset
|
94 |
} |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
810
diff
changeset
|
95 |
|
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
810
diff
changeset
|
96 |
@Override |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
810
diff
changeset
|
97 |
protected String inferBinaryName(Iterable<? extends File> path) { |
3995
73af8b6fb8bc
6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents:
3782
diff
changeset
|
98 |
String entryName = entry.getName(); |
1205
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
810
diff
changeset
|
99 |
String prefix = ((SymbolArchive) zarch).prefix.path; |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
810
diff
changeset
|
100 |
if (entryName.startsWith(prefix)) |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
810
diff
changeset
|
101 |
entryName = entryName.substring(prefix.length()); |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
810
diff
changeset
|
102 |
return removeExtension(entryName).replace('/', '.'); |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
810
diff
changeset
|
103 |
} |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
810
diff
changeset
|
104 |
} |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
810
diff
changeset
|
105 |
|
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
810
diff
changeset
|
106 |
|
810
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
diff
changeset
|
107 |
} |