summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGilles Dubochet <gilles.dubochet@epfl.ch>2008-04-16 15:10:19 +0000
committerGilles Dubochet <gilles.dubochet@epfl.ch>2008-04-16 15:10:19 +0000
commit51721cc3a491fe33dfdad925e4bf33c3268587e0 (patch)
tree6ece12bc1414ef9cc0397b3007325346d5f10c53 /src
parent92ec9e276b481844860a07f1e9e64dff2c4ce7f8 (diff)
downloadscala-51721cc3a491fe33dfdad925e4bf33c3268587e0.tar.gz
scala-51721cc3a491fe33dfdad925e4bf33c3268587e0.tar.bz2
scala-51721cc3a491fe33dfdad925e4bf33c3268587e0.zip
Fixed #580: error messages from SourceReader (c...
Fixed #580: error messages from SourceReader (concerning encoding) are now sent through the standard reporter. Removed obsolete AladdinReader.
Diffstat (limited to 'src')
-rw-r--r--src/compiler/scala/tools/nsc/Global.scala6
-rw-r--r--src/compiler/scala/tools/nsc/io/AladdinReader.scala85
-rw-r--r--src/compiler/scala/tools/nsc/io/SourceReader.scala8
3 files changed, 8 insertions, 91 deletions
diff --git a/src/compiler/scala/tools/nsc/Global.scala b/src/compiler/scala/tools/nsc/Global.scala
index 1125cd6f4c..07348bee1f 100644
--- a/src/compiler/scala/tools/nsc/Global.scala
+++ b/src/compiler/scala/tools/nsc/Global.scala
@@ -169,13 +169,13 @@ class Global(var settings: Settings, var reporter: Reporter) extends SymbolTable
}
try {
val clazz = Class.forName(settings.sourceReader.value)
- val ccon = clazz.getConstructor(Array[Class[T] forSome { type T }](classOf[java.nio.charset.CharsetDecoder]))
- ccon.newInstance(Array[AnyRef] (charset.newDecoder())).asInstanceOf[SourceReader];
+ val ccon = clazz.getConstructor(Array[Class[T] forSome { type T }](classOf[java.nio.charset.CharsetDecoder], classOf[Reporter]))
+ ccon.newInstance(Array[AnyRef] (charset.newDecoder(), reporter)).asInstanceOf[SourceReader];
//new SourceReader(charset.newDecoder())
} catch {
case e =>
error("exception while trying to instantiate source reader \""+settings.sourceReader.value+"\" ");
- new SourceReader(charset.newDecoder())
+ new SourceReader(charset.newDecoder(), reporter)
}
}
diff --git a/src/compiler/scala/tools/nsc/io/AladdinReader.scala b/src/compiler/scala/tools/nsc/io/AladdinReader.scala
deleted file mode 100644
index cf09fc0689..0000000000
--- a/src/compiler/scala/tools/nsc/io/AladdinReader.scala
+++ /dev/null
@@ -1,85 +0,0 @@
-package scala.tools.nsc.io
-
-import java.io.{File, FileInputStream, InputStream, IOException}
-import java.net.{ContentHandler, ContentHandlerFactory, URL, URLConnection}
-import java.nio.charset.CharsetDecoder
-
-/**
- * This class downloads the "code" field of a bug report of aladdin's bugtracking module
- * and compiles it.
- *
- * For instance, you can call the compiler with an argument "bug1023.scala"
- * This file must exists locally, and contain a bug identifier, like "#1023".
- * The AladdinReader will establish an HTTP connection and download bug #1023 - the file
- * contents will be replaced by what is found in the bugtracking database.
- */
-class AladdinReader(decoder: CharsetDecoder) extends SourceReader(decoder) {
-
- final val ALADDIN_URL = "http://scala-webapps.epfl.ch/bugtracking/bugs/json/"
-
- object AladdinHandler extends ContentHandler {
- def getContent(con: URLConnection) = {
- var state = 0
- val is = con.getInputStream
- val src = scala.io.Source.fromInputStream(is)
- while(state < 6 && src.hasNext) {
- state = (state,src.next) match {
- case (0,'\"') => 1
- case (1, 'c') => 2
- case (2, 'o') => 3
- case (3, 'd') => 4
- case (4, 'e') => 5
- case (5,'\"') => 6
- case _ => 0
- }
- }
- while(src.next != ':') {}
- while(src.next != '\"') {}
- val sb = new collection.mutable.ArrayBuffer[Char]()
- var c = ' '
- state = 0
- while(c != '\"' && src.hasNext) { (state,c) match {
- case (0,'\\') => state = 1; case (0, _) => sb+=(c);
- case (1, 'u') => state = 2; case (1, c) => sb+='\\'; sb+=c; state = 0
- case (2, '0') => state = 3; case (2, c) => sb+='\\'; sb+='u'; sb+=c; state = 0
- case (3, '0') => state = 4; case (3, c) => sb+='\\'; sb+='u'; sb+='0'; sb+=(c); state = 0
- case (4, '2') => state = 5;
- case (5, '2') => sb+='"'; state = 0
- case (4, '5') => state = 6;
- case (6, 'c') => sb+='\\'; state = 0
- case (4, c) => sb+='\\'; sb+='u'; sb+='0'; sb+='0'; sb+=(c); state = 0
- case (5, c) => sb+='\\'; sb+='u'; sb+='0'; sb+='0'; sb+='2'; sb+=(c); state = 0
- case (6, c) => sb+='\\'; sb+='u'; sb+='0'; sb+='0'; sb+='5'; sb+=(c); state = 0
- /*Console.print("["+c+"]"); */
- }; c = src.next; }
- is.close
- //Console.println("!!"+sb.toString+"!!") // DEBUG if you want to see what you are downloading
- sb.toArray
- }
- }
-
- java.net.URLConnection.setContentHandlerFactory(new ContentHandlerFactory { def createContentHandler(s:String) = AladdinHandler })
-
- private def wellformed(str: String): Boolean = try {
- str.charAt(0) == '#' && { Integer.parseInt(str.substring(1)); true }
- } catch {
- case _ => false
- }
-
- /** Reads the specified file. */
- @throws(classOf[java.net.MalformedURLException])
- override def read(file: File): Array[Char] = {
-
- val content = new String(super.read(file)).trim()
- if(!wellformed(content))
- throw FatalError("content should just be a bug identifier, like \"#1023\"")
-
- var bugURL = ALADDIN_URL + content.trim().substring(1)
- try {
- new java.net.URL(bugURL).getContent().asInstanceOf[Array[Char]]
- } catch {
- case e => throw FatalError("while getting content of URL, "+e.getClass()+" saying "+e.getMessage)
- }
- }
-
-}
diff --git a/src/compiler/scala/tools/nsc/io/SourceReader.scala b/src/compiler/scala/tools/nsc/io/SourceReader.scala
index 5f549c4a0e..4457a161fc 100644
--- a/src/compiler/scala/tools/nsc/io/SourceReader.scala
+++ b/src/compiler/scala/tools/nsc/io/SourceReader.scala
@@ -11,9 +11,10 @@ import java.io.{File, FileInputStream, InputStream, IOException}
import java.nio.{ByteBuffer, CharBuffer}
import java.nio.channels.{FileChannel, ReadableByteChannel, Channels}
import java.nio.charset.{CharsetDecoder, CoderResult}
+import scala.tools.nsc.reporters._
/** This class implements methods to read and decode source files. */
-class SourceReader(decoder: CharsetDecoder) {
+class SourceReader(decoder: CharsetDecoder, reporter: Reporter) {
import SourceReader.{decode, flush}
@@ -27,8 +28,9 @@ class SourceReader(decoder: CharsetDecoder) {
private var chars: CharBuffer = CharBuffer.allocate(0x4000)
private def reportEncodingError(filename:String) = {
- Console println "IO error while decoding "+filename+" with "+decoder.charset();
- Console println "Please try specifying another one using the -encoding option"
+ reporter.error(nsc.util.NoPosition,
+ "IO error while decoding "+filename+" with "+decoder.charset()+"\n"+
+ "Please try specifying another one using the -encoding option")
}
//########################################################################