Skip to content
Browse files

Backport from trunk of a large batch of revisions:

24909,24919,24941,24961,24963,24965,24981,24984,24986,24987,24999,
25000,25001,25002,25003,25004,25005,25006,25007,25008,25009,25010,
25015,25028,25029,25030,25031,25033,25037,25038,25039,25040,25041,
25044,25045,25046,25050,25052,25053,25054,25055,25057,25058,25059,
25061,25062,25063,25065,25066,25069,25070,25071,25072,25074,25075,
25076,25080,25081,25082,25083,25085,25087,25088,25090,25091,25092,
25093,25094,25095,25096,25097,25098,25099,25100,25101,25110,25111,
25112,25113,25114,25117,25119,25122,25124,25125,25126,25127,25128,
25130,25132,25133,25134,25135,25136,25137,25138,25138,25139,25140,
25141,25142,25144,25145,25146,25148,25149,25152,25153,25158,25160,
25161,25162,25164,25167,25169,25170,25171,25172,25202,25204,25208,
25209,25252
  • Loading branch information...
1 parent f346e54 commit 3307c3771777cf17d5b4d059726a1b484923d042 Antonio Cunei committed Jul 22, 2011
Showing with 3,904 additions and 2,400 deletions.
  1. +7 −2 META-INF/MANIFEST.MF
  2. +1 −1 lib/jline.jar.desired.sha1
  3. +1 −1 project/build.properties
  4. +17 −10 src/actors/scala/actors/Actor.scala
  5. +1 −1 src/compiler/scala/tools/ant/Scalac.scala
  6. +2 −2 src/compiler/scala/tools/ant/templates/tool-windows.tmpl
  7. +15 −8 src/compiler/scala/tools/cmd/gen/AnyVals.scala
  8. +12 −9 src/compiler/scala/tools/nsc/Global.scala
  9. +3 −12 src/compiler/scala/tools/nsc/ScriptRunner.scala
  10. +0 −6 src/compiler/scala/tools/nsc/ast/TreeDSL.scala
  11. +1 −1 src/compiler/scala/tools/nsc/ast/TreeGen.scala
  12. +22 −8 src/compiler/scala/tools/nsc/ast/TreeInfo.scala
  13. +8 −2 src/compiler/scala/tools/nsc/ast/Trees.scala
  14. +7 −4 src/compiler/scala/tools/nsc/ast/parser/SyntaxAnalyzer.scala
  15. +8 −9 src/compiler/scala/tools/nsc/backend/JavaPlatform.scala
  16. +19 −8 src/compiler/scala/tools/nsc/backend/jvm/GenJVM.scala
  17. +9 −1 src/compiler/scala/tools/nsc/backend/jvm/GenJVMUtil.scala
  18. +2 −2 src/compiler/scala/tools/nsc/doc/Uncompilable.scala
  19. +1 −0 src/compiler/scala/tools/nsc/doc/html/HtmlFactory.scala
  20. +2 −69 src/compiler/scala/tools/nsc/doc/html/HtmlPage.scala
  21. +93 −0 src/compiler/scala/tools/nsc/doc/html/Page.scala
  22. +1 −69 src/compiler/scala/tools/nsc/doc/html/page/Index.scala
  23. +68 −0 src/compiler/scala/tools/nsc/doc/html/page/IndexScript.scala
  24. +11 −1 src/compiler/scala/tools/nsc/doc/html/page/Template.scala
  25. +1 −4 src/compiler/scala/tools/nsc/interactive/Global.scala
  26. +21 −11 src/compiler/scala/tools/nsc/io/AbstractFile.scala
  27. +20 −17 src/compiler/scala/tools/nsc/io/File.scala
  28. +34 −12 src/compiler/scala/tools/nsc/io/Path.scala
  29. +15 −5 src/compiler/scala/tools/nsc/io/PlainFile.scala
  30. +15 −35 src/compiler/scala/tools/nsc/io/SourceReader.scala
  31. +6 −13 src/compiler/scala/tools/nsc/io/VirtualFile.scala
  32. +161 −263 src/compiler/scala/tools/nsc/io/ZipArchive.scala
  33. +1 −10 src/compiler/scala/tools/nsc/io/package.scala
  34. +4 −0 src/compiler/scala/tools/nsc/matching/MatchSupport.scala
  35. +4 −9 src/compiler/scala/tools/nsc/matching/Matrix.scala
  36. +21 −31 src/compiler/scala/tools/nsc/matching/MatrixAdditions.scala
  37. +22 −21 src/compiler/scala/tools/nsc/matching/ParallelMatching.scala
  38. +13 −29 src/compiler/scala/tools/nsc/matching/PatternBindings.scala
  39. +31 −39 src/compiler/scala/tools/nsc/matching/Patterns.scala
  40. +5 −5 src/compiler/scala/tools/nsc/reporters/AbstractReporter.scala
  41. +4 −5 src/compiler/scala/tools/nsc/reporters/ConsoleReporter.scala
  42. +29 −86 src/compiler/scala/tools/nsc/reporters/Reporter.scala
  43. +5 −7 src/compiler/scala/tools/nsc/reporters/StoreReporter.scala
  44. +1 −1 src/compiler/scala/tools/nsc/settings/AestheticSettings.scala
  45. +2 −0 src/compiler/scala/tools/nsc/settings/MutableSettings.scala
  46. +7 −9 src/compiler/scala/tools/nsc/settings/ScalaSettings.scala
  47. +62 −0 src/compiler/scala/tools/nsc/settings/Warnings.scala
  48. +2 −2 src/compiler/scala/tools/nsc/symtab/BrowsingLoaders.scala
  49. +23 −4 src/compiler/scala/tools/nsc/symtab/Definitions.scala
  50. +4 −2 src/compiler/scala/tools/nsc/symtab/Names.scala
  51. +0 −1 src/compiler/scala/tools/nsc/symtab/StdNames.scala
  52. +27 −4 src/compiler/scala/tools/nsc/symtab/SymbolLoaders.scala
  53. +20 −2 src/compiler/scala/tools/nsc/symtab/SymbolTable.scala
  54. +36 −32 src/compiler/scala/tools/nsc/symtab/Symbols.scala
  55. +32 −9 src/compiler/scala/tools/nsc/symtab/TypeDebugging.scala
  56. +358 −157 src/compiler/scala/tools/nsc/symtab/Types.scala
  57. +1 −1 src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala
  58. +78 −16 src/compiler/scala/tools/nsc/transform/Erasure.scala
  59. +13 −10 src/compiler/scala/tools/nsc/transform/Mixin.scala
  60. +459 −563 src/compiler/scala/tools/nsc/transform/SpecializeTypes.scala
  61. +1 −2 src/compiler/scala/tools/nsc/transform/UnCurry.scala
  62. +39 −31 src/compiler/scala/tools/nsc/typechecker/Contexts.scala
  63. +1 −1 src/compiler/scala/tools/nsc/typechecker/EtaExpansion.scala
  64. +159 −74 src/compiler/scala/tools/nsc/typechecker/Implicits.scala
  65. +258 −170 src/compiler/scala/tools/nsc/typechecker/Infer.scala
  66. +13 −4 src/compiler/scala/tools/nsc/typechecker/Namers.scala
  67. +126 −34 src/compiler/scala/tools/nsc/typechecker/RefChecks.scala
  68. +1 −1 src/compiler/scala/tools/nsc/typechecker/TypeDiagnostics.scala
  69. +120 −58 src/compiler/scala/tools/nsc/typechecker/Typers.scala
  70. +14 −5 src/compiler/scala/tools/nsc/util/CharArrayReader.scala
  71. +156 −127 src/compiler/scala/tools/nsc/util/ClassPath.scala
  72. +5 −3 src/compiler/scala/tools/nsc/util/MsilClassPath.scala
  73. +1 −1 src/compiler/scala/tools/nsc/util/SourceFile.scala
  74. +15 −7 src/compiler/scala/tools/util/PathResolver.scala
  75. +34 −1 src/compiler/scala/tools/util/StringOps.scala
  76. +4 −0 src/jline/TEST-NOTE.txt
  77. +3 −3 src/jline/project/build.properties
  78. +1 −1 src/jline/project/plugins/project/build.properties
  79. +3 −0 src/jline/src/main/java/scala/tools/jline/UnixTerminal.java
  80. +23 −7 src/jline/src/main/java/scala/tools/jline/console/ConsoleReader.java
  81. +14 −1 src/jline/src/main/java/scala/tools/jline/console/CursorBuffer.java
  82. +2 −0 src/jline/src/main/java/scala/tools/jline/console/Key.java
  83. +6 −0 src/jline/src/main/java/scala/tools/jline/console/Operation.java
  84. +4 −1 src/jline/src/main/resources/scala/tools/jline/keybindings.properties
  85. +42 −6 src/jline/src/test/java/scala/tools/jline/console/EditLineTest.java
  86. +6 −0 src/library-aux/scala/Any.scala
  87. +2 −0 src/library/scala/Boolean.scala
  88. +1 −0 src/library/scala/Byte.scala
  89. +1 −0 src/library/scala/Char.scala
  90. +1 −0 src/library/scala/Double.scala
  91. +5 −1 src/library/scala/Enumeration.scala
  92. +1 −0 src/library/scala/Float.scala
  93. +1 −0 src/library/scala/Int.scala
  94. +1 −0 src/library/scala/Long.scala
  95. +14 −15 src/library/scala/Option.scala
  96. +25 −16 src/library/scala/Predef.scala
  97. +1 −0 src/library/scala/Short.scala
  98. +3 −2 src/library/scala/Unit.scala
  99. +1 −1 src/library/scala/collection/GenIterableLike.scala
  100. +3 −3 src/library/scala/collection/GenIterableViewLike.scala
  101. +1 −1 src/library/scala/collection/GenMapLike.scala
  102. +1 −1 src/library/scala/collection/GenSeqLike.scala
  103. +3 −3 src/library/scala/collection/GenSeqViewLike.scala
  104. +5 −5 src/library/scala/collection/GenSetLike.scala
  105. +1 −1 src/library/scala/collection/GenTraversableLike.scala
  106. +3 −3 src/library/scala/collection/GenTraversableViewLike.scala
  107. +1 −1 src/library/scala/collection/SetLike.scala
  108. +22 −1 src/library/scala/collection/TraversableViewLike.scala
  109. +8 −10 src/library/scala/collection/immutable/NumericRange.scala
  110. +8 −3 src/library/scala/collection/immutable/Range.scala
  111. +4 −0 src/library/scala/collection/immutable/Stream.scala
  112. +10 −0 src/library/scala/collection/immutable/StringOps.scala
  113. +9 −2 src/library/scala/collection/immutable/WrappedString.scala
  114. +3 −2 src/library/scala/collection/mutable/ArrayStack.scala
  115. +2 −2 src/library/scala/collection/mutable/FlatHashTable.scala
  116. +7 −2 src/library/scala/collection/mutable/ListBuffer.scala
  117. +11 −0 src/library/scala/collection/mutable/StringBuilder.scala
  118. +3 −1 src/library/scala/collection/parallel/mutable/ParHashSet.scala
  119. +4 −2 src/library/scala/collection/parallel/package.scala
  120. +1 −2 src/library/scala/io/BufferedSource.scala
  121. +5 −2 src/library/scala/math/BigInt.scala
  122. +1 −1 src/library/scala/reflect/generic/AnnotationInfos.scala
  123. +0 −8 src/library/scala/reflect/generic/ByteCodecs.scala
  124. +1 −1 src/library/scala/reflect/generic/Constants.scala
  125. +27 −16 src/library/scala/reflect/generic/Flags.scala
  126. +1 −1 src/library/scala/reflect/generic/HasFlags.scala
  127. +1 −1 src/library/scala/reflect/generic/Names.scala
  128. +1 −1 src/library/scala/reflect/generic/PickleBuffer.scala
  129. +1 −1 src/library/scala/reflect/generic/PickleFormat.scala
  130. +1 −1 src/library/scala/reflect/generic/Scopes.scala
  131. +1 −1 src/library/scala/reflect/generic/StandardDefinitions.scala
  132. +1 −1 src/library/scala/reflect/generic/StdNames.scala
  133. +1 −1 src/library/scala/reflect/generic/Symbols.scala
  134. +1 −1 src/library/scala/reflect/generic/Trees.scala
  135. +1 −1 src/library/scala/reflect/generic/Types.scala
  136. +29 −15 src/library/scala/reflect/generic/UnPickler.scala
  137. +1 −0 src/library/scala/reflect/generic/Universe.scala
  138. +3 −1 src/library/scala/runtime/NonLocalReturnControl.scala
  139. +16 −0 src/library/scala/runtime/ScalaRunTime.scala
  140. +5 −1 src/library/scala/util/control/NoStackTrace.scala
  141. +1 −1 src/library/scala/xml/pull/XMLEventReader.scala
  142. +1 −1 src/partest/scala/tools/partest/nest/ConsoleRunner.scala
  143. +1 −1 src/partest/scala/tools/partest/nest/FileManager.scala
  144. +6 −6 src/partest/scala/tools/partest/nest/Worker.scala
  145. +7 −6 src/scalap/scala/tools/scalap/Main.scala
  146. +3 −3 src/swing/scala/swing/RichWindow.scala
  147. 0 test/{files → disabled}/pos/spec-List.scala
  148. +47 −0 test/files/jvm/actor-sync-send-timeout.scala
  149. +1 −1 test/files/jvm/manifests.check
  150. +13 −0 test/files/neg/abstract-inaccessible.check
  151. +1 −0 test/files/neg/abstract-inaccessible.flags
  152. +9 −0 test/files/neg/abstract-inaccessible.scala
  153. +1 −1 test/files/neg/bug278.check
  154. +4 −0 test/files/neg/bug4419.check
  155. +3 −0 test/files/neg/bug4419.scala
  156. +0 −4 test/files/neg/bug4533.check
  157. +0 −8 test/files/neg/bug4533.scala
  158. +4 −0 test/files/neg/bug4584.check
  159. +1 −0 test/files/neg/bug4584.scala
  160. +11 −0 test/files/neg/bug4727.check
  161. +7 −0 test/files/neg/bug4727.scala
  162. +2 −2 test/files/neg/bug588.check
  163. +2 −2 test/files/neg/bug752.check
  164. +3 −3 test/files/neg/divergent-implicit.check
  165. +4 −0 test/files/neg/nullary-override.check
  166. +1 −0 test/files/neg/nullary-override.flags
  167. +3 −0 test/files/neg/nullary-override.scala
  168. +2 −2 test/files/neg/t0003.check
  169. +1 −1 test/files/neg/t0015.check
  170. +0 −9 test/files/neg/t2179.check
  171. +11 −1 test/files/neg/t2641.check
  172. +1 −1 test/files/neg/t3507.check
  173. +0 −7 test/files/neg/t3774.check
  174. +2 −2 test/files/neg/unit2anyref.check
  175. +1 −1 test/files/neg/variances.check
  176. +1 −0 test/files/pos/bug1439.flags
  177. +2 −1 test/files/pos/{t1439.scala → bug1439.scala}
  178. +31 −0 test/files/pos/bug2094.scala
  179. +8 −0 test/files/pos/bug3048.scala
  180. +15 −0 test/files/pos/bug3343.scala
  181. +8 −0 test/files/pos/bug3528.scala
  182. +15 −0 test/files/pos/bug4018.scala
  183. +6 −0 test/files/pos/bug4237.scala
  184. +14 −0 test/files/pos/bug4501.scala
  185. +11 −0 test/files/pos/bug4553.scala
  186. +14 −0 test/files/pos/bug4731.scala
  187. +37 −0 test/files/pos/hk-infer.scala
  188. 0 test/files/{neg → pos}/t2179.scala
  189. 0 test/files/{neg → pos}/t3774.scala
  190. +4 −0 test/files/pos/t4547.scala
  191. +20 −0 test/files/pos/t4593.scala
  192. +27 −0 test/files/pos/t4692.scala
  193. +7 −0 test/files/pos/widen-existential.scala
  194. +29 −0 test/files/run/TestFlatMap.scala
  195. +1 −0 test/files/run/bug2308a.check
  196. +7 −0 test/files/run/bug2308a.scala
  197. +2 −0 test/files/run/bug4110.check
  198. +11 −0 test/files/run/bug4110.scala
  199. +1 −0 test/files/run/bug4570.check
  200. +8 −0 test/files/run/bug4570.scala
  201. +1 −0 test/files/run/bug4656.check
  202. +13 −0 test/files/run/bug4656.scala
  203. +11 −0 test/files/run/bug4660.scala
  204. +1 −0 test/files/run/bug4697.check
  205. +8 −0 test/files/run/bug4697.scala
  206. +1 −1 test/files/run/constrained-types.check
  207. +18 −0 test/files/run/getClassTest.check
  208. +66 −0 test/files/run/getClassTest.scala
  209. +9 −0 test/files/run/null-and-intersect.check
  210. +34 −0 test/files/run/null-and-intersect.scala
  211. +28 −0 test/files/run/view-headoption.check
  212. +18 −0 test/files/run/view-headoption.scala
  213. +7 −0 test/files/scalacheck/range.scala
  214. +1 −1 test/files/specialized/fft.check
  215. +2 −0 test/{files → pending}/pos/no-widen-locals.scala
  216. +37 −0 test/pending/pos/those-kinds-are-high.scala
  217. +52 −0 test/scaladoc/scala/IndexScriptTest.scala
  218. +0 −20 test/scaladoc/scala/IndexTest.scala
View
9 META-INF/MANIFEST.MF
@@ -9,8 +9,7 @@ Bundle-ClassPath:
bin,
lib/fjbg.jar,
lib/jline.jar,
- lib/msil.jar,
- lib/scala-library.jar
+ lib/msil.jar
Export-Package:
scala.tools.nsc,
scala.tools.nsc.ast,
@@ -22,6 +21,10 @@ Export-Package:
scala.tools.nsc.backend.opt,
scala.tools.nsc.dependencies,
scala.tools.nsc.doc,
+ scala.tools.nsc.doc.html,
+ scala.tools.nsc.doc.html.page,
+ scala.tools.nsc.doc.model,
+ scala.tools.nsc.doc.model.comment,
scala.tools.nsc.interactive,
scala.tools.nsc.interpreter,
scala.tools.nsc.io,
@@ -36,6 +39,8 @@ Export-Package:
scala.tools.nsc.typechecker,
scala.tools.nsc.util,
scala.tools.util,
+ scala.reflect.internal,
+ scala.reflect.internal.settings,
ch.epfl.lamp.compiler.msil,
ch.epfl.lamp.compiler.msil.emit,
ch.epfl.lamp.compiler.msil.util,
View
2 lib/jline.jar.desired.sha1
@@ -1 +1 @@
-5eade2bafa228aab1f5abc63e6062ce8052e4f6d ?jline.jar
+545b37930819a1196705e582a232abfeb252cc8d ?jline.jar
View
2 project/build.properties
@@ -2,7 +2,7 @@
#Sun Apr 11 14:24:47 CEST 2010
project.name=scala
def.scala.version=2.7.7
-sbt.version=0.7.5.RC0
+sbt.version=0.7.7
copyright=Copyright 2002-2011, LAMP/EPFL
build.scala.versions=2.7.7
project.initialize=false
View
27 src/actors/scala/actors/Actor.scala
@@ -590,20 +590,27 @@ trait Actor extends AbstractActor with ReplyReactor with ActorCanReply with Inpu
receiveTimeout
} else {
if (onTimeout.isEmpty) {
- waitingFor = f
- received = None
- isSuspended = true
+ if (!f.isDefinedAt(TIMEOUT))
+ sys.error("unhandled timeout")
+
val thisActor = this
onTimeout = Some(new TimerTask {
- def run() { thisActor.send(TIMEOUT, thisActor) }
+ def run() {
+ thisActor.send(TIMEOUT, thisActor)
+ }
})
Actor.timer.schedule(onTimeout.get, msec)
- scheduler.managedBlock(blocker)
- drainSendBuffer(mailbox)
- // keep going
- () => {}
- } else
- sys.error("unhandled timeout")
+ }
+
+ // It is possible that !onTimeout.isEmpty, but TIMEOUT is not yet in mailbox
+ // See SI-4759
+ waitingFor = f
+ received = None
+ isSuspended = true
+ scheduler.managedBlock(blocker)
+ drainSendBuffer(mailbox)
+ // keep going
+ () => {}
}
}
todo()
View
2 src/compiler/scala/tools/ant/Scalac.scala
@@ -615,7 +615,7 @@ class Scalac extends ScalaMatchingTask with ScalacShared {
file
}
- val res = execWithArgFiles(java, List(writeSettings.getCanonicalPath))
+ val res = execWithArgFiles(java, List(writeSettings.getAbsolutePath))
if (failonerror && res != 0)
buildError("Compilation failed because of an internal compiler error;"+
" see the error output for details.")
View
4 src/compiler/scala/tools/ant/templates/tool-windows.tmpl
@@ -21,7 +21,7 @@ set _JAVACMD=%JAVACMD%
if "%_JAVACMD%"=="" (
if not "%JAVA_HOME%"=="" (
- if exist "%JAVA_HOME%\bin\java.exe" set _JAVACMD=%JAVA_HOME%\bin\java.exe
+ if exist "%JAVA_HOME%\bin\java.exe" set "_JAVACMD=%JAVA_HOME%\bin\java.exe"
)
)
@@ -37,7 +37,7 @@ if "%_TOOL_CLASSPATH%"=="" (
for /d %%f in ("%_SCALA_HOME%\lib\*") do call :add_cpath "%%f"
)
-set _PROPS=-Dscala.home="%_SCALA_HOME%" -Denv.emacs="%EMACS%" @properties@
+set _PROPS=-Dscala.home="%_SCALA_HOME%" -Denv.emacs="%EMACS%" -Dscala.usejavacp=true @properties@
rem echo "%_JAVACMD%" %_JAVA_OPTS% %_PROPS% -cp "%_TOOL_CLASSPATH%" @class@ @toolflags@ %*
"%_JAVACMD%" %_JAVA_OPTS% %_PROPS% -cp "%_TOOL_CLASSPATH%" @class@ @toolflags@ %*
View
23 src/compiler/scala/tools/cmd/gen/AnyVals.scala
@@ -12,12 +12,12 @@ trait AnyValReps {
self: AnyVals =>
sealed abstract class AnyValNum(name: String) extends AnyValRep(name) {
- def isCardinal: Boolean = isIntegerType(this)
- def unaryOps = if (isCardinal) List("+", "-", "~") else List("+", "-")
- def bitwiseOps = if (isCardinal) List("|", "&", "^") else Nil
- def shiftOps = if (isCardinal) List("<<", ">>>", ">>") else Nil
- def comparisonOps = List("==", "!=", "<", "<=", ">", ">=")
- def otherOps = List("+", "-" ,"*", "/", "%")
+ def isCardinal: Boolean = isIntegerType(this)
+ def unaryOps = if (isCardinal) List("+", "-", "~") else List("+", "-")
+ def bitwiseOps = if (isCardinal) List("|", "&", "^") else Nil
+ def shiftOps = if (isCardinal) List("<<", ">>>", ">>") else Nil
+ def comparisonOps = List("==", "!=", "<", "<=", ">", ">=")
+ def otherOps = List("+", "-" ,"*", "/", "%")
// Given two numeric value types S and T , the operation type of S and T is defined as follows:
// If both S and T are subrange types then the operation type of S and T is Int.
@@ -49,7 +49,7 @@ trait AnyValReps {
)
xs1 ++ xs2
}
- def classLines = clumps.foldLeft(List[String]()) {
+ def classLines = (clumps :+ commonClassLines).foldLeft(List[String]()) {
case (res, Nil) => res
case (res, lines) =>
val xs = lines map {
@@ -80,6 +80,9 @@ trait AnyValReps {
sealed abstract class AnyValRep(val name: String) {
def classLines: List[String]
def objectLines: List[String]
+ def commonClassLines = List(
+ "def getClass(): Class[@name@]"
+ )
def lcname = name.toLowerCase
def boxedName = this match {
@@ -243,6 +246,8 @@ def &&(x: Boolean): Boolean = sys.error("stub")
def |(x: Boolean): Boolean = sys.error("stub")
def &(x: Boolean): Boolean = sys.error("stub")
def ^(x: Boolean): Boolean = sys.error("stub")
+
+def getClass(): Class[Boolean] = sys.error("stub")
""".trim.lines.toList
def objectLines = interpolate(allCompanions).lines.toList
@@ -254,7 +259,9 @@ def ^(x: Boolean): Boolean = sys.error("stub")
* only one value of type Unit: `()`.
*/
"""
- def classLines = Nil
+ def classLines = List(
+ """def getClass(): Class[Unit] = sys.error("stub")"""
+ )
def objectLines = interpolate(allCompanions).lines.toList
override def boxUnboxImpls = Map(
View
21 src/compiler/scala/tools/nsc/Global.scala
@@ -157,7 +157,10 @@ class Global(var settings: Settings, var reporter: Reporter) extends SymbolTable
def informTime(msg: String, start: Long) = informProgress(elapsedMessage(msg, start))
def logError(msg: String, t: Throwable): Unit = ()
- def log(msg: => AnyRef): Unit = if (opt.logPhase) inform("[log " + phase + "] " + msg)
+ // Over 200 closure objects are eliminated by inlining this.
+ @inline final def log(msg: => AnyRef): Unit =
+ if (settings.log containsPhase globalPhase)
+ inform("[log " + phase + "] " + msg)
def logThrowable(t: Throwable): Unit = globalError(throwableAsString(t))
def throwableAsString(t: Throwable): String =
@@ -232,7 +235,6 @@ class Global(var settings: Settings, var reporter: Reporter) extends SymbolTable
// debugging
def checkPhase = wasActive(settings.check)
def logPhase = isActive(settings.log)
- def typerDebug = settings.Ytyperdebug.value
def writeICode = settings.writeICode.value
// showing/printing things
@@ -255,9 +257,10 @@ class Global(var settings: Settings, var reporter: Reporter) extends SymbolTable
def profileClass = settings.YprofileClass.value
def profileMem = settings.YprofileMem.value
- // XXX: short term, but I can't bear to add another option.
- // scalac -Dscala.timings will make this true.
+ // shortish-term property based options
def timings = sys.props contains "scala.timings"
+ def inferDebug = (sys.props contains "scalac.debug.infer") || settings.Yinferdebug.value
+ def typerDebug = (sys.props contains "scalac.debug.typer") || settings.Ytyperdebug.value
}
// True if -Xscript has been set, indicating a script run.
@@ -323,7 +326,7 @@ class Global(var settings: Settings, var reporter: Reporter) extends SymbolTable
currentRun.currentUnit = unit
if (!cancelled(unit)) {
currentRun.informUnitStarting(this, unit)
- reporter.withSource(unit.source) { apply(unit) }
+ apply(unit)
}
currentRun.advanceUnit
} finally {
@@ -335,6 +338,7 @@ class Global(var settings: Settings, var reporter: Reporter) extends SymbolTable
/** Switch to turn on detailed type logs */
var printTypings = opt.typerDebug
+ var printInfers = opt.inferDebug
// phaseName = "parser"
object syntaxAnalyzer extends {
@@ -1051,9 +1055,7 @@ class Global(var settings: Settings, var reporter: Reporter) extends SymbolTable
def loop(ph: Phase) {
if (stop(ph)) refreshProgress
else {
- reporter.withSource(unit.source) {
- atPhase(ph)(ph.asInstanceOf[GlobalPhase] applyPhase unit)
- }
+ atPhase(ph)(ph.asInstanceOf[GlobalPhase] applyPhase unit)
loop(ph.next match {
case `ph` => null // ph == ph.next implies terminal, and null ends processing
case x => x
@@ -1091,7 +1093,7 @@ class Global(var settings: Settings, var reporter: Reporter) extends SymbolTable
/**
* Re-orders the source files to
* 1. ScalaObject
- * 2. LowPriorityImplicits / StandardEmbeddings (i.e. parents of Predef)
+ * 2. LowPriorityImplicits / EmbeddedControls (i.e. parents of Predef)
* 3. the rest
*
* 1 is to avoid cyclic reference errors.
@@ -1121,6 +1123,7 @@ class Global(var settings: Settings, var reporter: Reporter) extends SymbolTable
case "ScalaObject.scala" => 1
case "LowPriorityImplicits.scala" => 2
case "StandardEmbeddings.scala" => 2
+ case "EmbeddedControls.scala" => 2
case "Predef.scala" => 3 /* Predef.scala before Any.scala, etc. */
case _ => goLast
}
View
15 src/compiler/scala/tools/nsc/ScriptRunner.scala
@@ -5,18 +5,9 @@
package scala.tools.nsc
-import java.io.{
- InputStream, OutputStream,
- BufferedReader, FileInputStream, FileOutputStream,
- FileReader, InputStreamReader, PrintWriter, FileWriter,
- IOException
-}
-import io.{ Directory, File, Path, PlainFile }
+import io.{ Directory, File, Path }
+import java.io.IOException
import java.net.URL
-import java.util.jar.{ JarEntry, JarOutputStream }
-
-import util.{ waitingForThreads }
-import scala.tools.util.PathResolver
import scala.tools.nsc.reporters.{Reporter,ConsoleReporter}
import util.Exceptional.unwrap
@@ -136,7 +127,7 @@ class ScriptRunner extends HasCompileSocket {
/** The script runner calls sys.exit to communicate a return value, but this must
* not take place until there are no non-daemon threads running. Tickets #1955, #2006.
*/
- waitingForThreads {
+ util.waitingForThreads {
if (settings.save.value) {
val jarFile = jarFileFor(scriptFile)
def jarOK = jarFile.canRead && (jarFile isFresher File(scriptFile))
View
6 src/compiler/scala/tools/nsc/ast/TreeDSL.scala
@@ -253,12 +253,6 @@ trait TreeDSL {
class SymbolMethods(target: Symbol) {
def BIND(body: Tree) = Bind(target, body)
-
- // Option
- def IS_DEFINED() =
- if (target.tpe.typeSymbol == SomeClass) TRUE // is Some[_]
- else NOT(ID(target) DOT nme.isEmpty) // is Option[_]
-
def IS_NULL() = REF(target) OBJ_EQ NULL
def NOT_NULL() = REF(target) OBJ_NE NULL
View
2 src/compiler/scala/tools/nsc/ast/TreeGen.scala
@@ -211,7 +211,7 @@ abstract class TreeGen {
if (tree.tpe != null || !tree.hasSymbol) tree.tpe
else tree.symbol.tpe
- if (!global.phase.erasedTypes && settings.Xchecknull.value &&
+ if (!global.phase.erasedTypes && settings.warnSelectNullable.value &&
tpe <:< NotNullClass.tpe && !tpe.isNotNull)
mkRuntimeCall(nme.checkInitialized, List(tree))
else
View
30 src/compiler/scala/tools/nsc/ast/TreeInfo.scala
@@ -96,10 +96,11 @@ abstract class TreeInfo {
false
}
- def mayBeVarGetter(sym: Symbol) = sym.info match {
- case NullaryMethodType(_) => sym.owner.isClass && !sym.isStable
- case mt @ MethodType(_, _) => mt.isImplicit && sym.owner.isClass && !sym.isStable
- case _ => false
+ def mayBeVarGetter(sym: Symbol): Boolean = sym.info match {
+ case NullaryMethodType(_) => sym.owner.isClass && !sym.isStable
+ case PolyType(_, NullaryMethodType(_)) => sym.owner.isClass && !sym.isStable
+ case mt @ MethodType(_, _) => mt.isImplicit && sym.owner.isClass && !sym.isStable
+ case _ => false
}
def isVariableOrGetter(tree: Tree) = {
@@ -361,8 +362,9 @@ abstract class TreeInfo {
case _ => false
}
- /** Some handy extractors for spotting true and false expressions
- * through the haze of braces.
+ /** Some handy extractors for spotting trees through the
+ * the haze of irrelevant braces: i.e. Block(Nil, SomeTree)
+ * should not keep us from seeing SomeTree.
*/
abstract class SeeThroughBlocks[T] {
protected def unapplyImpl(x: Tree): T
@@ -372,9 +374,21 @@ abstract class TreeInfo {
}
}
object IsTrue extends SeeThroughBlocks[Boolean] {
- protected def unapplyImpl(x: Tree): Boolean = x equalsStructure Literal(Constant(true))
+ protected def unapplyImpl(x: Tree): Boolean = x match {
+ case Literal(Constant(true)) => true
+ case _ => false
+ }
}
object IsFalse extends SeeThroughBlocks[Boolean] {
- protected def unapplyImpl(x: Tree): Boolean = x equalsStructure Literal(Constant(false))
+ protected def unapplyImpl(x: Tree): Boolean = x match {
+ case Literal(Constant(false)) => true
+ case _ => false
+ }
+ }
+ object IsIf extends SeeThroughBlocks[Option[(Tree, Tree, Tree)]] {
+ protected def unapplyImpl(x: Tree) = x match {
+ case If(cond, thenp, elsep) => Some(cond, thenp, elsep)
+ case _ => None
+ }
}
}
View
10 src/compiler/scala/tools/nsc/ast/Trees.scala
@@ -949,6 +949,10 @@ trait Trees extends reflect.generic.Trees { self: SymbolTable =>
if (tree eq orig) super.transform(tree)
else tree
}
+ // Create a readable string describing a substitution.
+ private def substituterString(fromStr: String, toStr: String, from: List[Any], to: List[Any]): String = {
+ "subst[%s, %s](%s)".format(fromStr, toStr, (from, to).zipped map (_ + " -> " + _) mkString ", ")
+ }
class TreeSubstituter(from: List[Symbol], to: List[Tree]) extends Transformer {
override def transform(tree: Tree): Tree = tree match {
@@ -961,11 +965,13 @@ trait Trees extends reflect.generic.Trees { self: SymbolTable =>
case _ =>
super.transform(tree)
}
+ override def toString = substituterString("Symbol", "Tree", from, to)
}
class TreeTypeSubstituter(val from: List[Symbol], val to: List[Type]) extends Traverser {
val typeSubst = new SubstTypeMap(from, to)
def fromContains = typeSubst.fromContains
+ def isEmpty = from.isEmpty && to.isEmpty
override def traverse(tree: Tree) {
if (tree.tpe ne null) tree.tpe = typeSubst(tree.tpe)
@@ -994,7 +1000,7 @@ trait Trees extends reflect.generic.Trees { self: SymbolTable =>
super.traverse(tree)
}
override def apply[T <: Tree](tree: T): T = super.apply(tree.duplicate)
- override def toString() = "TreeSymSubstTraverser("+from+","+to+")"
+ override def toString() = "TreeSymSubstTraverser/" + substituterString("Symbol", "Symbol", from, to)
}
/** Substitute symbols in 'from' with symbols in 'to'. Returns a new
@@ -1025,7 +1031,7 @@ trait Trees extends reflect.generic.Trees { self: SymbolTable =>
super.transform(tree)
}
def apply[T <: Tree](tree: T): T = transform(tree).asInstanceOf[T]
- override def toString() = "TreeSymSubstituter("+from+","+to+")"
+ override def toString() = "TreeSymSubstituter/" + substituterString("Symbol", "Symbol", from, to)
}
class ChangeOwnerTraverser(val oldowner: Symbol, val newowner: Symbol) extends Traverser {
View
11 src/compiler/scala/tools/nsc/ast/parser/SyntaxAnalyzer.scala
@@ -21,12 +21,15 @@ abstract class SyntaxAnalyzer extends SubComponent with Parsers with MarkupParse
override val keepsTypeParams = false
def apply(unit: global.CompilationUnit) {
- global.informProgress("parsing " + unit)
+ import global._
+ informProgress("parsing " + unit)
unit.body =
if (unit.source.file.name.endsWith(".java")) new JavaUnitParser(unit).parse()
- else if (!global.reporter.incompleteHandled) new UnitParser(unit).smartParse()
- else new UnitParser(unit).parse()
- if (global.settings.Yrangepos.value && !global.reporter.hasErrors) global.validatePositions(unit.body)
+ else if (reporter.incompleteHandled) new UnitParser(unit).parse()
+ else new UnitParser(unit).smartParse()
+
+ if (settings.Yrangepos.value && !reporter.hasErrors)
+ validatePositions(unit.body)
}
}
}
View
17 src/compiler/scala/tools/nsc/backend/JavaPlatform.scala
@@ -13,10 +13,10 @@ import scala.tools.util.PathResolver
trait JavaPlatform extends Platform[AbstractFile] {
import global._
- import definitions.{ BoxesRunTimeClass, getMember }
+ import definitions._
lazy val classPath = new PathResolver(settings).result
- def rootLoader = new loaders.JavaPackageLoader(classPath)
+ def rootLoader = new loaders.JavaPackageLoader(classPath)
private def depAnalysisPhase =
if (settings.make.isDefault) Nil
@@ -26,20 +26,19 @@ trait JavaPlatform extends Platform[AbstractFile] {
flatten, // get rid of inner classes
liftcode, // generate reified trees
genJVM // generate .class files
- ) ::: depAnalysisPhase
+ ) ++ depAnalysisPhase
- lazy val externalEquals = getMember(BoxesRunTimeClass, nme.equals_)
- def externalEqualsNumNum = getMember(BoxesRunTimeClass, "equalsNumNum")
- def externalEqualsNumChar = getMember(BoxesRunTimeClass, "equalsNumChar")
- def externalEqualsNumObject = getMember(BoxesRunTimeClass, "equalsNumObject")
+ lazy val externalEquals = getMember(BoxesRunTimeClass, nme.equals_)
+ lazy val externalEqualsNumNum = getMember(BoxesRunTimeClass, "equalsNumNum")
+ lazy val externalEqualsNumChar = getMember(BoxesRunTimeClass, "equalsNumChar")
+ lazy val externalEqualsNumObject = getMember(BoxesRunTimeClass, "equalsNumObject")
/** We could get away with excluding BoxedBooleanClass for the
* purpose of equality testing since it need not compare equal
* to anything but other booleans, but it should be present in
* case this is put to other uses.
*/
- def isMaybeBoxed(sym: Symbol): Boolean = {
- import definitions._
+ def isMaybeBoxed(sym: Symbol) = {
(sym == ObjectClass) ||
(sym == JavaSerializableClass) ||
(sym == ComparableClass) ||
View
27 src/compiler/scala/tools/nsc/backend/jvm/GenJVM.scala
@@ -249,7 +249,7 @@ abstract class GenJVM extends SubComponent with GenJVMUtil with GenAndroid with
parents = parents.distinct
if (parents.tail.nonEmpty)
- ifaces = parents drop 1 map (x => javaName(x.typeSymbol)) toArray;
+ ifaces = mkArray(parents drop 1 map (x => javaName(x.typeSymbol)))
jclass = fjbgContext.JClass(javaFlags(c.symbol),
name,
@@ -280,7 +280,17 @@ abstract class GenJVM extends SubComponent with GenJVMUtil with GenAndroid with
!(sym.name.toString contains '$') && sym.hasModuleFlag && !sym.isImplClass && !sym.isNestedClass
}
- val lmoc = c.symbol.companionModule
+ // At some point this started throwing lots of exceptions as a compile was finishing.
+ // error: java.lang.AssertionError:
+ // assertion failed: List(object package$CompositeThrowable, object package$CompositeThrowable)
+ // ...is the one I've seen repeatedly. Suppressing.
+ val lmoc = (
+ try c.symbol.companionModule
+ catch { case x: AssertionError =>
+ Console.println("Suppressing failed assert: " + x)
+ NoSymbol
+ }
+ )
// add static forwarders if there are no name conflicts; see bugs #363 and #1735
if (lmoc != NoSymbol && !c.symbol.isInterface) {
if (isCandidateForForwarders(lmoc) && !settings.noForwarders.value) {
@@ -567,7 +577,7 @@ abstract class GenJVM extends SubComponent with GenJVMUtil with GenAndroid with
* in which case we treat every signature as valid. Medium term we
* should certainly write independent signature validation.
*/
- if (SigParser.isParserAvailable && !isValidSignature(sym, sig)) {
+ if (settings.Xverify.value && SigParser.isParserAvailable && !isValidSignature(sym, sig)) {
clasz.cunit.warning(sym.pos,
"""|compiler bug: created invalid generic signature for %s in %s
|signature: %s
@@ -744,8 +754,8 @@ abstract class GenJVM extends SubComponent with GenJVMUtil with GenAndroid with
jmethod = jclass.addNewMethod(flags,
javaName(m.symbol),
resTpe,
- m.params map (p => javaType(p.kind)) toArray,
- m.params map (p => javaName(p.sym)) toArray)
+ mkArray(m.params map (p => javaType(p.kind))),
+ mkArray(m.params map (p => javaName(p.sym))))
addRemoteException(jmethod, m.symbol)
@@ -939,8 +949,8 @@ abstract class GenJVM extends SubComponent with GenJVMUtil with GenAndroid with
accessFlags,
javaName(m),
javaType(methodInfo.resultType),
- paramJavaTypes.toArray,
- paramNames.toArray)
+ mkArray(paramJavaTypes),
+ mkArray(paramNames))
val mirrorCode = mirrorMethod.getCode().asInstanceOf[JExtendedCode]
mirrorCode.emitGETSTATIC(moduleName,
nme.MODULE_INSTANCE_FIELD.toString,
@@ -1483,8 +1493,9 @@ abstract class GenJVM extends SubComponent with GenJVMUtil with GenAndroid with
// assert(instr.pos.source.isEmpty || instr.pos.source.get == (clasz.cunit.source), "sources don't match")
// val crtLine = instr.pos.line.get(lastLineNr);
+
val crtLine = try {
- (instr.pos).line
+ if (instr.pos == NoPosition) lastLineNr else (instr.pos).line // check NoPosition to avoid costly exception
} catch {
case _: UnsupportedOperationException =>
log("Warning: wrong position in: " + method)
View
10 src/compiler/scala/tools/nsc/backend/jvm/GenJVMUtil.scala
@@ -68,6 +68,14 @@ trait GenJVMUtil {
GE -> LT
)
+ /** Specialized array conversion to prevent calling
+ * java.lang.reflect.Array.newInstance via TraversableOnce.toArray
+ */
+
+ def mkArray(xs: Traversable[JType]): Array[JType] = { val a = new Array[JType](xs.size); xs.copyToArray(a); a }
+ def mkArray(xs: Traversable[String]): Array[String] = { val a = new Array[String](xs.size); xs.copyToArray(a); a }
+
+
/** Return the a name of this symbol that can be used on the Java
* platform. It removes spaces from names.
*
@@ -109,7 +117,7 @@ trait GenJVMUtil {
if (s.isMethod)
new JMethodType(
if (s.isClassConstructor) JType.VOID else javaType(s.tpe.resultType),
- s.tpe.paramTypes map javaType toArray
+ mkArray(s.tpe.paramTypes map javaType)
)
else
javaType(s.tpe)
View
4 src/compiler/scala/tools/nsc/doc/Uncompilable.scala
@@ -13,7 +13,7 @@ trait Uncompilable {
val global: Global
val settings: Settings
- import global.{ reporter, inform, warning, newTypeName, newTermName, Symbol, Name, DocComment }
+ import global.{ reporter, inform, warning, newTypeName, newTermName, Symbol, Name, DocComment, NoSymbol }
import global.definitions.RootClass
private implicit def translateName(name: Global#Name) =
@@ -43,6 +43,6 @@ trait Uncompilable {
pairs
}
override def toString = pairs.size + " uncompilable symbols:\n" + (
- symbols map (x => " " + x.owner.fullName + " " + x.defString) mkString "\n"
+ symbols filterNot (_ == NoSymbol) map (x => " " + x.owner.fullName + " " + x.defString) mkString "\n"
)
}
View
1 src/compiler/scala/tools/nsc/doc/html/HtmlFactory.scala
@@ -97,6 +97,7 @@ class HtmlFactory(val universe: doc.Universe, index: doc.Index) {
copyResource("lib/unselected.png")
new page.Index(universe, index) writeFor this
+ new page.IndexScript(universe, index) writeFor this
writeTemplates(page => page.writeFor(this))
View
71 src/compiler/scala/tools/nsc/doc/html/HtmlPage.scala
@@ -15,18 +15,11 @@ import xml.dtd.{DocType, PublicID}
import scala.collection._
import scala.reflect.NameTransformer
import java.nio.channels.Channels
-import java.io.{FileOutputStream, File}
/** An html page that is part of a Scaladoc site.
* @author David Bernard
* @author Gilles Dubochet */
-abstract class HtmlPage { thisPage =>
-
- /** The path of this page, relative to the API site. `path.tail` is a list of folder names leading to this page (from
- * closest package to one-above-root package), `path.head` is the file name of this page. Note that `path` has a
- * length of at least one. */
- def path: List[String]
-
+abstract class HtmlPage extends Page { thisPage =>
/** The title of this page. */
protected def title: String
@@ -36,9 +29,6 @@ abstract class HtmlPage { thisPage =>
/** The body of this page. */
def body: NodeSeq
- /** Writes this page as a file. The file's location is relative to the generator's site root, and the encoding is
- * also defined by the generator.
- * @param generator The generator that is writing this page. */
def writeFor(site: HtmlFactory): Unit = {
val doctype =
DocType("html", PublicID("-//W3C//DTD XHTML 1.1//EN", "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"), Nil)
@@ -51,10 +41,7 @@ abstract class HtmlPage { thisPage =>
</head>
{ body }
</html>
- val pageFile = new File(site.siteRoot, absoluteLinkTo(thisPage.path))
- val pageFolder = pageFile.getParentFile
- if (!pageFolder.exists) pageFolder.mkdirs()
- val fos = new FileOutputStream(pageFile.getPath)
+ val fos = createFileOutputStream(site)
val w = Channels.newWriter(fos.getChannel, site.encoding)
try {
w.write("<?xml version='1.0' encoding='" + site.encoding + "'?>\n")
@@ -68,52 +55,6 @@ abstract class HtmlPage { thisPage =>
//XML.save(pageFile.getPath, html, site.encoding, xmlDecl = false, doctype = doctype)
}
- def templateToPath(tpl: TemplateEntity): List[String] = {
- def doName(tpl: TemplateEntity): String =
- NameTransformer.encode(tpl.name) + (if (tpl.isObject) "$" else "")
- def downPacks(pack: Package): List[String] =
- if (pack.isRootPackage) Nil else (doName(pack) :: downPacks(pack.inTemplate))
- def downInner(nme: String, tpl: TemplateEntity): (String, Package) = {
- tpl.inTemplate match {
- case inPkg: Package => (nme + ".html", inPkg)
- case inTpl => downInner(doName(inTpl) + "$" + nme, inTpl)
- }
- }
- val (file, pack) =
- tpl match {
- case p: Package => ("package.html", p)
- case _ => downInner(doName(tpl), tpl)
- }
- file :: downPacks(pack)
- }
-
- /** A relative link from this page to some destination class entity.
- * @param destEntity The class or object entity that the link will point to. */
- def relativeLinkTo(destClass: TemplateEntity): String =
- relativeLinkTo(templateToPath(destClass))
-
- /** A relative link from this page to some destination page in the Scaladoc site.
- * @param destPage The page that the link will point to. */
- def relativeLinkTo(destPage: HtmlPage): String = {
- relativeLinkTo(destPage.path)
- }
-
- /** A relative link from this page to some destination path.
- * @param destPath The path that the link will point to. */
- def relativeLinkTo(destPath: List[String]): String = {
- def relativize(from: List[String], to: List[String]): List[String] = (from, to) match {
- case (f :: fs, t :: ts) if (f == t) => // both paths are identical to that point
- relativize(fs, ts)
- case (fss, tss) =>
- List.fill(fss.length - 1)("..") ::: tss
- }
- relativize(thisPage.path.reverse, destPath.reverse).mkString("/")
- }
-
- def absoluteLinkTo(destPath: List[String]): String = {
- destPath.reverse.mkString("/")
- }
-
/** Transforms an optional comment into an styled HTML tree representing its body if it is defined, or into an empty
* node sequence if it is not. */
def commentToHtml(comment: Option[Comment]): NodeSeq =
@@ -229,14 +170,6 @@ abstract class HtmlPage { thisPage =>
case tpl :: tpls => templateToHtml(tpl) ++ sep ++ templatesToHtml(tpls, sep)
}
- def docEntityKindToString(ety: DocTemplateEntity) =
- if (ety.isTrait) "trait"
- else if (ety.isCaseClass) "case class"
- else if (ety.isClass) "class"
- else if (ety.isObject) "object"
- else if (ety.isPackage) "package"
- else "class" // FIXME: an entity *should* fall into one of the above categories, but AnyRef is somehow not
-
/** Returns the _big image name corresponding to the DocTemplate Entity (upper left icon) */
def docEntityKindToBigImage(ety: DocTemplateEntity) =
if (ety.isTrait && !ety.companion.isEmpty && ety.companion.get.visibility.isPublic && ety.companion.get.inSource != None) "trait_to_object_big.png"
View
93 src/compiler/scala/tools/nsc/doc/html/Page.scala
@@ -0,0 +1,93 @@
+package scala.tools.nsc.doc.html
+import scala.tools.nsc.doc.model._
+import java.io.{FileOutputStream, File}
+import scala.reflect.NameTransformer
+
+abstract class Page {
+ thisPage =>
+
+ /** The path of this page, relative to the API site. `path.tail` is a list of folder names leading to this page (from
+ * closest package to one-above-root package), `path.head` is the file name of this page. Note that `path` has a
+ * length of at least one. */
+ def path: List[String]
+
+ def absoluteLinkTo(path: List[String]) = path.reverse.mkString("/")
+
+ def createFileOutputStream(site: HtmlFactory) = {
+ val file = new File(site.siteRoot, absoluteLinkTo(thisPage.path))
+ val folder = file.getParentFile
+ if (! folder.exists) {
+ folder.mkdirs
+ }
+ new FileOutputStream(file.getPath)
+ }
+
+ /** Writes this page as a file. The file's location is relative to the generator's site root, and the encoding is
+ * also defined by the generator.
+ * @param generator The generator that is writing this page. */
+ def writeFor(site: HtmlFactory): Unit
+
+ def docEntityKindToString(ety: DocTemplateEntity) =
+ if (ety.isTrait) "trait"
+ else if (ety.isCaseClass) "case class"
+ else if (ety.isClass) "class"
+ else if (ety.isObject) "object"
+ else if (ety.isPackage) "package"
+ else "class" // FIXME: an entity *should* fall into one of the above categories, but AnyRef is somehow not
+
+ def templateToPath(tpl: TemplateEntity): List[String] = {
+ def doName(tpl: TemplateEntity): String =
+ NameTransformer.encode(tpl.name) + (if (tpl.isObject) "$" else "")
+ def downPacks(pack: Package): List[String] =
+ if (pack.isRootPackage) Nil else (doName(pack) :: downPacks(pack.inTemplate))
+ def downInner(nme: String, tpl: TemplateEntity): (String, Package) = {
+ tpl.inTemplate match {
+ case inPkg: Package => (nme + ".html", inPkg)
+ case inTpl => downInner(doName(inTpl) + "$" + nme, inTpl)
+ }
+ }
+ val (file, pack) =
+ tpl match {
+ case p: Package => ("package.html", p)
+ case _ => downInner(doName(tpl), tpl)
+ }
+ file :: downPacks(pack)
+ }
+
+ /** A relative link from this page to some destination class entity.
+ * @param destEntity The class or object entity that the link will point to. */
+ def relativeLinkTo(destClass: TemplateEntity): String =
+ relativeLinkTo(templateToPath(destClass))
+
+ /** A relative link from this page to some destination page in the Scaladoc site.
+ * @param destPage The page that the link will point to. */
+ def relativeLinkTo(destPage: HtmlPage): String = {
+ relativeLinkTo(destPage.path)
+ }
+
+ /** A relative link from this page to some destination path.
+ * @param destPath The path that the link will point to. */
+ def relativeLinkTo(destPath: List[String]): String = {
+ def relativize(from: List[String], to: List[String]): List[String] = (from, to) match {
+ case (f :: fs, t :: ts) if (f == t) => // both paths are identical to that point
+ relativize(fs, ts)
+ case (fss, tss) =>
+ List.fill(fss.length - 1)("..") ::: tss
+ }
+ relativize(thisPage.path.reverse, destPath.reverse).mkString("/")
+ }
+
+ def isExcluded(dtpl: DocTemplateEntity) = {
+ val qname = dtpl.qualifiedName
+ ( ( qname.startsWith("scala.Tuple") || qname.startsWith("scala.Product") ||
+ qname.startsWith("scala.Function") || qname.startsWith("scala.runtime.AbstractFunction")
+ ) && !(
+ qname == "scala.Tuple1" || qname == "scala.Tuple2" ||
+ qname == "scala.Product" || qname == "scala.Product1" || qname == "scala.Product2" ||
+ qname == "scala.Function" || qname == "scala.Function1" || qname == "scala.Function2" ||
+ qname == "scala.runtime.AbstractFunction0" || qname == "scala.runtime.AbstractFunction1" ||
+ qname == "scala.runtime.AbstractFunction2"
+ )
+ )
+ }
+}
View
70 src/compiler/scala/tools/nsc/doc/html/page/Index.scala
@@ -48,23 +48,7 @@ class Index(universe: doc.Universe, index: doc.Index) extends HtmlPage {
</div>
</body>
-
- def isExcluded(dtpl: DocTemplateEntity) = {
- val qname = dtpl.qualifiedName
- ( ( qname.startsWith("scala.Tuple") || qname.startsWith("scala.Product") ||
- qname.startsWith("scala.Function") || qname.startsWith("scala.runtime.AbstractFunction")
- ) && !(
- qname == "scala.Tuple1" || qname == "scala.Tuple2" ||
- qname == "scala.Product" || qname == "scala.Product1" || qname == "scala.Product2" ||
- qname == "scala.Function" || qname == "scala.Function1" || qname == "scala.Function2" ||
- qname == "scala.runtime.AbstractFunction0" || qname == "scala.runtime.AbstractFunction1" ||
- qname == "scala.runtime.AbstractFunction2"
- )
- )
- }
-
def browser =
- <xml:group>
<div id="browser" class="ui-layout-west">
<div class="ui-west-center">
<div id="filter"></div>
@@ -121,60 +105,8 @@ class Index(universe: doc.Universe, index: doc.Index) extends HtmlPage {
</xml:group>
}
packageElem(universe.rootPackage)
- }</div></div>{ scriptElement }
+ }</div></div><script src="index.js"></script>
</div>
- </xml:group>
-
- def mergeByQualifiedName(source: List[DocTemplateEntity]): Map[String, List[DocTemplateEntity]]= {
- var result = Map[String, List[DocTemplateEntity]]()
-
- for (t <- source) {
- val k = t.qualifiedName
- result += k -> (result.getOrElse(k, List()) :+ t)
- }
-
- result
- }
-
- def scriptElement = {
- val packages = allPackagesWithTemplates.toIterable.map(_ match {
- case (pack, templates) => {
- val merged = mergeByQualifiedName(templates)
-
- val ary = merged.keys.toList.sortBy(_.toLowerCase).map(key => {
- val pairs = merged(key).map(
- t => docEntityKindToString(t) -> relativeLinkTo(t)
- ) :+ ("name" -> key)
-
- JSONObject(scala.collection.immutable.Map(pairs : _*))
- })
-
- pack.qualifiedName -> JSONArray(ary)
- }
- }).toSeq
-
- val obj =
- JSONObject(scala.collection.immutable.Map(packages : _*)).toString()
-
- <script type="text/javascript">
- Index.PACKAGES = {scala.xml.Unparsed(obj)};
- </script>
- }
-
- def allPackagesWithTemplates: Map[Package, List[DocTemplateEntity]] = {
- Map(allPackages.map((key) => {
- key -> key.templates.filter(t => !t.isPackage && !isExcluded(t))
- }) : _*)
- }
-
- def allPackages: List[Package] = {
- def f(parent: Package): List[Package] = {
- parent.packages.flatMap(
- p => f(p) :+ p
- )
- }
- f(universe.rootPackage).sortBy(_.toString)
- }
def packageQualifiedName(ety: DocTemplateEntity): String =
if (ety.inTemplate.isPackage) ety.name else (packageQualifiedName(ety.inTemplate) + "." + ety.name)
View
68 src/compiler/scala/tools/nsc/doc/html/page/IndexScript.scala
@@ -0,0 +1,68 @@
+package scala.tools.nsc.doc.html.page
+import scala.tools.nsc.doc
+import scala.tools.nsc.doc.model.{Package, DocTemplateEntity}
+import scala.tools.nsc.doc.html.{Page, HtmlFactory}
+import java.nio.channels.Channels
+import scala.util.parsing.json.{JSONObject, JSONArray}
+
+class IndexScript(universe: doc.Universe, index: doc.Index) extends Page {
+ def path = List("index.js")
+
+ override def writeFor(site: HtmlFactory): Unit = {
+ val stream = createFileOutputStream(site)
+ val writer = Channels.newWriter(stream.getChannel, site.encoding)
+ try {
+ writer.write("Index.PACKAGES = " + packages.toString() + ";")
+ }
+ finally {
+ writer.close
+ stream.close
+ }
+ }
+
+ val packages = {
+ val pairs = allPackagesWithTemplates.toIterable.map(_ match {
+ case (pack, templates) => {
+ val merged = mergeByQualifiedName(templates)
+
+ val ary = merged.keys.toList.sortBy(_.toLowerCase).map(key => {
+ val pairs = merged(key).map(
+ t => docEntityKindToString(t) -> relativeLinkTo(t)
+ ) :+ ("name" -> key)
+
+ JSONObject(scala.collection.immutable.Map(pairs : _*))
+ })
+
+ pack.qualifiedName -> JSONArray(ary)
+ }
+ }).toSeq
+
+ JSONObject(scala.collection.immutable.Map(pairs : _*))
+ }
+
+ def mergeByQualifiedName(source: List[DocTemplateEntity]) = {
+ var result = Map[String, List[DocTemplateEntity]]()
+
+ for (t <- source) {
+ val k = t.qualifiedName
+ result += k -> (result.getOrElse(k, List()) :+ t)
+ }
+
+ result
+ }
+
+ def allPackages = {
+ def f(parent: Package): List[Package] = {
+ parent.packages.flatMap(
+ p => f(p) :+ p
+ )
+ }
+ f(universe.rootPackage).sortBy(_.toString)
+ }
+
+ def allPackagesWithTemplates = {
+ Map(allPackages.map((key) => {
+ key -> key.templates.filter(t => !t.isPackage && !isExcluded(t))
+ }) : _*)
+ }
+}
View
12 src/compiler/scala/tools/nsc/doc/html/page/Template.scala
@@ -31,9 +31,12 @@ class Template(tpl: DocTemplateEntity) extends HtmlPage {
val valueMembers =
tpl.methods ++ tpl.values ++ tpl.templates.filter(x => x.isObject || x.isPackage) sorted
- val (absValueMembers, concValueMembers) =
+ val (absValueMembers, nonAbsValueMembers) =
valueMembers partition (_.isAbstract)
+ val (deprValueMembers, concValueMembers) =
+ nonAbsValueMembers partition (_.deprecation.isDefined)
+
val typeMembers =
tpl.abstractTypes ++ tpl.aliasTypes ++ tpl.templates.filter(x => x.isTrait || x.isClass) sorted
@@ -132,6 +135,13 @@ class Template(tpl: DocTemplateEntity) extends HtmlPage {
</div>
}
+ { if (deprValueMembers.isEmpty) NodeSeq.Empty else
+ <div id="values" class="values members">
+ <h3>Deprecated Value Members</h3>
+ <ol>{ deprValueMembers map (memberToHtml(_)) }</ol>
+ </div>
+ }
+
{
NodeSeq fromSeq (for ((superTpl, superType) <- (tpl.linearizationTemplates zip tpl.linearizationTypes)) yield
<div class="parent" name={ superTpl.qualifiedName }>
View
5 src/compiler/scala/tools/nsc/interactive/Global.scala
@@ -942,10 +942,7 @@ class Global(settings: Settings, reporter: Reporter, projectName: String = "")
* @return true iff typechecked correctly
*/
private def applyPhase(phase: Phase, unit: CompilationUnit) {
- val oldSource = reporter.getSource
- reporter.withSource(unit.source) {
- atPhase(phase) { phase.asInstanceOf[GlobalPhase] applyPhase unit }
- }
+ atPhase(phase) { phase.asInstanceOf[GlobalPhase] applyPhase unit }
}
}
View
32 src/compiler/scala/tools/nsc/io/AbstractFile.scala
@@ -9,8 +9,6 @@ package io
import java.io.{ FileOutputStream, IOException, InputStream, OutputStream, BufferedOutputStream }
import java.net.URL
-import PartialFunction._
-
import scala.collection.mutable.ArrayBuffer
/**
@@ -19,7 +17,7 @@ import scala.collection.mutable.ArrayBuffer
*/
object AbstractFile {
/** Returns "getFile(new File(path))". */
- def getFile(path: String): AbstractFile = getFile(Path(path))
+ def getFile(path: String): AbstractFile = getFile(File(path))
def getFile(path: Path): AbstractFile = getFile(path.toFile)
/**
@@ -42,7 +40,7 @@ object AbstractFile {
*/
def getDirectory(file: File): AbstractFile =
if (file.isDirectory) new PlainFile(file)
- else if (file.isFile && Path.isJarOrZip(file)) ZipArchive fromFile file
+ else if (file.isFile && Path.isExtensionJarOrZip(file.jfile)) ZipArchive fromFile file
else null
/**
@@ -54,7 +52,7 @@ object AbstractFile {
* @return ...
*/
def getURL(url: URL): AbstractFile = {
- if (url == null || !Path.isJarOrZip(url.getPath)) null
+ if (url == null || !Path.isExtensionJarOrZip(url.getPath)) null
else ZipArchive fromURL url
}
}
@@ -92,7 +90,8 @@ abstract class AbstractFile extends AnyRef with Iterable[AbstractFile] {
def path: String
/** Checks extension case insensitively. */
- def hasExtension(other: String) = Path(path) hasExtension other
+ def hasExtension(other: String) = extension == other.toLowerCase
+ private lazy val extension: String = Path.extension(name)
/** The absolute file, if this is a relative file. */
def absolute: AbstractFile
@@ -102,7 +101,6 @@ abstract class AbstractFile extends AnyRef with Iterable[AbstractFile] {
/** Returns the underlying File if any and null otherwise. */
def file: JFile
- def sfile = Option(file) map (x => File(x)) // XXX
/** An underlying source, if known. Mostly, a zip/jar file. */
def underlyingSource: Option[AbstractFile] = None
@@ -111,7 +109,7 @@ abstract class AbstractFile extends AnyRef with Iterable[AbstractFile] {
def exists: Boolean = (file eq null) || file.exists
/** Does this abstract file represent something which can contain classfiles? */
- def isClassContainer = isDirectory || (sfile exists (Path isJarOrZip _))
+ def isClassContainer = isDirectory || (file != null && (extension == "jar" || extension == "zip"))
/** Create a file on disk, if one does not exist already. */
def create(): Unit
@@ -137,6 +135,8 @@ abstract class AbstractFile extends AnyRef with Iterable[AbstractFile] {
/** size of this file if it is a concrete file. */
def sizeOption: Option[Int] = None
+ def toURL: URL = if (file == null) null else file.toURI.toURL
+
/** Returns contents of file (if applicable) in a Char array.
* warning: use <code>Global.getSourceFile()</code> to use the proper
* encoding when converting to the char array.
@@ -199,7 +199,7 @@ abstract class AbstractFile extends AnyRef with Iterable[AbstractFile] {
private def lookup(getFile: (AbstractFile, String, Boolean) => AbstractFile,
path0: String,
directory: Boolean): AbstractFile = {
- val separator = JFile.separatorChar
+ val separator = java.io.File.separatorChar
// trim trailing '/'s
val path: String = if (path0.last == separator) path0 dropRight 1 else path0
val length = path.length()
@@ -217,13 +217,23 @@ abstract class AbstractFile extends AnyRef with Iterable[AbstractFile] {
file
}
+ private def fileOrSubdirectoryNamed(name: String, isDir: Boolean): AbstractFile = {
+ val lookup = lookupName(name, isDir)
+ if (lookup != null) lookup
+ else {
+ val jfile = new JFile(file, name)
+ if (isDir) jfile.mkdirs() else jfile.createNewFile()
+ new PlainFile(jfile)
+ }
+ }
+
/**
* Get the file in this directory with the given name,
* creating an empty file if it does not already existing.
*/
def fileNamed(name: String): AbstractFile = {
assert(isDirectory, "Tried to find '%s' in '%s' but it is not a directory".format(name, path))
- Option(lookupName(name, false)) getOrElse new PlainFile((sfile.get / name).createFile())
+ fileOrSubdirectoryNamed(name, false)
}
/**
@@ -232,7 +242,7 @@ abstract class AbstractFile extends AnyRef with Iterable[AbstractFile] {
*/
def subdirectoryNamed(name: String): AbstractFile = {
assert (isDirectory, "Tried to find '%s' in '%s' but it is not a directory".format(name, path))
- Option(lookupName(name, true)) getOrElse new PlainFile((sfile.get / name).createDirectory())
+ fileOrSubdirectoryNamed(name, true)
}
protected def unsupported(): Nothing = unsupported(null)
View
37 src/compiler/scala/tools/nsc/io/File.scala
@@ -17,14 +17,14 @@ import java.nio.channels.{ Channel, FileChannel }
import scala.io.Codec
object File {
- def pathSeparator = JFile.pathSeparator
- def separator = JFile.separator
+ def pathSeparator = java.io.File.pathSeparator
+ def separator = java.io.File.separator
def apply(path: Path)(implicit codec: Codec) = new File(path.jfile)(codec)
// Create a temporary file, which will be deleted upon jvm exit.
def makeTemp(prefix: String = Path.randomPrefix, suffix: String = null, dir: JFile = null) = {
- val jfile = JFile.createTempFile(prefix, suffix, dir)
+ val jfile = java.io.File.createTempFile(prefix, suffix, dir)
jfile.deleteOnExit()
apply(jfile)
}
@@ -43,20 +43,23 @@ object File {
// trigger java.lang.InternalErrors later when using it concurrently. We ignore all
// the exceptions so as not to cause spurious failures when no write access is available,
// e.g. google app engine.
- try {
- import Streamable.closing
- val tmp = JFile.createTempFile("bug6503430", null, null)
- try closing(new FileInputStream(tmp)) { in =>
- val inc = in.getChannel()
- closing(new FileOutputStream(tmp, true)) { out =>
- out.getChannel().transferFrom(inc, 0, 0)
- }
- }
- finally tmp.delete()
- }
- catch {
- case _: IllegalArgumentException | _: IllegalStateException | _: IOException | _: SecurityException => ()
- }
+ //
+ // XXX need to put this behind a setting.
+ //
+ // try {
+ // import Streamable.closing
+ // val tmp = java.io.File.createTempFile("bug6503430", null, null)
+ // try closing(new FileInputStream(tmp)) { in =>
+ // val inc = in.getChannel()
+ // closing(new FileOutputStream(tmp, true)) { out =>
+ // out.getChannel().transferFrom(inc, 0, 0)
+ // }
+ // }
+ // finally tmp.delete()
+ // }
+ // catch {
+ // case _: IllegalArgumentException | _: IllegalStateException | _: IOException | _: SecurityException => ()
+ // }
}
import File._
import Path._
View
46 src/compiler/scala/tools/nsc/io/Path.scala
@@ -28,6 +28,19 @@ import scala.util.Random.alphanumeric
*/
object Path {
+ def isExtensionJarOrZip(jfile: JFile): Boolean = isExtensionJarOrZip(jfile.getName)
+ def isExtensionJarOrZip(name: String): Boolean = {
+ val ext = extension(name)
+ ext == "jar" || ext == "zip"
+ }
+ def extension(name: String): String = {
+ var i = name.length - 1
+ while (i >= 0 && name.charAt(i) != '.')
+ i -= 1
+
+ if (i < 0) ""
+ else name.substring(i + 1).toLowerCase
+ }
def isJarOrZip(f: Path, examineFile: Boolean = true) = Jar.isJarOrZip(f, examineFile)
// not certain these won't be problematic, but looks good so far
@@ -52,9 +65,9 @@ object Path {
def onlyFiles(xs: Iterator[Path]): Iterator[File] = xs filter (_.isFile) map (_.toFile)
def onlyFiles(xs: List[Path]): List[File] = xs filter (_.isFile) map (_.toFile)
- def roots: List[Path] = JFile.listRoots().toList map Path.apply
+ def roots: List[Path] = java.io.File.listRoots().toList map Path.apply
- def apply(segments: Seq[String]): Path = apply(segments mkString JFile.separator)
+ def apply(segments: Seq[String]): Path = apply(segments mkString java.io.File.separator)
def apply(path: String): Path = apply(new JFile(path))
def apply(jfile: JFile): Path =
if (jfile.isFile) new File(jfile)
@@ -71,8 +84,8 @@ import Path._
* semantics regarding how a Path might relate to the world.
*/
class Path private[io] (val jfile: JFile) {
- val separator = JFile.separatorChar
- val separatorStr = JFile.separator
+ val separator = java.io.File.separatorChar
+ val separatorStr = java.io.File.separator
// Validation: this verifies that the type of this object and the
// contents of the filesystem are in agreement. All objects are
@@ -84,6 +97,7 @@ class Path private[io] (val jfile: JFile) {
def toFile: File = new File(jfile)
def toDirectory: Directory = new Directory(jfile)
def toAbsolute: Path = if (isAbsolute) this else Path(jfile.getAbsolutePath())
+ def toCanonical: Path = Path(jfile.getCanonicalPath())
def toURI: URI = jfile.toURI()
def toURL: URL = toURI.toURL()
/** If this path is absolute, returns it: otherwise, returns an absolute
@@ -117,7 +131,7 @@ class Path private[io] (val jfile: JFile) {
// identity
def name: String = jfile.getName()
def path: String = jfile.getPath()
- def normalize: Path = Path(jfile.getCanonicalPath())
+ def normalize: Path = Path(jfile.getAbsolutePath())
def isRootPath: Boolean = roots exists (_ isSame this)
def resolve(other: Path) = if (other.isAbsolute || isEmpty) other else /(other)
@@ -159,14 +173,22 @@ class Path private[io] (val jfile: JFile) {
if (p isSame this) Nil else p :: p.parents
}
// if name ends with an extension (e.g. "foo.jpg") returns the extension ("jpg"), otherwise ""
- def extension: String = (name lastIndexOf '.') match {
- case -1 => ""
- case idx => name drop (idx + 1)
+ def extension: String = {
+ var i = name.length - 1
+ while (i >= 0 && name.charAt(i) != '.')
+ i -= 1
+
+ if (i < 0) ""
+ else name.substring(i + 1)
}
+ // def extension: String = (name lastIndexOf '.') match {
+ // case -1 => ""
+ // case idx => name drop (idx + 1)
+ // }
// compares against extensions in a CASE INSENSITIVE way.
def hasExtension(ext: String, exts: String*) = {
- val xs = (ext +: exts) map (_.toLowerCase)
- xs contains extension.toLowerCase
+ val lower = extension.toLowerCase
+ ext.toLowerCase == lower || exts.exists(_.toLowerCase == lower)
}
// returns the filename without the extension.
def stripExtension: String = name stripSuffix ("." + extension)
@@ -191,7 +213,7 @@ class Path private[io] (val jfile: JFile) {
def isHidden = jfile.isHidden()
def isSymlink = {
val x = parent / name
- x.normalize != x.toAbsolute
+ x.toCanonical != x.toAbsolute
}
def isEmpty = path.length == 0
@@ -203,7 +225,7 @@ class Path private[io] (val jfile: JFile) {
// Boolean path comparisons
def endsWith(other: Path) = segments endsWith other.segments
def startsWith(other: Path) = segments startsWith other.segments
- def isSame(other: Path) = normalize == other.normalize
+ def isSame(other: Path) = toCanonical == other.toCanonical
def isFresher(other: Path) = lastModified > other.lastModified
// creations
View
20 src/compiler/scala/tools/nsc/io/PlainFile.scala
@@ -16,7 +16,15 @@ object PlainFile {
* by it. Otherwise, returns null.
*/
def fromPath(file: Path): PlainFile =
- if (file.exists) new PlainFile(file) else null
+ if (file.isDirectory) new PlainDirectory(file.toDirectory)
+ else if (file.isFile) new PlainFile(file)
+ else null
+}
+
+class PlainDirectory(givenPath: Directory) extends PlainFile(givenPath) {
+ override def isDirectory = true
+ override def iterator = givenPath.list filter (_.exists) map (x => new PlainFile(x))
+ override def delete(): Unit = givenPath.deleteRecursively()
}
/** This class implements an abstract file backed by a File.
@@ -27,7 +35,7 @@ class PlainFile(val givenPath: Path) extends AbstractFile {
val file = givenPath.jfile
override def underlyingSource = Some(this)
- private val fpath = try givenPath.normalize catch { case _: IOException => givenPath.toAbsolute }
+ private val fpath = givenPath.toAbsolute
/** Returns the name of this abstract file. */
def name = givenPath.name
@@ -36,16 +44,18 @@ class PlainFile(val givenPath: Path) extends AbstractFile {
def path = givenPath.path
/** The absolute file. */
- def absolute = new PlainFile(givenPath.normalize)
+ def absolute = new PlainFile(givenPath.toAbsolute)
override def container: AbstractFile = new PlainFile(givenPath.parent)
override def input = givenPath.toFile.inputStream()
override def output = givenPath.toFile.outputStream()
override def sizeOption = Some(givenPath.length.toInt)
override def hashCode(): Int = fpath.hashCode
- override def equals(that: Any): Boolean =
- cond(that) { case other: PlainFile => fpath == other.fpath }
+ override def equals(that: Any): Boolean = that match {
+ case x: PlainFile => fpath == x.fpath
+ case _ => false
+ }
/** Is this abstract file a directory? */
def isDirectory: Boolean = givenPath.isDirectory
View
50 src/compiler/scala/tools/nsc/io/SourceReader.scala
@@ -33,58 +33,38 @@ class SourceReader(decoder: CharsetDecoder, reporter: Reporter) {
"Please try specifying another one using the -encoding option")
}
- //########################################################################
- // Public Methods
-
/** Reads the file with the specified name. */
def read(filename: String): Array[Char]= read(new JFile(filename))
/** Reads the specified file. */
def read(file: JFile): Array[Char] = {
val c = new FileInputStream(file).getChannel
- try {
- read(c)
- } catch {
- case e:Exception =>
- if (true) e.printStackTrace
- reportEncodingError(file.toString())
- new Array[Char](0)
- } finally {
- c.close()
- }
+
+ try read(c)
+ catch { case e: Exception => reportEncodingError("" + file) ; Array() }
+ finally c.close()
}
/** Reads the specified file.
- *
- * @param file ...
- * @return ...
*/
def read(file: AbstractFile): Array[Char] = {
- file match {
- case p:PlainFile =>
- read(p.file) // bq: (!!!)
- case z:ZipArchive#FileEntry =>
- val c = Channels.newChannel(z.archive.getInputStream(z.entry))
- read(c)
- case _ =>
- val b = ByteBuffer.wrap(file.toByteArray)
- try {
- read(b)
- } catch {
- case e:Exception =>
- if (true) e.printStackTrace
- reportEncodingError(file.toString())
- new Array[Char](0)
- }
+ try file match {
+ case p: PlainFile => read(p.file)
+ case z: ZipArchive#Entry => read(Channels.newChannel(z.input))
+ case _ => read(ByteBuffer.wrap(file.toByteArray))
+ }
+ catch {
+ case e: Exception => reportEncodingError("" + file) ; Array()
}
}
/** Reads the specified byte channel. */
protected def read(input: ReadableByteChannel): Array[Char] = {
val decoder: CharsetDecoder = this.decoder.reset()
- val bytes: ByteBuffer = this.bytes; bytes.clear()
- var chars: CharBuffer = this.chars; chars.clear()
- var endOfInput: Boolean = false
+ val bytes: ByteBuffer = this.bytes; bytes.clear()
+ var chars: CharBuffer = this.chars; chars.clear()
+ var endOfInput = false
+
while (!endOfInput ) {
endOfInput = input.read(bytes) < 0
bytes.flip()
View
19 src/compiler/scala/tools/nsc/io/VirtualFile.scala
@@ -8,20 +8,13 @@ package scala.tools.nsc
package io
import java.io.{ ByteArrayInputStream, ByteArrayOutputStream, InputStream, OutputStream }
-import PartialFunction._
/** This class implements an in-memory file.
*
* @author Philippe Altherr
* @version 1.0, 23/03/2004
*/
-class VirtualFile(val name: String, _path: String) extends AbstractFile
-{
- assert((name ne null) && (path ne null), name + " - " + path)
-
- //########################################################################
- // Public Constructors
-
+class VirtualFile(val name: String, override val path: String) extends AbstractFile {
/**
* Initializes this instance with the specified name and an
* identical path.
@@ -31,18 +24,18 @@ class VirtualFile(val name: String, _path: String) extends AbstractFile
*/
def this(name: String) = this(name, name)
- override def hashCode = path.##
- override def equals(that: Any) = cond(that) { case x: VirtualFile => x.path == path }
+ override def hashCode = path.hashCode
+ override def equals(that: Any) = that match {
+ case x: VirtualFile => x.path == path
+ case _ => false
+ }
//########################################################################
// Private data
private var content = new Array[Byte](0)
//########################################################################
// Public Methods
-