Skip to content

Commit 0ccb010

Browse files
authored
Merge pull request scala#648 from dubinsky/add-type-annotations
Add type annotations
2 parents 94782c6 + 8851c09 commit 0ccb010

File tree

97 files changed

+1225
-1258
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

97 files changed

+1225
-1258
lines changed

jvm/src/test/scala-2.x/scala/xml/CompilerErrors.scala

+14-14
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ import org.junit.Test
44

55
class CompilerErrors extends CompilerTesting {
66
@Test
7-
def t7185() = {
7+
def t7185(): Unit = {
88
// the error message here differs a bit by Scala version
99
import util.Properties.versionNumberString
10-
val thing =
10+
val thing: String =
1111
if (versionNumberString.startsWith("2.12")) "method value"
1212
else "method"
1313
expectXmlError(s"""|overloaded $thing apply with alternatives:
@@ -20,7 +20,7 @@ class CompilerErrors extends CompilerTesting {
2020
}
2121

2222
@Test
23-
def t1878_typer() =
23+
def t1878_typer(): Unit =
2424
expectXmlError("_* may only come last",
2525
"""|object Test extends App {
2626
| // illegal - bug #1764
@@ -31,14 +31,14 @@ class CompilerErrors extends CompilerTesting {
3131

3232

3333
@Test
34-
def t1017() =
34+
def t1017(): Unit =
3535
expectXmlErrors(1, "not found: value foo",
3636
"""|object Test {
3737
| <x><x><x><x><x><x><x><x><x><x><x><x><x><x><x><x><x><x>{ foo }</x></x></x></x></x></x></x></x></x></x></x></x></x></x></x></x></x></x>
3838
|}""")
3939

4040
@Test
41-
def t1011() =
41+
def t1011(): Unit =
4242
expectXmlErrors(69, "not found: value entity",
4343
"""|import scala.xml._;
4444
|
@@ -177,9 +177,9 @@ class CompilerTesting {
177177

178178
def errorMessages(errorSnippet: String, compileOptions: String = "")(code: String): List[String] = {
179179
import scala.tools.reflect._
180-
val m = scala.reflect.runtime.currentMirror
181-
val tb = m.mkToolBox(options = compileOptions) //: ToolBox[m.universe.type]
182-
val fe = tb.frontEnd
180+
val m: scala.reflect.runtime.universe.Mirror = scala.reflect.runtime.currentMirror
181+
val tb: ToolBox[scala.reflect.runtime.universe.type] = m.mkToolBox(options = compileOptions) //: ToolBox[m.universe.type]
182+
val fe: FrontEnd = tb.frontEnd
183183

184184
try {
185185
tb.eval(tb.parse(code))
@@ -192,17 +192,17 @@ class CompilerTesting {
192192

193193
// note: `code` should have a | margin
194194
// the import's needed because toolbox compiler does not accumulate imports like the real one (TODO: verify hypothesis)
195-
def xmlErrorMessages(msg: String, code: String) =
195+
def xmlErrorMessages(msg: String, code: String): List[String] =
196196
errorMessages(msg)("import scala.xml.{TopScope => $scope}\n"+ code.stripMargin)
197197

198-
def expectXmlError(msg: String, code: String) = {
199-
val errors = xmlErrorMessages(msg, code)
198+
def expectXmlError(msg: String, code: String): Unit = {
199+
val errors: List[String] = xmlErrorMessages(msg, code)
200200
assert(errors exists (_ contains msg), errors mkString "\n")
201201
}
202202

203-
def expectXmlErrors(msgCount: Int, msg: String, code: String) = {
204-
val errors = xmlErrorMessages(msg, code)
205-
val errorCount = errors.count(_ contains msg)
203+
def expectXmlErrors(msgCount: Int, msg: String, code: String): Unit = {
204+
val errors: List[String] = xmlErrorMessages(msg, code)
205+
val errorCount: Int = errors.count(_ contains msg)
206206
assert(errorCount == msgCount, s"$errorCount occurrences of \'$msg\' found -- expected $msgCount in:\n${errors mkString "\n"}")
207207
}
208208
}

jvm/src/test/scala-2.x/scala/xml/XMLTestJVM2x.scala

+12-12
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,25 @@ import scala.xml.parsing.ConstructingParser
66

77
class XMLTestJVM2x {
88
@UnitTest
9-
def t2354: Unit = {
10-
val xml_good = "<title><![CDATA[Hello [tag]]]></title>"
11-
val xml_bad = "<title><![CDATA[Hello [tag] ]]></title>"
9+
def t2354(): Unit = {
10+
val xml_good: String = "<title><![CDATA[Hello [tag]]]></title>"
11+
val xml_bad: String = "<title><![CDATA[Hello [tag] ]]></title>"
1212

13-
val parser1 = ConstructingParser.fromSource(io.Source.fromString(xml_good), false)
14-
val parser2 = ConstructingParser.fromSource(io.Source.fromString(xml_bad), false)
13+
val parser1: ConstructingParser = ConstructingParser.fromSource(io.Source.fromString(xml_good), preserveWS = false)
14+
val parser2: ConstructingParser = ConstructingParser.fromSource(io.Source.fromString(xml_bad), preserveWS = false)
1515

1616
parser1.document()
1717
parser2.document()
1818
}
1919

2020
@UnitTest
21-
def t8253: Unit = {
21+
def t8253(): Unit = {
2222
// `identity(foo)` used to match the overly permissive match in SymbolXMLBuilder
2323
// which was intended to more specifically match `_root_.scala.xml.Text(...)`
2424

2525
import reflect.runtime.universe._ // not using the XML library in compiler tests
2626

27-
val ns1 = "ns1"
27+
val ns1: String = "ns1"
2828
assertEquals(reify(ns1).tree.toString, q"ns1".toString)
2929
assertEquals("<sample xmlns='ns1'/>",
3030
"""|{
@@ -69,21 +69,21 @@ class XMLTestJVM2x {
6969
}
7070

7171
@UnitTest
72-
def t8466lift: Unit = {
72+
def t8466lift(): Unit = {
7373
import scala.reflect.runtime.universe._
7474

75-
implicit val liftXmlComment = Liftable[Comment] { comment =>
75+
implicit val liftXmlComment: Liftable[Comment] = Liftable[Comment] { comment =>
7676
q"new _root_.scala.xml.Comment(${comment.commentText})"
7777
}
7878
liftXmlComment(Comment("foo"))
7979
assertEquals(q"${Comment("foo")}".toString, q"<!--foo-->".toString)
8080
}
8181

8282
@UnitTest
83-
def t8466unlift: Unit = {
83+
def t8466unlift(): Unit = {
8484
import scala.reflect.runtime.universe._
8585

86-
implicit val unliftXmlComment = Unliftable[Comment] {
86+
implicit val unliftXmlComment: Unliftable[Comment] = Unliftable[Comment] {
8787
case q"new _root_.scala.xml.Comment(${value: String})" => Comment(value)
8888
}
8989
unliftXmlComment.unapply(q"<!--foo-->")
@@ -92,7 +92,7 @@ class XMLTestJVM2x {
9292
}
9393

9494
@UnitTest
95-
def t9027: Unit = {
95+
def t9027(): Unit = {
9696
// used to be parsed as .println
9797

9898
import reflect.runtime._, universe._

jvm/src/test/scala/scala/xml/AttributeTest.scala

+12-12
Original file line numberDiff line numberDiff line change
@@ -7,31 +7,31 @@ import org.junit.Assert.assertNotEquals
77
class AttributeTestJVM {
88

99
@Test
10-
def attributeOrder: Unit = {
11-
val x = <x y="1" z="2"/>
10+
def attributeOrder(): Unit = {
11+
val x: Elem = <x y="1" z="2"/>
1212
assertEquals("""<x y="1" z="2"/>""", x.toString)
1313
}
1414

1515
@Test
16-
def attributesFromString: Unit = {
17-
val str = """<x y="1" z="2"/>"""
18-
val doc = XML.loadString(str)
16+
def attributesFromString(): Unit = {
17+
val str: String = """<x y="1" z="2"/>"""
18+
val doc: Elem = XML.loadString(str)
1919
assertEquals(str, doc.toString)
2020
}
2121

2222
@Test
23-
def attributesAndNamespaceFromString: Unit = {
24-
val str = """<x xmlns:w="w" y="1" z="2"/>"""
25-
val doc = XML.loadString(str)
23+
def attributesAndNamespaceFromString(): Unit = {
24+
val str: String = """<x xmlns:w="w" y="1" z="2"/>"""
25+
val doc: Elem = XML.loadString(str)
2626
assertNotEquals(str, doc.toString)
27-
val str2 = """<x y="1" z="2" xmlns:w="w"/>"""
28-
val doc2 = XML.loadString(str2)
27+
val str2: String = """<x y="1" z="2" xmlns:w="w"/>"""
28+
val doc2: Elem = XML.loadString(str2)
2929
assertEquals(str2, doc2.toString)
3030
}
3131

3232
@Test(expected=classOf[SAXParseException])
33-
def attributesFromStringWithDuplicate: Unit = {
34-
val str = """<elem one="test" one="test1" two="test2" three="test3"></elem>"""
33+
def attributesFromStringWithDuplicate(): Unit = {
34+
val str: String = """<elem one="test" one="test1" two="test2" three="test3"></elem>"""
3535
XML.loadString(str)
3636
}
3737
}

jvm/src/test/scala/scala/xml/BillionLaughsAttackTest.scala

+2-3
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ class BillionLaughsAttackTest {
1010
* this is the limit imposed by the JDK.
1111
*/
1212
@Test(expected=classOf[org.xml.sax.SAXParseException])
13-
def lolzTest: Unit = {
13+
def lolzTest(): Unit = {
1414
XML.loadString(lolz)
1515
}
1616

1717
// Copied from https://msdn.microsoft.com/en-us/magazine/ee335713.aspx
18-
val lolz =
18+
val lolz: String =
1919
"""<?xml version="1.0"?>
2020
|<!DOCTYPE lolz [
2121
| <!ENTITY lol "lol">
@@ -32,5 +32,4 @@ class BillionLaughsAttackTest {
3232
|]>
3333
|<lolz>&lol9;</lolz>
3434
|""".stripMargin
35-
3635
}

jvm/src/test/scala/scala/xml/ReuseNodesTest.scala

+13-13
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ object ReuseNodesTest {
1919

2020
class OriginalTranformr(rules: RewriteRule*) extends RuleTransformer(rules:_*) {
2121
override def transform(ns: Seq[Node]): Seq[Node] = {
22-
val xs = ns.toStream map transform
23-
val (xs1, xs2) = xs.zip(ns).span { case (x, n) => unchanged(n, x) }
22+
val xs: Seq[Seq[Node]] = ns.toStream map transform
23+
val (xs1: Seq[(Seq[Node], Node)], xs2: Seq[(Seq[Node], Node)]) = xs.zip(ns).span { case (x, n) => unchanged(n, x) }
2424

2525
if (xs2.isEmpty) ns
2626
else xs1.map(_._2) ++ xs2.head._1 ++ transform(ns.drop(xs1.length + 1))
@@ -30,7 +30,7 @@ object ReuseNodesTest {
3030

3131
class ModifiedTranformr(rules: RewriteRule*) extends RuleTransformer(rules:_*) {
3232
override def transform(ns: Seq[Node]): Seq[Node] = {
33-
val changed = ns flatMap transform
33+
val changed: Seq[Node] = ns flatMap transform
3434

3535
if (changed.length != ns.length || changed.zip(ns).exists(p => p._1 != p._2)) changed
3636
else ns
@@ -40,16 +40,16 @@ object ReuseNodesTest {
4040

4141
class AlternateTranformr(rules: RewriteRule*) extends RuleTransformer(rules:_*) {
4242
override def transform(ns: Seq[Node]): Seq[Node] = {
43-
val xs = ns.toStream.map(transform)
44-
val (xs1, xs2) = xs.zip(ns).span { case (x, n) => unchanged(n, x) }
43+
val xs: Seq[Seq[Node]] = ns.toStream.map(transform)
44+
val (xs1: Seq[(Seq[Node], Node)], xs2: Seq[(Seq[Node], Node)]) = xs.zip(ns).span { case (x, n) => unchanged(n, x) }
4545

4646
if (xs2.isEmpty) ns
4747
else xs1.map(_._2) ++ xs2.head._1 ++ transform(ns.drop(xs1.length + 1))
4848
}
4949
override def transform(n: Node): Seq[Node] = super.transform(n)
5050
}
5151

52-
def rewriteRule = new RewriteRule {
52+
def rewriteRule: RewriteRule = new RewriteRule {
5353
override def transform(n: Node): NodeSeq = n match {
5454
case n if n.label == "change" => Elem(
5555
n.prefix, "changed", n.attributes, n.scope, n.child.isEmpty, n.child : _*)
@@ -58,7 +58,7 @@ object ReuseNodesTest {
5858
}
5959

6060
@DataPoints
61-
def tranformers() = Array(
61+
def tranformers(): Array[RuleTransformer] = Array(
6262
new OriginalTranformr(rewriteRule),
6363
new ModifiedTranformr(rewriteRule),
6464
new AlternateTranformr(rewriteRule))
@@ -68,16 +68,16 @@ object ReuseNodesTest {
6868
class ReuseNodesTest {
6969

7070
@Theory
71-
def transformReferentialEquality(rt: RuleTransformer) = {
72-
val original = <p><lost/></p>
73-
val tranformed = rt.transform(original)
71+
def transformReferentialEquality(rt: RuleTransformer): Unit = {
72+
val original: Elem = <p><lost/></p>
73+
val tranformed: Seq[Node] = rt.transform(original)
7474
assertSame(original, tranformed)
7575
}
7676

7777
@Theory
78-
def transformReferentialEqualityOnly(rt: RuleTransformer) = {
79-
val original = <changed><change><lost/><a><b><c/></b></a></change><a><b><c/></b></a></changed>
80-
val transformed = rt.transform(original)
78+
def transformReferentialEqualityOnly(rt: RuleTransformer): Unit = {
79+
val original: Elem = <changed><change><lost/><a><b><c/></b></a></change><a><b><c/></b></a></changed>
80+
val transformed: Seq[Node] = rt.transform(original)
8181
recursiveAssert(original,transformed)
8282
}
8383

jvm/src/test/scala/scala/xml/SerializationTest.scala

+6-6
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,24 @@ import org.junit.Test
66

77
class SerializationTest {
88
@Test
9-
def xmlLiteral: Unit = {
10-
val n = <node/>
9+
def xmlLiteral(): Unit = {
10+
val n: Elem = <node/>
1111
assertEquals(n, JavaByteSerialization.roundTrip(n))
1212
}
1313

1414
@Test
15-
def empty: Unit = {
15+
def empty(): Unit = {
1616
assertEquals(NodeSeq.Empty, JavaByteSerialization.roundTrip(NodeSeq.Empty))
1717
}
1818

1919
@Test
20-
def unmatched: Unit = {
20+
def unmatched(): Unit = {
2121
assertEquals(NodeSeq.Empty, JavaByteSerialization.roundTrip(<xml/> \ "HTML"))
2222
}
2323

2424
@Test
25-
def implicitConversion: Unit = {
26-
val parent = <parent><child></child><child/></parent>
25+
def implicitConversion(): Unit = {
26+
val parent: Elem = <parent><child></child><child/></parent>
2727
val children: Seq[Node] = parent.child
2828
val asNodeSeq: NodeSeq = children
2929
assertEquals(asNodeSeq, JavaByteSerialization.roundTrip(asNodeSeq))

jvm/src/test/scala/scala/xml/XMLSyntaxTest.scala

+3-4
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ class XMLSyntaxTestJVM {
88
@Test
99
def test3(): Unit = {
1010
// this demonstrates how to handle entities
11-
val s = io.Source.fromString("<a>&nbsp;</a>")
12-
object parser extends xml.parsing.ConstructingParser(s, false /*ignore ws*/) {
11+
val s: io.Source = io.Source.fromString("<a>&nbsp;</a>")
12+
object parser extends xml.parsing.ConstructingParser(s, preserveWS = false /*ignore ws*/) {
1313
override def replacementText(entityName: String): io.Source = {
1414
entityName match {
1515
case "nbsp" => io.Source.fromString("\u0160")
@@ -18,9 +18,8 @@ class XMLSyntaxTestJVM {
1818
}
1919
nextch() // !!important, to initialize the parser
2020
}
21-
val parsed = parser.element(TopScope) // parse the source as element
21+
val parsed: NodeSeq = parser.element(TopScope) // parse the source as element
2222
// alternatively, we could call document()
2323
assertEquals("<a>Š</a>", parsed.toString)
2424
}
25-
2625
}

0 commit comments

Comments
 (0)