author | mchung |
Fri, 20 Jun 2014 13:36:10 -0700 | |
changeset 25303 | 5f9e68207588 |
parent 5847 | 1908176fd6e3 |
permissions | -rw-r--r-- |
1205
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
1 |
/* |
5520 | 2 |
* Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved. |
1205
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
4 |
* |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
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 |
1205
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
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. |
1205
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
10 |
* |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
15 |
* accompanied this code). |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
16 |
* |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
17 |
* You should have received a copy of the GNU General Public License version |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
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. |
|
1205
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
24 |
*/ |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
25 |
|
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
26 |
package com.sun.tools.javac.file; |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
27 |
|
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
28 |
import java.io.File; |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
29 |
import java.util.zip.ZipEntry; |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
30 |
import java.util.zip.ZipFile; |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
31 |
import javax.tools.JavaFileObject; |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
32 |
|
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
33 |
/** |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
34 |
* Used to represent a platform-neutral path within a platform-specific |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
35 |
* container, such as a directory or zip file. |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
36 |
* Internally, the file separator is always '/'. |
3380
a6c2bcab0fec
6865399: some javac files are missing Sun internal API comment
jjg
parents:
1205
diff
changeset
|
37 |
* |
5847
1908176fd6e3
6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents:
5520
diff
changeset
|
38 |
* <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
|
39 |
* 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
|
40 |
* 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
|
41 |
* deletion without notice.</b> |
1205
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
42 |
*/ |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
43 |
public abstract class RelativePath implements Comparable<RelativePath> { |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
44 |
/** |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
45 |
* @param p must use '/' as an internal separator |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
46 |
*/ |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
47 |
protected RelativePath(String p) { |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
48 |
path = p; |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
49 |
} |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
50 |
|
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
51 |
public abstract RelativeDirectory dirname(); |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
52 |
|
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
53 |
public abstract String basename(); |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
54 |
|
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
55 |
public File getFile(File directory) { |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
56 |
if (path.length() == 0) |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
57 |
return directory; |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
58 |
return new File(directory, path.replace('/', File.separatorChar)); |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
59 |
} |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
60 |
|
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
61 |
public int compareTo(RelativePath other) { |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
62 |
return path.compareTo(other.path); |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
63 |
} |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
64 |
|
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
65 |
@Override |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
66 |
public boolean equals(Object other) { |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
67 |
if (!(other instanceof RelativePath)) |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
68 |
return false; |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
69 |
return path.equals(((RelativePath) other).path); |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
70 |
} |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
71 |
|
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
72 |
@Override |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
73 |
public int hashCode() { |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
74 |
return path.hashCode(); |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
75 |
} |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
76 |
|
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
77 |
@Override |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
78 |
public String toString() { |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
79 |
return "RelPath[" + path + "]"; |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
80 |
} |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
81 |
|
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
82 |
public String getPath() { |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
83 |
return path; |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
84 |
} |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
85 |
|
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
86 |
protected final String path; |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
87 |
|
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
88 |
/** |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
89 |
* Used to represent a platform-neutral subdirectory within a platform-specific |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
90 |
* container, such as a directory or zip file. |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
91 |
* Internally, the file separator is always '/', and if the path is not empty, |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
92 |
* it always ends in a '/' as well. |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
93 |
*/ |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
94 |
public static class RelativeDirectory extends RelativePath { |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
95 |
|
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
96 |
static RelativeDirectory forPackage(CharSequence packageName) { |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
97 |
return new RelativeDirectory(packageName.toString().replace('.', '/')); |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
98 |
} |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
99 |
|
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
100 |
/** |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
101 |
* @param p must use '/' as an internal separator |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
102 |
*/ |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
103 |
public RelativeDirectory(String p) { |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
104 |
super(p.length() == 0 || p.endsWith("/") ? p : p + "/"); |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
105 |
} |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
106 |
|
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
107 |
/** |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
108 |
* @param p must use '/' as an internal separator |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
109 |
*/ |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
110 |
public RelativeDirectory(RelativeDirectory d, String p) { |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
111 |
this(d.path + p); |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
112 |
} |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
113 |
|
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
114 |
@Override |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
115 |
public RelativeDirectory dirname() { |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
116 |
int l = path.length(); |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
117 |
if (l == 0) |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
118 |
return this; |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
119 |
int sep = path.lastIndexOf('/', l - 2); |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
120 |
return new RelativeDirectory(path.substring(0, sep + 1)); |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
121 |
} |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
122 |
|
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
123 |
@Override |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
124 |
public String basename() { |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
125 |
int l = path.length(); |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
126 |
if (l == 0) |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
127 |
return path; |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
128 |
int sep = path.lastIndexOf('/', l - 2); |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
129 |
return path.substring(sep + 1, l - 1); |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
130 |
} |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
131 |
|
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
132 |
/** |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
133 |
* Return true if this subdirectory "contains" the other path. |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
134 |
* A subdirectory path does not contain itself. |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
135 |
**/ |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
136 |
boolean contains(RelativePath other) { |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
137 |
return other.path.length() > path.length() && other.path.startsWith(path); |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
138 |
} |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
139 |
|
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
140 |
@Override |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
141 |
public String toString() { |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
142 |
return "RelativeDirectory[" + path + "]"; |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
143 |
} |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
144 |
} |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
145 |
|
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
146 |
/** |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
147 |
* Used to represent a platform-neutral file within a platform-specific |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
148 |
* container, such as a directory or zip file. |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
149 |
* Internally, the file separator is always '/'. It never ends in '/'. |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
150 |
*/ |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
151 |
public static class RelativeFile extends RelativePath { |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
152 |
static RelativeFile forClass(CharSequence className, JavaFileObject.Kind kind) { |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
153 |
return new RelativeFile(className.toString().replace('.', '/') + kind.extension); |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
154 |
} |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
155 |
|
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
156 |
public RelativeFile(String p) { |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
157 |
super(p); |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
158 |
if (p.endsWith("/")) |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
159 |
throw new IllegalArgumentException(p); |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
160 |
} |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
161 |
|
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
162 |
/** |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
163 |
* @param p must use '/' as an internal separator |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
164 |
*/ |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
165 |
public RelativeFile(RelativeDirectory d, String p) { |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
166 |
this(d.path + p); |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
167 |
} |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
168 |
|
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
169 |
RelativeFile(RelativeDirectory d, RelativePath p) { |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
170 |
this(d, p.path); |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
171 |
} |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
172 |
|
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
173 |
@Override |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
174 |
public RelativeDirectory dirname() { |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
175 |
int sep = path.lastIndexOf('/'); |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
176 |
return new RelativeDirectory(path.substring(0, sep + 1)); |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
177 |
} |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
178 |
|
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
179 |
@Override |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
180 |
public String basename() { |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
181 |
int sep = path.lastIndexOf('/'); |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
182 |
return path.substring(sep + 1); |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
183 |
} |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
184 |
|
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
185 |
ZipEntry getZipEntry(ZipFile zip) { |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
186 |
return zip.getEntry(path); |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
187 |
} |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
188 |
|
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
189 |
@Override |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
190 |
public String toString() { |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
191 |
return "RelativeFile[" + path + "]"; |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
192 |
} |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
193 |
|
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
194 |
} |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
195 |
|
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
diff
changeset
|
196 |
} |