boolean binaryExists = ((this.mode & BINARY) != 0) && doesFileExist(fileName + SUFFIX_STRING_class, qualifiedPackageName);
boolean sourceExists = ((this.mode & SOURCE) != 0) && doesFileExist(fileName + SUFFIX_STRING_java, qualifiedPackageName);
if (sourceExists && !asBinaryOnly) {
String fullSourcePath = this.path + qualifiedBinaryFileName.substring(0, qualifiedBinaryFileName.length() - 6) + SUFFIX_STRING_java;
if (!binaryExists)
return new NameEnvironmentAnswer(new CompilationUnit(null,
fullSourcePath, this.encoding, this.destinationPath),
fetchAccessRestriction(qualifiedBinaryFileName));
String fullBinaryPath = this.path + qualifiedBinaryFileName;
long binaryModified = new File(fullBinaryPath).lastModified();
long sourceModified = new File(fullSourcePath).lastModified();
if (sourceModified > binaryModified)
return new NameEnvironmentAnswer(new CompilationUnit(null,
fullSourcePath, this.encoding, this.destinationPath),
fetchAccessRestriction(qualifiedBinaryFileName));
}
if (binaryExists) {
try {
ClassFileReader reader = ClassFileReader.read(this.path + qualifiedBinaryFileName);
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=321115, package names are to be treated case sensitive.
String typeSearched = qualifiedPackageName.length() > 0 ?
qualifiedPackageName.replace(File.separatorChar, '/') + "/" + fileName //$NON-NLS-1$
: fileName;
if (!CharOperation.equals(reader.getName(), typeSearched.toCharArray())) {
reader = null;
}
if (reader != null)
return new NameEnvironmentAnswer(
reader,
fetchAccessRestriction(qualifiedBinaryFileName));
} catch (IOException e) {
// treat as if file is missing
} catch (ClassFormatException e) {