switch (c.getStatus()) {
case CS_UNDEFINED: {
if (tracing)
dtEvent("loadDefinition: STATUS IS UNDEFINED");
Identifier nm = c.getName();
Package pkg;
try {
pkg = getPackage(nm.getQualifier());
} catch (IOException e) {
// If we can't get at the package, then we'll just
// have to set the class to be not found.
c.setDefinition(null, CS_NOTFOUND);
error(0, "io.exception", c);
if (tracing)
dtExit("loadDefinition: IO EXCEPTION (package)");
return;
}
ClassFile binfile = pkg.getBinaryFile(nm.getName());
if (binfile == null) {
// must be source, there is no binary
c.setDefinition(null, CS_SOURCE);
if (tracing)
dtExit("loadDefinition: MUST BE SOURCE (no binary) " +
c.getName());
return;
}
ClassFile srcfile = pkg.getSourceFile(nm.getName());
if (srcfile == null) {
if (tracing)
dtEvent("loadDefinition: NO SOURCE " + c.getName());
BinaryClass bc = null;
try {
bc = loadFile(binfile);
} catch (IOException e) {
// If we can't access the binary, set the class to
// be not found. (bug id 4030497)
c.setDefinition(null, CS_NOTFOUND);
error(0, "io.exception", binfile);
if (tracing)
dtExit("loadDefinition: IO EXCEPTION (binary)");
return;
}
if ((bc != null) && !bc.getName().equals(nm)) {
error(0, "wrong.class", binfile.getPath(), c, bc);
bc = null;
if (tracing)
dtEvent("loadDefinition: WRONG CLASS (binary)");
}
if (bc == null) {
// no source nor binary found
c.setDefinition(null, CS_NOTFOUND);
if (tracing)
dtExit("loadDefinition: NOT FOUND (source or binary)");
return;
}
// Couldn't find the source, try the one mentioned in the binary
if (bc.getSource() != null) {
srcfile = new ClassFile(new File((String)bc.getSource()));
// Look for the source file
srcfile = pkg.getSourceFile(srcfile.getName());
if ((srcfile != null) && srcfile.exists()) {
if (tracing)
dtEvent("loadDefinition: FILENAME IN BINARY " +
srcfile);
if (srcfile.lastModified() > binfile.lastModified()) {
// must be source, it is newer than the binary
c.setDefinition(bc, CS_SOURCE);
if (tracing)
dtEvent("loadDefinition: SOURCE IS NEWER " +
srcfile);
bc.loadNested(this);
if (tracing)
dtExit("loadDefinition: MUST BE SOURCE " +
c.getName());
return;
}
if (dependencies()) {
c.setDefinition(bc, CS_UNDECIDED);
if (tracing)
dtEvent("loadDefinition: UNDECIDED " +
c.getName());
} else {
c.setDefinition(bc, CS_BINARY);
if (tracing)
dtEvent("loadDefinition: MUST BE BINARY " +
c.getName());
}
bc.loadNested(this);
if (tracing)
dtExit("loadDefinition: EXIT " +
c.getName() + ", status " + c.getStatus());
return;
}
}
// It must be binary, there is no source
c.setDefinition(bc, CS_BINARY);
if (tracing)
dtEvent("loadDefinition: MUST BE BINARY (no source) " +
c.getName());
bc.loadNested(this);
if (tracing)
dtExit("loadDefinition: EXIT " +
c.getName() + ", status " + c.getStatus());
return;
}
BinaryClass bc = null;
try {
if (srcfile.lastModified() > binfile.lastModified()) {
// must be source, it is newer than the binary
c.setDefinition(null, CS_SOURCE);
if (tracing)
dtEvent("loadDefinition: MUST BE SOURCE (younger than binary) " +
c.getName());
return;
}
bc = loadFile(binfile);
} catch (IOException e) {
error(0, "io.exception", binfile);
if (tracing)
dtEvent("loadDefinition: IO EXCEPTION (binary)");
}
if ((bc != null) && !bc.getName().equals(nm)) {
error(0, "wrong.class", binfile.getPath(), c, bc);
bc = null;
if (tracing)
dtEvent("loadDefinition: WRONG CLASS (binary)");
}
if (bc != null) {
Identifier name = bc.getName();
if (name.equals(c.getName())) {
if (dependencies()) {
c.setDefinition(bc, CS_UNDECIDED);
if (tracing)
dtEvent("loadDefinition: UNDECIDED " + name);
} else {
c.setDefinition(bc, CS_BINARY);
if (tracing)
dtEvent("loadDefinition: MUST BE BINARY " + name);
}
} else {
c.setDefinition(null, CS_NOTFOUND);
if (tracing)
dtEvent("loadDefinition: NOT FOUND (source or binary)");
if (dependencies()) {
getClassDeclaration(name).setDefinition(bc, CS_UNDECIDED);
if (tracing)
dtEvent("loadDefinition: UNDECIDED " + name);
} else {
getClassDeclaration(name).setDefinition(bc, CS_BINARY);
if (tracing)
dtEvent("loadDefinition: MUST BE BINARY " + name);
}
}
} else {
c.setDefinition(null, CS_NOTFOUND);
if (tracing)
dtEvent("loadDefinition: NOT FOUND (source or binary)");
}
if (bc != null && bc == c.getClassDefinition())
bc.loadNested(this);
if (tracing) dtExit("loadDefinition: EXIT " +
c.getName() + ", status " + c.getStatus());
return;
}
case CS_UNDECIDED: {
if (tracing) dtEvent("loadDefinition: STATUS IS UNDECIDED");
Hashtable tab = new Hashtable();
if (!needsCompilation(tab, c)) {
// All undecided classes that this class depends on must be binary
for (Enumeration e = tab.keys() ; e.hasMoreElements() ; ) {
ClassDeclaration dep = (ClassDeclaration)e.nextElement();
if (dep.getStatus() == CS_UNDECIDED) {
// must be binary, dependencies need compilation
dep.setDefinition(dep.getClassDefinition(), CS_BINARY);
if (tracing)
dtEvent("loadDefinition: MUST BE BINARY " + dep);
}
}
}
if (tracing) dtExit("loadDefinition: EXIT " +
c.getName() + ", status " + c.getStatus());
return;
}
case CS_SOURCE: {
if (tracing) dtEvent("loadDefinition: STATUS IS SOURCE");
ClassFile srcfile = null;
Package pkg = null;
if (c.getClassDefinition() != null) {
// Use the source file name from the binary class file
try {
pkg = getPackage(c.getName().getQualifier());
srcfile = pkg.getSourceFile((String)c.getClassDefinition().getSource());
} catch (IOException e) {
error(0, "io.exception", c);
if (tracing)
dtEvent("loadDefinition: IO EXCEPTION (package)");
}
if (srcfile == null) {
String fn = (String)c.getClassDefinition().getSource();
srcfile = new ClassFile(new File(fn));
}
} else {
// Get a source file name from the package
Identifier nm = c.getName();
try {
pkg = getPackage(nm.getQualifier());
srcfile = pkg.getSourceFile(nm.getName());
} catch (IOException e) {
error(0, "io.exception", c);
if (tracing)
dtEvent("loadDefinition: IO EXCEPTION (package)");
}