blob: 19c0914186533493f0216c387b4fd92b8dc050bb (
plain) (
blame)
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
38
39
40
41
42
43
44
45
46
47
48
49
50
|
package org.eclipse.jdt.internal.compiler.batch;
/*
* (c) Copyright IBM Corp. 2000, 2001.
* All Rights Reserved.
*/
import java.io.*;
import org.eclipse.jdt.internal.compiler.env.*;
import org.eclipse.jdt.internal.compiler.util.Util;
public class CompilationUnit implements ICompilationUnit {
public char[] contents;
public char[] fileName;
public char[] mainTypeName;
public CompilationUnit(char[] contents, String fileName) {
this.contents = contents;
this.fileName = fileName.toCharArray();
int start = fileName.lastIndexOf("/") + 1; //$NON-NLS-1$
if (start == 0 || start < fileName.lastIndexOf("\\")) //$NON-NLS-1$
start = fileName.lastIndexOf("\\") + 1; //$NON-NLS-1$
int end = fileName.lastIndexOf("."); //$NON-NLS-1$
if (end == -1)
end = fileName.length();
this.mainTypeName = fileName.substring(start, end).toCharArray();
}
public char[] getContents() {
if (contents != null)
return contents; // answer the cached source
// otherwise retrieve it
try {
return Util.getFileCharContent(new File(new String(fileName)));
} catch (IOException e) {
}
return new char[0];
}
public char[] getFileName() {
return fileName;
}
public char[] getMainTypeName() {
return mainTypeName;
}
public String toString() {
return "CompilationUnit[" + new String(fileName) + "]"; //$NON-NLS-2$ //$NON-NLS-1$
}
}
|