diff options
author | paltherr <paltherr@epfl.ch> | 2004-03-21 12:51:41 +0000 |
---|---|---|
committer | paltherr <paltherr@epfl.ch> | 2004-03-21 12:51:41 +0000 |
commit | 49332fe728c05d76cb140da690df002ba213ddd5 (patch) | |
tree | d679a5a8910eb0e09693e4d03f0492a4c3ea8b0f /sources/scalac | |
parent | ca196dd13c1008176b162d006838767e8b4d83b7 (diff) | |
download | scala-49332fe728c05d76cb140da690df002ba213ddd5.tar.gz scala-49332fe728c05d76cb140da690df002ba213ddd5.tar.bz2 scala-49332fe728c05d76cb140da690df002ba213ddd5.zip |
- Added methods Global.getSourceFile
- Renamed bytes into content in SourceFile
- Replaced SourceFile constructors by SourceFile(AbstractFile, byte[])
Diffstat (limited to 'sources/scalac')
-rw-r--r-- | sources/scalac/Global.java | 45 | ||||
-rw-r--r-- | sources/scalac/symtab/SourceCompleter.java | 8 |
2 files changed, 34 insertions, 19 deletions
diff --git a/sources/scalac/Global.java b/sources/scalac/Global.java index c6885d6447..718c5c919b 100644 --- a/sources/scalac/Global.java +++ b/sources/scalac/Global.java @@ -19,7 +19,6 @@ import java.io.OutputStream; import java.util.*; import scala.tools.util.AbstractFile; -import scala.tools.util.ByteArrayFile; import scala.tools.util.Position; import scala.tools.util.SourceFile; @@ -256,6 +255,32 @@ public abstract class Global { currentPhase = currentPhase.prev; } + /** Creates a virtual source file with given name and content. */ + public SourceFile getSourceFile(String sourcename, String content) { + return new SourceFile(sourcename, content.getBytes()); + } + + /** Reads and returns the source file in file with given name. */ + public SourceFile getSourceFile(String filename) throws IOException { + return getSourceFile(AbstractFile.open(null, filename)); + } + + /** Reads and returns the source file in given abstract file. */ + public SourceFile getSourceFile(AbstractFile file) throws IOException { + if (!file.exists()) throw new FileNotFoundException( + "source file '" + file.getPath() + "' could not be found"); + byte[] content = file.read(); + return new SourceFile(file, content); + } + + /** Reads and returns the source file of given clasz. */ + public SourceFile getSourceFile(Symbol clasz) throws IOException { + assert clasz.isClass() && clasz.isStatic(): Debug.show(clasz); + AbstractFile file = classPath.openFile( + SourceRepresentation.externalizeFileName(clasz, ".scala")); + return getSourceFile(file); + } + /** the top-level compilation process */ public void compile(String[] files, boolean console) { @@ -263,17 +288,10 @@ public abstract class Global { // parse files List units = new ArrayList(files.length); for (int i = 0; i < files.length; i++) { - String filename = files[i]; - AbstractFile file = AbstractFile.open(null, filename); - if (file.exists()) { - try { - SourceFile source = new SourceFile(file); - units.add(new Unit(this, source, console)); - } catch (IOException exception) { - error(exception.getMessage()); - } - } else { - error("file '" + filename + "' not found"); + try { + units.add(new Unit(this, getSourceFile(files[i]), console)); + } catch (IOException exception) { + error(exception.getMessage()); } } this.units = (Unit[])units.toArray(new Unit[units.size()]); @@ -289,8 +307,7 @@ public abstract class Global { */ public void compile(String filename, String input, boolean console) { reporter.resetCounters(); - ByteArrayFile file = new ByteArrayFile(filename, input.getBytes()); - SourceFile source = new SourceFile(file); + SourceFile source = getSourceFile(filename, input); units = new Unit[]{new Unit(this, source, console)}; compile(); } diff --git a/sources/scalac/symtab/SourceCompleter.java b/sources/scalac/symtab/SourceCompleter.java index cb44daeea8..9fd3ebb468 100644 --- a/sources/scalac/symtab/SourceCompleter.java +++ b/sources/scalac/symtab/SourceCompleter.java @@ -34,17 +34,15 @@ public class SourceCompleter extends SymbolLoader { /** complete class symbol c by loading the unit */ public String doComplete(Symbol clasz) throws IOException { - AbstractFile file = global.classPath.openFile( - SourceRepresentation.externalizeFileName(clasz, ".scala")); - if (!file.exists()) throw new FileNotFoundException(file.getPath()); - Unit unit = new Unit(global, new SourceFile(file), false, mixinOnly); + SourceFile source = global.getSourceFile(clasz); + Unit unit = new Unit(global, source, false, mixinOnly); Phase phase = global.currentPhase; global.currentPhase = global.PHASE.PARSER.phase(); global.PHASE.PARSER.phase().apply(new Unit[] {unit}); global.currentPhase = global.PHASE.ANALYZER.phase(); ((AnalyzerPhase)global.PHASE.ANALYZER.phase()).lateEnter(global, unit, clasz); global.currentPhase = phase; - return "source file '" + file + "'"; + return "source file '" + source.getFile() + "'"; } } |