diff options
author | Sean McDirmid <sean.mcdirmid@gmail.com> | 2006-01-19 16:52:17 +0000 |
---|---|---|
committer | Sean McDirmid <sean.mcdirmid@gmail.com> | 2006-01-19 16:52:17 +0000 |
commit | 8a41146ae3528dfb246887f939dcbdf583deb42b (patch) | |
tree | 234837c9c7c81a68c4228f15078784f4b717d7fa /src | |
parent | 487f837c816d60db7638775c1047d3459f51e4e7 (diff) | |
download | scala-8a41146ae3528dfb246887f939dcbdf583deb42b.tar.gz scala-8a41146ae3528dfb246887f939dcbdf583deb42b.tar.bz2 scala-8a41146ae3528dfb246887f939dcbdf583deb42b.zip |
Diffstat (limited to 'src')
-rw-r--r-- | src/compiler/scala/tools/nsc/symtab/SymbolLoaders.scala | 66 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/util/ClassPath.scala | 112 | ||||
-rw-r--r-- | src/compiler/scala/tools/util/AbstractFile.java | 6 | ||||
-rw-r--r-- | src/compiler/scala/tools/util/PlainFile.java | 5 |
4 files changed, 104 insertions, 85 deletions
diff --git a/src/compiler/scala/tools/nsc/symtab/SymbolLoaders.scala b/src/compiler/scala/tools/nsc/symtab/SymbolLoaders.scala index db8fc433fe..4cf036339e 100644 --- a/src/compiler/scala/tools/nsc/symtab/SymbolLoaders.scala +++ b/src/compiler/scala/tools/nsc/symtab/SymbolLoaders.scala @@ -120,46 +120,50 @@ abstract class SymbolLoaders { val classes = new HashMap[String, ClassPath.Context]; val packages = new HashMap[String, ClassPath.Context]; for (val dir <- directory.entries) if (dir.location != null) { - val it = dir.location.list(); - while (it.hasNext()) { - val file = it.next().asInstanceOf[AbstractFile]; - if (file.isDirectory() && directory.validPackage(file.getName()) && !packages.isDefinedAt(file.getName())) - packages(file.getName()) = directory.find(file.getName(), true); - else if (!file.isDirectory() && file.getName().endsWith(".class")) { - val name = file.getName().substring(0, file.getName().length() - (".class").length()); - if (isValid(name) && !classes.isDefinedAt(name)) - classes(name) = directory.find(name, false); - } - } + val it = dir.location.list(); + while (it.hasNext()) { + val file = it.next().asInstanceOf[AbstractFile]; + if (file.isDirectory() && directory.validPackage(file.getName()) && !packages.isDefinedAt(file.getName())) + packages(file.getName()) = directory.find(file.getName(), true); + else if (!file.isDirectory() && file.getName().endsWith(".class")) { + val name = file.getName().substring(0, file.getName().length() - (".class").length()); + if (isValid(name) && !classes.isDefinedAt(name)) { + val clazz = directory.find(name, false); + if (clazz != null) classes(name) = clazz; + } + } + } } for (val dir <- directory.entries) if (dir.source != null) { - val jt = dir.source.location.list(); - while (jt.hasNext()) { - val file = jt.next().asInstanceOf[AbstractFile]; - if (file.isDirectory() && directory.validPackage(file.getName()) && !packages.isDefinedAt(file.getName())) - packages(file.getName()) = directory.find(file.getName(), true); - else if (dir.source.compile && !file.isDirectory() && file.getName().endsWith(".scala")) { - val name = file.getName().substring(0, file.getName().length() - (".scala").length()); - if (isValid(name) && !classes.isDefinedAt(name)) - classes(name) = directory.find(name, false); - } - } + val jt = dir.source.location.list(); + while (jt.hasNext()) { + val file = jt.next().asInstanceOf[AbstractFile]; + if (file.isDirectory() && directory.validPackage(file.getName()) && !packages.isDefinedAt(file.getName())) + packages(file.getName()) = directory.find(file.getName(), true); + else if (dir.source.compile && !file.isDirectory() && file.getName().endsWith(".scala")) { + val name = file.getName().substring(0, file.getName().length() - (".scala").length()); + if (isValid(name) && !classes.isDefinedAt(name)) { + val source = directory.find(name, false); + if (source != null) classes(name) = source; + } + } + } } //if (!packages.isEmpty) System.err.println("COMPLETE: " + packages); //if (! classes.isEmpty) System.err.println("COMPLETE: " + classes); // do classes first for (val Pair(name, file) <- classes.elements) { - val loader = if (!file.isSourceFile) { + val loader = if (!file.isSourceFile) { // System.err.println("CLASSFILE: " + file.file + " in " + file); - new ClassfileLoader(file.classFile, file.sourceFile, file.sourcePath); - } else { - assert(file.sourceFile != null); - //System.err.println("SOURCEFILE: " + file.sourceFile + " in " + file); - - new SourcefileLoader(file.sourceFile); - } - enterClassAndModule(name, loader); + new ClassfileLoader(file.classFile, file.sourceFile, file.sourcePath); + } else { + assert(file.sourceFile != null); + //System.err.println("SOURCEFILE: " + file.sourceFile + " in " + file); + + new SourcefileLoader(file.sourceFile); + } + enterClassAndModule(name, loader); } for (val Pair(name, file) <- packages.elements) enterPackage(name, new PackageLoader(file)); } diff --git a/src/compiler/scala/tools/nsc/util/ClassPath.scala b/src/compiler/scala/tools/nsc/util/ClassPath.scala index 41c59a351d..a4acfae9cb 100644 --- a/src/compiler/scala/tools/nsc/util/ClassPath.scala +++ b/src/compiler/scala/tools/nsc/util/ClassPath.scala @@ -24,19 +24,21 @@ import java.util.StringTokenizer; object ClassPath { class Source(val location : AbstractFile, val compile : Boolean) { - assert(location != null); - override def toString() : String = "" + location + " " + compile; + // assert(location != null, "cannot find source location"); + // assert(location.getFile() != null, "cannot find source location " + " " + location + " " + location.getClass()); + override def toString() : String = "" + location + " " + compile; } - abstract class Entry { - def location : AbstractFile; + abstract class Entry(val location: AbstractFile) { + // assert(location != null, "cannot find classpath location"); + // assert(location.getFile() != null, "cannot find classpath location " + " " + location + " " + location.getClass()); def source : Source; } - class Output(val location : AbstractFile, val sourceFile : AbstractFile) extends Entry { + class Output(location0 : AbstractFile, val sourceFile : AbstractFile) extends Entry(location0) { def source = if (sourceFile != null) new Source(sourceFile, true); else null; } - class Library(val location: AbstractFile) extends Entry { + class Library(location0: AbstractFile) extends Entry(location0) { def doc : AbstractFile = null; def sourceFile : AbstractFile = null; def source = if (sourceFile == null) null else new Source(sourceFile, false); @@ -46,37 +48,38 @@ object ClassPath { class Context(val entries : List[Entry]) { def find(name : String, isDir : boolean) : Context = if (isPackage) { def find0(entries : List[Entry]) : Context = { - if (entries.isEmpty) new Context(Nil); - else { - val ret = find0(entries.tail); - val head = entries.head; - - - val clazz = if (head.location == null) null; else - head.location.lookupPath(name + (if (!isDir) ".class" else ""), isDir); - - val source0 = if (head.source == null) null; else { - val source1 = head.source.location.lookupPath(name + (if (isDir) "" else ".scala"), isDir); - if (source1 == null && !isDir && clazz != null) head.source.location; - else source1; - } - if (clazz == null && source0 == null) ret; - else { - object entry extends Entry { - override def location = clazz; - override def source = - if (source0 == null) null; - else new Source(source0, head.source.compile); - }; - new Context(entry :: ret.entries); - } - } + if (entries.isEmpty) new Context(Nil); + else { + val ret = find0(entries.tail); + val head = entries.head; + val clazz = if (head.location == null) null; + else head.location.lookupPath(name + (if (!isDir) ".class" else ""), isDir); + + val source0 = if (head.source == null) null; else { + val source1 = head.source.location.lookupPath(name + (if (isDir) "" else ".scala"), isDir); + if (source1 == null && !isDir && clazz != null) head.source.location; + else source1; + } + if (clazz == null && source0 == null) ret; + else { + object entry extends Entry(clazz) { + override def source = + if (source0 == null) null; + else new Source(source0, head.source.compile); + }; + + new Context(entry :: ret.entries); + } + } } val ret = find0(entries); if (false && this.toString().indexOf("scala") != -1) - System.err.println("FIND " + name + " in " + this + " => " + ret); - assert(!ret.entries.isEmpty, ""+this+" "+name); - ret; + System.err.println("FIND " + name + " in " + this + " => " + ret); + + if (ret.entries.isEmpty) { + System.err.println("BAD_FILE: " + name + " in " + this); + null; + } else ret; } else null; @@ -118,7 +121,9 @@ object ClassPath { else false; } - def sourceFile = if ( isSourceFile) entries.head.source.location else null; + def sourceFile = if (entries.head.source != null && !entries.head.source.location.isDirectory()) + entries.head.source.location else null; + def classFile = if (!isSourceFile) entries.head .location else null; def sourcePath = if (!isSourceFile && entries.head.source != null) entries.head.source.location else null; @@ -143,12 +148,19 @@ object ClassPath { addFilesInPath(boot); addArchivesInExtDirPath(extdirs); + val clazzes = AbstractFile.getDirectory(output); + if (clazzes == null) throw new FileNotFoundException("output location \"" + output + "\" not found"); + val strtok = new StringTokenizer(source, File.pathSeparator); - while (strtok.hasMoreTokens()) { - val output0 = (new Output(AbstractFile.getDirectory(output), AbstractFile.getDirectory(strtok.nextToken()))); - if (output0.location == null) throw new FileNotFoundException("output location \"" + output + "\" not found"); - //System.err.println("OUTPUT: " + output); - entries += output0; + if (!strtok.hasMoreTokens()) { + val output0 = (new Output(clazzes, null)); + entries += output0; + } else while (strtok.hasMoreTokens()) { + val sources = AbstractFile.getDirectory(strtok.nextToken()); + + val output0 = (new Output(clazzes, sources)); + //System.err.println("OUTPUT: " + output); + entries += output0; } addFilesInPath(classpath); //System.err.println("CLASSPATH: " + root); @@ -174,16 +186,16 @@ object ClassPath { private def addArchivesInExtDirPath(path: String) = { val strtok = new StringTokenizer(path, File.pathSeparator); while (strtok.hasMoreTokens()) { - val file = AbstractFile.getDirectory(strtok.nextToken()); - val files = (if (file != null) file.list() else null); - if (files != null) while(files.hasNext()) { - val file0 = files.next().asInstanceOf[AbstractFile]; - val name = file0.getName(); - if (name.endsWith(".jar") || name.endsWith(".zip")) { - val archive = AbstractFile.getDirectory(new File(file.getFile(), name)); - if (archive != null) entries += (new Library(archive)); - } - } + val file = AbstractFile.getDirectory(strtok.nextToken()); + val files = (if (file != null) file.list() else null); + if (files != null) while(files.hasNext()) { + val file0 = files.next().asInstanceOf[AbstractFile]; + val name = file0.getName(); + if (name.endsWith(".jar") || name.endsWith(".zip")) { + val archive = AbstractFile.getDirectory(new File(file.getFile(), name)); + if (archive != null) entries += (new Library(archive)); + } + } } } diff --git a/src/compiler/scala/tools/util/AbstractFile.java b/src/compiler/scala/tools/util/AbstractFile.java index 723d983a4a..24df046799 100644 --- a/src/compiler/scala/tools/util/AbstractFile.java +++ b/src/compiler/scala/tools/util/AbstractFile.java @@ -43,7 +43,7 @@ public abstract class AbstractFile { * abstract regular file backed by it. Otherwise, returns null. */ public static AbstractFile getFile(File file) { - return file.isFile() ? new PlainFile(file) : null; + return file.isFile() && file.exists() ? new PlainFile(file) : null; } @@ -58,8 +58,8 @@ public abstract class AbstractFile { * backed by it. Otherwise, returns null. */ public static AbstractFile getDirectory(File file) { - if (file.isDirectory()) return new PlainFile(file); - if (file.isFile()) { + if (file.isDirectory() && file.exists()) return new PlainFile(file); + if (file.isFile() && file.exists()) { String path = file.getPath(); if (path.endsWith(".jar") || path.endsWith(".zip")) return ZipArchive.fromFile(file); diff --git a/src/compiler/scala/tools/util/PlainFile.java b/src/compiler/scala/tools/util/PlainFile.java index aee80cb52f..1bd2664cea 100644 --- a/src/compiler/scala/tools/util/PlainFile.java +++ b/src/compiler/scala/tools/util/PlainFile.java @@ -46,6 +46,7 @@ public class PlainFile extends AbstractFile { protected PlainFile(File file) { this.file = file; assert file != null; + if (!file.exists()) throw new Error("non-existent file: " + file); } //######################################################################## @@ -141,7 +142,9 @@ public class PlainFile extends AbstractFile { public AbstractFile lookupName(String name, boolean directory) { assert isDirectory(): "not a directory '" + this + "'"; File child = new File(file, name); - if (directory ? !child.isDirectory() : !child.isFile()) return null; + if (!child.exists()) return null; + if (directory != child.isDirectory()) return null; + if (directory == child.isFile() ) return null; return new PlainFile(child); } |