View | Details | Raw Unified | Return to bug 126803
Collapse All | Expand All

(-)batch/org/eclipse/jdt/internal/compiler/batch/ClasspathJar.java (-3 / +11 lines)
Lines 17-22 Link Here
17
import java.util.zip.ZipEntry;
17
import java.util.zip.ZipEntry;
18
import java.util.zip.ZipFile;
18
import java.util.zip.ZipFile;
19
19
20
import org.eclipse.jdt.core.compiler.CharOperation;
20
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader;
21
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader;
21
import org.eclipse.jdt.internal.compiler.env.AccessRuleSet;
22
import org.eclipse.jdt.internal.compiler.env.AccessRuleSet;
22
import org.eclipse.jdt.internal.compiler.env.NameEnvironmentAnswer;
23
import org.eclipse.jdt.internal.compiler.env.NameEnvironmentAnswer;
Lines 27-32 Link Here
27
private ZipFile zipFile;
28
private ZipFile zipFile;
28
private boolean closeZipFileAtEnd;
29
private boolean closeZipFileAtEnd;
29
private Hashtable packageCache;
30
private Hashtable packageCache;
31
private char[] normalizedPath;
30
32
31
public ClasspathJar(File file) throws IOException {
33
public ClasspathJar(File file) throws IOException {
32
	this(file, true, null);
34
	this(file, true, null);
Lines 90-98 Link Here
90
public String toString() {
92
public String toString() {
91
	return "Classpath for jar file " + this.file.getPath(); //$NON-NLS-1$
93
	return "Classpath for jar file " + this.file.getPath(); //$NON-NLS-1$
92
}
94
}
93
public String normalizedPath(){
95
public char[] normalizedPath() {
94
	String rawName = this.file.getPath();
96
	if (this.normalizedPath == null) {
95
	return rawName.substring(0, rawName.lastIndexOf('.'));
97
		char[] rawName = this.file.getPath().toCharArray();
98
		if (File.separatorChar == '\\') {
99
			CharOperation.replace(rawName, '\\', '/');
100
		}
101
		this.normalizedPath = CharOperation.subarray(rawName, 0, CharOperation.lastIndexOf('.', rawName));
102
	}
103
	return this.normalizedPath;
96
}
104
}
97
public String getPath(){
105
public String getPath(){
98
	return this.file.getPath();
106
	return this.file.getPath();
(-)batch/org/eclipse/jdt/internal/compiler/batch/FileSystem.java (-20 / +22 lines)
Lines 12-17 Link Here
12
12
13
import java.io.File;
13
import java.io.File;
14
import java.io.IOException;
14
import java.io.IOException;
15
import java.util.HashSet;
16
import java.util.Set;
15
17
16
import org.eclipse.jdt.core.compiler.CharOperation;
18
import org.eclipse.jdt.core.compiler.CharOperation;
17
import org.eclipse.jdt.internal.compiler.env.AccessRuleSet;
19
import org.eclipse.jdt.internal.compiler.env.AccessRuleSet;
Lines 21-27 Link Here
21
23
22
public class FileSystem implements INameEnvironment, SuffixConstants {
24
public class FileSystem implements INameEnvironment, SuffixConstants {
23
	Classpath[] classpaths;
25
	Classpath[] classpaths;
24
	String[] knownFileNames;
26
	Set knownFileNames;
25
27
26
	interface Classpath {
28
	interface Classpath {
27
		NameEnvironmentAnswer findClass(char[] typeName, String qualifiedPackageName, String qualifiedBinaryFileName);
29
		NameEnvironmentAnswer findClass(char[] typeName, String qualifiedPackageName, String qualifiedBinaryFileName);
Lines 37-43 Link Here
37
		 * (resp. '.zip') extension for jar (resp. zip) files.
39
		 * (resp. '.zip') extension for jar (resp. zip) files.
38
		 * @return a normalized path for file based classpath entries
40
		 * @return a normalized path for file based classpath entries
39
		 */
41
		 */
40
		String normalizedPath();
42
		char[] normalizedPath();
41
		/**
43
		/**
42
		 * Return the path for file based classpath entries. This is an absolute path
44
		 * Return the path for file based classpath entries. This is an absolute path
43
		 * ending with a file separator for directories, an absolute path including the '.jar'
45
		 * ending with a file separator for directories, an absolute path including the '.jar'
Lines 117-142 Link Here
117
	return result;
119
	return result;
118
}
120
}
119
private void initializeKnownFileNames(String[] initialFileNames) {
121
private void initializeKnownFileNames(String[] initialFileNames) {
120
	this.knownFileNames = new String[initialFileNames.length];
122
	this.knownFileNames = new HashSet(initialFileNames.length * 2);
121
	for (int i = initialFileNames.length; --i >= 0;) {
123
	for (int i = initialFileNames.length; --i >= 0;) {
122
		String fileName = initialFileNames[i];
124
		char[] fileName = initialFileNames[i].toCharArray();
123
		String matchingPathName = null;
125
		char[] matchingPathName = null;
124
		if (fileName.lastIndexOf(".") != -1) //$NON-NLS-1$
126
		final int lastIndexOf = CharOperation.lastIndexOf('.', fileName);
125
			fileName = fileName.substring(0, fileName.lastIndexOf('.')); // remove trailing ".java"
127
		if (lastIndexOf != -1) {
126
128
			fileName = CharOperation.subarray(fileName, 0, lastIndexOf);
127
		fileName = convertPathSeparators(fileName);
129
		}
130
		CharOperation.replace(fileName, '\\', '/');
128
		for (int j = 0; j < classpaths.length; j++){
131
		for (int j = 0; j < classpaths.length; j++){
129
			String matchCandidate = this.classpaths[j].normalizedPath();
132
			char[] matchCandidate = this.classpaths[j].normalizedPath();
130
			if (this.classpaths[j] instanceof  ClasspathDirectory && 
133
			if (this.classpaths[j] instanceof  ClasspathDirectory && 
131
					fileName.startsWith(matchCandidate) && 
134
					CharOperation.prefixEquals(matchCandidate, fileName) && 
132
					(matchingPathName == null || 
135
					(matchingPathName == null ||
133
							matchCandidate.length() < matchingPathName.length()))
136
							matchCandidate.length < matchingPathName.length))
134
				matchingPathName = matchCandidate;
137
				matchingPathName = matchCandidate;
135
		}
138
		}
136
		if (matchingPathName == null)
139
		if (matchingPathName == null) {
137
			this.knownFileNames[i] = fileName; // leave as is...
140
			this.knownFileNames.add(new String(fileName)); // leave as is...
138
		else
141
		} else {
139
			this.knownFileNames[i] = fileName.substring(matchingPathName.length());
142
			this.knownFileNames.add(new String(CharOperation.subarray(fileName, matchingPathName.length, fileName.length)));
143
		}
140
		matchingPathName = null;
144
		matchingPathName = null;
141
	}
145
	}
142
}
146
}
Lines 150-158 Link Here
150
		 : path.replace('/', '\\');
154
		 : path.replace('/', '\\');
151
}
155
}
152
private NameEnvironmentAnswer findClass(String qualifiedTypeName, char[] typeName){
156
private NameEnvironmentAnswer findClass(String qualifiedTypeName, char[] typeName){
153
	for (int i = 0, length = this.knownFileNames.length; i < length; i++)
157
	if (this.knownFileNames.contains(qualifiedTypeName)) return null; // looking for a file which we know was provided at the beginning of the compilation
154
		if (qualifiedTypeName.equals(this.knownFileNames[i]))
155
			return null; // looking for a file which we know was provided at the beginning of the compilation
156
158
157
	String qualifiedBinaryFileName = qualifiedTypeName + SUFFIX_STRING_class;
159
	String qualifiedBinaryFileName = qualifiedTypeName + SUFFIX_STRING_class;
158
	String qualifiedPackageName =
160
	String qualifiedPackageName =
(-)batch/org/eclipse/jdt/internal/compiler/batch/ClasspathDirectory.java (-6 / +14 lines)
Lines 14-29 Link Here
14
import java.io.IOException;
14
import java.io.IOException;
15
import java.util.Hashtable;
15
import java.util.Hashtable;
16
16
17
import org.eclipse.jdt.core.compiler.CharOperation;
17
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader;
18
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader;
18
import org.eclipse.jdt.internal.compiler.env.AccessRuleSet;
19
import org.eclipse.jdt.internal.compiler.env.AccessRuleSet;
19
import org.eclipse.jdt.internal.compiler.env.NameEnvironmentAnswer;
20
import org.eclipse.jdt.internal.compiler.env.NameEnvironmentAnswer;
20
21
21
public class ClasspathDirectory extends ClasspathLocation {
22
public class ClasspathDirectory extends ClasspathLocation {
22
23
23
String path;
24
private char[] normalizedPath;
24
Hashtable directoryCache;
25
private String path;
25
String[] missingPackageHolder = new String[1];
26
private Hashtable directoryCache;
26
String encoding;
27
private String[] missingPackageHolder = new String[1];
28
private String encoding;
27
public int mode; // ability to only consider one kind of files (source vs. binaries), by default use both
29
public int mode; // ability to only consider one kind of files (source vs. binaries), by default use both
28
30
29
public static final int SOURCE = 1;
31
public static final int SOURCE = 1;
Lines 133-140 Link Here
133
public String toString() {
135
public String toString() {
134
	return "ClasspathDirectory " + this.path; //$NON-NLS-1$
136
	return "ClasspathDirectory " + this.path; //$NON-NLS-1$
135
}
137
}
136
public String normalizedPath() {
138
public char[] normalizedPath() {
137
	return this.path;
139
	if (this.normalizedPath == null) {
140
		this.normalizedPath = this.path.toCharArray();
141
		if (File.separatorChar == '\\') {
142
			CharOperation.replace(this.normalizedPath, '\\', '/');
143
		}
144
	}
145
	return this.normalizedPath;
138
}
146
}
139
public String getPath() {
147
public String getPath() {
140
	return this.path;
148
	return this.path;
(-)batch/org/eclipse/jdt/internal/compiler/batch/CompilationUnit.java (-18 / +18 lines)
Lines 25-51 Link Here
25
	
25
	
26
public CompilationUnit(char[] contents, String fileName, String encoding) {
26
public CompilationUnit(char[] contents, String fileName, String encoding) {
27
	this.contents = contents;
27
	this.contents = contents;
28
	if (File.separator.equals("/")) { //$NON-NLS-1$
28
	char[] fileNameCharArray = fileName.toCharArray();
29
		if (fileName.indexOf("\\") != -1) { //$NON-NLS-1$
29
	switch(File.separatorChar) {
30
			fileName = fileName.replace('\\', File.separatorChar);
30
		case '/' :
31
		}
31
			if (CharOperation.indexOf('\\', fileNameCharArray) != -1) {
32
	} else {
32
				CharOperation.replace(fileNameCharArray, '\\', '/');
33
		// the file separator is \
33
			}
34
		if (fileName.indexOf('/') != -1) {
34
			break;
35
			fileName = fileName.replace('/', File.separatorChar);
35
		case '\\' :
36
		}
36
			if (CharOperation.indexOf('/', fileNameCharArray) != -1) {
37
				CharOperation.replace(fileNameCharArray, '/', '\\');
38
			}
37
	}
39
	}
38
	this.fileName = fileName.toCharArray();
40
	this.fileName = fileNameCharArray;
41
	int start = CharOperation.lastIndexOf(File.separatorChar, fileNameCharArray) + 1; 
39
42
40
	int start = fileName.lastIndexOf("/") + 1; //$NON-NLS-1$
43
	int end = CharOperation.lastIndexOf('.', fileNameCharArray);
41
	if (start == 0 || start < fileName.lastIndexOf("\\")) //$NON-NLS-1$
44
	if (end == -1) {
42
		start = fileName.lastIndexOf("\\") + 1; //$NON-NLS-1$
45
		end = fileNameCharArray.length;
43
46
	}
44
	int end = fileName.lastIndexOf("."); //$NON-NLS-1$
45
	if (end == -1)
46
		end = fileName.length();
47
47
48
	this.mainTypeName = fileName.substring(start, end).toCharArray();
48
	this.mainTypeName = CharOperation.subarray(fileNameCharArray, start, end);
49
	this.encoding = encoding;
49
	this.encoding = encoding;
50
}
50
}
51
public char[] getContents() {
51
public char[] getContents() {

Return to bug 126803