|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| |
|
16 |
| |
|
17 |
| |
|
18 |
| |
|
19 |
| |
|
20 |
| |
|
21 |
| |
|
22 |
| |
|
23 |
| |
|
24 |
| |
|
25 |
| |
|
26 |
| |
|
27 |
| |
|
28 |
| |
|
29 |
| |
|
30 |
| |
|
31 |
| |
|
32 |
| |
|
33 |
| |
|
34 |
| |
|
35 |
| |
|
36 |
| |
|
37 |
| package edu.rice.cs.drjava.model; |
|
38 |
| |
|
39 |
| import java.io.File; |
|
40 |
| import java.util.Set; |
|
41 |
| import java.util.HashSet; |
|
42 |
| import edu.rice.cs.drjava.DrJava; |
|
43 |
| import edu.rice.cs.drjava.config.OptionConstants; |
|
44 |
| import edu.rice.cs.plt.io.IOUtil; |
|
45 |
| |
|
46 |
| |
|
47 |
| |
|
48 |
| |
|
49 |
| public class DrJavaFileUtils { |
|
50 |
| |
|
51 |
| |
|
52 |
0
| public static Set<String> getSourceFileExtensions() {
|
|
53 |
0
| HashSet<String> extensions = new HashSet<String>();
|
|
54 |
0
| extensions.add(OptionConstants.JAVA_FILE_EXTENSION);
|
|
55 |
0
| extensions.add(OptionConstants.DJ_FILE_EXTENSION);
|
|
56 |
0
| extensions.add(OptionConstants.OLD_DJ0_FILE_EXTENSION);
|
|
57 |
0
| extensions.add(OptionConstants.OLD_DJ1_FILE_EXTENSION);
|
|
58 |
0
| extensions.add(OptionConstants.OLD_DJ2_FILE_EXTENSION);
|
|
59 |
0
| return extensions;
|
|
60 |
| } |
|
61 |
| |
|
62 |
| |
|
63 |
| |
|
64 |
0
| public static String getSuggestedFileExtension() {
|
|
65 |
0
| return OptionConstants.LANGUAGE_LEVEL_EXTENSIONS[DrJava.getConfig().getSetting(OptionConstants.LANGUAGE_LEVEL)];
|
|
66 |
| } |
|
67 |
| |
|
68 |
| |
|
69 |
| |
|
70 |
| |
|
71 |
| |
|
72 |
| |
|
73 |
| |
|
74 |
| |
|
75 |
| |
|
76 |
923
| public static boolean isSourceFile(String fileName) {
|
|
77 |
923
| return fileName.endsWith(OptionConstants.JAVA_FILE_EXTENSION)
|
|
78 |
| || fileName.endsWith(OptionConstants.DJ_FILE_EXTENSION) |
|
79 |
| || fileName.endsWith(OptionConstants.OLD_DJ0_FILE_EXTENSION) |
|
80 |
| || fileName.endsWith(OptionConstants.OLD_DJ1_FILE_EXTENSION) |
|
81 |
| || fileName.endsWith(OptionConstants.OLD_DJ2_FILE_EXTENSION); |
|
82 |
| } |
|
83 |
| |
|
84 |
| |
|
85 |
103
| public static boolean isSourceFile(File f) {
|
|
86 |
103
| File canonicalFile = IOUtil.attemptCanonicalFile(f);
|
|
87 |
103
| String fileName = canonicalFile.getPath();
|
|
88 |
103
| return isSourceFile(fileName);
|
|
89 |
| } |
|
90 |
| |
|
91 |
| |
|
92 |
| |
|
93 |
| |
|
94 |
| |
|
95 |
| |
|
96 |
| |
|
97 |
5996
| public static boolean isLLFile(String fileName) {
|
|
98 |
5999
| return fileName.endsWith(OptionConstants.DJ_FILE_EXTENSION)
|
|
99 |
| || fileName.endsWith(OptionConstants.OLD_DJ0_FILE_EXTENSION) |
|
100 |
| || fileName.endsWith(OptionConstants.OLD_DJ1_FILE_EXTENSION) |
|
101 |
| || fileName.endsWith(OptionConstants.OLD_DJ2_FILE_EXTENSION); |
|
102 |
| } |
|
103 |
| |
|
104 |
| |
|
105 |
13
| public static boolean isLLFile(File f) {
|
|
106 |
13
| File canonicalFile = IOUtil.attemptCanonicalFile(f);
|
|
107 |
13
| String fileName = canonicalFile.getPath();
|
|
108 |
13
| return isLLFile(fileName);
|
|
109 |
| } |
|
110 |
| |
|
111 |
| |
|
112 |
| |
|
113 |
| |
|
114 |
| |
|
115 |
| |
|
116 |
9
| public static boolean isOldLLFile(String fileName) {
|
|
117 |
9
| return fileName.endsWith(OptionConstants.OLD_DJ0_FILE_EXTENSION)
|
|
118 |
| || fileName.endsWith(OptionConstants.OLD_DJ1_FILE_EXTENSION) |
|
119 |
| || fileName.endsWith(OptionConstants.OLD_DJ2_FILE_EXTENSION); |
|
120 |
| } |
|
121 |
| |
|
122 |
| |
|
123 |
9
| public static boolean isOldLLFile(File f) {
|
|
124 |
9
| File canonicalFile = IOUtil.attemptCanonicalFile(f);
|
|
125 |
9
| String fileName = canonicalFile.getPath();
|
|
126 |
9
| return isOldLLFile(fileName);
|
|
127 |
| } |
|
128 |
| |
|
129 |
| |
|
130 |
| |
|
131 |
| |
|
132 |
0
| public static boolean isOldProjectFile(String fileName) {
|
|
133 |
0
| return fileName.endsWith(OptionConstants.OLD_PROJECT_FILE_EXTENSION);
|
|
134 |
| } |
|
135 |
| |
|
136 |
| |
|
137 |
0
| public static boolean isOldProjectFile(File f) {
|
|
138 |
0
| File canonicalFile = IOUtil.attemptCanonicalFile(f);
|
|
139 |
0
| String fileName = canonicalFile.getPath();
|
|
140 |
0
| return isOldProjectFile(fileName);
|
|
141 |
| } |
|
142 |
| |
|
143 |
| |
|
144 |
| |
|
145 |
| |
|
146 |
| |
|
147 |
| |
|
148 |
0
| public static boolean isProjectFile(String fileName) {
|
|
149 |
0
| return fileName.endsWith(OptionConstants.PROJECT_FILE_EXTENSION)
|
|
150 |
| || fileName.endsWith(OptionConstants.PROJECT_FILE_EXTENSION2) |
|
151 |
| || fileName.endsWith(OptionConstants.OLD_PROJECT_FILE_EXTENSION); |
|
152 |
| } |
|
153 |
| |
|
154 |
| |
|
155 |
0
| public static boolean isProjectFile(File f) {
|
|
156 |
0
| File canonicalFile = IOUtil.attemptCanonicalFile(f);
|
|
157 |
0
| String fileName = canonicalFile.getPath();
|
|
158 |
0
| return isProjectFile(fileName);
|
|
159 |
| } |
|
160 |
| |
|
161 |
| |
|
162 |
| |
|
163 |
| |
|
164 |
| |
|
165 |
| |
|
166 |
| |
|
167 |
0
| public static String getJavaForLLFile(String fileName) {
|
|
168 |
0
| if (fileName.endsWith(OptionConstants.DJ_FILE_EXTENSION)) {
|
|
169 |
0
| return fileName.substring(0, fileName.lastIndexOf(OptionConstants.DJ_FILE_EXTENSION))
|
|
170 |
| + OptionConstants.JAVA_FILE_EXTENSION; |
|
171 |
| } |
|
172 |
0
| else if (fileName.endsWith(OptionConstants.OLD_DJ0_FILE_EXTENSION)) {
|
|
173 |
0
| return fileName.substring(0, fileName.lastIndexOf(OptionConstants.OLD_DJ0_FILE_EXTENSION))
|
|
174 |
| + OptionConstants.JAVA_FILE_EXTENSION; |
|
175 |
| } |
|
176 |
0
| else if (fileName.endsWith(OptionConstants.OLD_DJ1_FILE_EXTENSION)) {
|
|
177 |
0
| return fileName.substring(0, fileName.lastIndexOf(OptionConstants.OLD_DJ1_FILE_EXTENSION))
|
|
178 |
| + OptionConstants.JAVA_FILE_EXTENSION; |
|
179 |
| } |
|
180 |
0
| else if (fileName.endsWith(OptionConstants.OLD_DJ2_FILE_EXTENSION)) {
|
|
181 |
0
| return fileName.substring(0, fileName.lastIndexOf(OptionConstants.OLD_DJ2_FILE_EXTENSION))
|
|
182 |
| + OptionConstants.JAVA_FILE_EXTENSION; |
|
183 |
| } |
|
184 |
0
| else return fileName;
|
|
185 |
| } |
|
186 |
| |
|
187 |
| |
|
188 |
0
| public static File getJavaForLLFile(File f) {
|
|
189 |
0
| File canonicalFile = IOUtil.attemptCanonicalFile(f);
|
|
190 |
0
| String fileName = canonicalFile.getPath();
|
|
191 |
0
| return new File(getJavaForLLFile(fileName));
|
|
192 |
| } |
|
193 |
| |
|
194 |
| |
|
195 |
| |
|
196 |
| |
|
197 |
0
| public static File getDJForJavaFile(File f) {
|
|
198 |
0
| return getFileWithDifferentExt(f, OptionConstants.JAVA_FILE_EXTENSION, OptionConstants.DJ_FILE_EXTENSION);
|
|
199 |
| } |
|
200 |
| |
|
201 |
| |
|
202 |
| |
|
203 |
| |
|
204 |
0
| public static File getDJ0ForJavaFile(File f) {
|
|
205 |
0
| return getFileWithDifferentExt(f, OptionConstants.JAVA_FILE_EXTENSION, OptionConstants.OLD_DJ0_FILE_EXTENSION);
|
|
206 |
| } |
|
207 |
| |
|
208 |
| |
|
209 |
| |
|
210 |
| |
|
211 |
0
| public static File getDJ1ForJavaFile(File f) {
|
|
212 |
0
| return getFileWithDifferentExt(f, OptionConstants.JAVA_FILE_EXTENSION, OptionConstants.OLD_DJ1_FILE_EXTENSION);
|
|
213 |
| } |
|
214 |
| |
|
215 |
| |
|
216 |
| |
|
217 |
| |
|
218 |
1
| public static File getDJ2ForJavaFile(File f) {
|
|
219 |
1
| return getFileWithDifferentExt(f, OptionConstants.JAVA_FILE_EXTENSION, OptionConstants.OLD_DJ2_FILE_EXTENSION);
|
|
220 |
| } |
|
221 |
| |
|
222 |
| |
|
223 |
| |
|
224 |
| |
|
225 |
312
| public static String getDJForJavaFile(String f) {
|
|
226 |
312
| return getFileWithDifferentExt(f, OptionConstants.JAVA_FILE_EXTENSION, OptionConstants.DJ_FILE_EXTENSION);
|
|
227 |
| } |
|
228 |
| |
|
229 |
| |
|
230 |
| |
|
231 |
| |
|
232 |
312
| public static String getDJ0ForJavaFile(String f) {
|
|
233 |
312
| return getFileWithDifferentExt(f, OptionConstants.JAVA_FILE_EXTENSION, OptionConstants.OLD_DJ0_FILE_EXTENSION);
|
|
234 |
| } |
|
235 |
| |
|
236 |
| |
|
237 |
| |
|
238 |
| |
|
239 |
312
| public static String getDJ1ForJavaFile(String f) {
|
|
240 |
312
| return getFileWithDifferentExt(f, OptionConstants.JAVA_FILE_EXTENSION, OptionConstants.OLD_DJ1_FILE_EXTENSION);
|
|
241 |
| } |
|
242 |
| |
|
243 |
| |
|
244 |
| |
|
245 |
| |
|
246 |
312
| public static String getDJ2ForJavaFile(String f) {
|
|
247 |
312
| return getFileWithDifferentExt(f, OptionConstants.JAVA_FILE_EXTENSION, OptionConstants.OLD_DJ2_FILE_EXTENSION);
|
|
248 |
| } |
|
249 |
| |
|
250 |
| |
|
251 |
| |
|
252 |
| |
|
253 |
| |
|
254 |
| |
|
255 |
0
| public static String getNewLLForOldLLFile(String fileName) {
|
|
256 |
0
| if (fileName.endsWith(OptionConstants.OLD_DJ0_FILE_EXTENSION)) {
|
|
257 |
0
| return fileName.substring(0, fileName.lastIndexOf(OptionConstants.OLD_DJ0_FILE_EXTENSION))
|
|
258 |
| + OptionConstants.DJ_FILE_EXTENSION; |
|
259 |
| } |
|
260 |
0
| else if (fileName.endsWith(OptionConstants.OLD_DJ1_FILE_EXTENSION)) {
|
|
261 |
0
| return fileName.substring(0, fileName.lastIndexOf(OptionConstants.OLD_DJ1_FILE_EXTENSION))
|
|
262 |
| + OptionConstants.DJ_FILE_EXTENSION; |
|
263 |
| } |
|
264 |
0
| else if (fileName.endsWith(OptionConstants.OLD_DJ2_FILE_EXTENSION)) {
|
|
265 |
0
| return fileName.substring(0, fileName.lastIndexOf(OptionConstants.OLD_DJ2_FILE_EXTENSION))
|
|
266 |
| + OptionConstants.JAVA_FILE_EXTENSION; |
|
267 |
| } |
|
268 |
0
| else return fileName;
|
|
269 |
| } |
|
270 |
| |
|
271 |
| |
|
272 |
0
| public static File getNewLLForOldLLFile(File f) {
|
|
273 |
0
| File canonicalFile = IOUtil.attemptCanonicalFile(f);
|
|
274 |
0
| String fileName = canonicalFile.getPath();
|
|
275 |
0
| return new File(getNewLLForOldLLFile(fileName));
|
|
276 |
| } |
|
277 |
| |
|
278 |
| |
|
279 |
| |
|
280 |
1249
| public static String getFileWithDifferentExt(String fileName, String source, String dest) {
|
|
281 |
1249
| if (fileName.endsWith(source)) {
|
|
282 |
1249
| return fileName.substring(0, fileName.lastIndexOf(source)) + dest;
|
|
283 |
| } |
|
284 |
0
| else return fileName;
|
|
285 |
| } |
|
286 |
| |
|
287 |
| |
|
288 |
| |
|
289 |
1
| public static File getFileWithDifferentExt(File f, String source, String dest) {
|
|
290 |
1
| File canonicalFile = IOUtil.attemptCanonicalFile(f);
|
|
291 |
1
| String fileName = canonicalFile.getPath();
|
|
292 |
1
| return new File(getFileWithDifferentExt(fileName, source, dest));
|
|
293 |
| } |
|
294 |
| |
|
295 |
| |
|
296 |
| |
|
297 |
| |
|
298 |
| |
|
299 |
| |
|
300 |
0
| public static String getPackageDir(String className) {
|
|
301 |
| |
|
302 |
0
| int lastDotIndex = className.lastIndexOf(".");
|
|
303 |
0
| if (lastDotIndex == -1) {
|
|
304 |
| |
|
305 |
0
| return "";
|
|
306 |
| } |
|
307 |
| else { |
|
308 |
0
| String packageName = className.substring(0, lastDotIndex);
|
|
309 |
0
| packageName = packageName.replace('.', File.separatorChar);
|
|
310 |
0
| return packageName + File.separatorChar;
|
|
311 |
| } |
|
312 |
| } |
|
313 |
| |
|
314 |
| |
|
315 |
0
| public static String removeExtension(String fileName) {
|
|
316 |
0
| int lastDotIndex = fileName.lastIndexOf(".");
|
|
317 |
0
| if (lastDotIndex == -1) {
|
|
318 |
| |
|
319 |
0
| return fileName;
|
|
320 |
| } |
|
321 |
0
| return fileName.substring(0, lastDotIndex);
|
|
322 |
| } |
|
323 |
| |
|
324 |
| |
|
325 |
1
| public static String getExtension(String fileName) {
|
|
326 |
1
| int lastDotIndex = fileName.lastIndexOf(".");
|
|
327 |
1
| if (lastDotIndex == -1) {
|
|
328 |
| |
|
329 |
0
| return "";
|
|
330 |
| } |
|
331 |
1
| return fileName.substring(lastDotIndex);
|
|
332 |
| } |
|
333 |
| |
|
334 |
| } |