Skip to content
This repository
Browse code

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...
commit 3307c3771777cf17d5b4d059726a1b484923d042 1 parent f346e54
Antonio Cunei authored

Showing 218 changed files with 3,904 additions and 2,400 deletions. Show diff stats Hide diff stats

  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
9 META-INF/MANIFEST.MF
@@ -9,8 +9,7 @@ Bundle-ClassPath:
9 9 bin,
10 10 lib/fjbg.jar,
11 11 lib/jline.jar,
12   - lib/msil.jar,
13   - lib/scala-library.jar
  12 + lib/msil.jar
14 13 Export-Package:
15 14 scala.tools.nsc,
16 15 scala.tools.nsc.ast,
@@ -22,6 +21,10 @@ Export-Package:
22 21 scala.tools.nsc.backend.opt,
23 22 scala.tools.nsc.dependencies,
24 23 scala.tools.nsc.doc,
  24 + scala.tools.nsc.doc.html,
  25 + scala.tools.nsc.doc.html.page,
  26 + scala.tools.nsc.doc.model,
  27 + scala.tools.nsc.doc.model.comment,
25 28 scala.tools.nsc.interactive,
26 29 scala.tools.nsc.interpreter,
27 30 scala.tools.nsc.io,
@@ -36,6 +39,8 @@ Export-Package:
36 39 scala.tools.nsc.typechecker,
37 40 scala.tools.nsc.util,
38 41 scala.tools.util,
  42 + scala.reflect.internal,
  43 + scala.reflect.internal.settings,
39 44 ch.epfl.lamp.compiler.msil,
40 45 ch.epfl.lamp.compiler.msil.emit,
41 46 ch.epfl.lamp.compiler.msil.util,
2  lib/jline.jar.desired.sha1
... ... @@ -1 +1 @@
1   -5eade2bafa228aab1f5abc63e6062ce8052e4f6d ?jline.jar
  1 +545b37930819a1196705e582a232abfeb252cc8d ?jline.jar
2  project/build.properties
@@ -2,7 +2,7 @@
2 2 #Sun Apr 11 14:24:47 CEST 2010
3 3 project.name=scala
4 4 def.scala.version=2.7.7
5   -sbt.version=0.7.5.RC0
  5 +sbt.version=0.7.7
6 6 copyright=Copyright 2002-2011, LAMP/EPFL
7 7 build.scala.versions=2.7.7
8 8 project.initialize=false
27 src/actors/scala/actors/Actor.scala
@@ -590,20 +590,27 @@ trait Actor extends AbstractActor with ReplyReactor with ActorCanReply with Inpu
590 590 receiveTimeout
591 591 } else {
592 592 if (onTimeout.isEmpty) {
593   - waitingFor = f
594   - received = None
595   - isSuspended = true
  593 + if (!f.isDefinedAt(TIMEOUT))
  594 + sys.error("unhandled timeout")
  595 +
596 596 val thisActor = this
597 597 onTimeout = Some(new TimerTask {
598   - def run() { thisActor.send(TIMEOUT, thisActor) }
  598 + def run() {
  599 + thisActor.send(TIMEOUT, thisActor)
  600 + }
599 601 })
600 602 Actor.timer.schedule(onTimeout.get, msec)
601   - scheduler.managedBlock(blocker)
602   - drainSendBuffer(mailbox)
603   - // keep going
604   - () => {}
605   - } else
606   - sys.error("unhandled timeout")
  603 + }
  604 +
  605 + // It is possible that !onTimeout.isEmpty, but TIMEOUT is not yet in mailbox
  606 + // See SI-4759
  607 + waitingFor = f
  608 + received = None
  609 + isSuspended = true
  610 + scheduler.managedBlock(blocker)
  611 + drainSendBuffer(mailbox)
  612 + // keep going
  613 + () => {}
607 614 }
608 615 }
609 616 todo()
2  src/compiler/scala/tools/ant/Scalac.scala
@@ -615,7 +615,7 @@ class Scalac extends ScalaMatchingTask with ScalacShared {
615 615
616 616 file
617 617 }
618   - val res = execWithArgFiles(java, List(writeSettings.getCanonicalPath))
  618 + val res = execWithArgFiles(java, List(writeSettings.getAbsolutePath))
619 619 if (failonerror && res != 0)
620 620 buildError("Compilation failed because of an internal compiler error;"+
621 621 " see the error output for details.")
4 src/compiler/scala/tools/ant/templates/tool-windows.tmpl
@@ -21,7 +21,7 @@ set _JAVACMD=%JAVACMD%
21 21
22 22 if "%_JAVACMD%"=="" (
23 23 if not "%JAVA_HOME%"=="" (
24   - if exist "%JAVA_HOME%\bin\java.exe" set _JAVACMD=%JAVA_HOME%\bin\java.exe
  24 + if exist "%JAVA_HOME%\bin\java.exe" set "_JAVACMD=%JAVA_HOME%\bin\java.exe"
25 25 )
26 26 )
27 27
@@ -37,7 +37,7 @@ if "%_TOOL_CLASSPATH%"=="" (
37 37 for /d %%f in ("%_SCALA_HOME%\lib\*") do call :add_cpath "%%f"
38 38 )
39 39
40   -set _PROPS=-Dscala.home="%_SCALA_HOME%" -Denv.emacs="%EMACS%" @properties@
  40 +set _PROPS=-Dscala.home="%_SCALA_HOME%" -Denv.emacs="%EMACS%" -Dscala.usejavacp=true @properties@
41 41
42 42 rem echo "%_JAVACMD%" %_JAVA_OPTS% %_PROPS% -cp "%_TOOL_CLASSPATH%" @class@ @toolflags@ %*
43 43 "%_JAVACMD%" %_JAVA_OPTS% %_PROPS% -cp "%_TOOL_CLASSPATH%" @class@ @toolflags@ %*
23 src/compiler/scala/tools/cmd/gen/AnyVals.scala
@@ -12,12 +12,12 @@ trait AnyValReps {
12 12 self: AnyVals =>
13 13
14 14 sealed abstract class AnyValNum(name: String) extends AnyValRep(name) {
15   - def isCardinal: Boolean = isIntegerType(this)
16   - def unaryOps = if (isCardinal) List("+", "-", "~") else List("+", "-")
17   - def bitwiseOps = if (isCardinal) List("|", "&", "^") else Nil
18   - def shiftOps = if (isCardinal) List("<<", ">>>", ">>") else Nil
19   - def comparisonOps = List("==", "!=", "<", "<=", ">", ">=")
20   - def otherOps = List("+", "-" ,"*", "/", "%")
  15 + def isCardinal: Boolean = isIntegerType(this)
  16 + def unaryOps = if (isCardinal) List("+", "-", "~") else List("+", "-")
  17 + def bitwiseOps = if (isCardinal) List("|", "&", "^") else Nil
  18 + def shiftOps = if (isCardinal) List("<<", ">>>", ">>") else Nil
  19 + def comparisonOps = List("==", "!=", "<", "<=", ">", ">=")
  20 + def otherOps = List("+", "-" ,"*", "/", "%")
21 21
22 22 // Given two numeric value types S and T , the operation type of S and T is defined as follows:
23 23 // If both S and T are subrange types then the operation type of S and T is Int.
@@ -49,7 +49,7 @@ trait AnyValReps {
49 49 )
50 50 xs1 ++ xs2
51 51 }
52   - def classLines = clumps.foldLeft(List[String]()) {
  52 + def classLines = (clumps :+ commonClassLines).foldLeft(List[String]()) {
53 53 case (res, Nil) => res
54 54 case (res, lines) =>
55 55 val xs = lines map {
@@ -80,6 +80,9 @@ trait AnyValReps {
80 80 sealed abstract class AnyValRep(val name: String) {
81 81 def classLines: List[String]
82 82 def objectLines: List[String]
  83 + def commonClassLines = List(
  84 + "def getClass(): Class[@name@]"
  85 + )
83 86
84 87 def lcname = name.toLowerCase
85 88 def boxedName = this match {
@@ -243,6 +246,8 @@ def &&(x: Boolean): Boolean = sys.error("stub")
243 246 def |(x: Boolean): Boolean = sys.error("stub")
244 247 def &(x: Boolean): Boolean = sys.error("stub")
245 248 def ^(x: Boolean): Boolean = sys.error("stub")
  249 +
  250 +def getClass(): Class[Boolean] = sys.error("stub")
246 251 """.trim.lines.toList
247 252
248 253 def objectLines = interpolate(allCompanions).lines.toList
@@ -254,7 +259,9 @@ def ^(x: Boolean): Boolean = sys.error("stub")
254 259 * only one value of type Unit: `()`.
255 260 */
256 261 """
257   - def classLines = Nil
  262 + def classLines = List(
  263 + """def getClass(): Class[Unit] = sys.error("stub")"""
  264 + )
258 265 def objectLines = interpolate(allCompanions).lines.toList
259 266
260 267 override def boxUnboxImpls = Map(
21 src/compiler/scala/tools/nsc/Global.scala
@@ -157,7 +157,10 @@ class Global(var settings: Settings, var reporter: Reporter) extends SymbolTable
157 157 def informTime(msg: String, start: Long) = informProgress(elapsedMessage(msg, start))
158 158
159 159 def logError(msg: String, t: Throwable): Unit = ()
160   - def log(msg: => AnyRef): Unit = if (opt.logPhase) inform("[log " + phase + "] " + msg)
  160 + // Over 200 closure objects are eliminated by inlining this.
  161 + @inline final def log(msg: => AnyRef): Unit =
  162 + if (settings.log containsPhase globalPhase)
  163 + inform("[log " + phase + "] " + msg)
161 164
162 165 def logThrowable(t: Throwable): Unit = globalError(throwableAsString(t))
163 166 def throwableAsString(t: Throwable): String =
@@ -232,7 +235,6 @@ class Global(var settings: Settings, var reporter: Reporter) extends SymbolTable
232 235 // debugging
233 236 def checkPhase = wasActive(settings.check)
234 237 def logPhase = isActive(settings.log)
235   - def typerDebug = settings.Ytyperdebug.value
236 238 def writeICode = settings.writeICode.value
237 239
238 240 // showing/printing things
@@ -255,9 +257,10 @@ class Global(var settings: Settings, var reporter: Reporter) extends SymbolTable
255 257 def profileClass = settings.YprofileClass.value
256 258 def profileMem = settings.YprofileMem.value
257 259
258   - // XXX: short term, but I can't bear to add another option.
259   - // scalac -Dscala.timings will make this true.
  260 + // shortish-term property based options
260 261 def timings = sys.props contains "scala.timings"
  262 + def inferDebug = (sys.props contains "scalac.debug.infer") || settings.Yinferdebug.value
  263 + def typerDebug = (sys.props contains "scalac.debug.typer") || settings.Ytyperdebug.value
261 264 }
262 265
263 266 // True if -Xscript has been set, indicating a script run.
@@ -323,7 +326,7 @@ class Global(var settings: Settings, var reporter: Reporter) extends SymbolTable
323 326 currentRun.currentUnit = unit
324 327 if (!cancelled(unit)) {
325 328 currentRun.informUnitStarting(this, unit)
326   - reporter.withSource(unit.source) { apply(unit) }
  329 + apply(unit)
327 330 }
328 331 currentRun.advanceUnit
329 332 } finally {
@@ -335,6 +338,7 @@ class Global(var settings: Settings, var reporter: Reporter) extends SymbolTable
335 338
336 339 /** Switch to turn on detailed type logs */
337 340 var printTypings = opt.typerDebug
  341 + var printInfers = opt.inferDebug
338 342
339 343 // phaseName = "parser"
340 344 object syntaxAnalyzer extends {
@@ -1051,9 +1055,7 @@ class Global(var settings: Settings, var reporter: Reporter) extends SymbolTable
1051 1055 def loop(ph: Phase) {
1052 1056 if (stop(ph)) refreshProgress
1053 1057 else {
1054   - reporter.withSource(unit.source) {
1055   - atPhase(ph)(ph.asInstanceOf[GlobalPhase] applyPhase unit)
1056   - }
  1058 + atPhase(ph)(ph.asInstanceOf[GlobalPhase] applyPhase unit)
1057 1059 loop(ph.next match {
1058 1060 case `ph` => null // ph == ph.next implies terminal, and null ends processing
1059 1061 case x => x
@@ -1091,7 +1093,7 @@ class Global(var settings: Settings, var reporter: Reporter) extends SymbolTable
1091 1093 /**
1092 1094 * Re-orders the source files to
1093 1095 * 1. ScalaObject
1094   - * 2. LowPriorityImplicits / StandardEmbeddings (i.e. parents of Predef)
  1096 + * 2. LowPriorityImplicits / EmbeddedControls (i.e. parents of Predef)
1095 1097 * 3. the rest
1096 1098 *
1097 1099 * 1 is to avoid cyclic reference errors.
@@ -1121,6 +1123,7 @@ class Global(var settings: Settings, var reporter: Reporter) extends SymbolTable
1121 1123 case "ScalaObject.scala" => 1
1122 1124 case "LowPriorityImplicits.scala" => 2
1123 1125 case "StandardEmbeddings.scala" => 2
  1126 + case "EmbeddedControls.scala" => 2
1124 1127 case "Predef.scala" => 3 /* Predef.scala before Any.scala, etc. */
1125 1128 case _ => goLast
1126 1129 }
15 src/compiler/scala/tools/nsc/ScriptRunner.scala
@@ -5,18 +5,9 @@
5 5
6 6 package scala.tools.nsc
7 7
8   -import java.io.{
9   - InputStream, OutputStream,
10   - BufferedReader, FileInputStream, FileOutputStream,
11   - FileReader, InputStreamReader, PrintWriter, FileWriter,
12   - IOException
13   -}
14   -import io.{ Directory, File, Path, PlainFile }
  8 +import io.{ Directory, File, Path }
  9 +import java.io.IOException
15 10 import java.net.URL
16   -import java.util.jar.{ JarEntry, JarOutputStream }
17   -
18   -import util.{ waitingForThreads }
19   -import scala.tools.util.PathResolver
20 11 import scala.tools.nsc.reporters.{Reporter,ConsoleReporter}
21 12 import util.Exceptional.unwrap
22 13
@@ -136,7 +127,7 @@ class ScriptRunner extends HasCompileSocket {
136 127 /** The script runner calls sys.exit to communicate a return value, but this must
137 128 * not take place until there are no non-daemon threads running. Tickets #1955, #2006.
138 129 */
139   - waitingForThreads {
  130 + util.waitingForThreads {
140 131 if (settings.save.value) {
141 132 val jarFile = jarFileFor(scriptFile)
142 133 def jarOK = jarFile.canRead && (jarFile isFresher File(scriptFile))
6 src/compiler/scala/tools/nsc/ast/TreeDSL.scala
@@ -253,12 +253,6 @@ trait TreeDSL {
253 253
254 254 class SymbolMethods(target: Symbol) {
255 255 def BIND(body: Tree) = Bind(target, body)
256   -
257   - // Option
258   - def IS_DEFINED() =
259   - if (target.tpe.typeSymbol == SomeClass) TRUE // is Some[_]
260   - else NOT(ID(target) DOT nme.isEmpty) // is Option[_]
261   -
262 256 def IS_NULL() = REF(target) OBJ_EQ NULL
263 257 def NOT_NULL() = REF(target) OBJ_NE NULL
264 258
2  src/compiler/scala/tools/nsc/ast/TreeGen.scala
@@ -211,7 +211,7 @@ abstract class TreeGen {
211 211 if (tree.tpe != null || !tree.hasSymbol) tree.tpe
212 212 else tree.symbol.tpe
213 213
214   - if (!global.phase.erasedTypes && settings.Xchecknull.value &&
  214 + if (!global.phase.erasedTypes && settings.warnSelectNullable.value &&
215 215 tpe <:< NotNullClass.tpe && !tpe.isNotNull)
216 216 mkRuntimeCall(nme.checkInitialized, List(tree))
217 217 else
30 src/compiler/scala/tools/nsc/ast/TreeInfo.scala
@@ -96,10 +96,11 @@ abstract class TreeInfo {
96 96 false
97 97 }
98 98
99   - def mayBeVarGetter(sym: Symbol) = sym.info match {
100   - case NullaryMethodType(_) => sym.owner.isClass && !sym.isStable
101   - case mt @ MethodType(_, _) => mt.isImplicit && sym.owner.isClass && !sym.isStable
102   - case _ => false
  99 + def mayBeVarGetter(sym: Symbol): Boolean = sym.info match {
  100 + case NullaryMethodType(_) => sym.owner.isClass && !sym.isStable
  101 + case PolyType(_, NullaryMethodType(_)) => sym.owner.isClass && !sym.isStable
  102 + case mt @ MethodType(_, _) => mt.isImplicit && sym.owner.isClass && !sym.isStable
  103 + case _ => false
103 104 }
104 105
105 106 def isVariableOrGetter(tree: Tree) = {
@@ -361,8 +362,9 @@ abstract class TreeInfo {
361 362 case _ => false
362 363 }
363 364
364   - /** Some handy extractors for spotting true and false expressions
365   - * through the haze of braces.
  365 + /** Some handy extractors for spotting trees through the
  366 + * the haze of irrelevant braces: i.e. Block(Nil, SomeTree)
  367 + * should not keep us from seeing SomeTree.
366 368 */
367 369 abstract class SeeThroughBlocks[T] {
368 370 protected def unapplyImpl(x: Tree): T
@@ -372,9 +374,21 @@ abstract class TreeInfo {
372 374 }
373 375 }
374 376 object IsTrue extends SeeThroughBlocks[Boolean] {
375   - protected def unapplyImpl(x: Tree): Boolean = x equalsStructure Literal(Constant(true))
  377 + protected def unapplyImpl(x: Tree): Boolean = x match {
  378 + case Literal(Constant(true)) => true
  379 + case _ => false
  380 + }
376 381 }
377 382 object IsFalse extends SeeThroughBlocks[Boolean] {
378   - protected def unapplyImpl(x: Tree): Boolean = x equalsStructure Literal(Constant(false))
  383 + protected def unapplyImpl(x: Tree): Boolean = x match {
  384 + case Literal(Constant(false)) => true
  385 + case _ => false
  386 + }
  387 + }
  388 + object IsIf extends SeeThroughBlocks[Option[(Tree, Tree, Tree)]] {
  389 + protected def unapplyImpl(x: Tree) = x match {
  390 + case If(cond, thenp, elsep) => Some(cond, thenp, elsep)
  391 + case _ => None
  392 + }
379 393 }
380 394 }
10 src/compiler/scala/tools/nsc/ast/Trees.scala
@@ -949,6 +949,10 @@ trait Trees extends reflect.generic.Trees { self: SymbolTable =>
949 949 if (tree eq orig) super.transform(tree)
950 950 else tree
951 951 }
  952 + // Create a readable string describing a substitution.
  953 + private def substituterString(fromStr: String, toStr: String, from: List[Any], to: List[Any]): String = {
  954 + "subst[%s, %s](%s)".format(fromStr, toStr, (from, to).zipped map (_ + " -> " + _) mkString ", ")
  955 + }
952 956
953 957 class TreeSubstituter(from: List[Symbol], to: List[Tree]) extends Transformer {
954 958 override def transform(tree: Tree): Tree = tree match {
@@ -961,11 +965,13 @@ trait Trees extends reflect.generic.Trees { self: SymbolTable =>
961 965 case _ =>
962 966 super.transform(tree)
963 967 }
  968 + override def toString = substituterString("Symbol", "Tree", from, to)
964 969 }
965 970
966 971 class TreeTypeSubstituter(val from: List[Symbol], val to: List[Type]) extends Traverser {
967 972 val typeSubst = new SubstTypeMap(from, to)
968 973 def fromContains = typeSubst.fromContains
  974 + def isEmpty = from.isEmpty && to.isEmpty
969 975
970 976 override def traverse(tree: Tree) {
971 977 if (tree.tpe ne null) tree.tpe = typeSubst(tree.tpe)
@@ -994,7 +1000,7 @@ trait Trees extends reflect.generic.Trees { self: SymbolTable =>
994 1000 super.traverse(tree)
995 1001 }
996 1002 override def apply[T <: Tree](tree: T): T = super.apply(tree.duplicate)
997   - override def toString() = "TreeSymSubstTraverser("+from+","+to+")"
  1003 + override def toString() = "TreeSymSubstTraverser/" + substituterString("Symbol", "Symbol", from, to)
998 1004 }
999 1005
1000 1006 /** Substitute symbols in 'from' with symbols in 'to'. Returns a new
@@ -1025,7 +1031,7 @@ trait Trees extends reflect.generic.Trees { self: SymbolTable =>
1025 1031 super.transform(tree)
1026 1032 }
1027 1033 def apply[T <: Tree](tree: T): T = transform(tree).asInstanceOf[T]
1028   - override def toString() = "TreeSymSubstituter("+from+","+to+")"
  1034 + override def toString() = "TreeSymSubstituter/" + substituterString("Symbol", "Symbol", from, to)
1029 1035 }
1030 1036
1031 1037 class ChangeOwnerTraverser(val oldowner: Symbol, val newowner: Symbol) extends Traverser {
11 src/compiler/scala/tools/nsc/ast/parser/SyntaxAnalyzer.scala
@@ -21,12 +21,15 @@ abstract class SyntaxAnalyzer extends SubComponent with Parsers with MarkupParse
21 21 override val keepsTypeParams = false
22 22
23 23 def apply(unit: global.CompilationUnit) {
24   - global.informProgress("parsing " + unit)
  24 + import global._
  25 + informProgress("parsing " + unit)
25 26 unit.body =
26 27 if (unit.source.file.name.endsWith(".java")) new JavaUnitParser(unit).parse()
27   - else if (!global.reporter.incompleteHandled) new UnitParser(unit).smartParse()
28   - else new UnitParser(unit).parse()
29   - if (global.settings.Yrangepos.value && !global.reporter.hasErrors) global.validatePositions(unit.body)
  28 + else if (reporter.incompleteHandled) new UnitParser(unit).parse()
  29 + else new UnitParser(unit).smartParse()
  30 +
  31 + if (settings.Yrangepos.value && !reporter.hasErrors)
  32 + validatePositions(unit.body)
30 33 }
31 34 }
32 35 }
17 src/compiler/scala/tools/nsc/backend/JavaPlatform.scala
@@ -13,10 +13,10 @@ import scala.tools.util.PathResolver
13 13
14 14 trait JavaPlatform extends Platform[AbstractFile] {
15 15 import global._
16   - import definitions.{ BoxesRunTimeClass, getMember }
  16 + import definitions._
17 17
18 18 lazy val classPath = new PathResolver(settings).result
19   - def rootLoader = new loaders.JavaPackageLoader(classPath)
  19 + def rootLoader = new loaders.JavaPackageLoader(classPath)
20 20
21 21 private def depAnalysisPhase =
22 22 if (settings.make.isDefault) Nil
@@ -26,20 +26,19 @@ trait JavaPlatform extends Platform[AbstractFile] {
26 26 flatten, // get rid of inner classes
27 27 liftcode, // generate reified trees
28 28 genJVM // generate .class files
29   - ) ::: depAnalysisPhase
  29 + ) ++ depAnalysisPhase
30 30
31   - lazy val externalEquals = getMember(BoxesRunTimeClass, nme.equals_)
32   - def externalEqualsNumNum = getMember(BoxesRunTimeClass, "equalsNumNum")
33   - def externalEqualsNumChar = getMember(BoxesRunTimeClass, "equalsNumChar")
34   - def externalEqualsNumObject = getMember(BoxesRunTimeClass, "equalsNumObject")
  31 + lazy val externalEquals = getMember(BoxesRunTimeClass, nme.equals_)
  32 + lazy val externalEqualsNumNum = getMember(BoxesRunTimeClass, "equalsNumNum")
  33 + lazy val externalEqualsNumChar = getMember(BoxesRunTimeClass, "equalsNumChar")
  34 + lazy val externalEqualsNumObject = getMember(BoxesRunTimeClass, "equalsNumObject")
35 35
36 36 /** We could get away with excluding BoxedBooleanClass for the
37 37 * purpose of equality testing since it need not compare equal
38 38 * to anything but other booleans, but it should be present in
39 39 * case this is put to other uses.
40 40 */
41   - def isMaybeBoxed(sym: Symbol): Boolean = {
42   - import definitions._
  41 + def isMaybeBoxed(sym: Symbol) = {
43 42 (sym == ObjectClass) ||
44 43 (sym == JavaSerializableClass) ||
45 44 (sym == ComparableClass) ||
27 src/compiler/scala/tools/nsc/backend/jvm/GenJVM.scala
@@ -249,7 +249,7 @@ abstract class GenJVM extends SubComponent with GenJVMUtil with GenAndroid with
249 249 parents = parents.distinct
250 250
251 251 if (parents.tail.nonEmpty)
252   - ifaces = parents drop 1 map (x => javaName(x.typeSymbol)) toArray;
  252 + ifaces = mkArray(parents drop 1 map (x => javaName(x.typeSymbol)))
253 253
254 254 jclass = fjbgContext.JClass(javaFlags(c.symbol),
255 255 name,
@@ -280,7 +280,17 @@ abstract class GenJVM extends SubComponent with GenJVMUtil with GenAndroid with
280 280 !(sym.name.toString contains '$') && sym.hasModuleFlag && !sym.isImplClass && !sym.isNestedClass
281 281 }
282 282
283   - val lmoc = c.symbol.companionModule
  283 + // At some point this started throwing lots of exceptions as a compile was finishing.
  284 + // error: java.lang.AssertionError:
  285 + // assertion failed: List(object package$CompositeThrowable, object package$CompositeThrowable)
  286 + // ...is the one I've seen repeatedly. Suppressing.
  287 + val lmoc = (
  288 + try c.symbol.companionModule
  289 + catch { case x: AssertionError =>
  290 + Console.println("Suppressing failed assert: " + x)
  291 + NoSymbol
  292 + }
  293 + )
284 294 // add static forwarders if there are no name conflicts; see bugs #363 and #1735
285 295 if (lmoc != NoSymbol && !c.symbol.isInterface) {
286 296 if (isCandidateForForwarders(lmoc) && !settings.noForwarders.value) {
@@ -567,7 +577,7 @@ abstract class GenJVM extends SubComponent with GenJVMUtil with GenAndroid with
567 577 * in which case we treat every signature as valid. Medium term we
568 578 * should certainly write independent signature validation.
569 579 */
570   - if (SigParser.isParserAvailable && !isValidSignature(sym, sig)) {
  580 + if (settings.Xverify.value && SigParser.isParserAvailable && !isValidSignature(sym, sig)) {
571 581 clasz.cunit.warning(sym.pos,
572 582 """|compiler bug: created invalid generic signature for %s in %s
573 583 |signature: %s
@@ -744,8 +754,8 @@ abstract class GenJVM extends SubComponent with GenJVMUtil with GenAndroid with
744 754 jmethod = jclass.addNewMethod(flags,
745 755 javaName(m.symbol),
746 756 resTpe,
747   - m.params map (p => javaType(p.kind)) toArray,
748   - m.params map (p => javaName(p.sym)) toArray)
  757 + mkArray(m.params map (p => javaType(p.kind))),
  758 + mkArray(m.params map (p => javaName(p.sym))))
749 759
750 760 addRemoteException(jmethod, m.symbol)
751 761
@@ -939,8 +949,8 @@ abstract class GenJVM extends SubComponent with GenJVMUtil with GenAndroid with
939 949 accessFlags,
940 950 javaName(m),
941 951 javaType(methodInfo.resultType),
942   - paramJavaTypes.toArray,
943   - paramNames.toArray)
  952 + mkArray(paramJavaTypes),
  953 + mkArray(paramNames))
944 954 val mirrorCode = mirrorMethod.getCode().asInstanceOf[JExtendedCode]
945 955 mirrorCode.emitGETSTATIC(moduleName,
946 956 nme.MODULE_INSTANCE_FIELD.toString,
@@ -1483,8 +1493,9 @@ abstract class GenJVM extends SubComponent with GenJVMUtil with GenAndroid with
1483 1493
1484 1494 // assert(instr.pos.source.isEmpty || instr.pos.source.get == (clasz.cunit.source), "sources don't match")
1485 1495 // val crtLine = instr.pos.line.get(lastLineNr);
  1496 +
1486 1497 val crtLine = try {
1487   - (instr.pos).line
  1498 + if (instr.pos == NoPosition) lastLineNr else (instr.pos).line // check NoPosition to avoid costly exception
1488 1499 } catch {
1489 1500 case _: UnsupportedOperationException =>
1490 1501 log("Warning: wrong position in: " + method)
10 src/compiler/scala/tools/nsc/backend/jvm/GenJVMUtil.scala
@@ -68,6 +68,14 @@ trait GenJVMUtil {
68 68 GE -> LT
69 69 )
70 70
  71 + /** Specialized array conversion to prevent calling
  72 + * java.lang.reflect.Array.newInstance via TraversableOnce.toArray
  73 + */
  74 +
  75 + def mkArray(xs: Traversable[JType]): Array[JType] = { val a = new Array[JType](xs.size); xs.copyToArray(a); a }
  76 + def mkArray(xs: Traversable[String]): Array[String] = { val a = new Array[String](xs.size); xs.copyToArray(a); a }
  77 +
  78 +
71 79 /** Return the a name of this symbol that can be used on the Java
72 80 * platform. It removes spaces from names.
73 81 *
@@ -109,7 +117,7 @@ trait GenJVMUtil {
109 117 if (s.isMethod)
110 118 new JMethodType(
111 119 if (s.isClassConstructor) JType.VOID else javaType(s.tpe.resultType),
112   - s.tpe.paramTypes map javaType toArray
  120 + mkArray(s.tpe.paramTypes map javaType)
113 121 )
114 122 else
115 123 javaType(s.tpe)
4 src/compiler/scala/tools/nsc/doc/Uncompilable.scala
@@ -13,7 +13,7 @@ trait Uncompilable {
13 13 val global: Global
14 14 val settings: Settings
15 15
16   - import global.{ reporter, inform, warning, newTypeName, newTermName, Symbol, Name, DocComment }
  16 + import global.{ reporter, inform, warning, newTypeName, newTermName, Symbol, Name, DocComment, NoSymbol }
17 17 import global.definitions.RootClass
18 18
19 19 private implicit def translateName(name: Global#Name) =
@@ -43,6 +43,6 @@ trait Uncompilable {
43 43 pairs
44 44 }
45 45 override def toString = pairs.size + " uncompilable symbols:\n" + (
46   - symbols map (x => " " + x.owner.fullName + " " + x.defString) mkString "\n"
  46 + symbols filterNot (_ == NoSymbol) map (x => " " + x.owner.fullName + " " + x.defString) mkString "\n"
47 47 )
48 48 }
1  src/compiler/scala/tools/nsc/doc/html/HtmlFactory.scala
@@ -97,6 +97,7 @@ class HtmlFactory(val universe: doc.Universe, index: doc.Index) {
97 97 copyResource("lib/unselected.png")
98 98
99 99 new page.Index(universe, index) writeFor this
  100 + new page.IndexScript(universe, index) writeFor this
100 101
101 102 writeTemplates(page => page.writeFor(this))
102 103
71 src/compiler/scala/tools/nsc/doc/html/HtmlPage.scala
@@ -15,18 +15,11 @@ import xml.dtd.{DocType, PublicID}
15 15 import scala.collection._
16 16 import scala.reflect.NameTransformer
17 17 import java.nio.channels.Channels
18   -import java.io.{FileOutputStream, File}
19 18
20 19 /** An html page that is part of a Scaladoc site.
21 20 * @author David Bernard
22 21 * @author Gilles Dubochet */
23   -abstract class HtmlPage { thisPage =>
24   -
25   - /** The path of this page, relative to the API site. `path.tail` is a list of folder names leading to this page (from
26   - * closest package to one-above-root package), `path.head` is the file name of this page. Note that `path` has a
27   - * length of at least one. */
28   - def path: List[String]
29   -
  22 +abstract class HtmlPage extends Page { thisPage =>
30 23 /** The title of this page. */
31 24 protected def title: String
32 25
@@ -36,9 +29,6 @@ abstract class HtmlPage { thisPage =>
36 29 /** The body of this page. */
37 30 def body: NodeSeq
38 31
39   - /** Writes this page as a file. The file's location is relative to the generator's site root, and the encoding is
40   - * also defined by the generator.
41   - * @param generator The generator that is writing this page. */
42 32 def writeFor(site: HtmlFactory): Unit = {
43 33 val doctype =
44 34 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 =>
51 41 </head>
52 42 { body }
53 43 </html>
54   - val pageFile = new File(site.siteRoot, absoluteLinkTo(thisPage.path))
55   - val pageFolder = pageFile.getParentFile
56   - if (!pageFolder.exists) pageFolder.mkdirs()
57   - val fos = new FileOutputStream(pageFile.getPath)
  44 + val fos = createFileOutputStream(site)
58 45 val w = Channels.newWriter(fos.getChannel, site.encoding)
59 46 try {
60 47 w.write("<?xml version='1.0' encoding='" + site.encoding + "'?>\n")
@@ -68,52 +55,6 @@ abstract class HtmlPage { thisPage =>
68 55 //XML.save(pageFile.getPath, html, site.encoding, xmlDecl = false, doctype = doctype)
69 56 }
70 57
71   - def templateToPath(tpl: TemplateEntity): List[String] = {
72   - def doName(tpl: TemplateEntity): String =
73   - NameTransformer.encode(tpl.name) + (if (tpl.isObject) "$" else "")
74   - def downPacks(pack: Package): List[String] =
75   - if (pack.isRootPackage) Nil else (doName(pack) :: downPacks(pack.inTemplate))
76   - def downInner(nme: String, tpl: TemplateEntity): (String, Package) = {
77   - tpl.inTemplate match {
78   - case inPkg: Package => (nme + ".html", inPkg)
79   - case inTpl => downInner(doName(inTpl) + "$" + nme, inTpl)
80   - }
81   - }
82   - val (file, pack) =
83   - tpl match {
84   - case p: Package => ("package.html", p)
85   - case _ => downInner(doName(tpl), tpl)
86   - }
87   - file :: downPacks(pack)
88   - }
89   -
90   - /** A relative link from this page to some destination class entity.
91   - * @param destEntity The class or object entity that the link will point to. */
92   - def relativeLinkTo(destClass: TemplateEntity): String =
93   - relativeLinkTo(templateToPath(destClass))
94   -
95   - /** A relative link from this page to some destination page in the Scaladoc site.
96   - * @param destPage The page that the link will point to. */
97   - def relativeLinkTo(destPage: HtmlPage): String = {
98   - relativeLinkTo(destPage.path)
99   - }
100   -
101   - /** A relative link from this page to some destination path.
102   - * @param destPath The path that the link will point to. */
103   - def relativeLinkTo(destPath: List[String]): String = {
104   - def relativize(from: List[String], to: List[String]): List[String] = (from, to) match {
105   - case (f :: fs, t :: ts) if (f == t) => // both paths are identical to that point
106   - relativize(fs, ts)
107   - case (fss, tss) =>
108   - List.fill(fss.length - 1)("..") ::: tss
109   - }
110   - relativize(thisPage.path.reverse, destPath.reverse).mkString("/")
111   - }
112   -
113   - def absoluteLinkTo(destPath: List[String]): String = {
114   - destPath.reverse.mkString("/")
115   - }
116   -
117 58 /** Transforms an optional comment into an styled HTML tree representing its body if it is defined, or into an empty
118 59 * node sequence if it is not. */
119 60 def commentToHtml(comment: Option[Comment]): NodeSeq =
@@ -229,14 +170,6 @@ abstract class HtmlPage { thisPage =>
229 170 case tpl :: tpls => templateToHtml(tpl) ++ sep ++ templatesToHtml(tpls, sep)
230 171 }
231 172
232   - def docEntityKindToString(ety: DocTemplateEntity) =
233   - if (ety.isTrait) "trait"
234   - else if (ety.isCaseClass) "case class"
235   - else if (ety.isClass) "class"
236   - else if (ety.isObject) "object"
237   - else if (ety.isPackage) "package"
238   - else "class" // FIXME: an entity *should* fall into one of the above categories, but AnyRef is somehow not
239   -
240 173 /** Returns the _big image name corresponding to the DocTemplate Entity (upper left icon) */
241 174 def docEntityKindToBigImage(ety: DocTemplateEntity) =
242 175 if (ety.isTrait && !ety.companion.isEmpty && ety.companion.get.visibility.isPublic && ety.companion.get.inSource != None) "trait_to_object_big.png"
93 src/compiler/scala/tools/nsc/doc/html/Page.scala
... ... @@ -0,0 +1,93 @@
  1 +package scala.tools.nsc.doc.html
  2 +import scala.tools.nsc.doc.model._
  3 +import java.io.{FileOutputStream, File}
  4 +import scala.reflect.NameTransformer
  5 +
  6 +abstract class Page {
  7 + thisPage =>
  8 +
  9 + /** The path of this page, relative to the API site. `path.tail` is a list of folder names leading to this page (from
  10 + * closest package to one-above-root package), `path.head` is the file name of this page. Note that `path` has a
  11 + * length of at least one. */
  12 + def path: List[String]
  13 +
  14 + def absoluteLinkTo(path: List[String]) = path.reverse.mkString("/")
  15 +
  16 + def createFileOutputStream(site: HtmlFactory) = {
  17 + val file = new File(site.siteRoot, absoluteLinkTo(thisPage.path))
  18 + val folder = file.getParentFile
  19 + if (! folder.exists) {
  20 + folder.mkdirs
  21 + }
  22 + new FileOutputStream(file.getPath)
  23 + }
  24 +
  25 + /** Writes this page as a file. The file's location is relative to the generator's site root, and the encoding is
  26 + * also defined by the generator.
  27 + * @param generator The generator that is writing this page. */
  28 + def writeFor(site: HtmlFactory): Unit
  29 +
  30 + def docEntityKindToString(ety: DocTemplateEntity) =
  31 + if (ety.isTrait) "trait"
  32 + else if (ety.isCaseClass) "case class"
  33 + else if (ety.isClass) "class"
  34 + else if (ety.isObject) "object"
  35 + else if (ety.isPackage) "package"
  36 + else "class" // FIXME: an entity *should* fall into one of the above categories, but AnyRef is somehow not
  37 +
  38 + def templateToPath(tpl: TemplateEntity): List[String] = {
  39 + def doName(tpl: TemplateEntity): String =
  40 + NameTransformer.encode(tpl.name) + (if (tpl.isObject) "$" else "")
  41 + def downPacks(pack: Package): List[String] =
  42 + if (pack.isRootPackage) Nil else (doName(pack) :: downPacks(pack.inTemplate))
  43 + def downInner(nme: String, tpl: TemplateEntity): (String, Package) = {
  44 + tpl.inTemplate match {
  45 + case inPkg: Package => (nme + ".html", inPkg)
  46 + case inTpl => downInner(doName(inTpl) + "$" + nme, inTpl)
  47 + }
  48 + }
  49 + val (file, pack) =
  50 + tpl match {
  51 + case p: Package => ("package.html", p)
  52 + case _ => downInner(doName(tpl), tpl)
  53 + }
  54 + file :: downPacks(pack)
  55 + }
  56 +
  57 + /** A relative link from this page to some destination class entity.
  58 + * @param destEntity The class or object entity that the link will point to. */
  59 + def relativeLinkTo(destClass: TemplateEntity): String =
  60 + relativeLinkTo(templateToPath(destClass))
  61 +
  62 + /** A relative link from this page to some destination page in the Scaladoc site.
  63 + * @param destPage The page that the link will point to. */
  64 + def relativeLinkTo(destPage: HtmlPage): String = {
  65 + relativeLinkTo(destPage.path)
  66 + }
  67 +
  68 + /** A relative link from this page to some destination path.
  69 + * @param destPath The path that the link will point to. */
  70 + def relativeLinkTo(destPath: List[String]): String = {
  71 + def relativize(from: List[String], to: List[String]): List[String] = (from, to) match {
  72 + case (f :: fs, t :: ts) if (f == t) => // both paths are identical to that point
  73 + relativize(fs, ts)
  74 + case (fss, tss) =>
  75 + List.fill(fss.length - 1)("..") ::: tss
  76 + }
  77 + relativize(thisPage.path.reverse, destPath.reverse).mkString("/")
  78 + }
  79 +
  80 + def isExcluded(dtpl: DocTemplateEntity) = {
  81 + val qname = dtpl.qualifiedName
  82 + ( ( qname.startsWith("scala.Tuple") || qname.startsWith("scala.Product") ||
  83 + qname.startsWith("scala.Function") || qname.startsWith("scala.runtime.AbstractFunction")
  84 + ) && !(
  85 + qname == "scala.Tuple1" || qname == "scala.Tuple2" ||
  86 + qname == "scala.Product" || qname == "scala.Product1" || qname == "scala.Product2" ||
  87 + qname == "scala.Function" || qname == "scala.Function1" || qname == "scala.Function2" ||
  88 + qname == "scala.runtime.AbstractFunction0" || qname == "scala.runtime.AbstractFunction1" ||
  89 + qname == "scala.runtime.AbstractFunction2"
  90 + )
  91 + )
  92 + }
  93 +}
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 {
48 48 </div>
49 49 </body>
50 50
51   -
52   - def isExcluded(dtpl: DocTemplateEntity) = {
53   - val qname = dtpl.qualifiedName
54   - ( ( qname.startsWith("scala.Tuple") || qname.startsWith("scala.Product") ||
55   - qname.startsWith("scala.Function") || qname.startsWith("scala.runtime.AbstractFunction")
56   - ) && !(
57   - qname == "scala.Tuple1" || qname == "scala.Tuple2" ||
58   - qname == "scala.Product" || qname == "scala.Product1" || qname == "scala.Product2" ||
59   - qname == "scala.Function" || qname == "scala.Function1" || qname == "scala.Function2" ||
60   - qname == "scala.runtime.AbstractFunction0" || qname == "scala.runtime.AbstractFunction1" ||
61   - qname == "scala.runtime.AbstractFunction2"
62   - )
63   - )
64   - }
65   -
66 51 def browser =
67   - <xml:group>
68 52 <div id="browser" class="ui-layout-west">
69 53 <div class="ui-west-center">
70 54 <div id="filter"></div>
@@ -121,60 +105,8 @@ class Index(universe: doc.Universe, index: doc.Index) extends HtmlPage {
121 105 </xml:group>
122 106 }
123 107 packageElem(universe.rootPackage)
124   - }</div></div>{ scriptElement }
  108 + }</div></div><script src="index.js"></script>
125 109 </div>
126   - </xml:group>
127   -
128   - def mergeByQualifiedName(source: List[DocTemplateEntity]): Map[String, List[DocTemplateEntity]]= {
129   - var result = Map[String, List[DocTemplateEntity]]()
130   -
131   - for (t <- source) {
132   - val k = t.qualifiedName
133   - result += k -> (result.getOrElse(k, List()) :+ t)
134   - }
135   -
136   - result
137   - }
138   -
139   - def scriptElement = {
140   - val packages = allPackagesWithTemplates.toIterable.map(_ match {
141   - case (pack, templates) => {
142   - val merged = mergeByQualifiedName(templates)
143   -
144   - val ary = merged.keys.toList.sortBy(_.toLowerCase).map(key => {
145   - val pairs = merged(key).map(
146   - t => docEntityKindToString(t) -> relativeLinkTo(t)
147   - ) :+ ("name" -> key)
148   -
149   - JSONObject(scala.collection.immutable.Map(pairs : _*))
150   - })
151   -
152   - pack.qualifiedName -> JSONArray(ary)
153   - }
154   - }).toSeq
155   -
156   - val obj =
157   - JSONObject(scala.collection.immutable.Map(packages : _*)).toString()
158   -
159   - <script type="text/javascript">
160   - Index.PACKAGES = {scala.xml.Unparsed(obj)};
161   - </script>
162   - }
163   -
164   - def allPackagesWithTemplates: Map[Package, List[DocTemplateEntity]] = {
165   - Map(allPackages.map((key) => {
166   - key -> key.templates.filter(t => !t.isPackage && !isExcluded(t))
167   - }) : _*)
168   - }
169   -
170   - def allPackages: List[Package] = {
171   - def f(parent: Package): List[Package] = {
172   - parent.packages.flatMap(
173   - p => f(p) :+ p
174   - )
175   - }
176   - f(universe.rootPackage).sortBy(_.toString)
177   - }
178 110
179 111 def packageQualifiedName(ety: DocTemplateEntity): String =
180 112 if (ety.inTemplate.isPackage) ety.name else (packageQualifiedName(ety.inTemplate) + "." + ety.name)
68 src/compiler/scala/tools/nsc/doc/html/page/IndexScript.scala
... ... @@ -0,0 +1,68 @@
  1 +package scala.tools.nsc.doc.html.page
  2 +import scala.tools.nsc.doc
  3 +import scala.tools.nsc.doc.model.{Package, DocTemplateEntity}
  4 +import scala.tools.nsc.doc.html.{Page, HtmlFactory}
  5 +import java.nio.channels.Channels
  6 +import scala.util.parsing.json.{JSONObject, JSONArray}
  7 +
  8 +class IndexScript(universe: doc.Universe, index: doc.Index) extends Page {
  9 + def path = List("index.js")
  10 +
  11 + override def writeFor(site: HtmlFactory): Unit = {
  12 + val stream = createFileOutputStream(site)
  13 + val writer = Channels.newWriter(stream.getChannel, site.encoding)
  14 + try {
  15 + writer.write("Index.PACKAGES = " + packages.toString() + ";")
  16 + }
  17 + finally {
  18 + writer.close
  19 + stream.close
  20 + }
  21 + }
  22 +
  23 + val packages = {
  24 + val pairs = allPackagesWithTemplates.toIterable.map(_ match {
  25 + case (pack, templates) => {
  26 + val merged = mergeByQualifiedName(templates)
  27 +
  28 + val ary = merged.keys.toList.sortBy(_.toLowerCase).map(key => {
  29 + val pairs = merged(key).map(
  30 + t => docEntityKindToString(t) -> relativeLinkTo(t)
  31 + ) :+ ("name" -> key)
  32 +
  33 + JSONObject(scala.collection.immutable.Map(pairs : _*))
  34 + })
  35 +
  36 + pack.qualifiedName -> JSONArray(ary)
  37 + }
  38 + }).toSeq
  39 +
  40 + JSONObject(scala.collection.immutable.Map(pairs : _*))
  41 + }
  42 +