Getting rid of some unused Java files in scala/tools/util because they now have scala equivalents in scala/tools/nsc/util.
git-svn-id: http://lampsvn.epfl.ch/svn-repos/scala/scala/trunk@5497 5e8d7ff9-d8ef-0310-90f0-a4852d11357a
This commit is contained in:
parent
32e2b6239f
commit
9607f607e0
|
@ -1,144 +0,0 @@
|
|||
/* ____ ____ ____ ____ ______ *\
|
||||
** / __// __ \/ __// __ \/ ____/ SOcos COmpiles Scala **
|
||||
** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002, LAMP/EPFL **
|
||||
** /_____/\____/\___/\____/____/ **
|
||||
\* */
|
||||
|
||||
// $Id$
|
||||
|
||||
package scala.tools.util;
|
||||
|
||||
import java.util.HashSet;
|
||||
|
||||
/**
|
||||
* This abstract class implements most aspects of a Reporter, only how
|
||||
* things are displayed has to be implemented in subclasses.
|
||||
*/
|
||||
public abstract class AbstractReporter implements Reporter {
|
||||
|
||||
//########################################################################
|
||||
// Private Fields
|
||||
|
||||
/** Log of error positions (used to avoid printing errors twice) */
|
||||
private final HashSet positions;
|
||||
|
||||
/** Whether information messages should be issued */
|
||||
private boolean verbose;
|
||||
/** Whether warnings should be issued */
|
||||
private boolean nowarn;
|
||||
/** Whether a prompt should be displayed after errors and warnings */
|
||||
private boolean prompt;
|
||||
|
||||
/** Number of warning issued totally */
|
||||
private int warnings;
|
||||
/** Number of errors issued totally */
|
||||
private int errors;
|
||||
|
||||
//########################################################################
|
||||
// Public Constructors
|
||||
|
||||
/** Initializes a new instance. */
|
||||
public AbstractReporter() {
|
||||
this.positions = new HashSet();
|
||||
this.verbose = false;
|
||||
this.nowarn = false;
|
||||
this.prompt = false;
|
||||
this.warnings = 0;
|
||||
this.errors = 0;
|
||||
}
|
||||
|
||||
//########################################################################
|
||||
// Public Methods - Display
|
||||
|
||||
/** Displays the information. The position may be null. */
|
||||
public abstract void displayInfo(Position position, String message);
|
||||
|
||||
/** Displays the warning. The position may be null. */
|
||||
public abstract void displayWarning(Position position, String message);
|
||||
|
||||
/** Displays the error. The position may be null. */
|
||||
public abstract void displayError(Position position, String message);
|
||||
|
||||
/** Displays a prompt. */
|
||||
public abstract void displayPrompt();
|
||||
|
||||
//########################################################################
|
||||
// Public Methods - Flags
|
||||
|
||||
public boolean verbose() {
|
||||
return verbose;
|
||||
}
|
||||
|
||||
public boolean nowarn() {
|
||||
return nowarn;
|
||||
}
|
||||
|
||||
public boolean prompt() {
|
||||
return prompt;
|
||||
}
|
||||
|
||||
|
||||
public void verbose(boolean verbose) {
|
||||
this.verbose = verbose;
|
||||
}
|
||||
|
||||
public void nowarn(boolean nowarn) {
|
||||
this.nowarn = nowarn;
|
||||
}
|
||||
|
||||
public void prompt(boolean prompt) {
|
||||
this.prompt = prompt;
|
||||
}
|
||||
|
||||
//########################################################################
|
||||
// Public Methods - Count
|
||||
|
||||
public int warnings() {
|
||||
return warnings;
|
||||
}
|
||||
|
||||
public int errors() {
|
||||
return errors;
|
||||
}
|
||||
|
||||
public void resetCounters() {
|
||||
errors = 0;
|
||||
warnings = 0;
|
||||
}
|
||||
|
||||
//########################################################################
|
||||
// Public Methods - Report
|
||||
|
||||
public void info(Position position, String message, boolean force) {
|
||||
if (force || verbose) displayInfo(null, message);
|
||||
}
|
||||
|
||||
public void warning(Position position, String message) {
|
||||
boolean hidden = testAndLog(position);
|
||||
if (nowarn) return;
|
||||
if (!hidden || prompt) displayWarning(position, message);
|
||||
if (!hidden) warnings++;
|
||||
if (prompt) displayPrompt();
|
||||
}
|
||||
|
||||
public void error(Position position, String message) {
|
||||
boolean hidden = testAndLog(position);
|
||||
if (!hidden || prompt) displayError(position, message);
|
||||
if (!hidden) errors++;
|
||||
if (prompt) displayPrompt();
|
||||
}
|
||||
|
||||
//########################################################################
|
||||
// Private Methods
|
||||
|
||||
/** Logs a position and returns true if it was already logged. */
|
||||
private boolean testAndLog(Position position) {
|
||||
if (position == null) return false;
|
||||
if (position.getColumnNumber() == 0) return false;
|
||||
if (positions.contains(position)) return true;
|
||||
positions.add(position);
|
||||
return false;
|
||||
}
|
||||
|
||||
//########################################################################
|
||||
}
|
|
@ -1,109 +0,0 @@
|
|||
/* ____ ____ ____ ____ ______ *\
|
||||
** / __// __ \/ __// __ \/ ____/ SOcos COmpiles Scala **
|
||||
** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002, LAMP/EPFL **
|
||||
** /_____/\____/\___/\____/____/ **
|
||||
\* */
|
||||
|
||||
// $Id$
|
||||
|
||||
package scala.tools.util;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/** This class represents a Java/Scala class path. */
|
||||
public class ClassPath {
|
||||
|
||||
//########################################################################
|
||||
// Public Functions
|
||||
|
||||
/**
|
||||
* Adds all zip and jar archives found in the specified extension
|
||||
* directory path to the specified file set. See also remark about
|
||||
* file order in method "addFilesFromPath".
|
||||
*/
|
||||
public static void addArchivesInExtDirPath(Set/*<File>*/files,String path){
|
||||
Set extdirs = new LinkedHashSet();
|
||||
addFilesInPath(extdirs, path);
|
||||
for (Iterator i = extdirs.iterator(); i.hasNext(); )
|
||||
addArchivesInExtDir(files, (File)i.next());
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds all zip and jar archives found in the specified extension
|
||||
* directory to the specified file set. See also remark about file
|
||||
* order in method "addFilesFromPath".
|
||||
*/
|
||||
public static void addArchivesInExtDir(Set/*<File>*/ files, File extdir) {
|
||||
String[] names = extdir.list();
|
||||
if (names == null) return;
|
||||
for (int i = 0; i < names.length; i++) {
|
||||
if (names[i].endsWith(".jar") || names[i].endsWith(".zip")) {
|
||||
File archive = new File(extdir, names[i]);
|
||||
if (archive.isFile()) files.add(archive);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses the specified path and adds all files that exist to the
|
||||
* specified file set. If order needs to be preserved, one should
|
||||
* pass in an order preserving implementation of Set.
|
||||
*/
|
||||
public static void addFilesInPath(Set/*<File>*/ files, String path) {
|
||||
path += File.pathSeparator;
|
||||
for (int i = 0; i < path.length(); ) {
|
||||
int j = path.indexOf(File.pathSeparator, i);
|
||||
File file = new File(path.substring(i, j));
|
||||
if (file.exists()) files.add(file);
|
||||
i = j + 1;
|
||||
}
|
||||
}
|
||||
|
||||
//########################################################################
|
||||
// Private Fields
|
||||
|
||||
/** The abstract directory represented by this class path */
|
||||
private final AbstractFile root;
|
||||
|
||||
//########################################################################
|
||||
// Public Constructors
|
||||
|
||||
/** Initializes this instance with the specified paths. */
|
||||
public ClassPath(String classpath,
|
||||
String sourcepath,
|
||||
String bootclasspath,
|
||||
String extdirs)
|
||||
{
|
||||
Set files = new LinkedHashSet();
|
||||
addFilesInPath(files, bootclasspath);
|
||||
addArchivesInExtDirPath(files, extdirs);
|
||||
addFilesInPath(files, sourcepath);
|
||||
addFilesInPath(files, classpath);
|
||||
ArrayList dirs = new ArrayList(files.size());
|
||||
for (Iterator i = files.iterator(); i.hasNext(); ) {
|
||||
AbstractFile dir = AbstractFile.getDirectory((File)i.next());
|
||||
if (dir != null) dirs.add(dir);
|
||||
}
|
||||
Object[] array = dirs.toArray(new AbstractFile[dirs.size()]);
|
||||
this.root = DirectoryPath.fromArray("<root>", (AbstractFile[])array);
|
||||
}
|
||||
|
||||
//########################################################################
|
||||
// Public Methods
|
||||
|
||||
/** Returns the root of this class path. */
|
||||
public AbstractFile getRoot() {
|
||||
return root;
|
||||
}
|
||||
|
||||
/** Returns a string representation of this class path. */
|
||||
public String toString() {
|
||||
return root.toString();
|
||||
}
|
||||
|
||||
//########################################################################
|
||||
}
|
|
@ -1,167 +0,0 @@
|
|||
/* ____ ____ ____ ____ ______ *\
|
||||
** / __// __ \/ __// __ \/ ____/ SOcos COmpiles Scala **
|
||||
** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002, LAMP/EPFL **
|
||||
** /_____/\____/\___/\____/____/ **
|
||||
\* */
|
||||
|
||||
// $Id$
|
||||
|
||||
package scala.tools.util;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
|
||||
/**
|
||||
* This class implements a Reporter that displays messages on a text
|
||||
* console.
|
||||
*/
|
||||
public class ConsoleReporter extends AbstractReporter {
|
||||
|
||||
//########################################################################
|
||||
// Private Fields
|
||||
|
||||
/** The reader to ask for failures on demand */
|
||||
private final BufferedReader reader;
|
||||
/** The writer to print messages */
|
||||
private final PrintWriter writer;
|
||||
|
||||
//########################################################################
|
||||
// Public Fields
|
||||
|
||||
/** Whether a short file name should be displayed before errors */
|
||||
public boolean shortname;
|
||||
|
||||
//########################################################################
|
||||
// Public Constructors
|
||||
|
||||
/** Initializes a new instance. */
|
||||
public ConsoleReporter() {
|
||||
this(
|
||||
new BufferedReader(new InputStreamReader(System.in)),
|
||||
new PrintWriter(System.err, true));
|
||||
}
|
||||
|
||||
/** Initializes a new instance. */
|
||||
public ConsoleReporter(BufferedReader reader, PrintWriter writer) {
|
||||
this.reader = reader;
|
||||
this.writer = writer;
|
||||
}
|
||||
|
||||
//########################################################################
|
||||
// Public Methods - Count
|
||||
|
||||
/** Returns the number of errors issued totally as a string */
|
||||
public String getErrorCountString() {
|
||||
return getCountString(errors(), "error");
|
||||
}
|
||||
|
||||
/** Returns the number of warnings issued totally as a string */
|
||||
public String getWarningCountString() {
|
||||
return getCountString(warnings(), "warning");
|
||||
}
|
||||
|
||||
/** Returns a string meaning "n elements". */
|
||||
public String getCountString(int n, String elements) {
|
||||
switch (n) {
|
||||
case 0: return "no " + elements + "s";
|
||||
case 1: return "one " + elements;
|
||||
case 2: return "two " + elements + "s";
|
||||
case 3: return "three " + elements + "s";
|
||||
case 4: return "four " + elements + "s";
|
||||
default: return n + " " + elements + "s";
|
||||
}
|
||||
}
|
||||
|
||||
//########################################################################
|
||||
// Public Methods - Print
|
||||
|
||||
/** Prints the message. */
|
||||
public void printMessage(String message) {
|
||||
writer.println(message);
|
||||
}
|
||||
|
||||
/** Prints the message with the given position indication. */
|
||||
public void printMessage(Position position, String message) {
|
||||
if (position != null) {
|
||||
message = " " + message;
|
||||
if (position.getLineNumber() != 0)
|
||||
message = position.getLineNumber() + ":" + message;
|
||||
if (shortname)
|
||||
message = position.getName() + ":" + message;
|
||||
else
|
||||
message = position.getPath() + ":" + message;
|
||||
}
|
||||
printMessage(message);
|
||||
printSourceLine(position);
|
||||
}
|
||||
|
||||
/** Prints the warning message. */
|
||||
public void printWarning(Position position, String message) {
|
||||
message = "warning: " + message;
|
||||
printMessage(position, message);
|
||||
}
|
||||
|
||||
/** Prints the error message. */
|
||||
public void printError(Position position, String message) {
|
||||
if (position == null) message = "error: " + message;
|
||||
printMessage(position, message);
|
||||
}
|
||||
|
||||
/** Prints the source line of the given position. */
|
||||
public void printSourceLine(Position position) {
|
||||
String line = position == null ? null : position.getLineContent();
|
||||
if (line == null) return;
|
||||
printMessage(line);
|
||||
printColumnMarker(position);
|
||||
}
|
||||
|
||||
/** Prints the column marker of the given position. */
|
||||
public void printColumnMarker(Position position) {
|
||||
int column = position == null ? 0 : position.getColumnNumber();
|
||||
StringBuffer buffer = new StringBuffer(column);
|
||||
for (int i = 1; i < column; i++) buffer.append(' ');
|
||||
if (column > 0) buffer.append('^');
|
||||
printMessage(buffer.toString());
|
||||
}
|
||||
|
||||
/** Prints the number of errors and warnings if their are non-zero. */
|
||||
public void printSummary() {
|
||||
if (warnings() > 0) printMessage(getWarningCountString() + " found");
|
||||
if (errors() > 0) printMessage(getErrorCountString() + " found");
|
||||
}
|
||||
|
||||
//########################################################################
|
||||
// Public Methods - Display
|
||||
|
||||
public void displayInfo(Position position, String message) {
|
||||
printMessage(position, message);
|
||||
}
|
||||
|
||||
public void displayWarning(Position position, String message) {
|
||||
printWarning(position, message);
|
||||
}
|
||||
|
||||
public void displayError(Position position, String message) {
|
||||
printError(position, message);
|
||||
}
|
||||
|
||||
public void displayPrompt() {
|
||||
try {
|
||||
while (true) {
|
||||
writer.print("r)esume, a)bort: ");
|
||||
writer.flush();
|
||||
String line = reader.readLine();
|
||||
if (line == null) continue; else line = line.toLowerCase();
|
||||
if ("abort".startsWith(line))
|
||||
throw new Error("user abort");
|
||||
if ("resume".startsWith(line)) return;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new Error("input read error");
|
||||
}
|
||||
}
|
||||
|
||||
//########################################################################
|
||||
}
|
|
@ -1,192 +0,0 @@
|
|||
/* ____ ____ ____ ____ ______ *\
|
||||
** / __// __ \/ __// __ \/ ____/ SOcos COmpiles Scala **
|
||||
** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002, LAMP/EPFL **
|
||||
** /_____/\____/\___/\____/____/ **
|
||||
\* */
|
||||
|
||||
// $Id$
|
||||
|
||||
package scala.tools.util;
|
||||
|
||||
/**
|
||||
* This class represents a position in a source file. Such a position
|
||||
* is defined by a source file (mandatory), a line number (optional)
|
||||
* and a column number (optional, may be specified only if the line
|
||||
* number is defined).
|
||||
*
|
||||
* Line (Column) numbers range from 0 to Integer.MAX_VALUE. A value of
|
||||
* 0 indicates that the line (column) is undefined, 1 represents the
|
||||
* first line (column). Negative values are prohibited.
|
||||
*
|
||||
* The class provides also functions to encode a line number and a
|
||||
* column number into one single integer. The encode line (column)
|
||||
* numbers range from 0 to LINE_MASK (COLUMN_MASK), where 0 indicates
|
||||
* that the line (column) is the undefined and 1 represents the first
|
||||
* line (column). Line (Column) numbers greater than LINE_MASK
|
||||
* (COLUMN_MASK) are replaced by LINE_MASK (COLUMN_MASK). Furthermore,
|
||||
* if the encoded line number is LINE_MASK, the column number is
|
||||
* always set to 0.
|
||||
*
|
||||
* The following properties hold:
|
||||
* - the undefined position is 0: encode(0,0) == 0
|
||||
* - encodings are non-negative : encode(line,column) >= 0
|
||||
* - position order is preserved:
|
||||
* (line1 < line2) || (line1 == line2 && column1 < column2)
|
||||
* implies
|
||||
* encode(line1,column1) <= encode(line2,column2)
|
||||
*/
|
||||
public class Position {
|
||||
|
||||
//########################################################################
|
||||
// Public Constants
|
||||
|
||||
/** Number of bits used to encode the line number */
|
||||
public static final int LINE_BITS = 20;
|
||||
/** Number of bits used to encode the column number */
|
||||
public static final int COLUMN_BITS = 31 - LINE_BITS; // no negatives => 31
|
||||
|
||||
/** Mask to decode the line number */
|
||||
public static final int LINE_MASK = (1 << LINE_BITS) - 1;
|
||||
/** Mask to decode the column number */
|
||||
public static final int COLUMN_MASK = (1 << COLUMN_BITS) - 1;
|
||||
|
||||
/** The undefined position */
|
||||
public static final int NOPOS = 0;
|
||||
|
||||
/** The first position in a source file */
|
||||
public static final int FIRSTPOS = encode(1, 1);
|
||||
|
||||
//########################################################################
|
||||
// Public Functions
|
||||
|
||||
/** Encodes a position into a single integer. */
|
||||
public static int encode(int line, int column) {
|
||||
assert line >= 0 : line;
|
||||
assert line == 0 ? column == 0 : column >= 0 : line + "," + column;
|
||||
if (line >= LINE_MASK) { line = LINE_MASK; column = 0; }
|
||||
if (column > COLUMN_MASK) column = COLUMN_MASK;
|
||||
return (line << COLUMN_BITS) | column;
|
||||
}
|
||||
|
||||
/** Returns the line number of the encoded position. */
|
||||
public static int line(int position) {
|
||||
return (position >> COLUMN_BITS) & LINE_MASK;
|
||||
}
|
||||
|
||||
/** Returns the column number of the encoded position. */
|
||||
public static int column(int position) {
|
||||
return position & COLUMN_MASK;
|
||||
}
|
||||
|
||||
/** Returns a string representation of the encoded position. */
|
||||
public static String toString(int position) {
|
||||
return line(position) + ":" + column(position);
|
||||
}
|
||||
|
||||
//########################################################################
|
||||
// Private Fields
|
||||
|
||||
/** The position's source file */
|
||||
private final SourceFile source;
|
||||
|
||||
/** The position's line number */
|
||||
private final int line;
|
||||
|
||||
/** The position's column number */
|
||||
private final int column;
|
||||
|
||||
//########################################################################
|
||||
// Public Constructors
|
||||
|
||||
/** Initializes a new instance. */
|
||||
public Position(String sourcename) {
|
||||
this(new SourceFile(sourcename, new char[0]));
|
||||
}
|
||||
|
||||
/** Initializes a new instance. */
|
||||
public Position(SourceFile source) {
|
||||
this(source, 0, 0);
|
||||
}
|
||||
|
||||
/** Initializes a new instance. */
|
||||
public Position(SourceFile source, int position) {
|
||||
this(source, line(position), column(position));
|
||||
}
|
||||
|
||||
/** Initializes a new instance. */
|
||||
public Position(SourceFile source, int line, int column) {
|
||||
this.source = source;
|
||||
this.line = line;
|
||||
this.column = column;
|
||||
assert source != null;
|
||||
assert line >= 0 : line;
|
||||
assert line == 0 ? column == 0 : column >= 0 : line + "," + column;
|
||||
}
|
||||
|
||||
//########################################################################
|
||||
// Public Methods
|
||||
|
||||
/** Returns the underlying abstract file's name. */
|
||||
public String getName() {
|
||||
return source.getFile().getName();
|
||||
}
|
||||
|
||||
/** Returns the underlying abstract file's path position. */
|
||||
public String getPath() {
|
||||
return source.getFile().getPath();
|
||||
}
|
||||
|
||||
/** Returns the underlying abstract file. */
|
||||
public AbstractFile getAbstractFile() {
|
||||
return source.getFile();
|
||||
}
|
||||
|
||||
/** Returns the source file. */
|
||||
public SourceFile getSourceFile() {
|
||||
return source;
|
||||
}
|
||||
|
||||
/** Returns the line content or null if it's unavailable. */
|
||||
public String getLineContent() {
|
||||
return line == 0 ? null : source.getLine(line);
|
||||
}
|
||||
|
||||
/** Returns the line number. */
|
||||
public int getLineNumber() {
|
||||
return line;
|
||||
}
|
||||
|
||||
/** Returns the column number. */
|
||||
public int getColumnNumber() {
|
||||
return column;
|
||||
}
|
||||
|
||||
/** Returns the line and column numbers encoded in an int. */
|
||||
public int getLineAndColumnNumber() {
|
||||
return encode(line, column);
|
||||
}
|
||||
|
||||
/** Returns a string representation of this position. */
|
||||
public String toString() {
|
||||
StringBuffer buffer = new StringBuffer(source.getFile().getPath());
|
||||
if (line > 0) buffer.append(":").append(line);
|
||||
if (line > 0 && column > 0) buffer.append(":").append(column);
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
/** Returns the hash code of this position. */
|
||||
public int hashCode() {
|
||||
return source.hashCode() ^ getLineAndColumnNumber();
|
||||
}
|
||||
|
||||
/** Returns true iff the given object represents the same position. */
|
||||
public boolean equals(Object object) {
|
||||
if (!(object instanceof Position)) return false;
|
||||
Position that = (Position)object;
|
||||
return this.source == that.source
|
||||
&& this.line == that.line
|
||||
&& this.column == that.column;
|
||||
}
|
||||
|
||||
//########################################################################
|
||||
}
|
|
@ -1,62 +0,0 @@
|
|||
/* ____ ____ ____ ____ ______ *\
|
||||
** / __// __ \/ __// __ \/ ____/ SOcos COmpiles Scala **
|
||||
** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002, LAMP/EPFL **
|
||||
** /_____/\____/\___/\____/____/ **
|
||||
\* */
|
||||
|
||||
// $Id$
|
||||
|
||||
package scala.tools.util;
|
||||
|
||||
/**
|
||||
* This interface provides methods to issue information, warning and
|
||||
* error messages.
|
||||
*/
|
||||
public interface Reporter {
|
||||
|
||||
//########################################################################
|
||||
// Public Methods - Flags
|
||||
|
||||
/** Are information messages issued? */
|
||||
public boolean verbose();
|
||||
/** Are warnings issued? */
|
||||
public boolean nowarn();
|
||||
/** Is a prompt displayed after errors and warnings? */
|
||||
public boolean prompt();
|
||||
|
||||
/** Sets whether information messages are issued. */
|
||||
public void verbose(boolean verbose);
|
||||
/** Sets whether warnings are issued. */
|
||||
public void nowarn(boolean nowarn);
|
||||
/** Sets whether a prompt is displayed after errors and warnings. */
|
||||
public void prompt(boolean prompt);
|
||||
|
||||
//########################################################################
|
||||
// Public Methods - Count
|
||||
|
||||
/** Returns the number of warnings issued. */
|
||||
public int warnings();
|
||||
|
||||
/** Returns the number of errors issued. */
|
||||
public int errors();
|
||||
|
||||
/** Resets all counters. */
|
||||
public void resetCounters();
|
||||
|
||||
//########################################################################
|
||||
// Public Methods - Report
|
||||
|
||||
/**
|
||||
* Issues an information. The position may be null. If force is
|
||||
* true, the message is displayed even in non-verbose mode.
|
||||
*/
|
||||
public void info(Position position, String message, boolean force);
|
||||
|
||||
/** Issues a warning. The position may be null. */
|
||||
public void warning(Position position, String message);
|
||||
|
||||
/** Issues an error. The position may be null. */
|
||||
public void error(Position position, String message);
|
||||
|
||||
//########################################################################
|
||||
}
|
|
@ -1,39 +0,0 @@
|
|||
/* ____ ____ ____ ____ ______ *\
|
||||
** / __// __ \/ __// __ \/ ____/ SOcos COmpiles Scala **
|
||||
** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002, LAMP/EPFL **
|
||||
** /_____/\____/\___/\____/____/ **
|
||||
\* */
|
||||
|
||||
// $Id$
|
||||
|
||||
package scala.tools.util;
|
||||
|
||||
/**
|
||||
* This class implements a timer that uses a Reporter to issue
|
||||
* timings.
|
||||
*/
|
||||
public class ReporterTimer extends AbstractTimer {
|
||||
|
||||
//########################################################################
|
||||
// Private Fields
|
||||
|
||||
/** A reporter to report timing information */
|
||||
private final Reporter reporter;
|
||||
|
||||
//########################################################################
|
||||
// Public Constructors
|
||||
|
||||
public ReporterTimer(Reporter reporter) {
|
||||
this.reporter = reporter;
|
||||
}
|
||||
|
||||
//########################################################################
|
||||
// Public Methods
|
||||
|
||||
/** Issues a timing information (duration in milliseconds). */
|
||||
public void issue(String message, long duration) {
|
||||
reporter.info(null, "[" + message + " in " + duration + "ms]", false);
|
||||
}
|
||||
|
||||
//########################################################################
|
||||
}
|
|
@ -1,122 +0,0 @@
|
|||
/* ____ ____ ____ ____ ______ *\
|
||||
** / __// __ \/ __// __ \/ ____/ SOcos COmpiles Scala **
|
||||
** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002, LAMP/EPFL **
|
||||
** /_____/\____/\___/\____/____/ **
|
||||
\* */
|
||||
|
||||
// $Id$
|
||||
|
||||
package scala.tools.util;
|
||||
|
||||
|
||||
/** This class represents a single source file. */
|
||||
public class SourceFile {
|
||||
|
||||
//########################################################################
|
||||
// Public Constants
|
||||
|
||||
/** Constants used for source parsing */
|
||||
public static final char LF = 0x0A;
|
||||
public static final char FF = 0x0C;
|
||||
public static final char CR = 0x0D;
|
||||
public static final char SU = 0x1A;
|
||||
|
||||
//########################################################################
|
||||
// Private Fields
|
||||
|
||||
/** The underlying file */
|
||||
private final AbstractFile file;
|
||||
|
||||
/** The content of this source file */
|
||||
private final char[] content;
|
||||
|
||||
/** The position of the last line returned by getLine */
|
||||
private int lineNumber = 0;
|
||||
private int lineStart = 0;
|
||||
private int lineLength = 0;
|
||||
private int nextIndex = 0;
|
||||
|
||||
//########################################################################
|
||||
// Public Constructors
|
||||
|
||||
/** Initializes this instance with given name and content. */
|
||||
public SourceFile(String sourcename, char[] content) {
|
||||
this(new CharArrayFile(sourcename, content), content);
|
||||
}
|
||||
|
||||
/** Initializes this instance with given file and content. */
|
||||
public SourceFile(AbstractFile file, char[] content) {
|
||||
this.file = file;
|
||||
this.content = normalize(content);
|
||||
}
|
||||
|
||||
//########################################################################
|
||||
// Public Methods
|
||||
|
||||
/** Returns the underlying file. */
|
||||
public AbstractFile getFile() {
|
||||
return file;
|
||||
}
|
||||
|
||||
/** Returns the content of this source file. */
|
||||
public char[] getContent() {
|
||||
return content;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an instance of Position representing the given line and
|
||||
* column of this source file.
|
||||
*/
|
||||
public Position getPosition(int line, int column) {
|
||||
return new Position(this, line, column);
|
||||
}
|
||||
|
||||
/** Returns the specified line. */
|
||||
public String getLine(int line) {
|
||||
int index = lineNumber <= line ? nextIndex : (lineNumber = 0);
|
||||
for (; index < content.length && lineNumber < line; lineNumber++) {
|
||||
lineStart = index;
|
||||
for (; index < content.length; index++) {
|
||||
if (content[index] == CR) break;
|
||||
if (content[index] == LF) break;
|
||||
if (content[index] == FF) break;
|
||||
}
|
||||
lineLength = index - lineStart;
|
||||
if (index < content.length)
|
||||
index++;
|
||||
if (index < content.length)
|
||||
if (content[index - 1] == CR && content[index] == LF) index++;
|
||||
}
|
||||
nextIndex = index;
|
||||
return new String(content, lineStart, lineLength);
|
||||
}
|
||||
|
||||
/** Returns the path of the underlying file. */
|
||||
public String toString() {
|
||||
return file.toString();
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return file.hashCode();
|
||||
}
|
||||
|
||||
public boolean equals(Object that) {
|
||||
return that instanceof SourceFile &&
|
||||
file.equals(((SourceFile) that).file);
|
||||
}
|
||||
|
||||
//########################################################################
|
||||
// Private Functions
|
||||
|
||||
/** Ensures that the last char of the array is SU. */
|
||||
private static char[] normalize(char[] input) {
|
||||
if (input.length > 0 && input[input.length - 1] == SU)
|
||||
return input;
|
||||
char[] content = new char[input.length + 1];
|
||||
System.arraycopy(input, 0, content, 0, input.length);
|
||||
content[input.length] = SU;
|
||||
return content;
|
||||
}
|
||||
|
||||
//########################################################################
|
||||
}
|
Loading…
Reference in New Issue