diff --git a/jvm/src/test/scala-2.x/scala/xml/CompilerErrors.scala b/jvm/src/test/scala-2.x/scala/xml/CompilerErrors.scala
index b847a827c..5a8e03e9c 100644
--- a/jvm/src/test/scala-2.x/scala/xml/CompilerErrors.scala
+++ b/jvm/src/test/scala-2.x/scala/xml/CompilerErrors.scala
@@ -4,10 +4,10 @@ import org.junit.Test
class CompilerErrors extends CompilerTesting {
@Test
- def t7185() = {
+ def t7185(): Unit = {
// the error message here differs a bit by Scala version
import util.Properties.versionNumberString
- val thing =
+ val thing: String =
if (versionNumberString.startsWith("2.12")) "method value"
else "method"
expectXmlError(s"""|overloaded $thing apply with alternatives:
@@ -20,7 +20,7 @@ class CompilerErrors extends CompilerTesting {
}
@Test
- def t1878_typer() =
+ def t1878_typer(): Unit =
expectXmlError("_* may only come last",
"""|object Test extends App {
| // illegal - bug #1764
@@ -31,14 +31,14 @@ class CompilerErrors extends CompilerTesting {
@Test
- def t1017() =
+ def t1017(): Unit =
expectXmlErrors(1, "not found: value foo",
"""|object Test {
| { foo }
|}""")
@Test
- def t1011() =
+ def t1011(): Unit =
expectXmlErrors(69, "not found: value entity",
"""|import scala.xml._;
|
@@ -177,9 +177,9 @@ class CompilerTesting {
def errorMessages(errorSnippet: String, compileOptions: String = "")(code: String): List[String] = {
import scala.tools.reflect._
- val m = scala.reflect.runtime.currentMirror
- val tb = m.mkToolBox(options = compileOptions) //: ToolBox[m.universe.type]
- val fe = tb.frontEnd
+ val m: scala.reflect.runtime.universe.Mirror = scala.reflect.runtime.currentMirror
+ val tb: ToolBox[scala.reflect.runtime.universe.type] = m.mkToolBox(options = compileOptions) //: ToolBox[m.universe.type]
+ val fe: FrontEnd = tb.frontEnd
try {
tb.eval(tb.parse(code))
@@ -192,17 +192,17 @@ class CompilerTesting {
// note: `code` should have a | margin
// the import's needed because toolbox compiler does not accumulate imports like the real one (TODO: verify hypothesis)
- def xmlErrorMessages(msg: String, code: String) =
+ def xmlErrorMessages(msg: String, code: String): List[String] =
errorMessages(msg)("import scala.xml.{TopScope => $scope}\n"+ code.stripMargin)
- def expectXmlError(msg: String, code: String) = {
- val errors = xmlErrorMessages(msg, code)
+ def expectXmlError(msg: String, code: String): Unit = {
+ val errors: List[String] = xmlErrorMessages(msg, code)
assert(errors exists (_ contains msg), errors mkString "\n")
}
- def expectXmlErrors(msgCount: Int, msg: String, code: String) = {
- val errors = xmlErrorMessages(msg, code)
- val errorCount = errors.count(_ contains msg)
+ def expectXmlErrors(msgCount: Int, msg: String, code: String): Unit = {
+ val errors: List[String] = xmlErrorMessages(msg, code)
+ val errorCount: Int = errors.count(_ contains msg)
assert(errorCount == msgCount, s"$errorCount occurrences of \'$msg\' found -- expected $msgCount in:\n${errors mkString "\n"}")
}
}
diff --git a/jvm/src/test/scala-2.x/scala/xml/XMLTestJVM2x.scala b/jvm/src/test/scala-2.x/scala/xml/XMLTestJVM2x.scala
index 8a66a07e7..3d885717f 100644
--- a/jvm/src/test/scala-2.x/scala/xml/XMLTestJVM2x.scala
+++ b/jvm/src/test/scala-2.x/scala/xml/XMLTestJVM2x.scala
@@ -6,25 +6,25 @@ import scala.xml.parsing.ConstructingParser
class XMLTestJVM2x {
@UnitTest
- def t2354: Unit = {
- val xml_good = "
"
- val xml_bad = ""
+ def t2354(): Unit = {
+ val xml_good: String = ""
+ val xml_bad: String = ""
- val parser1 = ConstructingParser.fromSource(io.Source.fromString(xml_good), false)
- val parser2 = ConstructingParser.fromSource(io.Source.fromString(xml_bad), false)
+ val parser1: ConstructingParser = ConstructingParser.fromSource(io.Source.fromString(xml_good), preserveWS = false)
+ val parser2: ConstructingParser = ConstructingParser.fromSource(io.Source.fromString(xml_bad), preserveWS = false)
parser1.document()
parser2.document()
}
@UnitTest
- def t8253: Unit = {
+ def t8253(): Unit = {
// `identity(foo)` used to match the overly permissive match in SymbolXMLBuilder
// which was intended to more specifically match `_root_.scala.xml.Text(...)`
import reflect.runtime.universe._ // not using the XML library in compiler tests
- val ns1 = "ns1"
+ val ns1: String = "ns1"
assertEquals(reify(ns1).tree.toString, q"ns1".toString)
assertEquals("",
"""|{
@@ -69,10 +69,10 @@ class XMLTestJVM2x {
}
@UnitTest
- def t8466lift: Unit = {
+ def t8466lift(): Unit = {
import scala.reflect.runtime.universe._
- implicit val liftXmlComment = Liftable[Comment] { comment =>
+ implicit val liftXmlComment: Liftable[Comment] = Liftable[Comment] { comment =>
q"new _root_.scala.xml.Comment(${comment.commentText})"
}
liftXmlComment(Comment("foo"))
@@ -80,10 +80,10 @@ class XMLTestJVM2x {
}
@UnitTest
- def t8466unlift: Unit = {
+ def t8466unlift(): Unit = {
import scala.reflect.runtime.universe._
- implicit val unliftXmlComment = Unliftable[Comment] {
+ implicit val unliftXmlComment: Unliftable[Comment] = Unliftable[Comment] {
case q"new _root_.scala.xml.Comment(${value: String})" => Comment(value)
}
unliftXmlComment.unapply(q"")
@@ -92,7 +92,7 @@ class XMLTestJVM2x {
}
@UnitTest
- def t9027: Unit = {
+ def t9027(): Unit = {
// used to be parsed as .println
import reflect.runtime._, universe._
diff --git a/jvm/src/test/scala/scala/xml/AttributeTest.scala b/jvm/src/test/scala/scala/xml/AttributeTest.scala
index 11511d1d0..24046ec5c 100644
--- a/jvm/src/test/scala/scala/xml/AttributeTest.scala
+++ b/jvm/src/test/scala/scala/xml/AttributeTest.scala
@@ -7,31 +7,31 @@ import org.junit.Assert.assertNotEquals
class AttributeTestJVM {
@Test
- def attributeOrder: Unit = {
- val x =
+ def attributeOrder(): Unit = {
+ val x: Elem =
assertEquals("""""", x.toString)
}
@Test
- def attributesFromString: Unit = {
- val str = """"""
- val doc = XML.loadString(str)
+ def attributesFromString(): Unit = {
+ val str: String = """"""
+ val doc: Elem = XML.loadString(str)
assertEquals(str, doc.toString)
}
@Test
- def attributesAndNamespaceFromString: Unit = {
- val str = """"""
- val doc = XML.loadString(str)
+ def attributesAndNamespaceFromString(): Unit = {
+ val str: String = """"""
+ val doc: Elem = XML.loadString(str)
assertNotEquals(str, doc.toString)
- val str2 = """"""
- val doc2 = XML.loadString(str2)
+ val str2: String = """"""
+ val doc2: Elem = XML.loadString(str2)
assertEquals(str2, doc2.toString)
}
@Test(expected=classOf[SAXParseException])
- def attributesFromStringWithDuplicate: Unit = {
- val str = """"""
+ def attributesFromStringWithDuplicate(): Unit = {
+ val str: String = """"""
XML.loadString(str)
}
}
diff --git a/jvm/src/test/scala/scala/xml/BillionLaughsAttackTest.scala b/jvm/src/test/scala/scala/xml/BillionLaughsAttackTest.scala
index 88e1e99b2..434ab86a3 100644
--- a/jvm/src/test/scala/scala/xml/BillionLaughsAttackTest.scala
+++ b/jvm/src/test/scala/scala/xml/BillionLaughsAttackTest.scala
@@ -10,12 +10,12 @@ class BillionLaughsAttackTest {
* this is the limit imposed by the JDK.
*/
@Test(expected=classOf[org.xml.sax.SAXParseException])
- def lolzTest: Unit = {
+ def lolzTest(): Unit = {
XML.loadString(lolz)
}
// Copied from https://msdn.microsoft.com/en-us/magazine/ee335713.aspx
- val lolz =
+ val lolz: String =
"""
|
@@ -32,5 +32,4 @@ class BillionLaughsAttackTest {
|]>
|&lol9;
|""".stripMargin
-
}
diff --git a/jvm/src/test/scala/scala/xml/ReuseNodesTest.scala b/jvm/src/test/scala/scala/xml/ReuseNodesTest.scala
index 0b0bfd8cb..3adbeb698 100644
--- a/jvm/src/test/scala/scala/xml/ReuseNodesTest.scala
+++ b/jvm/src/test/scala/scala/xml/ReuseNodesTest.scala
@@ -19,8 +19,8 @@ object ReuseNodesTest {
class OriginalTranformr(rules: RewriteRule*) extends RuleTransformer(rules:_*) {
override def transform(ns: Seq[Node]): Seq[Node] = {
- val xs = ns.toStream map transform
- val (xs1, xs2) = xs.zip(ns).span { case (x, n) => unchanged(n, x) }
+ val xs: Seq[Seq[Node]] = ns.toStream map transform
+ val (xs1: Seq[(Seq[Node], Node)], xs2: Seq[(Seq[Node], Node)]) = xs.zip(ns).span { case (x, n) => unchanged(n, x) }
if (xs2.isEmpty) ns
else xs1.map(_._2) ++ xs2.head._1 ++ transform(ns.drop(xs1.length + 1))
@@ -30,7 +30,7 @@ object ReuseNodesTest {
class ModifiedTranformr(rules: RewriteRule*) extends RuleTransformer(rules:_*) {
override def transform(ns: Seq[Node]): Seq[Node] = {
- val changed = ns flatMap transform
+ val changed: Seq[Node] = ns flatMap transform
if (changed.length != ns.length || changed.zip(ns).exists(p => p._1 != p._2)) changed
else ns
@@ -40,8 +40,8 @@ object ReuseNodesTest {
class AlternateTranformr(rules: RewriteRule*) extends RuleTransformer(rules:_*) {
override def transform(ns: Seq[Node]): Seq[Node] = {
- val xs = ns.toStream.map(transform)
- val (xs1, xs2) = xs.zip(ns).span { case (x, n) => unchanged(n, x) }
+ val xs: Seq[Seq[Node]] = ns.toStream.map(transform)
+ val (xs1: Seq[(Seq[Node], Node)], xs2: Seq[(Seq[Node], Node)]) = xs.zip(ns).span { case (x, n) => unchanged(n, x) }
if (xs2.isEmpty) ns
else xs1.map(_._2) ++ xs2.head._1 ++ transform(ns.drop(xs1.length + 1))
@@ -49,7 +49,7 @@ object ReuseNodesTest {
override def transform(n: Node): Seq[Node] = super.transform(n)
}
- def rewriteRule = new RewriteRule {
+ def rewriteRule: RewriteRule = new RewriteRule {
override def transform(n: Node): NodeSeq = n match {
case n if n.label == "change" => Elem(
n.prefix, "changed", n.attributes, n.scope, n.child.isEmpty, n.child : _*)
@@ -58,7 +58,7 @@ object ReuseNodesTest {
}
@DataPoints
- def tranformers() = Array(
+ def tranformers(): Array[RuleTransformer] = Array(
new OriginalTranformr(rewriteRule),
new ModifiedTranformr(rewriteRule),
new AlternateTranformr(rewriteRule))
@@ -68,16 +68,16 @@ object ReuseNodesTest {
class ReuseNodesTest {
@Theory
- def transformReferentialEquality(rt: RuleTransformer) = {
- val original =
- val tranformed = rt.transform(original)
+ def transformReferentialEquality(rt: RuleTransformer): Unit = {
+ val original: Elem =
+ val tranformed: Seq[Node] = rt.transform(original)
assertSame(original, tranformed)
}
@Theory
- def transformReferentialEqualityOnly(rt: RuleTransformer) = {
- val original =
- val transformed = rt.transform(original)
+ def transformReferentialEqualityOnly(rt: RuleTransformer): Unit = {
+ val original: Elem =
+ val transformed: Seq[Node] = rt.transform(original)
recursiveAssert(original,transformed)
}
diff --git a/jvm/src/test/scala/scala/xml/SerializationTest.scala b/jvm/src/test/scala/scala/xml/SerializationTest.scala
index 37da4c296..e8c5c8800 100644
--- a/jvm/src/test/scala/scala/xml/SerializationTest.scala
+++ b/jvm/src/test/scala/scala/xml/SerializationTest.scala
@@ -6,24 +6,24 @@ import org.junit.Test
class SerializationTest {
@Test
- def xmlLiteral: Unit = {
- val n =
+ def xmlLiteral(): Unit = {
+ val n: Elem =
assertEquals(n, JavaByteSerialization.roundTrip(n))
}
@Test
- def empty: Unit = {
+ def empty(): Unit = {
assertEquals(NodeSeq.Empty, JavaByteSerialization.roundTrip(NodeSeq.Empty))
}
@Test
- def unmatched: Unit = {
+ def unmatched(): Unit = {
assertEquals(NodeSeq.Empty, JavaByteSerialization.roundTrip( \ "HTML"))
}
@Test
- def implicitConversion: Unit = {
- val parent =
+ def implicitConversion(): Unit = {
+ val parent: Elem =
val children: Seq[Node] = parent.child
val asNodeSeq: NodeSeq = children
assertEquals(asNodeSeq, JavaByteSerialization.roundTrip(asNodeSeq))
diff --git a/jvm/src/test/scala/scala/xml/XMLSyntaxTest.scala b/jvm/src/test/scala/scala/xml/XMLSyntaxTest.scala
index 4225545ee..e3ac914fd 100644
--- a/jvm/src/test/scala/scala/xml/XMLSyntaxTest.scala
+++ b/jvm/src/test/scala/scala/xml/XMLSyntaxTest.scala
@@ -8,8 +8,8 @@ class XMLSyntaxTestJVM {
@Test
def test3(): Unit = {
// this demonstrates how to handle entities
- val s = io.Source.fromString(" ")
- object parser extends xml.parsing.ConstructingParser(s, false /*ignore ws*/) {
+ val s: io.Source = io.Source.fromString(" ")
+ object parser extends xml.parsing.ConstructingParser(s, preserveWS = false /*ignore ws*/) {
override def replacementText(entityName: String): io.Source = {
entityName match {
case "nbsp" => io.Source.fromString("\u0160")
@@ -18,9 +18,8 @@ class XMLSyntaxTestJVM {
}
nextch() // !!important, to initialize the parser
}
- val parsed = parser.element(TopScope) // parse the source as element
+ val parsed: NodeSeq = parser.element(TopScope) // parse the source as element
// alternatively, we could call document()
assertEquals("Š", parsed.toString)
}
-
}
diff --git a/jvm/src/test/scala/scala/xml/XMLTest.scala b/jvm/src/test/scala/scala/xml/XMLTest.scala
index 3363a1fb5..a8f4dd826 100644
--- a/jvm/src/test/scala/scala/xml/XMLTest.scala
+++ b/jvm/src/test/scala/scala/xml/XMLTest.scala
@@ -9,11 +9,13 @@ import org.junit.Assert.assertEquals
import java.io.StringWriter
import java.io.ByteArrayOutputStream
import java.io.StringReader
+import scala.xml.dtd.{DocType, PublicID}
+import scala.xml.parsing.ConstructingParser
import scala.xml.Utility.sort
object XMLTestJVM {
- val e: scala.xml.MetaData = Null //Node.NoAttributes
- val sc: scala.xml.NamespaceBinding = TopScope
+ val e: MetaData = Null //Node.NoAttributes
+ val sc: NamespaceBinding = TopScope
}
class XMLTestJVM {
@@ -22,20 +24,20 @@ class XMLTestJVM {
def Elem(prefix: String, label: String, attributes: MetaData, scope: NamespaceBinding, child: Node*): Elem =
scala.xml.Elem.apply(prefix, label, attributes, scope, minimizeEmpty = true, child: _*)
- lazy val parsedxml1 = XML.load(new InputSource(new StringReader("")))
- lazy val parsedxml11 = XML.load(new InputSource(new StringReader("")))
- val xmlFile2 = "Peter BunemanDan SuciuData on ze webJohn MitchellFoundations of Programming Languages"
- lazy val parsedxml2 = XML.load(new InputSource(new StringReader(xmlFile2)))
+ lazy val parsedxml1: Elem = XML.load(new InputSource(new StringReader("")))
+ lazy val parsedxml11: Elem = XML.load(new InputSource(new StringReader("")))
+ val xmlFile2: String = "Peter BunemanDan SuciuData on ze webJohn MitchellFoundations of Programming Languages"
+ lazy val parsedxml2: Elem = XML.load(new InputSource(new StringReader(xmlFile2)))
@UnitTest
- def equality = {
- val c = new Node {
- override def label = "hello"
- override def hashCode() =
+ def equality(): Unit = {
+ val c: Node = new Node {
+ override def label: String = "hello"
+ override def hashCode(): Int =
Utility.hashCode(prefix, label, this.attributes.hashCode(), scope.hashCode(), child)
- override def child = Elem(null, "world", e, sc)
+ override def child: Seq[Node] = Elem(null, "world", e, sc)
//def attributes = e
- override def text = ""
+ override def text: String = ""
}
assertEquals(c, parsedxml11)
@@ -43,10 +45,10 @@ class XMLTestJVM {
assertTrue(List(parsedxml1) sameElements List(parsedxml11))
assertTrue(Array(parsedxml1).toList sameElements List(parsedxml11))
- val x2 = "Peter BunemanDan SuciuData on ze web"
+ val x2: String = "Peter BunemanDan SuciuData on ze web"
- val i = new InputSource(new StringReader(x2))
- val x2p = scala.xml.XML.load(i)
+ val i: InputSource = new InputSource(new StringReader(x2))
+ val x2p: Elem = XML.load(i)
assertEquals(Elem(null, "book", e, sc,
Elem(null, "author", e, sc, Text("Peter Buneman")),
@@ -56,7 +58,7 @@ class XMLTestJVM {
}
@UnitTest
- def xpath = {
+ def xpath(): Unit = {
assertTrue(parsedxml1 \ "_" sameElements List(Elem(null, "world", e, sc)))
assertTrue(parsedxml1 \ "world" sameElements List(Elem(null, "world", e, sc)))
@@ -100,7 +102,7 @@ class XMLTestJVM {
}
@UnitTest
- def xpathDESCENDANTS = {
+ def xpathDESCENDANTS(): Unit = {
assertTrue(
(parsedxml2 \\ "author") sameElements List(
Elem(null, "author", e, sc, Text("Peter Buneman")),
@@ -140,34 +142,34 @@ class XMLTestJVM {
}
@UnitTest
- def unparsed = {
+ def unparsed(): Unit = {
// println("attribute value normalization")
- val xmlAttrValueNorm = ""
+ val xmlAttrValueNorm: String = ""
{
- val isrcA = new InputSource(new StringReader(xmlAttrValueNorm))
- val parsedxmlA = XML.load(isrcA)
- val c = (parsedxmlA \ "@nom").text.charAt(0)
+ val isrcA: InputSource = new InputSource(new StringReader(xmlAttrValueNorm))
+ val parsedxmlA: Elem = XML.load(isrcA)
+ val c: Char = (parsedxmlA \ "@nom").text.charAt(0)
assertTrue(c == '\u015e')
}
// buraq: if the following test fails with 'character x not allowed', it is
// related to the mutable variable in a closures in MarkupParser.parsecharref
{
- val isr = scala.io.Source.fromString(xmlAttrValueNorm)
- val pxmlB = scala.xml.parsing.ConstructingParser.fromSource(isr, false)
- val parsedxmlB = pxmlB.element(TopScope)
- val c = (parsedxmlB \ "@nom").text.charAt(0)
+ val isr: scala.io.Source = scala.io.Source.fromString(xmlAttrValueNorm)
+ val pxmlB: ConstructingParser = ConstructingParser.fromSource(isr, preserveWS = false)
+ val parsedxmlB: NodeSeq = pxmlB.element(TopScope)
+ val c: Char = (parsedxmlB \ "@nom").text.charAt(0)
assertTrue(c == '\u015e')
}
// #60 test by round trip
- val p = scala.xml.parsing.ConstructingParser.fromSource(scala.io.Source.fromString(""), true)
- val n = p.element(scala.xml.NamespaceBinding("bar", "BAR", scala.xml.TopScope))(0)
+ val p: ConstructingParser = ConstructingParser.fromSource(scala.io.Source.fromString(""), preserveWS = true)
+ val n: Node = p.element(NamespaceBinding("bar", "BAR", TopScope))(0)
assertTrue(n.attributes.get("BAR", n, "attr").nonEmpty)
}
- def f(s: String) = {
+ def f(s: String): Elem = {
{
for (item <- s split ',') yield { item }
@@ -176,7 +178,7 @@ class XMLTestJVM {
}
@UnitTest
- def nodeBuffer =
+ def nodeBuffer(): Unit =
assertEquals(
"""
abc
@@ -185,8 +187,8 @@ class XMLTestJVM {
object Serialize {
@throws(classOf[java.io.IOException])
def write[A](o: A): Array[Byte] = {
- val ba = new ByteArrayOutputStream(512)
- val out = new java.io.ObjectOutputStream(ba)
+ val ba: ByteArrayOutputStream = new ByteArrayOutputStream(512)
+ val out: java.io.ObjectOutputStream = new java.io.ObjectOutputStream(ba)
out.writeObject(o)
out.close()
ba.toByteArray
@@ -194,7 +196,7 @@ class XMLTestJVM {
@throws(classOf[java.io.IOException])
@throws(classOf[ClassNotFoundException])
def read[A](buffer: Array[Byte]): A = {
- val in =
+ val in: java.io.ObjectInputStream =
new java.io.ObjectInputStream(new java.io.ByteArrayInputStream(buffer))
in.readObject().asInstanceOf[A]
}
@@ -207,40 +209,38 @@ class XMLTestJVM {
}
}
- import Serialize._
-
@UnitTest
- def serializeAttribute = {
+ def serializeAttribute(): Unit = {
// Attribute
- val a1 = new PrefixedAttribute("xml", "src", Text("hello"), Null)
- val _a1: Attribute = read(write(a1))
- check(a1, _a1)
+ val a1: PrefixedAttribute = new PrefixedAttribute("xml", "src", Text("hello"), Null)
+ val _a1: Attribute = Serialize.read(Serialize.write(a1))
+ Serialize.check(a1, _a1)
}
@UnitTest
- def serializeDocument = {
+ def serializeDocument(): Unit = {
// Document
- val d1 = new Document
+ val d1: Document = new Document
d1.docElem =
d1.encoding = Some("UTF-8")
- val _d1: Document = read(write(d1))
- check(d1, _d1)
+ val _d1: Document = Serialize.read(Serialize.write(d1))
+ Serialize.check(d1, _d1)
}
@UnitTest
- def serializeElem = {
+ def serializeElem(): Unit = {
// Elem
- val e1 = title
- val _e1: Elem = read(write(e1))
- check(e1, _e1)
+ val e1: Elem = title
+ val _e1: Elem = Serialize.read(Serialize.write(e1))
+ Serialize.check(e1, _e1)
}
@UnitTest
- def serializeComplex = {
+ def serializeComplex(): Unit = {
case class Person(name: String, age: Int)
class AddressBook(a: Person*) {
private val people: List[Person] = a.toList
- def toXHTML =
+ def toXHTML: Elem =
Last Name |
@@ -255,19 +255,19 @@ class XMLTestJVM {
}
- val people = new AddressBook(
+ val people: AddressBook = new AddressBook(
Person("Tom", 20),
Person("Bob", 22),
Person("James", 19))
- val e2 =
+ val e2: Elem =
{ people.toXHTML }
- val _e2: Elem = read(write(e2))
- check(e2, _e2)
+ val _e2: Elem = Serialize.read(Serialize.write(e2))
+ Serialize.check(e2, _e2)
}
// t-486
@@ -284,7 +284,7 @@ class XMLTestJVM {
@UnitTest
- def wsdl = {
+ def wsdl(): Unit = {
assertEquals("""
""", wsdlTemplate1("service1").toString)
assertEquals("""
@@ -295,52 +295,50 @@ class XMLTestJVM {
// Issue found with ISO-8859-1 in #121 that was fixed with UTF-8 default
@UnitTest
- def writeReadNoDeclarationDefaultEncoding: Unit = {
- val chars = ((32 to 126) ++ (160 to 255)).map(_.toChar)
- val xml = { chars.mkString }
+ def writeReadNoDeclarationDefaultEncoding(): Unit = {
+ val chars: Seq[Char] = ((32 to 126) ++ (160 to 255)).map(_.toChar)
+ val xml: Elem = { chars.mkString }
// com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException:
// Invalid byte 1 of 1-byte UTF-8 sequence.
// scala.xml.XML.save("foo.xml", xml)
// scala.xml.XML.loadFile("foo.xml").toString
- val outputStream = new java.io.ByteArrayOutputStream
- val streamWriter = new java.io.OutputStreamWriter(outputStream, "UTF-8")
+ val outputStream: java.io.ByteArrayOutputStream = new java.io.ByteArrayOutputStream
+ val streamWriter: java.io.OutputStreamWriter = new java.io.OutputStreamWriter(outputStream, "UTF-8")
- XML.write(streamWriter, xml, XML.encoding, false, null)
+ XML.write(streamWriter, xml, XML.encoding, xmlDecl = false, null)
streamWriter.flush()
- val inputStream = new java.io.ByteArrayInputStream(outputStream.toByteArray)
- val streamReader = new java.io.InputStreamReader(inputStream, XML.encoding)
+ val inputStream: java.io.ByteArrayInputStream = new java.io.ByteArrayInputStream(outputStream.toByteArray)
+ val streamReader: java.io.InputStreamReader = new java.io.InputStreamReader(inputStream, XML.encoding)
assertEquals(xml.toString, XML.load(streamReader).toString)
}
@UnitTest
- def t0663 = {
- val src = scala.io.Source.fromString("")
- val parser = xml.parsing.ConstructingParser.fromSource(src, true)
+ def t0663(): Unit = {
+ val src: scala.io.Source = scala.io.Source.fromString("")
+ val parser: ConstructingParser = ConstructingParser.fromSource(src, preserveWS = true)
assertEquals("", parser.document().toString)
}
@UnitTest
- def t1079 = assertFalse( == )
-
- import dtd.{DocType, PublicID}
+ def t1079(): Unit = assertFalse( == )
@UnitTest
- def t1620 = {
- val dt = DocType("foo", PublicID("-//Foo Corp//DTD 1.0//EN", "foo.dtd"), Seq())
- var pw = new StringWriter()
- XML.write(pw, , "utf-8", true, dt)
+ def t1620(): Unit = {
+ val dt: DocType = DocType("foo", PublicID("-//Foo Corp//DTD 1.0//EN", "foo.dtd"), Seq())
+ var pw: StringWriter = new StringWriter()
+ XML.write(pw, , "utf-8", xmlDecl = true, dt)
pw.flush()
assertEquals("""
""", pw.toString)
pw = new StringWriter()
- val dt2 = DocType("foo", PublicID("-//Foo Corp//DTD 1.0//EN", null), Seq())
- XML.write(pw, , "utf-8", true, dt2)
+ val dt2: DocType = DocType("foo", PublicID("-//Foo Corp//DTD 1.0//EN", null), Seq())
+ XML.write(pw, , "utf-8", xmlDecl = true, dt2)
pw.flush()
assertEquals("""
@@ -348,11 +346,11 @@ class XMLTestJVM {
}
@UnitTest
- def t1773 = {
- val xs = List(
+ def t1773(): Unit = {
+ val xs: List[Elem] = List(
,
,
- { xml.NodeSeq.Empty },
+ { NodeSeq.Empty },
{ "" },
{ if (true) "" else "I like turtles" })
@@ -360,18 +358,18 @@ class XMLTestJVM {
}
@UnitTest
- def t2771 = {
- val xml1 =
- val xml2 = scala.xml.XML.loadString("""""")
+ def t2771(): Unit = {
+ val xml1: Elem =
+ val xml2: Elem = XML.loadString("""""")
- def backslashSearch(x: xml.Elem) = "root:-" + (x \ "@{nsUri}at") + "-sub:-" + (x \ "sub" \ "@{nsUri}at") + "-"
+ def backslashSearch(x: Elem): String = "root:-" + (x \ "@{nsUri}at") + "-sub:-" + (x \ "sub" \ "@{nsUri}at") + "-"
assertEquals("root:-rootVal-sub:-subVal-", backslashSearch(xml1))
assertEquals("root:-rootVal-sub:-subVal-", backslashSearch(xml2))
}
@UnitTest
- def t3886 = {
+ def t3886(): Unit = {
assertTrue( == )
assertTrue( != )
assertTrue( != )
@@ -382,19 +380,19 @@ class XMLTestJVM {
}
@UnitTest
- def t4387 = {
+ def t4387(): Unit = {
import XML.loadString
- def mkElem(arg: String) =
+ def mkElem(arg: String): Elem =
- val x1 = mkElem("5")
- val x2 = mkElem("50")
+ val x1: Elem = mkElem("5")
+ val x2: Elem = mkElem("50")
assertEquals(x1, loadString("" + x1))
assertTrue(x2 != loadString("" + x1))
}
@UnitTest
- def t5052 = {
+ def t5052(): Unit = {
assertTrue( xml_== )
assertTrue( xml_== )
assertTrue( xml_== )
@@ -402,8 +400,8 @@ class XMLTestJVM {
}
@UnitTest
- def t5115 = {
- def assertHonorsIterableContract(i: Iterable[_]) = assertEquals(i.size.toLong, i.iterator.size.toLong)
+ def t5115(): Unit = {
+ def assertHonorsIterableContract(i: Iterable[_]): Unit = assertEquals(i.size.toLong, i.iterator.size.toLong)
assertHonorsIterableContract(.attributes)
assertHonorsIterableContract(.attributes)
@@ -416,39 +414,39 @@ class XMLTestJVM {
}
@UnitTest
- def t5843 = {
- val foo = scala.xml.Attribute(null, "foo", "1", scala.xml.Null)
- val bar = scala.xml.Attribute(null, "bar", "2", foo)
- val ns = scala.xml.NamespaceBinding(null, "uri", scala.xml.TopScope)
+ def t5843(): Unit = {
+ val foo: Attribute = Attribute(null, "foo", "1", Null)
+ val bar: Attribute = Attribute(null, "bar", "2", foo)
+ val ns: NamespaceBinding = NamespaceBinding(null, "uri", TopScope)
assertEquals(""" foo="1"""", foo.toString)
- assertEquals(null, scala.xml.TopScope.getURI(foo.pre))
+ assertEquals(null, TopScope.getURI(foo.pre))
assertEquals(""" bar="2"""", bar.remove("foo").toString)
assertEquals(""" foo="1"""", bar.remove("bar").toString)
- assertEquals(""" bar="2"""", bar.remove(null, scala.xml.TopScope, "foo").toString)
- assertEquals(""" foo="1"""", bar.remove(null, scala.xml.TopScope, "bar").toString)
+ assertEquals(""" bar="2"""", bar.remove(null, TopScope, "foo").toString)
+ assertEquals(""" foo="1"""", bar.remove(null, TopScope, "bar").toString)
assertEquals(""" bar="2" foo="1"""", bar.toString)
assertEquals(""" bar="2" foo="1"""", bar.remove(null, ns, "foo").toString)
assertEquals(""" bar="2" foo="1"""", bar.remove(null, ns, "bar").toString)
}
@UnitTest
- def t6939 = {
- val foo =
+ def t6939(): Unit = {
+ val foo: Elem =
assertEquals(foo.child.head.scope.toString, """ xmlns:x="http://bar.com/"""")
- val fooDefault =
+ val fooDefault: Elem =
assertEquals(fooDefault.child.head.scope.toString, """ xmlns="http://bar.com/"""")
- val foo2 = scala.xml.XML.loadString("""""")
+ val foo2: Elem = XML.loadString("""""")
assertEquals(foo2.child.head.scope.toString, """ xmlns:x="http://bar.com/"""")
- val foo2Default = scala.xml.XML.loadString("""""")
+ val foo2Default: Elem = XML.loadString("""""")
assertEquals(foo2Default.child.head.scope.toString, """ xmlns="http://bar.com/"""")
}
@UnitTest
- def t7074 = {
+ def t7074(): Unit = {
assertEquals("""""", sort().toString)
assertEquals("""""", sort().toString)
assertEquals("""""", sort().toString)
@@ -461,26 +459,26 @@ class XMLTestJVM {
}
@UnitTest
- def t9060 = {
- val expected = """"""
+ def t9060(): Unit = {
+ val expected: String = """"""
assertEquals(expected, XML.loadString(expected).toString)
}
@UnitTest
- def attributes = {
- val noAttr =
- val attrNull =
- val attrNone =
- val preAttrNull =
- val preAttrNone =
+ def attributes(): Unit = {
+ val noAttr: Elem =
+ val attrNull: Elem =
+ val attrNone: Elem =
+ val preAttrNull: Elem =
+ val preAttrNone: Elem =
assertEquals(noAttr, attrNull)
assertEquals(noAttr, attrNone)
assertEquals(noAttr, preAttrNull)
assertEquals(noAttr, preAttrNone)
- val xml1 =
- val xml2 =
- val xml3 =
+ val xml1: Elem =
+ val xml2: Elem =
+ val xml3: Elem =
assertEquals(xml1, xml2)
assertEquals(xml1, xml3)
@@ -500,12 +498,12 @@ class XMLTestJVM {
assertEquals("""""", .toString)
}
- import java.io.{ Console => _, _ }
- import scala.xml.parsing._
@UnitTest
- def dontLoop: Unit = {
- val xml = " "
- val sink = new PrintStream(new ByteArrayOutputStream())
+ def dontLoop(): Unit = {
+ import java.io.{ Console => _, _ }
+
+ val xml: String = " "
+ val sink: PrintStream = new PrintStream(new ByteArrayOutputStream())
Console.withOut(sink) {
Console.withErr(sink) {
ConstructingParser.fromSource(io.Source.fromString(xml), preserveWS = true).document().docElem
@@ -514,59 +512,59 @@ class XMLTestJVM {
}
/** Default SAXParserFactory */
- val defaultParserFactory = javax.xml.parsers.SAXParserFactory.newInstance
+ val defaultParserFactory: javax.xml.parsers.SAXParserFactory = javax.xml.parsers.SAXParserFactory.newInstance
@throws(classOf[org.xml.sax.SAXNotRecognizedException])
- def issue17UnrecognizedFeature: Unit = {
+ def issue17UnrecognizedFeature(): Unit = {
assertTrue(defaultParserFactory.getFeature("foobar"))
}
@UnitTest
- def issue17SecureProcessing: Unit = {
+ def issue17SecureProcessing(): Unit = {
assertTrue(defaultParserFactory.getFeature("http://javax.xml.XMLConstants/feature/secure-processing"))
}
@UnitTest
- def issue17ExternalGeneralEntities: Unit = {
+ def issue17ExternalGeneralEntities(): Unit = {
assertTrue(defaultParserFactory.getFeature("http://xml.org/sax/features/external-general-entities"))
}
@UnitTest
- def issue17LoadExternalDtd: Unit = {
+ def issue17LoadExternalDtd(): Unit = {
assertTrue(defaultParserFactory.getFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd"))
}
@UnitTest
- def issue17DisallowDoctypeDecl: Unit = {
+ def issue17DisallowDoctypeDecl(): Unit = {
assertFalse(defaultParserFactory.getFeature("http://apache.org/xml/features/disallow-doctype-decl"))
}
@UnitTest
- def issue17ExternalParameterEntities: Unit = {
+ def issue17ExternalParameterEntities(): Unit = {
assertTrue(defaultParserFactory.getFeature("http://xml.org/sax/features/external-parameter-entities"))
}
@UnitTest
- def issue17ResolveDtdUris: Unit = {
+ def issue17ResolveDtdUris(): Unit = {
assertTrue(defaultParserFactory.getFeature("http://xml.org/sax/features/resolve-dtd-uris"))
}
@UnitTest
- def issue17isXIncludeAware: Unit = {
+ def issue17isXIncludeAware(): Unit = {
assertFalse(XML.parser.isXIncludeAware)
}
@UnitTest
- def issue17isNamespaceAware: Unit = {
+ def issue17isNamespaceAware(): Unit = {
assertFalse(XML.parser.isNamespaceAware)
}
@UnitTest
- def issue28: Unit = {
- val x =
+ def issue28(): Unit = {
+ val x: Elem =
// val ns = new NamespaceBinding("x", "gaga", sc)
// val x = Elem("x", "foo", e, ns)
- val pp = new xml.PrettyPrinter(80, 2)
+ val pp: PrettyPrinter = new PrettyPrinter(80, 2)
// This assertion passed
assertEquals("""""", x.toString)
// This was the bug, producing an errant xmlns attribute
@@ -574,15 +572,15 @@ class XMLTestJVM {
}
@UnitTest( expected = classOf[scala.xml.SAXParseException] )
- def issue35: Unit = {
- val broken = " suffix")
roundtrip("prefix suffix")
@@ -599,7 +597,7 @@ class XMLTestJVM {
}
@UnitTest
- def cdataParsing: Unit = {
+ def cdataParsing(): Unit = {
roundtrip(" suffix")
roundtrip("prefix suffix")
roundtrip("prefix suffix")
@@ -612,7 +610,7 @@ class XMLTestJVM {
def roundtripNodes(xml: String): Unit = assertEquals(xml, XML.loadStringNodes(xml).map(_.toString).mkString(""))
@UnitTest
- def xmlLoaderLoadNodes: Unit = {
+ def xmlLoaderLoadNodes(): Unit = {
roundtripNodes("text")
roundtripNodes("text")
roundtripNodes("""" to this string buffer.
*/
- override def buildString(sb: StringBuilder) =
+ override def buildString(sb: StringBuilder): StringBuilder =
sb append ""
}
diff --git a/shared/src/main/scala/scala/xml/Document.scala b/shared/src/main/scala/scala/xml/Document.scala
index 0ff3ad2d8..e242794f8 100644
--- a/shared/src/main/scala/scala/xml/Document.scala
+++ b/shared/src/main/scala/scala/xml/Document.scala
@@ -92,13 +92,13 @@ class Document extends NodeSeq with Serializable {
* then certain properties (indicated in their descriptions below) may
* be unknown. If it is true, those properties are never unknown.
*/
- var allDeclarationsProcessed = false
+ var allDeclarationsProcessed: Boolean = false
// methods for NodeSeq
override def theSeq: Seq[Node] = this.docElem
- override def canEqual(other: Any) = other match {
+ override def canEqual(other: Any): Boolean = other match {
case _: Document => true
case _ => false
}
diff --git a/shared/src/main/scala/scala/xml/Elem.scala b/shared/src/main/scala/scala/xml/Elem.scala
index 20feb40a9..dcbe8f5a3 100755
--- a/shared/src/main/scala/scala/xml/Elem.scala
+++ b/shared/src/main/scala/scala/xml/Elem.scala
@@ -26,7 +26,7 @@ object Elem {
def apply(prefix: String, label: String, attributes: MetaData, scope: NamespaceBinding, minimizeEmpty: Boolean, child: Node*): Elem =
new Elem(prefix, label, attributes, scope, minimizeEmpty, child: _*)
- def unapplySeq(n: Node) = n match {
+ def unapplySeq(n: Node) /* TODO type annotation */ = n match {
case _: SpecialNode | _: Group => None
case _ => Some((n.prefix, n.label, n.attributes, n.scope, n.child.toSeq))
}
@@ -60,10 +60,10 @@ class Elem(
override val child: Node*
) extends Node with Serializable {
- final override def doCollectNamespaces = true
- final override def doTransform = true
+ final override def doCollectNamespaces: Boolean = true
+ final override def doTransform: Boolean = true
- override val attributes = MetaData.normalize(attributes1, scope)
+ override val attributes: MetaData = MetaData.normalize(attributes1, scope)
if (prefix == "")
throw new IllegalArgumentException("prefix of zero length, use null instead")
@@ -106,5 +106,5 @@ class Elem(
/**
* Returns concatenation of `text(n)` for each child `n`.
*/
- override def text = (child map (_.text)).mkString
+ override def text: String = (child map (_.text)).mkString
}
diff --git a/shared/src/main/scala/scala/xml/EntityRef.scala b/shared/src/main/scala/scala/xml/EntityRef.scala
index 17eb0543d..38f20689a 100644
--- a/shared/src/main/scala/scala/xml/EntityRef.scala
+++ b/shared/src/main/scala/scala/xml/EntityRef.scala
@@ -20,11 +20,11 @@ package xml
* @param entityName the name of the entity reference, for example `amp`.
*/
case class EntityRef(entityName: String) extends SpecialNode {
- final override def doCollectNamespaces = false
- final override def doTransform = false
- override def label = "#ENTITY"
+ final override def doCollectNamespaces: Boolean = false
+ final override def doTransform: Boolean = false
+ override def label: String = "#ENTITY"
- override def text = entityName match {
+ override def text: String = entityName match {
case "lt" => "<"
case "gt" => ">"
case "amp" => "&"
@@ -39,7 +39,6 @@ case class EntityRef(entityName: String) extends SpecialNode {
* @param sb the string buffer.
* @return the modified string buffer `sb`.
*/
- override def buildString(sb: StringBuilder) =
+ override def buildString(sb: StringBuilder): StringBuilder =
sb.append("&").append(entityName).append(";")
-
}
diff --git a/shared/src/main/scala/scala/xml/Equality.scala b/shared/src/main/scala/scala/xml/Equality.scala
index 716a912e1..11877f47e 100644
--- a/shared/src/main/scala/scala/xml/Equality.scala
+++ b/shared/src/main/scala/scala/xml/Equality.scala
@@ -63,7 +63,7 @@ object Equality {
}
def compareBlithely(x1: AnyRef, x2: AnyRef): Boolean = {
if (x1 == null || x2 == null)
- return (x1 eq x2)
+ return x1 eq x2
x2 match {
case s: String => compareBlithely(x1, s)
@@ -78,7 +78,7 @@ trait Equality extends scala.Equals {
protected def basisForHashCode: Seq[Any]
def strict_==(other: Equality): Boolean
- def strict_!=(other: Equality) = !strict_==(other)
+ def strict_!=(other: Equality): Boolean = !strict_==(other)
/**
* We insist we're only equal to other `xml.Equality` implementors,
@@ -96,18 +96,18 @@ trait Equality extends scala.Equals {
* are final since clearly individual classes cannot be trusted
* to maintain a semblance of order.
*/
- override def hashCode() = basisForHashCode.##
- override def equals(other: Any) = doComparison(other, blithe = false)
- final def xml_==(other: Any) = doComparison(other, blithe = true)
- final def xml_!=(other: Any) = !xml_==(other)
+ override def hashCode(): Int = basisForHashCode.##
+ override def equals(other: Any): Boolean = doComparison(other, blithe = false)
+ final def xml_==(other: Any): Boolean = doComparison(other, blithe = true)
+ final def xml_!=(other: Any): Boolean = !xml_==(other)
/**
* The "blithe" parameter expresses the caller's unconcerned attitude
* regarding the usual constraints on equals. The method is thereby
* given carte blanche to declare any two things equal.
*/
- private def doComparison(other: Any, blithe: Boolean) = {
- val strictlyEqual = other match {
+ private def doComparison(other: Any, blithe: Boolean): Boolean = {
+ val strictlyEqual: Boolean = other match {
case x: AnyRef if this eq x => true
case x: Equality => (x canEqual this) && (this strict_== x)
case _ => false
diff --git a/shared/src/main/scala/scala/xml/Group.scala b/shared/src/main/scala/scala/xml/Group.scala
index 9ad9f6ff1..471979d4a 100644
--- a/shared/src/main/scala/scala/xml/Group.scala
+++ b/shared/src/main/scala/scala/xml/Group.scala
@@ -21,29 +21,29 @@ import scala.collection.Seq
* @author Burak Emir
*/
final case class Group(nodes: Seq[Node]) extends Node {
- override def theSeq = nodes
+ override def theSeq: Seq[Node] = nodes
- override def canEqual(other: Any) = other match {
+ override def canEqual(other: Any): Boolean = other match {
case x: Group => true
case _ => false
}
- override def strict_==(other: Equality) = other match {
+ override def strict_==(other: Equality): Boolean = other match {
case Group(xs) => nodes sameElements xs
case _ => false
}
- override protected def basisForHashCode = nodes
+ override protected def basisForHashCode: Seq[Node] = nodes
/**
* Since Group is very much a hack it throws an exception if you
* try to do anything with it.
*/
- private def fail(msg: String) = throw new UnsupportedOperationException("class Group does not support method '%s'" format msg)
+ private def fail(msg: String): Nothing = throw new UnsupportedOperationException("class Group does not support method '%s'" format msg)
- override def label = fail("label")
- override def attributes = fail("attributes")
- override def namespace = fail("namespace")
- override def child = fail("child")
- def buildString(sb: StringBuilder) = fail("toString(StringBuilder)")
+ override def label: Nothing = fail("label")
+ override def attributes: Nothing = fail("attributes")
+ override def namespace: Nothing = fail("namespace")
+ override def child /* TODO type annotation */ = fail("child")
+ def buildString(sb: StringBuilder): Nothing = fail("toString(StringBuilder)")
}
diff --git a/shared/src/main/scala/scala/xml/MetaData.scala b/shared/src/main/scala/scala/xml/MetaData.scala
index 06470c299..4607ea6c7 100644
--- a/shared/src/main/scala/scala/xml/MetaData.scala
+++ b/shared/src/main/scala/scala/xml/MetaData.scala
@@ -43,7 +43,7 @@ object MetaData {
} else if (md.value eq null) {
iterate(md.next, normalized_attribs, set)
} else {
- val key = getUniversalKey(md, scope)
+ val key: String = getUniversalKey(md, scope)
if (set(key)) {
iterate(md.next, normalized_attribs, set)
} else {
@@ -57,7 +57,7 @@ object MetaData {
/**
* returns key if md is unprefixed, pre+key is md is prefixed
*/
- def getUniversalKey(attrib: MetaData, scope: NamespaceBinding) = attrib match {
+ def getUniversalKey(attrib: MetaData, scope: NamespaceBinding): String = attrib match {
case prefixed: PrefixedAttribute => scope.getURI(prefixed.pre) + prefixed.key
case unprefixed: UnprefixedAttribute => unprefixed.key
}
@@ -134,7 +134,7 @@ abstract class MetaData
/** if owner is the element of this metadata item, returns namespace */
def getNamespace(owner: Node): String
- def hasNext = Null != next
+ def hasNext: Boolean = Null != next
def length: Int = length(0)
@@ -142,11 +142,11 @@ abstract class MetaData
def isPrefixed: Boolean
- override def canEqual(other: Any) = other match {
+ override def canEqual(other: Any): Boolean = other match {
case _: MetaData => true
case _ => false
}
- override def strict_==(other: Equality) = other match {
+ override def strict_==(other: Equality): Boolean = other match {
case m: MetaData => this.asAttrMap == m.asAttrMap
case _ => false
}
@@ -172,7 +172,7 @@ abstract class MetaData
* Returns a String containing "prefix:key" if the first key is
* prefixed, and "key" otherwise.
*/
- def prefixedKey = this match {
+ def prefixedKey: String = this match {
case x: Attribute if x.isPrefixed => x.pre + ":" + key
case _ => key
}
diff --git a/shared/src/main/scala/scala/xml/NamespaceBinding.scala b/shared/src/main/scala/scala/xml/NamespaceBinding.scala
index 030358b9d..84c085f4e 100644
--- a/shared/src/main/scala/scala/xml/NamespaceBinding.scala
+++ b/shared/src/main/scala/scala/xml/NamespaceBinding.scala
@@ -52,18 +52,18 @@ case class NamespaceBinding(prefix: String, uri: String, parent: NamespaceBindin
case Nil => stop
case x :: xs => NamespaceBinding(x, this.getURI(x), fromPrefixList(xs))
}
- val ps0 = prefixList(this).reverse
- val ps = ps0.distinct
+ val ps0: List[String] = prefixList(this).reverse
+ val ps: List[String] = ps0.distinct
if (ps.size == ps0.size) this
else fromPrefixList(ps)
}
- override def canEqual(other: Any) = other match {
+ override def canEqual(other: Any): Boolean = other match {
case _: NamespaceBinding => true
case _ => false
}
- override def strict_==(other: Equality) = other match {
+ override def strict_==(other: Equality): Boolean = other match {
case x: NamespaceBinding => (prefix == x.prefix) && (uri == x.uri) && (parent == x.parent)
case _ => false
}
@@ -79,7 +79,7 @@ case class NamespaceBinding(prefix: String, uri: String, parent: NamespaceBindin
private def doBuildString(sb: StringBuilder, stop: NamespaceBinding): Unit = {
if (List(null, stop, TopScope).contains(this)) return
- val s = " xmlns%s=\"%s\"".format(
+ val s: String = " xmlns%s=\"%s\"".format(
if (prefix != null) ":" + prefix else "",
if (uri != null) uri else ""
)
diff --git a/shared/src/main/scala/scala/xml/Node.scala b/shared/src/main/scala/scala/xml/Node.scala
index 6e68a084d..1b2716f5a 100755
--- a/shared/src/main/scala/scala/xml/Node.scala
+++ b/shared/src/main/scala/scala/xml/Node.scala
@@ -26,9 +26,9 @@ object Node {
final def NoAttributes: MetaData = Null
/** the empty namespace */
- val EmptyNamespace = ""
+ val EmptyNamespace: String = ""
- def unapplySeq(n: Node) = Some((n.label, n.attributes, n.child.toSeq))
+ def unapplySeq(n: Node) /* TODO type annotation */ = Some((n.label, n.attributes, n.child.toSeq))
}
/**
@@ -55,11 +55,11 @@ abstract class Node extends NodeSeq {
/**
* used internally. Atom/Molecule = -1 PI = -2 Comment = -3 EntityRef = -5
*/
- def isAtom = this.isInstanceOf[Atom[_]]
+ def isAtom: Boolean = this.isInstanceOf[Atom[_]]
/** The logic formerly found in typeTag$, as best I could infer it. */
- def doCollectNamespaces = true // if (tag >= 0) DO collect namespaces
- def doTransform = true // if (tag < 0) DO NOT transform
+ def doCollectNamespaces: Boolean = true // if (tag >= 0) DO collect namespaces
+ def doTransform: Boolean = true // if (tag < 0) DO NOT transform
/**
* method returning the namespace bindings of this node. by default, this
@@ -71,7 +71,7 @@ abstract class Node extends NodeSeq {
/**
* convenience, same as `getNamespace(this.prefix)`
*/
- def namespace = getNamespace(this.prefix)
+ def namespace: String = getNamespace(this.prefix)
/**
* Convenience method, same as `scope.getURI(pre)` but additionally
@@ -139,7 +139,7 @@ abstract class Node extends NodeSeq {
*/
def descendant_or_self: List[Node] = this :: descendant
- override def canEqual(other: Any) = other match {
+ override def canEqual(other: Any): Boolean = other match {
case x: Group => false
case x: Node => true
case _ => false
@@ -148,7 +148,7 @@ abstract class Node extends NodeSeq {
override protected def basisForHashCode: Seq[Any] =
prefix :: label :: attributes :: nonEmptyChildren.toList
- override def strict_==(other: Equality) = other match {
+ override def strict_==(other: Equality): Boolean = other match {
case _: Group => false
case x: Node =>
(prefix == x.prefix) &&
diff --git a/shared/src/main/scala/scala/xml/NodeSeq.scala b/shared/src/main/scala/scala/xml/NodeSeq.scala
index fe16be05a..89d81372b 100644
--- a/shared/src/main/scala/scala/xml/NodeSeq.scala
+++ b/shared/src/main/scala/scala/xml/NodeSeq.scala
@@ -13,8 +13,7 @@
package scala
package xml
-import scala.collection.{ mutable, immutable, AbstractSeq }
-import mutable.{ Builder, ListBuffer }
+import scala.collection.{mutable, immutable, AbstractSeq}
import ScalaVersionSpecific.CBF
import scala.language.implicitConversions
import scala.collection.Seq
@@ -25,9 +24,9 @@ import scala.collection.Seq
* @author Burak Emir
*/
object NodeSeq {
- final val Empty = fromSeq(Nil)
+ final val Empty: NodeSeq = fromSeq(Nil)
def fromSeq(s: Seq[Node]): NodeSeq = new NodeSeq {
- override def theSeq = s
+ override def theSeq: Seq[Node] = s
}
// ---
@@ -38,7 +37,7 @@ object NodeSeq {
implicit def canBuildFrom: CBF[Coll, Node, NodeSeq] = ScalaVersionSpecific.NodeSeqCBF
// ---
- def newBuilder: Builder[Node, NodeSeq] = new ListBuffer[Node] mapResult fromSeq
+ def newBuilder: mutable.Builder[Node, NodeSeq] = new mutable.ListBuffer[Node] mapResult fromSeq
implicit def seqToNodeSeq(s: Seq[Node]): NodeSeq = fromSeq(s)
}
@@ -50,15 +49,15 @@ object NodeSeq {
*/
abstract class NodeSeq extends AbstractSeq[Node] with immutable.Seq[Node] with ScalaVersionSpecificNodeSeq with Equality with Serializable {
def theSeq: Seq[Node]
- override def length = theSeq.length
- override def iterator = theSeq.iterator
+ override def length: Int = theSeq.length
+ override def iterator: Iterator[Node] = theSeq.iterator
override def apply(i: Int): Node = theSeq(i)
def apply(f: Node => Boolean): NodeSeq = filter(f)
def xml_sameElements[A](that: Iterable[A]): Boolean = {
- val these = this.iterator
- val those = that.iterator
+ val these: Iterator[Node] = this.iterator
+ val those: Iterator[A] = that.iterator
while (these.hasNext && those.hasNext)
if (these.next() xml_!= those.next())
return false
@@ -68,12 +67,12 @@ abstract class NodeSeq extends AbstractSeq[Node] with immutable.Seq[Node] with S
override protected def basisForHashCode: Seq[Any] = theSeq
- override def canEqual(other: Any) = other match {
+ override def canEqual(other: Any): Boolean = other match {
case _: NodeSeq => true
case _ => false
}
- override def strict_==(other: Equality) = other match {
+ override def strict_==(other: Equality): Boolean = other match {
case x: NodeSeq => (length == x.length) && (theSeq sameElements x.theSeq)
case _ => false
}
@@ -95,15 +94,15 @@ abstract class NodeSeq extends AbstractSeq[Node] with immutable.Seq[Node] with S
* The document order is preserved.
*/
def \(that: String): NodeSeq = {
- def fail = throw new IllegalArgumentException(that)
- def atResult = {
- lazy val y = this(0)
- val attr =
+ def fail: Nothing = throw new IllegalArgumentException(that)
+ def atResult: NodeSeq = {
+ lazy val y: Node = this(0)
+ val attr: Option[Seq[Node]] =
if (that.length == 1) fail
else if (that(1) == '{') {
- val i = that indexOf '}'
+ val i: Int = that indexOf '}'
if (i == -1) fail
- val (uri, key) = (that.substring(2, i), that.substring(i + 1, that.length()))
+ val (uri: String, key: String) = (that.substring(2, i), that.substring(i + 1, that.length()))
if (uri == "" || key == "") fail
else y.attribute(uri, key)
} else y.attribute(that drop 1)
@@ -114,7 +113,7 @@ abstract class NodeSeq extends AbstractSeq[Node] with immutable.Seq[Node] with S
}
}
- def makeSeq(cond: (Node) => Boolean) =
+ def makeSeq(cond: Node => Boolean): NodeSeq =
NodeSeq fromSeq (this flatMap (_.child) filter cond)
that match {
@@ -144,8 +143,8 @@ abstract class NodeSeq extends AbstractSeq[Node] with immutable.Seq[Node] with S
* The document order is preserved.
*/
def \\(that: String): NodeSeq = {
- def fail = throw new IllegalArgumentException(that)
- def filt(cond: (Node) => Boolean) = this flatMap (_.descendant_or_self) filter cond
+ def fail: Nothing = throw new IllegalArgumentException(that)
+ def filt(cond: Node => Boolean): NodeSeq = this flatMap (_.descendant_or_self) filter cond
that match {
case "" => fail
case "_" => filt(!_.isAtom)
diff --git a/shared/src/main/scala/scala/xml/Null.scala b/shared/src/main/scala/scala/xml/Null.scala
index 3800f185f..e7bf3627b 100644
--- a/shared/src/main/scala/scala/xml/Null.scala
+++ b/shared/src/main/scala/scala/xml/Null.scala
@@ -25,43 +25,43 @@ import scala.collection.Seq
* @author Burak Emir
*/
case object Null extends MetaData {
- override def iterator = Iterator.empty
- override def size = 0
+ override def iterator /* TODO type annotation */ = Iterator.empty
+ override def size: Int = 0
override def append(m: MetaData, scope: NamespaceBinding = TopScope): MetaData = m
override def filter(f: MetaData => Boolean): MetaData = this
- override def copy(next: MetaData) = next
- override def getNamespace(owner: Node) = null
+ override def copy(next: MetaData): MetaData = next
+ override def getNamespace(owner: Node) /* TODO type annotation */ = null
- override def hasNext = false
- override def next = null
- override def key = null
- override def value = null
- override def isPrefixed = false
+ override def hasNext: Boolean = false
+ override def next /* TODO type annotation */ = null
+ override def key /* TODO type annotation */ = null
+ override def value /* TODO type annotation */ = null
+ override def isPrefixed: Boolean = false
- override def length = 0
- override def length(i: Int) = i
+ override def length: Int = 0
+ override def length(i: Int): Int = i
- override def strict_==(other: Equality) = other match {
+ override def strict_==(other: Equality): Boolean = other match {
case x: MetaData => x.length == 0
case _ => false
}
override protected def basisForHashCode: Seq[Any] = Nil
- override def apply(namespace: String, scope: NamespaceBinding, key: String) = null
- override def apply(key: String) =
+ override def apply(namespace: String, scope: NamespaceBinding, key: String) /* TODO type annotation */ = null
+ override def apply(key: String) /* TODO type annotation */ =
if (isNameStart(key.head)) null
else throw new IllegalArgumentException("not a valid attribute name '" + key + "', so can never match !")
- override protected def toString1(sb: StringBuilder) = ()
+ override protected def toString1(sb: StringBuilder): Unit = ()
override protected def toString1(): String = ""
override def toString(): String = ""
override def buildString(sb: StringBuilder): StringBuilder = sb
- override def wellformed(scope: NamespaceBinding) = true
+ override def wellformed(scope: NamespaceBinding): Boolean = true
- override def remove(key: String) = this
- override def remove(namespace: String, scope: NamespaceBinding, key: String) = this
+ override def remove(key: String) /* TODO type annotation */ = this
+ override def remove(namespace: String, scope: NamespaceBinding, key: String) /* TODO type annotation */ = this
}
diff --git a/shared/src/main/scala/scala/xml/PCData.scala b/shared/src/main/scala/scala/xml/PCData.scala
index 0b85bfe88..372630ddc 100644
--- a/shared/src/main/scala/scala/xml/PCData.scala
+++ b/shared/src/main/scala/scala/xml/PCData.scala
@@ -40,7 +40,7 @@ class PCData(data: String) extends Atom[String](data) {
* @author Burak Emir
*/
object PCData {
- def apply(data: String) = new PCData(data)
+ def apply(data: String): PCData = new PCData(data)
def unapply(other: Any): Option[String] = other match {
case x: PCData => Some(x.data)
case _ => None
diff --git a/shared/src/main/scala/scala/xml/PrefixedAttribute.scala b/shared/src/main/scala/scala/xml/PrefixedAttribute.scala
index eddea4156..fcbeaccf4 100644
--- a/shared/src/main/scala/scala/xml/PrefixedAttribute.scala
+++ b/shared/src/main/scala/scala/xml/PrefixedAttribute.scala
@@ -29,7 +29,7 @@ class PrefixedAttribute(
override val value: Seq[Node],
val next1: MetaData)
extends Attribute {
- override val next = if (value ne null) next1 else next1.remove(key)
+ override val next: MetaData = if (value ne null) next1 else next1.remove(key)
/** same as this(pre, key, Text(value), next), or no attribute if value is null */
def this(pre: String, key: String, value: String, next: MetaData) =
@@ -43,10 +43,10 @@ class PrefixedAttribute(
* Returns a copy of this unprefixed attribute with the given
* next field.
*/
- override def copy(next: MetaData) =
+ override def copy(next: MetaData): PrefixedAttribute =
new PrefixedAttribute(pre, key, value, next)
- override def getNamespace(owner: Node) =
+ override def getNamespace(owner: Node): String =
owner.getNamespace(pre)
/** forwards the call to next (because caller looks for unprefixed attribute */
@@ -64,5 +64,5 @@ class PrefixedAttribute(
}
object PrefixedAttribute {
- def unapply(x: PrefixedAttribute) = Some((x.pre, x.key, x.value, x.next))
+ def unapply(x: PrefixedAttribute) /* TODO type annotation */ = Some((x.pre, x.key, x.value, x.next))
}
diff --git a/shared/src/main/scala/scala/xml/PrettyPrinter.scala b/shared/src/main/scala/scala/xml/PrettyPrinter.scala
index 90b683ddb..261b05bf0 100755
--- a/shared/src/main/scala/scala/xml/PrettyPrinter.scala
+++ b/shared/src/main/scala/scala/xml/PrettyPrinter.scala
@@ -33,21 +33,21 @@ class PrettyPrinter(width: Int, step: Int, minimizeEmpty: Boolean) {
def this(width: Int, step: Int) = this(width, step, minimizeEmpty = false)
- val minimizeMode = if (minimizeEmpty) MinimizeMode.Always else MinimizeMode.Default
+ val minimizeMode: MinimizeMode.Value = if (minimizeEmpty) MinimizeMode.Always else MinimizeMode.Default
class BrokenException() extends java.lang.Exception
class Item
case object Break extends Item {
- override def toString = "\\"
+ override def toString: String = "\\"
}
case class Box(col: Int, s: String) extends Item
case class Para(s: String) extends Item
protected var items: List[Item] = Nil
- protected var cur = 0
+ protected var cur: Int = 0
- protected def reset() = {
+ protected def reset(): Unit = {
cur = 0
items = Nil
}
@@ -56,10 +56,10 @@ class PrettyPrinter(width: Int, step: Int, minimizeEmpty: Boolean) {
* Try to cut at whitespace.
*/
protected def cut(s: String, ind: Int): List[Item] = {
- val tmp = width - cur
+ val tmp: Int = width - cur
if (s.length <= tmp)
return List(Box(ind, s))
- var i = s indexOf ' '
+ var i: Int = s indexOf ' '
if (i > tmp || i == -1) throw new BrokenException() // cannot break
var last: List[Int] = Nil
@@ -69,7 +69,7 @@ class PrettyPrinter(width: Int, step: Int, minimizeEmpty: Boolean) {
}
var res: List[Item] = Nil
while (Nil != last) try {
- val b = Box(ind, s.substring(0, last.head))
+ val b: Box = Box(ind, s.substring(0, last.head))
cur = ind
res = b :: Break :: cut(s.substring(last.head, s.length), ind)
// backtrack
@@ -83,7 +83,7 @@ class PrettyPrinter(width: Int, step: Int, minimizeEmpty: Boolean) {
/**
* Try to make indented box, if possible, else para.
*/
- protected def makeBox(ind: Int, s: String) =
+ protected def makeBox(ind: Int, s: String): Unit =
if (cur + s.length > width) { // fits in this line
items ::= Box(ind, s)
cur += s.length
@@ -91,18 +91,18 @@ class PrettyPrinter(width: Int, step: Int, minimizeEmpty: Boolean) {
catch { case _: BrokenException => makePara(ind, s) } // give up, para
// dont respect indent in para, but afterwards
- protected def makePara(ind: Int, s: String) = {
+ protected def makePara(ind: Int, s: String): Unit = {
items = Break :: Para(s) :: Break :: items
cur = ind
}
// respect indent
- protected def makeBreak() = { // using wrapping here...
+ protected def makeBreak(): Unit = { // using wrapping here...
items = Break :: items
cur = 0
}
- protected def leafTag(n: Node) = {
+ protected def leafTag(n: Node): String = {
def mkLeaf(sb: StringBuilder): Unit = {
sb append '<'
n nameToString sb
@@ -113,7 +113,7 @@ class PrettyPrinter(width: Int, step: Int, minimizeEmpty: Boolean) {
}
protected def startTag(n: Node, pscope: NamespaceBinding): (String, Int) = {
- var i = 0
+ var i: Int = 0
def mkStart(sb: StringBuilder): Unit = {
sb append '<'
n nameToString sb
@@ -125,7 +125,7 @@ class PrettyPrinter(width: Int, step: Int, minimizeEmpty: Boolean) {
(sbToString(mkStart), i)
}
- protected def endTag(n: Node) = {
+ protected def endTag(n: Node): String = {
def mkEnd(sb: StringBuilder): Unit = {
sb append ""
n nameToString sb
@@ -135,17 +135,17 @@ class PrettyPrinter(width: Int, step: Int, minimizeEmpty: Boolean) {
}
protected def childrenAreLeaves(n: Node): Boolean = {
- def isLeaf(l: Node) = l match {
+ def isLeaf(l: Node): Boolean = l match {
case _: Atom[_] | _: Comment | _: EntityRef | _: ProcInstr => true
case _ => false
}
n.child forall isLeaf
}
- protected def fits(test: String) =
+ protected def fits(test: String): Boolean =
test.length < width - cur
- private def doPreserve(node: Node) =
+ private def doPreserve(node: Node): Boolean =
node.attribute(XML.namespace, XML.space).exists(_.toString == XML.preserve)
protected def traverse(node: Node, pscope: NamespaceBinding, ind: Int): Unit = node match {
@@ -157,8 +157,8 @@ class PrettyPrinter(width: Int, step: Int, minimizeEmpty: Boolean) {
case g@Group(xs) =>
traverse(xs.iterator, pscope, ind)
case _ =>
- val test = {
- val sb = new StringBuilder()
+ val test: String = {
+ val sb: StringBuilder = new StringBuilder()
Utility.serialize(node, pscope, sb, stripComments = false, minimizeTags = minimizeMode)
if (doPreserve(node)) sb.toString
else TextBuffer.fromString(sb.toString).toText(0).data
@@ -166,11 +166,11 @@ class PrettyPrinter(width: Int, step: Int, minimizeEmpty: Boolean) {
if (childrenAreLeaves(node) && fits(test)) {
makeBox(ind, test)
} else {
- val ((stg, len2), etg) =
+ val ((stg: String, len2: Int), etg: String) =
if (node.child.isEmpty && minimizeEmpty) {
// force the tag to be self-closing
- val firstAttribute = test.indexOf(' ')
- val firstBreak = if (firstAttribute != -1) firstAttribute else test.lastIndexOf('/')
+ val firstAttribute: Int = test.indexOf(' ')
+ val firstBreak: Int = if (firstAttribute != -1) firstAttribute else test.lastIndexOf('/')
((test, firstBreak), "")
} else {
(startTag(node, pscope), endTag(node))
@@ -226,10 +226,10 @@ class PrettyPrinter(width: Int, step: Int, minimizeEmpty: Boolean) {
}
def format(n: Node, pscope: NamespaceBinding, sb: StringBuilder): Unit = { // entry point
- var lastwasbreak = false
+ var lastwasbreak: Boolean = false
reset()
traverse(n, pscope, 0)
- var cur = 0
+ var cur: Int = 0
for (b <- items.reverse) b match {
case Break =>
if (!lastwasbreak) sb.append('\n') // on windows: \r\n ?
diff --git a/shared/src/main/scala/scala/xml/ProcInstr.scala b/shared/src/main/scala/scala/xml/ProcInstr.scala
index 1d67825dd..7dbdab978 100644
--- a/shared/src/main/scala/scala/xml/ProcInstr.scala
+++ b/shared/src/main/scala/scala/xml/ProcInstr.scala
@@ -28,16 +28,16 @@ case class ProcInstr(target: String, proctext: String) extends SpecialNode {
if (target.toLowerCase == "xml")
throw new IllegalArgumentException(target + " is reserved")
- final override def doCollectNamespaces = false
- final override def doTransform = false
+ final override def doCollectNamespaces: Boolean = false
+ final override def doTransform: Boolean = false
- final override def label = "#PI"
- override def text = ""
+ final override def label: String = "#PI"
+ override def text: String = ""
/**
* appends "<?" target (" "+text)?+"?>"
* to this stringbuffer.
*/
- override def buildString(sb: StringBuilder) =
+ override def buildString(sb: StringBuilder): StringBuilder =
sb append "%s%s?>".format(target, if (proctext == "") "" else " " + proctext)
}
diff --git a/shared/src/main/scala/scala/xml/QNode.scala b/shared/src/main/scala/scala/xml/QNode.scala
index 059297026..9b1e56e26 100644
--- a/shared/src/main/scala/scala/xml/QNode.scala
+++ b/shared/src/main/scala/scala/xml/QNode.scala
@@ -20,5 +20,5 @@ package xml
* @author Burak Emir
*/
object QNode {
- def unapplySeq(n: Node) = Some((n.scope.getURI(n.prefix), n.label, n.attributes, n.child.toSeq))
+ def unapplySeq(n: Node) /* TODO type annotation */ = Some((n.scope.getURI(n.prefix), n.label, n.attributes, n.child.toSeq))
}
diff --git a/shared/src/main/scala/scala/xml/SpecialNode.scala b/shared/src/main/scala/scala/xml/SpecialNode.scala
index b10ce16d7..e9a4d007f 100644
--- a/shared/src/main/scala/scala/xml/SpecialNode.scala
+++ b/shared/src/main/scala/scala/xml/SpecialNode.scala
@@ -22,13 +22,13 @@ package xml
abstract class SpecialNode extends Node {
/** always empty */
- final override def attributes = Null
+ final override def attributes: Null.type = Null
/** always Node.EmptyNamespace */
- final override def namespace = null
+ final override def namespace: scala.Null = null
/** always empty */
- final override def child = Nil
+ final override def child /* TODO type annotation */ = Nil
/** Append string representation to the given string buffer argument. */
def buildString(sb: StringBuilder): StringBuilder
diff --git a/shared/src/main/scala/scala/xml/Text.scala b/shared/src/main/scala/scala/xml/Text.scala
index 0232e69b1..a2085b0f2 100644
--- a/shared/src/main/scala/scala/xml/Text.scala
+++ b/shared/src/main/scala/scala/xml/Text.scala
@@ -37,7 +37,7 @@ class Text(data: String) extends Atom[String](data) {
* @author Burak Emir
*/
object Text {
- def apply(data: String) = new Text(data)
+ def apply(data: String): Text = new Text(data)
def unapply(other: Any): Option[String] = other match {
case x: Text => Some(x.data)
case _ => None
diff --git a/shared/src/main/scala/scala/xml/TextBuffer.scala b/shared/src/main/scala/scala/xml/TextBuffer.scala
index d8aed3127..fc9e8ba9a 100644
--- a/shared/src/main/scala/scala/xml/TextBuffer.scala
+++ b/shared/src/main/scala/scala/xml/TextBuffer.scala
@@ -27,7 +27,7 @@ object TextBuffer {
* character, and leading and trailing space will be removed completely.
*/
class TextBuffer {
- val sb = new StringBuilder()
+ val sb: StringBuilder = new StringBuilder()
/**
* Appends this string to the text buffer, trimming whitespaces as needed.
diff --git a/shared/src/main/scala/scala/xml/TopScope.scala b/shared/src/main/scala/scala/xml/TopScope.scala
index 743df8532..0fcc2287f 100644
--- a/shared/src/main/scala/scala/xml/TopScope.scala
+++ b/shared/src/main/scala/scala/xml/TopScope.scala
@@ -20,7 +20,7 @@ package xml
*/
object TopScope extends NamespaceBinding(null, null, null) {
- import XML.{ xml, namespace }
+ import XML.{xml, namespace}
override def getURI(prefix1: String): String =
if (prefix1 == xml) namespace else null
@@ -28,8 +28,8 @@ object TopScope extends NamespaceBinding(null, null, null) {
override def getPrefix(uri1: String): String =
if (uri1 == namespace) xml else null
- override def toString() = ""
+ override def toString(): String = ""
- override def buildString(stop: NamespaceBinding) = ""
- override def buildString(sb: StringBuilder, ignore: NamespaceBinding) = {}
+ override def buildString(stop: NamespaceBinding): String = ""
+ override def buildString(sb: StringBuilder, ignore: NamespaceBinding): Unit = ()
}
diff --git a/shared/src/main/scala/scala/xml/Unparsed.scala b/shared/src/main/scala/scala/xml/Unparsed.scala
index 80bde6873..0781018a1 100644
--- a/shared/src/main/scala/scala/xml/Unparsed.scala
+++ b/shared/src/main/scala/scala/xml/Unparsed.scala
@@ -37,6 +37,6 @@ class Unparsed(data: String) extends Atom[String](data) {
* @author Burak Emir
*/
object Unparsed {
- def apply(data: String) = new Unparsed(data)
- def unapply(x: Unparsed) = Some(x.data)
+ def apply(data: String): Unparsed = new Unparsed(data)
+ def unapply(x: Unparsed): Some[String] = Some(x.data)
}
diff --git a/shared/src/main/scala/scala/xml/UnprefixedAttribute.scala b/shared/src/main/scala/scala/xml/UnprefixedAttribute.scala
index 9a7b71be2..c33e5587f 100644
--- a/shared/src/main/scala/scala/xml/UnprefixedAttribute.scala
+++ b/shared/src/main/scala/scala/xml/UnprefixedAttribute.scala
@@ -25,8 +25,8 @@ class UnprefixedAttribute(
override val value: Seq[Node],
next1: MetaData)
extends Attribute {
- final override val pre = null
- override val next = if (value ne null) next1 else next1.remove(key)
+ final override val pre: scala.Null = null
+ override val next: MetaData = if (value ne null) next1 else next1.remove(key)
/** same as this(key, Text(value), next), or no attribute if value is null */
def this(key: String, value: String, next: MetaData) =
@@ -37,7 +37,7 @@ class UnprefixedAttribute(
this(key, value.orNull, next)
/** returns a copy of this unprefixed attribute with the given next field*/
- override def copy(next: MetaData) = new UnprefixedAttribute(key, value, next)
+ override def copy(next: MetaData): UnprefixedAttribute = new UnprefixedAttribute(key, value, next)
final override def getNamespace(owner: Node): String = null
@@ -62,5 +62,5 @@ class UnprefixedAttribute(
next(namespace, scope, key)
}
object UnprefixedAttribute {
- def unapply(x: UnprefixedAttribute) = Some((x.key, x.value, x.next))
+ def unapply(x: UnprefixedAttribute) /* TODO type annotation */ = Some((x.key, x.value, x.next))
}
diff --git a/shared/src/main/scala/scala/xml/Utility.scala b/shared/src/main/scala/scala/xml/Utility.scala
index d95931a8c..c812e4b6b 100755
--- a/shared/src/main/scala/scala/xml/Utility.scala
+++ b/shared/src/main/scala/scala/xml/Utility.scala
@@ -24,7 +24,7 @@ import scala.collection.Seq
* @author Burak Emir
*/
object Utility extends AnyRef with parsing.TokenTests {
- final val SU = '\u001A'
+ final val SU: Char = '\u001A'
// [Martin] This looks dubious. We don't convert StringBuilders to
// Strings anywhere else, why do it here?
@@ -32,12 +32,12 @@ object Utility extends AnyRef with parsing.TokenTests {
// helper for the extremely oft-repeated sequence of creating a
// StringBuilder, passing it around, and then grabbing its String.
- private[xml] def sbToString(f: (StringBuilder) => Unit): String = {
- val sb = new StringBuilder
+ private[xml] def sbToString(f: StringBuilder => Unit): String = {
+ val sb: StringBuilder = new StringBuilder
f(sb)
sb.toString
}
- private[xml] def isAtomAndNotText(x: Node) = x.isAtom && !x.isInstanceOf[Text]
+ private[xml] def isAtomAndNotText(x: Node): Boolean = x.isAtom && !x.isInstanceOf[Text]
/**
* Trims an element - call this method, when you know that it is an
@@ -50,7 +50,7 @@ object Utility extends AnyRef with parsing.TokenTests {
*/
def trim(x: Node): Node = x match {
case Elem(pre, lab, md, scp, child@_*) =>
- val children = combineAdjacentTextNodes(child) flatMap trimProper
+ val children: Seq[Node] = combineAdjacentTextNodes(child) flatMap trimProper
Elem(pre, lab, md, scp, children.isEmpty, children: _*)
}
@@ -67,7 +67,7 @@ object Utility extends AnyRef with parsing.TokenTests {
*/
def trimProper(x: Node): Seq[Node] = x match {
case Elem(pre, lab, md, scp, child@_*) =>
- val children = combineAdjacentTextNodes(child) flatMap trimProper
+ val children: Seq[Node] = combineAdjacentTextNodes(child) flatMap trimProper
Elem(pre, lab, md, scp, children.isEmpty, children: _*)
case Text(s) =>
new TextBuffer().append(s).toText
@@ -77,9 +77,9 @@ object Utility extends AnyRef with parsing.TokenTests {
/** returns a sorted attribute list */
def sort(md: MetaData): MetaData = if ((md eq Null) || (md.next eq Null)) md else {
- val key = md.key
- val smaller = sort(md.filter { m => m.key < key })
- val greater = sort(md.filter { m => m.key > key })
+ val key: String = md.key
+ val smaller: MetaData = sort(md.filter { m => m.key < key })
+ val greater: MetaData = sort(md.filter { m => m.key > key })
smaller.foldRight (md copy greater) ((x, xs) => x copy xs)
}
@@ -89,7 +89,7 @@ object Utility extends AnyRef with parsing.TokenTests {
*/
def sort(n: Node): Node = n match {
case Elem(pre, lab, md, scp, child@_*) =>
- val children = child map sort
+ val children: Seq[Node] = child map sort
Elem(pre, lab, sort(md), scp, children.isEmpty, children: _*)
case _ => n
}
@@ -104,15 +104,15 @@ object Utility extends AnyRef with parsing.TokenTests {
* For reasons unclear escape and unescape are a long ways from
* being logical inverses.
*/
- val pairs = Map(
+ val pairs: Map[String, Char] = Map(
"lt" -> '<',
"gt" -> '>',
"amp" -> '&',
"quot" -> '"',
"apos" -> '\''
)
- val escMap = (pairs - "apos") map { case (s, c) => c -> ("&%s;" format s) }
- val unescMap = pairs
+ val escMap: Map[Char, String] = (pairs - "apos") map { case (s, c) => c -> ("&%s;" format s) }
+ val unescMap: Map[String, Char] = pairs
}
import Escapes.{ escMap, unescMap }
@@ -252,11 +252,11 @@ object Utility extends AnyRef with parsing.TokenTests {
{
if (children.isEmpty) ()
else if (children forall isAtomAndNotText) { // add space
- val it = children.iterator
- val f = it.next()
+ val it: Iterator[Node] = children.iterator
+ val f: Node = it.next()
serialize(f, pscope, sb, stripComments, decodeEntities, preserveWhitespace, minimizeTags)
while (it.hasNext) {
- val x = it.next()
+ val x: Node = it.next()
sb.append(' ')
serialize(x, pscope, sb, stripComments, decodeEntities, preserveWhitespace, minimizeTags)
}
@@ -274,7 +274,7 @@ object Utility extends AnyRef with parsing.TokenTests {
/**
* Returns a hashcode for the given constituents of a node
*/
- def hashCode(pre: String, label: String, attribHashCode: Int, scpeHash: Int, children: Seq[Node]) =
+ def hashCode(pre: String, label: String, attribHashCode: Int, scpeHash: Int, children: Seq[Node]): Int =
scala.util.hashing.MurmurHash3.orderedHash(label +: attribHashCode +: scpeHash +: children, pre.##)
def appendQuoted(s: String): String = sbToString(appendQuoted(s, _))
@@ -283,8 +283,8 @@ object Utility extends AnyRef with parsing.TokenTests {
* Appends "s" if string `s` does not contain ",
* 's' otherwise.
*/
- def appendQuoted(s: String, sb: StringBuilder) = {
- val ch = if (s contains '"') '\'' else '"'
+ def appendQuoted(s: String, sb: StringBuilder): StringBuilder = {
+ val ch: Char = if (s contains '"') '\'' else '"'
sb.append(ch).append(s).append(ch)
}
@@ -304,7 +304,7 @@ object Utility extends AnyRef with parsing.TokenTests {
def getName(s: String, index: Int): String = {
if (index >= s.length) null
else {
- val xs = s drop index
+ val xs: String = s drop index
if (xs.nonEmpty && isNameStart(xs.head)) xs takeWhile isNameChar
else ""
}
@@ -315,13 +315,13 @@ object Utility extends AnyRef with parsing.TokenTests {
* error message if it isn't.
*/
def checkAttributeValue(value: String): String = {
- var i = 0
+ var i: Int = 0
while (i < value.length) {
value.charAt(i) match {
case '<' =>
return "< not allowed in attribute value"
case '&' =>
- val n = getName(value, i + 1)
+ val n: String = getName(value, i + 1)
if (n eq null)
return "malformed entity reference in attribute value [" + value + "]"
i = i + n.length + 1
@@ -335,19 +335,19 @@ object Utility extends AnyRef with parsing.TokenTests {
}
def parseAttributeValue(value: String): Seq[Node] = {
- val sb = new StringBuilder
+ val sb: StringBuilder = new StringBuilder
var rfb: StringBuilder = null
- val nb = new NodeBuffer()
+ val nb: NodeBuffer = new NodeBuffer()
- val it = value.iterator
+ val it: Iterator[Char] = value.iterator
while (it.hasNext) {
- var c = it.next()
+ var c: Char = it.next()
// entity! flush buffer into text node
if (c == '&') {
c = it.next()
if (c == '#') {
c = it.next()
- val theChar = parseCharRef ({ () => c }, { () => c = it.next() }, { s => throw new RuntimeException(s) }, { s => throw new RuntimeException(s) })
+ val theChar: String = parseCharRef ({ () => c }, { () => c = it.next() }, { s => throw new RuntimeException(s) }, { s => throw new RuntimeException(s) })
sb.append(theChar)
} else {
if (rfb eq null) rfb = new StringBuilder()
@@ -357,7 +357,7 @@ object Utility extends AnyRef with parsing.TokenTests {
rfb.append(c)
c = it.next()
}
- val ref = rfb.toString()
+ val ref: String = rfb.toString()
rfb.clear()
unescape(ref, sb) match {
case null =>
@@ -372,7 +372,7 @@ object Utility extends AnyRef with parsing.TokenTests {
} else sb append c
}
if (sb.nonEmpty) { // flush buffer
- val x = Text(sb.toString())
+ val x: Text = Text(sb.toString())
if (nb.isEmpty)
return x
else
@@ -389,9 +389,9 @@ object Utility extends AnyRef with parsing.TokenTests {
* See [66]
*/
def parseCharRef(ch: () => Char, nextch: () => Unit, reportSyntaxError: String => Unit, reportTruncatedError: String => Unit): String = {
- val hex = (ch() == 'x') && { nextch(); true }
- val base = if (hex) 16 else 10
- var i = 0
+ val hex: Boolean = (ch() == 'x') && { nextch(); true }
+ val base: Int = if (hex) 16 else 10
+ var i: Int = 0
while (ch() != ';') {
ch() match {
case '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' =>
diff --git a/shared/src/main/scala/scala/xml/XML.scala b/shared/src/main/scala/scala/xml/XML.scala
index 531afcc97..9838d1505 100755
--- a/shared/src/main/scala/scala/xml/XML.scala
+++ b/shared/src/main/scala/scala/xml/XML.scala
@@ -14,20 +14,19 @@ package scala
package xml
import factory.XMLLoader
-import java.io.{File, FileDescriptor, FileInputStream, FileOutputStream}
-import java.io.{InputStream, Reader, StringReader}
+import java.io.{File, FileDescriptor, FileInputStream, FileOutputStream, InputStream, Reader, StringReader, Writer}
import java.nio.channels.Channels
import scala.util.control.Exception.ultimately
object Source {
- def fromFile(file: File) = new InputSource(new FileInputStream(file))
- def fromFile(fd: FileDescriptor) = new InputSource(new FileInputStream(fd))
- def fromFile(name: String) = new InputSource(new FileInputStream(name))
+ def fromFile(file: File): InputSource = new InputSource(new FileInputStream(file))
+ def fromFile(fd: FileDescriptor): InputSource = new InputSource(new FileInputStream(fd))
+ def fromFile(name: String): InputSource = new InputSource(new FileInputStream(name))
- def fromInputStream(is: InputStream) = new InputSource(is)
- def fromReader(reader: Reader) = new InputSource(reader)
- def fromSysId(sysID: String) = new InputSource(sysID)
- def fromString(string: String) = fromReader(new StringReader(string))
+ def fromInputStream(is: InputStream): InputSource = new InputSource(is)
+ def fromReader(reader: Reader): InputSource = new InputSource(reader)
+ def fromSysId(sysID: String): InputSource = new InputSource(sysID)
+ def fromString(string: String): InputSource = fromReader(new StringReader(string))
}
/**
@@ -38,18 +37,18 @@ object MinimizeMode extends Enumeration {
* Minimize empty tags if they were originally empty when parsed, or if they were constructed
* with [[scala.xml.Elem]]`#minimizeEmpty` == true
*/
- val Default = Value
+ val Default: Value = Value
/**
* Always minimize empty tags. Note that this may be problematic for XHTML, in which
* case [[scala.xml.Xhtml]]`#toXhtml` should be used instead.
*/
- val Always = Value
+ val Always: Value = Value
/**
* Never minimize empty tags.
*/
- val Never = Value
+ val Never: Value = Value
}
/**
@@ -60,13 +59,13 @@ object MinimizeMode extends Enumeration {
* @author Burak Emir
*/
object XML extends XMLLoader[Elem] {
- val xml = "xml"
- val xmlns = "xmlns"
- val namespace = "http://www.w3.org/XML/1998/namespace"
- val preserve = "preserve"
- val space = "space"
- val lang = "lang"
- val encoding = "UTF-8"
+ val xml: String = "xml"
+ val xmlns: String = "xmlns"
+ val namespace: String = "http://www.w3.org/XML/1998/namespace"
+ val preserve: String = "preserve"
+ val space: String = "space"
+ val lang: String = "lang"
+ val encoding: String = "UTF-8"
/** Returns an XMLLoader whose load* methods will use the supplied SAXParser. */
def withSAXParser(p: SAXParser): XMLLoader[Elem] =
@@ -97,8 +96,8 @@ object XML extends XMLLoader[Elem] {
xmlDecl: Boolean = false,
doctype: dtd.DocType = null): Unit =
{
- val fos = new FileOutputStream(filename)
- val w = Channels.newWriter(fos.getChannel, enc)
+ val fos: FileOutputStream = new FileOutputStream(filename)
+ val w: Writer = Channels.newWriter(fos.getChannel, enc)
ultimately(w.close())(
write(w, node, enc, xmlDecl, doctype)
diff --git a/shared/src/main/scala/scala/xml/Xhtml.scala b/shared/src/main/scala/scala/xml/Xhtml.scala
index c0ec1d3b9..962a4d734 100644
--- a/shared/src/main/scala/scala/xml/Xhtml.scala
+++ b/shared/src/main/scala/scala/xml/Xhtml.scala
@@ -39,7 +39,7 @@ object Xhtml {
* Elements which we believe are safe to minimize if minimizeTags is true.
* See http://www.w3.org/TR/xhtml1/guidelines.html#C_3
*/
- private val minimizableElements =
+ private val minimizableElements: List[String] =
List("base", "meta", "link", "hr", "br", "param", "img", "area", "input", "col")
def toXhtml(
@@ -51,11 +51,11 @@ object Xhtml {
preserveWhitespace: Boolean = false,
minimizeTags: Boolean = true): Unit =
{
- def decode(er: EntityRef) = XhtmlEntities.entMap.get(er.entityName) match {
+ def decode(er: EntityRef): StringBuilder = XhtmlEntities.entMap.get(er.entityName) match {
case Some(chr) if chr.toInt >= 128 => sb.append(chr)
case _ => er.buildString(sb)
}
- def shortForm =
+ def shortForm: Boolean =
minimizeTags &&
(x.child == null || x.child.isEmpty) &&
(minimizableElements contains x.label)
@@ -99,7 +99,7 @@ object Xhtml {
if (children.isEmpty)
return
- val doSpaces = children forall isAtomAndNotText // interleave spaces
+ val doSpaces: Boolean = children forall isAtomAndNotText // interleave spaces
for (c <- children.take(children.length - 1)) {
toXhtml(c, pscope, sb, stripComments, decodeEntities, preserveWhitespace, minimizeTags)
if (doSpaces) sb append ' '
diff --git a/shared/src/main/scala/scala/xml/dtd/ContentModel.scala b/shared/src/main/scala/scala/xml/dtd/ContentModel.scala
index 2f8506b8e..ad944b0e9 100644
--- a/shared/src/main/scala/scala/xml/dtd/ContentModel.scala
+++ b/shared/src/main/scala/scala/xml/dtd/ContentModel.scala
@@ -38,11 +38,11 @@ object ContentModel extends WordExp {
}
case class ElemName(name: String) extends Label {
- override def toString = """ElemName("%s")""" format name
+ override def toString: String = """ElemName("%s")""" format name
}
- def isMixed(cm: ContentModel) = cond(cm) { case _: MIXED => true }
- def containsText(cm: ContentModel) = (cm == PCDATA) || isMixed(cm)
+ def isMixed(cm: ContentModel): Boolean = cond(cm) { case _: MIXED => true }
+ def containsText(cm: ContentModel): Boolean = (cm == PCDATA) || isMixed(cm)
def getLabels(r: RegExp): Set[String] = {
def traverse(r: RegExp): Set[String] = r match { // !!! check for match translation problem
@@ -105,11 +105,11 @@ case object ANY extends ContentModel {
override def buildString(sb: StringBuilder): StringBuilder = sb.append("ANY")
}
sealed abstract class DFAContentModel extends ContentModel {
- import ContentModel.{ ElemName, Translator }
+ import ContentModel.{ElemName, Translator}
def r: RegExp
lazy val dfa: DetWordAutom[ElemName] = {
- val nfa = Translator.automatonFrom(r, 1)
+ val nfa: NondetWordAutom[ElemName] = Translator.automatonFrom(r, 1)
new SubsetConstruction(nfa).determinize
}
}
@@ -118,7 +118,7 @@ case class MIXED(override val r: RegExp) extends DFAContentModel {
import ContentModel.Alt
override def buildString(sb: StringBuilder): StringBuilder = {
- val newAlt = r match { case Alt(rs@_*) => Alt(rs drop 1: _*) }
+ val newAlt: Alt = r match { case Alt(rs@_*) => Alt(rs drop 1: _*) }
sb append "(#PCDATA|"
ContentModel.buildString(newAlt: RegExp, sb)
diff --git a/shared/src/main/scala/scala/xml/dtd/DTD.scala b/shared/src/main/scala/scala/xml/dtd/DTD.scala
index 996e7f325..6c5772210 100644
--- a/shared/src/main/scala/scala/xml/dtd/DTD.scala
+++ b/shared/src/main/scala/scala/xml/dtd/DTD.scala
@@ -23,7 +23,7 @@ import scala.collection.Seq
* @author Burak Emir
*/
abstract class DTD {
- var externalID: ExternalID = null
+ var externalID: ExternalID = _
var decls: List[Decl] = Nil
def notations: Seq[NotationDecl] = Nil
def unparsedEntities: Seq[EntityDecl] = Nil
@@ -32,7 +32,7 @@ abstract class DTD {
var attr: mutable.Map[String, AttListDecl] = new mutable.HashMap[String, AttListDecl]()
var ent: mutable.Map[String, EntityDecl] = new mutable.HashMap[String, EntityDecl]()
- override def toString =
+ override def toString: String =
"DTD [\n%s%s]".format(
Option(externalID).getOrElse(""),
decls.mkString("", "\n", "\n")
diff --git a/shared/src/main/scala/scala/xml/dtd/Decl.scala b/shared/src/main/scala/scala/xml/dtd/Decl.scala
index 80ebc20d8..0a1ded00e 100644
--- a/shared/src/main/scala/scala/xml/dtd/Decl.scala
+++ b/shared/src/main/scala/scala/xml/dtd/Decl.scala
@@ -109,14 +109,14 @@ sealed abstract class EntityDef {
case class IntDef(value: String) extends EntityDef {
private def validateValue(): Unit = {
- var tmp = value
- var ix = tmp indexOf '%'
+ var tmp: String = value
+ var ix: Int = tmp indexOf '%'
while (ix != -1) {
- val iz = tmp.indexOf(';', ix)
+ val iz: Int = tmp.indexOf(';', ix)
if (iz == -1 && iz == ix + 1)
throw new IllegalArgumentException("no % allowed in entity value, except for parameter-entity-references")
else {
- val n = tmp.substring(ix, iz)
+ val n: String = tmp.substring(ix, iz)
if (!Utility.isName(n))
throw new IllegalArgumentException("internal entity def: \"" + n + "\" must be an XML Name")
@@ -156,12 +156,12 @@ sealed abstract class DefaultDecl {
case object REQUIRED extends DefaultDecl {
override def toString(): String = "#REQUIRED"
- override def buildString(sb: StringBuilder) = sb append "#REQUIRED"
+ override def buildString(sb: StringBuilder): StringBuilder = sb append "#REQUIRED"
}
case object IMPLIED extends DefaultDecl {
override def toString(): String = "#IMPLIED"
- override def buildString(sb: StringBuilder) = sb append "#IMPLIED"
+ override def buildString(sb: StringBuilder): StringBuilder = sb append "#IMPLIED"
}
case class DEFAULT(fixed: Boolean, attValue: String) extends DefaultDecl {
diff --git a/shared/src/main/scala/scala/xml/dtd/DocType.scala b/shared/src/main/scala/scala/xml/dtd/DocType.scala
index 62161a566..6a6c6e9e7 100644
--- a/shared/src/main/scala/scala/xml/dtd/DocType.scala
+++ b/shared/src/main/scala/scala/xml/dtd/DocType.scala
@@ -30,8 +30,8 @@ case class DocType(name: String, extID: ExternalID, intSubset: Seq[dtd.Decl]) {
throw new IllegalArgumentException(name + " must be an XML Name")
/** returns "<!DOCTYPE + name + extID? + ("["+intSubSet+"]")? >" */
- final override def toString = {
- def intString =
+ final override def toString: String = {
+ def intString: String =
if (intSubset.isEmpty) ""
else intSubset.mkString("[", "", "]")
diff --git a/shared/src/main/scala/scala/xml/dtd/ExternalID.scala b/shared/src/main/scala/scala/xml/dtd/ExternalID.scala
index 7344e4034..2bd80c803 100644
--- a/shared/src/main/scala/scala/xml/dtd/ExternalID.scala
+++ b/shared/src/main/scala/scala/xml/dtd/ExternalID.scala
@@ -20,16 +20,16 @@ package dtd
* @author Burak Emir
*/
sealed abstract class ExternalID extends parsing.TokenTests {
- def quoted(s: String) = {
- val c = if (s contains '"') '\'' else '"'
+ def quoted(s: String): String = {
+ val c: Char = if (s contains '"') '\'' else '"'
c.toString + s + c
}
// public != null: PUBLIC " " publicLiteral " " [systemLiteral]
// public == null: SYSTEM " " systemLiteral
override def toString: String = {
- lazy val quotedSystemLiteral = quoted(systemId)
- lazy val quotedPublicLiteral = quoted(publicId)
+ lazy val quotedSystemLiteral: String = quoted(systemId)
+ lazy val quotedPublicLiteral: String = quoted(publicId)
if (publicId == null) "SYSTEM " + quotedSystemLiteral
else "PUBLIC " + quotedPublicLiteral +
@@ -49,7 +49,7 @@ sealed abstract class ExternalID extends parsing.TokenTests {
* @param systemId the system identifier literal
*/
case class SystemID(override val systemId: String) extends ExternalID {
- override val publicId = null
+ override val publicId: scala.Null = null
if (!checkSysID(systemId))
throw new IllegalArgumentException("can't use both \" and ' in systemId")
@@ -70,13 +70,13 @@ case class PublicID(override val publicId: String, override val systemId: String
throw new IllegalArgumentException("can't use both \" and ' in systemId")
/** the constant "#PI" */
- def label = "#PI"
+ def label: String = "#PI"
/** always empty */
- def attribute = Node.NoAttributes
+ def attribute: MetaData = Node.NoAttributes
/** always empty */
- def child = Nil
+ def child: Nil.type = Nil
}
/**
@@ -85,8 +85,8 @@ case class PublicID(override val publicId: String, override val systemId: String
* @author Michael Bayne
*/
object NoExternalID extends ExternalID {
- override val publicId = null
- override val systemId = null
+ override val publicId /* TODO type annotation */ = null
+ override val systemId /* TODO type annotation */ = null
- override def toString = ""
+ override def toString: String = ""
}
diff --git a/shared/src/main/scala/scala/xml/dtd/Tokens.scala b/shared/src/main/scala/scala/xml/dtd/Tokens.scala
index 9d6542a16..48696af58 100644
--- a/shared/src/main/scala/scala/xml/dtd/Tokens.scala
+++ b/shared/src/main/scala/scala/xml/dtd/Tokens.scala
@@ -18,17 +18,17 @@ class Tokens {
// Tokens
- final val TOKEN_PCDATA = 0
- final val NAME = 1
- final val LPAREN = 3
- final val RPAREN = 4
- final val COMMA = 5
- final val STAR = 6
- final val PLUS = 7
- final val OPT = 8
- final val CHOICE = 9
- final val END = 10
- final val S = 13
+ final val TOKEN_PCDATA: Int = 0
+ final val NAME: Int = 1
+ final val LPAREN: Int = 3
+ final val RPAREN: Int = 4
+ final val COMMA: Int = 5
+ final val STAR: Int = 6
+ final val PLUS: Int = 7
+ final val OPT: Int = 8
+ final val CHOICE: Int = 9
+ final val END: Int = 10
+ final val S: Int = 13
final def token2string(i: Int): String = i match {
case 0 => "#PCDATA"
diff --git a/shared/src/main/scala/scala/xml/dtd/ValidationException.scala b/shared/src/main/scala/scala/xml/dtd/ValidationException.scala
index 127f5ae2e..9b521c8ab 100644
--- a/shared/src/main/scala/scala/xml/dtd/ValidationException.scala
+++ b/shared/src/main/scala/scala/xml/dtd/ValidationException.scala
@@ -20,26 +20,26 @@ case class ValidationException(e: String) extends Exception(e)
* @author Burak Emir
*/
object MakeValidationException {
- def fromFixedAttribute(k: String, value: String, actual: String) =
+ def fromFixedAttribute(k: String, value: String, actual: String): ValidationException =
ValidationException("value of attribute " + k + " FIXED to \"" +
value + "\", but document tries \"" + actual + "\"")
- def fromNonEmptyElement() =
+ def fromNonEmptyElement(): ValidationException =
ValidationException("element should be *empty*")
- def fromUndefinedElement(label: String) =
+ def fromUndefinedElement(label: String): ValidationException =
ValidationException("element \"" + label + "\" not allowed here")
- def fromUndefinedAttribute(key: String) =
+ def fromUndefinedAttribute(key: String): ValidationException =
ValidationException("attribute " + key + " not allowed here")
- def fromMissingAttribute(allKeys: Set[String]) = {
- val sb = new StringBuilder("missing value for REQUIRED attribute")
+ def fromMissingAttribute(allKeys: Set[String]): ValidationException = {
+ val sb: StringBuilder = new StringBuilder("missing value for REQUIRED attribute")
if (allKeys.size > 1) sb.append('s')
allKeys foreach (k => sb append "'%s'".format(k))
ValidationException(sb.toString())
}
- def fromMissingAttribute(key: String, tpe: String) =
+ def fromMissingAttribute(key: String, tpe: String): ValidationException =
ValidationException("missing value for REQUIRED attribute %s of type %s".format(key, tpe))
}
diff --git a/shared/src/main/scala/scala/xml/dtd/impl/Base.scala b/shared/src/main/scala/scala/xml/dtd/impl/Base.scala
index 4dffb7830..8180459be 100644
--- a/shared/src/main/scala/scala/xml/dtd/impl/Base.scala
+++ b/shared/src/main/scala/scala/xml/dtd/impl/Base.scala
@@ -29,41 +29,41 @@ private[dtd] abstract class Base {
object Alt {
/** `Alt( R,R,R* )`. */
- def apply(rs: _regexpT*) =
+ def apply(rs: _regexpT*): Alt =
if (rs.size < 2) throw new SyntaxError("need at least 2 branches in Alt")
else new Alt(rs: _*)
// Can't enforce that statically without changing the interface
// def apply(r1: _regexpT, r2: _regexpT, rs: _regexpT*) = new Alt(Seq(r1, r2) ++ rs: _*)
- def unapplySeq(x: Alt) = Some(x.rs)
+ def unapplySeq(x: Alt): Some[Seq[_regexpT]] = Some(x.rs)
}
class Alt private (val rs: _regexpT*) extends RegExp {
- final override val isNullable = rs exists (_.isNullable)
+ final override val isNullable: Boolean = rs exists (_.isNullable)
}
object Sequ {
/** Sequ( R,R* ) */
- def apply(rs: _regexpT*) = if (rs.isEmpty) Eps else new Sequ(rs: _*)
- def unapplySeq(x: Sequ) = Some(x.rs)
+ def apply(rs: _regexpT*): RegExp = if (rs.isEmpty) Eps else new Sequ(rs: _*)
+ def unapplySeq(x: Sequ): Some[Seq[_regexpT]] = Some(x.rs)
}
class Sequ private (val rs: _regexpT*) extends RegExp {
- final override val isNullable = rs forall (_.isNullable)
+ final override val isNullable: Boolean = rs forall (_.isNullable)
}
case class Star(r: _regexpT) extends RegExp {
- final override lazy val isNullable = true
+ final override lazy val isNullable: Boolean = true
}
// The empty Sequ.
case object Eps extends RegExp {
- final override lazy val isNullable = true
- override def toString = "Eps"
+ final override lazy val isNullable: Boolean = true
+ override def toString: String = "Eps"
}
/** this class can be used to add meta information to regexps. */
class Meta(r1: _regexpT) extends RegExp {
- final override val isNullable = r1.isNullable
- def r = r1
+ final override val isNullable: Boolean = r1.isNullable
+ def r: _regexpT = r1
}
}
diff --git a/shared/src/main/scala/scala/xml/dtd/impl/BaseBerrySethi.scala b/shared/src/main/scala/scala/xml/dtd/impl/BaseBerrySethi.scala
index 84ea9fdb0..9d515938c 100644
--- a/shared/src/main/scala/scala/xml/dtd/impl/BaseBerrySethi.scala
+++ b/shared/src/main/scala/scala/xml/dtd/impl/BaseBerrySethi.scala
@@ -28,7 +28,7 @@ private[dtd] abstract class BaseBerrySethi {
val lang: Base
import lang.{ Alt, Eps, Meta, RegExp, Sequ, Star }
- protected var pos = 0
+ protected var pos: Int = 0
// results which hold all info for the NondetWordAutomaton
protected var follow: mutable.HashMap[Int, Set[Int]] = _
@@ -41,12 +41,12 @@ private[dtd] abstract class BaseBerrySethi {
final val emptySet: Set[Int] = Set()
- private def doComp(r: RegExp, compFunction: RegExp => Set[Int]) = r match {
+ private def doComp(r: RegExp, compFunction: RegExp => Set[Int]): Set[Int] = r match {
case x: Alt => (x.rs map compFirst).foldLeft(emptySet)(_ ++ _)
case Eps => emptySet
case x: Meta => compFunction(x.r)
case x: Sequ =>
- val (l1, l2) = x.rs span (_.isNullable)
+ val (l1: Seq[lang._regexpT], l2: Seq[lang._regexpT]) = x.rs span (_.isNullable)
((l1 ++ (l2 take 1)) map compFunction).foldLeft(emptySet)(_ ++ _)
case Star(t) => compFunction(t)
case _ => throw new IllegalArgumentException("unexpected pattern " + r.getClass)
@@ -67,7 +67,7 @@ private[dtd] abstract class BaseBerrySethi {
follow(0) =
if (rs.isEmpty) emptySet
else rs.foldRight(Set(pos))((p, fol) => {
- val first = compFollow1(fol, p)
+ val first: Set[Int] = compFollow1(fol, p)
if (p.isNullable) fol ++ first
else first
@@ -85,7 +85,7 @@ private[dtd] abstract class BaseBerrySethi {
case x: Star => compFollow1(fol1 ++ compFirst(x.r), x.r)
case x: Sequ =>
x.rs.foldRight(fol1) { (p, fol) =>
- val first = compFollow1(fol, p)
+ val first: Set[Int] = compFollow1(fol, p)
if (p.isNullable) fol ++ first
else first
diff --git a/shared/src/main/scala/scala/xml/dtd/impl/DetWordAutom.scala b/shared/src/main/scala/scala/xml/dtd/impl/DetWordAutom.scala
index 26fd06e07..56df1f9f5 100644
--- a/shared/src/main/scala/scala/xml/dtd/impl/DetWordAutom.scala
+++ b/shared/src/main/scala/scala/xml/dtd/impl/DetWordAutom.scala
@@ -30,15 +30,15 @@ private[dtd] abstract class DetWordAutom[T <: AnyRef] {
val delta: Array[scala.collection.mutable.Map[T, Int]]
val default: Array[Int]
- def isFinal(q: Int) = finals(q) != 0
- def isSink(q: Int) = delta(q).isEmpty && default(q) == q
- def next(q: Int, label: T) = delta(q).getOrElse(label, default(q))
+ def isFinal(q: Int): Boolean = finals(q) != 0
+ def isSink(q: Int): Boolean = delta(q).isEmpty && default(q) == q
+ def next(q: Int, label: T): Int = delta(q).getOrElse(label, default(q))
- override def toString = {
- val sb = new StringBuilder("[DetWordAutom nstates=")
+ override def toString: String = {
+ val sb: StringBuilder = new StringBuilder("[DetWordAutom nstates=")
sb.append(nstates)
sb.append(" finals=")
- val map = finals.zipWithIndex.map(_.swap).toMap
+ val map: Map[Int, Int] = finals.zipWithIndex.map(_.swap).toMap
sb.append(map.toString())
sb.append(" delta=\n")
diff --git a/shared/src/main/scala/scala/xml/dtd/impl/Inclusion.scala b/shared/src/main/scala/scala/xml/dtd/impl/Inclusion.scala
index 45d984ff0..67ea19e4b 100644
--- a/shared/src/main/scala/scala/xml/dtd/impl/Inclusion.scala
+++ b/shared/src/main/scala/scala/xml/dtd/impl/Inclusion.scala
@@ -29,30 +29,30 @@ private[dtd] trait Inclusion[A <: AnyRef] {
/**
* Returns true if `dfa1` is included in `dfa2`.
*/
- def inclusion(dfa1: DetWordAutom[A], dfa2: DetWordAutom[A]) = {
+ def inclusion(dfa1: DetWordAutom[A], dfa2: DetWordAutom[A]): Boolean = {
- def encode(q1: Int, q2: Int) = 1 + q1 + q2 * dfa1.nstates
- def decode2(c: Int) = (c - 1) / dfa1.nstates //integer division
- def decode1(c: Int) = (c - 1) % dfa1.nstates
+ def encode(q1: Int, q2: Int): Int = 1 + q1 + q2 * dfa1.nstates
+ def decode2(c: Int): Int = (c - 1) / dfa1.nstates //integer division
+ def decode1(c: Int): Int = (c - 1) % dfa1.nstates
- var q1 = 0 //dfa1.initstate; // == 0
- var q2 = 0 //dfa2.initstate; // == 0
+ var q1: Int = 0 //dfa1.initstate; // == 0
+ var q2: Int = 0 //dfa2.initstate; // == 0
- val max = 1 + dfa1.nstates * dfa2.nstates
- val mark = new Array[Int](max)
+ val max: Int = 1 + dfa1.nstates * dfa2.nstates
+ val mark: Array[Int] = new Array[Int](max)
- var result = true
- var current = encode(q1, q2)
- var last = current
+ var result: Boolean = true
+ var current: Int = encode(q1, q2)
+ var last: Int = current
mark(last) = max // mark (q1,q2)
while (current != 0 && result) {
//Console.println("current = [["+q1+" "+q2+"]] = "+current);
for (letter <- labels) {
- val r1 = dfa1.next(q1, letter)
- val r2 = dfa2.next(q2, letter)
+ val r1: Int = dfa1.next(q1, letter)
+ val r2: Int = dfa2.next(q2, letter)
if (dfa1.isFinal(r1) && !dfa2.isFinal(r2))
result = false
- val test = encode(r1, r2)
+ val test: Int = encode(r1, r2)
//Console.println("test = [["+r1+" "+r2+"]] = "+test);
if (mark(test) == 0) {
mark(last) = test
@@ -60,7 +60,7 @@ private[dtd] trait Inclusion[A <: AnyRef] {
last = test
}
}
- val ncurrent = mark(current)
+ val ncurrent: Int = mark(current)
if (ncurrent != max) {
q1 = decode1(ncurrent)
q2 = decode2(ncurrent)
diff --git a/shared/src/main/scala/scala/xml/dtd/impl/NondetWordAutom.scala b/shared/src/main/scala/scala/xml/dtd/impl/NondetWordAutom.scala
index 306f64c0f..e12a72a2f 100644
--- a/shared/src/main/scala/scala/xml/dtd/impl/NondetWordAutom.scala
+++ b/shared/src/main/scala/scala/xml/dtd/impl/NondetWordAutom.scala
@@ -13,7 +13,7 @@
package scala
package xml.dtd.impl
-import scala.collection.{ immutable, mutable }
+import scala.collection.{immutable, mutable}
import scala.collection.Seq
/**
@@ -33,16 +33,16 @@ private[dtd] abstract class NondetWordAutom[T <: AnyRef] {
val default: Array[immutable.BitSet]
/** @return true if the state is final */
- final def isFinal(state: Int) = finals(state) > 0
+ final def isFinal(state: Int): Boolean = finals(state) > 0
/** @return tag of final state */
- final def finalTag(state: Int) = finals(state)
+ final def finalTag(state: Int): Int = finals(state)
/** @return true if the set of states contains at least one final state */
final def containsFinal(Q: immutable.BitSet): Boolean = Q exists isFinal
/** @return true if there are no accepting states */
- final def isEmpty = (0 until nstates) forall (x => !isFinal(x))
+ final def isEmpty: Boolean = (0 until nstates) forall (x => !isFinal(x))
/** @return a immutable.BitSet with the next states for given state and label */
def next(q: Int, a: T): immutable.BitSet = delta(q).getOrElse(a, default(q))
@@ -51,14 +51,14 @@ private[dtd] abstract class NondetWordAutom[T <: AnyRef] {
def next(Q: immutable.BitSet, a: T): immutable.BitSet = next(Q, next(_, a))
def nextDefault(Q: immutable.BitSet): immutable.BitSet = next(Q, default)
- private def next(Q: immutable.BitSet, f: (Int) => immutable.BitSet): immutable.BitSet =
+ private def next(Q: immutable.BitSet, f: Int => immutable.BitSet): immutable.BitSet =
Q.toSet.map(f).foldLeft(immutable.BitSet.empty)(_ ++ _)
- private def finalStates = 0 until nstates filter isFinal
- override def toString = {
+ private def finalStates: immutable.Seq[Int] = 0 until nstates filter isFinal
+ override def toString: String = {
- val finalString = Map(finalStates map (j => j -> finals(j)): _*).toString
- val deltaString = (0 until nstates)
+ val finalString: String = Map(finalStates map (j => j -> finals(j)): _*).toString
+ val deltaString: String = (0 until nstates)
.map(i => " %d->%s\n _>%s\n".format(i, delta(i), default(i))).mkString
"[NondetWordAutom nstates=%d finals=%s delta=\n%s".format(nstates, finalString, deltaString)
diff --git a/shared/src/main/scala/scala/xml/dtd/impl/SubsetConstruction.scala b/shared/src/main/scala/scala/xml/dtd/impl/SubsetConstruction.scala
index 38c570223..7c73932a1 100644
--- a/shared/src/main/scala/scala/xml/dtd/impl/SubsetConstruction.scala
+++ b/shared/src/main/scala/scala/xml/dtd/impl/SubsetConstruction.scala
@@ -13,30 +13,31 @@
package scala
package xml.dtd.impl
-import scala.collection.{ mutable, immutable }
+import scala.collection.{immutable, mutable}
// TODO: still used in ContentModel -- @deprecated("This class will be removed", "2.10.0")
private[dtd] class SubsetConstruction[T <: AnyRef](val nfa: NondetWordAutom[T]) {
import nfa.labels
- def selectTag(Q: immutable.BitSet, finals: Array[Int]) =
+ def selectTag(Q: immutable.BitSet, finals: Array[Int]): Int =
(Q map finals filter (_ > 0)).min
def determinize: DetWordAutom[T] = {
// for assigning numbers to bitsets
- val indexMap = mutable.Map[immutable.BitSet, Int]()
- val invIndexMap = mutable.Map[Int, immutable.BitSet]()
- var ix = 0
+ val indexMap: mutable.Map[immutable.BitSet, Int] = mutable.Map[immutable.BitSet, Int]()
+ val invIndexMap: mutable.Map[Int, immutable.BitSet] = mutable.Map[Int, immutable.BitSet]()
+ var ix: Int = 0
// we compute the dfa with states = bitsets
- val q0 = immutable.BitSet(0) // the set { 0 }
- val sink = immutable.BitSet.empty // the set { }
+ val q0: immutable.BitSet = immutable.BitSet(0) // the set { 0 }
+ val sink: immutable.BitSet = immutable.BitSet.empty // the set { }
- var states = Set(q0, sink) // initial set of sets
- val delta = new mutable.HashMap[immutable.BitSet, mutable.HashMap[T, immutable.BitSet]]
- val deftrans = mutable.Map(q0 -> sink, sink -> sink) // initial transitions
+ var states: Set[immutable.BitSet] = Set(q0, sink) // initial set of sets
+ val delta: mutable.HashMap[immutable.BitSet, mutable.HashMap[T, immutable.BitSet]] =
+ new mutable.HashMap[immutable.BitSet, mutable.HashMap[T, immutable.BitSet]]
+ val deftrans: mutable.Map[immutable.BitSet, immutable.BitSet] = mutable.Map(q0 -> sink, sink -> sink) // initial transitions
val finals: mutable.Map[immutable.BitSet, Int] = mutable.Map()
- var rest = immutable.List.empty[immutable.BitSet]
+ var rest: immutable.List[immutable.BitSet] = immutable.List.empty[immutable.BitSet]
rest = q0 :: sink :: rest
@@ -55,7 +56,7 @@ private[dtd] class SubsetConstruction[T <: AnyRef](val nfa: NondetWordAutom[T])
addFinal(q0) // initial state may also be a final state
while (rest.nonEmpty) {
- val P = rest.head
+ val P: immutable.BitSet = rest.head
rest = rest.tail
// assign a number to this bitset
indexMap(P) = ix
@@ -63,36 +64,36 @@ private[dtd] class SubsetConstruction[T <: AnyRef](val nfa: NondetWordAutom[T])
ix += 1
// make transition map
- val Pdelta = new mutable.HashMap[T, immutable.BitSet]
+ val Pdelta: mutable.HashMap[T, immutable.BitSet] = new mutable.HashMap[T, immutable.BitSet]
delta.update(P, Pdelta)
labels foreach { label =>
- val Q = nfa.next(P, label)
+ val Q: immutable.BitSet = nfa.next(P, label)
Pdelta.update(label, Q)
add(Q)
}
// collect default transitions
- val Pdef = nfa nextDefault P
+ val Pdef: immutable.BitSet = nfa nextDefault P
deftrans(P) = Pdef
add(Pdef)
}
// create DetWordAutom, using indices instead of sets
- val nstatesR = states.size
- val deltaR = new Array[mutable.Map[T, Int]](nstatesR)
- val defaultR = new Array[Int](nstatesR)
- val finalsR = new Array[Int](nstatesR)
+ val nstatesR: Int = states.size
+ val deltaR: Array[mutable.Map[T, Int]] = new Array[mutable.Map[T, Int]](nstatesR)
+ val defaultR: Array[Int] = new Array[Int](nstatesR)
+ val finalsR: Array[Int] = new Array[Int](nstatesR)
for (Q <- states) {
- val q = indexMap(Q)
- val trans = delta(Q)
- val transDef = deftrans(Q)
- val qDef = indexMap(transDef)
- val ntrans = new mutable.HashMap[T, Int]()
+ val q: Int = indexMap(Q)
+ val trans: mutable.Map[T, immutable.BitSet] = delta(Q)
+ val transDef: immutable.BitSet = deftrans(Q)
+ val qDef: Int = indexMap(transDef)
+ val ntrans: mutable.Map[T, Int] = new mutable.HashMap[T, Int]()
for ((label, value) <- trans) {
- val p = indexMap(value)
+ val p: Int = indexMap(value)
if (p != qDef)
ntrans.update(label, p)
}
@@ -104,10 +105,10 @@ private[dtd] class SubsetConstruction[T <: AnyRef](val nfa: NondetWordAutom[T])
finals foreach { case (k, v) => finalsR(indexMap(k)) = v }
new DetWordAutom[T] {
- override val nstates = nstatesR
- override val delta = deltaR
- override val default = defaultR
- override val finals = finalsR
+ override val nstates: Int = nstatesR
+ override val delta: Array[mutable.Map[T, Int]] = deltaR
+ override val default: Array[Int] = defaultR
+ override val finals: Array[Int] = finalsR
}
}
}
diff --git a/shared/src/main/scala/scala/xml/dtd/impl/WordBerrySethi.scala b/shared/src/main/scala/scala/xml/dtd/impl/WordBerrySethi.scala
index 19a5880df..2e0f5cb5b 100644
--- a/shared/src/main/scala/scala/xml/dtd/impl/WordBerrySethi.scala
+++ b/shared/src/main/scala/scala/xml/dtd/impl/WordBerrySethi.scala
@@ -13,7 +13,7 @@
package scala
package xml.dtd.impl
-import scala.collection.{ immutable, mutable }
+import scala.collection.{immutable, mutable}
import scala.collection.Seq
/**
@@ -98,7 +98,7 @@ private[dtd] abstract class WordBerrySethi extends BaseBerrySethi {
}
protected def makeTransition(src: Int, dest: Int, label: _labelT): Unit = {
- val q = deltaq(src)
+ val q: mutable.Map[lang._labelT, List[Int]] = deltaq(src)
q.update(label, dest :: q.getOrElse(label, Nil))
}
@@ -148,22 +148,22 @@ private[dtd] abstract class WordBerrySethi extends BaseBerrySethi {
if (x.isNullable) // initial state is final
finals = finals.updated(0, finalTag)
- val delta1 = deltaq.zipWithIndex.map(_.swap).toMap
- val finalsArr = (0 until pos map (k => finals.getOrElse(k, 0))).toArray // 0 == not final
+ val delta1: immutable.Map[Int, mutable.HashMap[lang._labelT, List[Int]]] = deltaq.zipWithIndex.map(_.swap).toMap
+ val finalsArr: Array[Int] = (0 until pos map (k => finals.getOrElse(k, 0))).toArray // 0 == not final
val deltaArr: Array[mutable.Map[_labelT, immutable.BitSet]] =
(0 until pos map { x =>
mutable.HashMap(delta1(x).toSeq map { case (k, v) => k -> immutable.BitSet(v: _*) }: _*)
}).toArray
- val defaultArr = (0 until pos map (k => immutable.BitSet(defaultq(k): _*))).toArray
+ val defaultArr: Array[immutable.BitSet] = (0 until pos map (k => immutable.BitSet(defaultq(k): _*))).toArray
new NondetWordAutom[_labelT] {
- override val nstates = pos
- override val labels = WordBerrySethi.this.labels.toList
- override val finals = finalsArr
- override val delta = deltaArr
- override val default = defaultArr
+ override val nstates: Int = pos
+ override val labels: Seq[lang._labelT] = WordBerrySethi.this.labels.toList
+ override val finals: Array[Int] = finalsArr
+ override val delta: Array[mutable.Map[lang._labelT, immutable.BitSet]] = deltaArr
+ override val default: Array[immutable.BitSet] = defaultArr
}
case z =>
automatonFrom(Sequ(z.asInstanceOf[this.lang._regexpT]), finalTag)
diff --git a/shared/src/main/scala/scala/xml/dtd/impl/WordExp.scala b/shared/src/main/scala/scala/xml/dtd/impl/WordExp.scala
index a3974ced1..c5b07d7ff 100644
--- a/shared/src/main/scala/scala/xml/dtd/impl/WordExp.scala
+++ b/shared/src/main/scala/scala/xml/dtd/impl/WordExp.scala
@@ -49,12 +49,12 @@ private[dtd] abstract class WordExp extends Base {
type _labelT <: Label
case class Letter(a: _labelT) extends RegExp {
- final override lazy val isNullable = false
- var pos = -1
+ final override lazy val isNullable: Boolean = false
+ var pos: Int = -1
}
case class Wildcard() extends RegExp {
- final override lazy val isNullable = false
- var pos = -1
+ final override lazy val isNullable: Boolean = false
+ var pos: Int = -1
}
}
diff --git a/shared/src/main/scala/scala/xml/factory/NodeFactory.scala b/shared/src/main/scala/scala/xml/factory/NodeFactory.scala
index 93746e611..4f83c48b9 100644
--- a/shared/src/main/scala/scala/xml/factory/NodeFactory.scala
+++ b/shared/src/main/scala/scala/xml/factory/NodeFactory.scala
@@ -17,16 +17,16 @@ package factory
import scala.collection.Seq
trait NodeFactory[A <: Node] {
- val ignoreComments = false
- val ignoreProcInstr = false
+ val ignoreComments: Boolean = false
+ val ignoreProcInstr: Boolean = false
/* default behaviour is to use hash-consing */
- val cache = new scala.collection.mutable.HashMap[Int, List[A]]
+ val cache: scala.collection.mutable.HashMap[Int, List[A]] = new scala.collection.mutable.HashMap[Int, List[A]]
protected def create(pre: String, name: String, attrs: MetaData, scope: NamespaceBinding, children: Seq[Node]): A
protected def construct(hash: Int, old: List[A], pre: String, name: String, attrSeq: MetaData, scope: NamespaceBinding, children: Seq[Node]): A = {
- val el = create(pre, name, attrSeq, scope, children)
+ val el: A = create(pre, name, attrSeq, scope, children)
cache.update(hash, el :: old)
el
}
@@ -42,8 +42,8 @@ trait NodeFactory[A <: Node] {
eqElements(n.child, children)
def makeNode(pre: String, name: String, attrSeq: MetaData, scope: NamespaceBinding, children: Seq[Node]): A = {
- val hash = Utility.hashCode(pre, name, attrSeq.##, scope.##, children)
- def cons(old: List[A]) = construct(hash, old, pre, name, attrSeq, scope, children)
+ val hash: Int = Utility.hashCode(pre, name, attrSeq.##, scope.##, children)
+ def cons(old: List[A]): A = construct(hash, old, pre, name, attrSeq, scope, children)
cache.get(hash) match {
case Some(list) => // find structurally equal
diff --git a/shared/src/main/scala/scala/xml/factory/XMLLoader.scala b/shared/src/main/scala/scala/xml/factory/XMLLoader.scala
index 5cdc9461e..8e7dd7455 100644
--- a/shared/src/main/scala/scala/xml/factory/XMLLoader.scala
+++ b/shared/src/main/scala/scala/xml/factory/XMLLoader.scala
@@ -28,9 +28,9 @@ trait XMLLoader[T <: Node] {
import scala.xml.Source._
def adapter: FactoryAdapter = new NoBindingFactoryAdapter()
- private lazy val parserInstance = new ThreadLocal[SAXParser] {
+ private lazy val parserInstance: ThreadLocal[SAXParser] = new ThreadLocal[SAXParser] {
override def initialValue: SAXParser = {
- val parser = SAXParserFactory.newInstance()
+ val parser: SAXParserFactory = SAXParserFactory.newInstance()
parser.setFeature("http://javax.xml.XMLConstants/feature/secure-processing", true)
parser.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false)
parser.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true)
diff --git a/shared/src/main/scala/scala/xml/include/CircularIncludeException.scala b/shared/src/main/scala/scala/xml/include/CircularIncludeException.scala
index 07a20e3f8..ecff559df 100644
--- a/shared/src/main/scala/scala/xml/include/CircularIncludeException.scala
+++ b/shared/src/main/scala/scala/xml/include/CircularIncludeException.scala
@@ -25,5 +25,4 @@ class CircularIncludeException(message: String) extends XIncludeException {
* as its error detail message.
*/
def this() = this(null)
-
}
diff --git a/shared/src/main/scala/scala/xml/include/XIncludeException.scala b/shared/src/main/scala/scala/xml/include/XIncludeException.scala
index 89f42dcce..ddc1419fc 100644
--- a/shared/src/main/scala/scala/xml/include/XIncludeException.scala
+++ b/shared/src/main/scala/scala/xml/include/XIncludeException.scala
@@ -32,7 +32,7 @@ class XIncludeException(message: String) extends Exception(message) {
*/
def this() = this(null)
- private var rootCause: Throwable = null
+ private var rootCause: Throwable = _
/**
* When an `IOException`, `MalformedURLException` or other generic
@@ -58,5 +58,4 @@ class XIncludeException(message: String) extends Exception(message) {
* `XIncludeException` to be thrown
*/
def getRootCause(): Throwable = this.rootCause
-
}
diff --git a/shared/src/main/scala/scala/xml/include/sax/EncodingHeuristics.scala b/shared/src/main/scala/scala/xml/include/sax/EncodingHeuristics.scala
index 2d4573155..fe8b0e323 100644
--- a/shared/src/main/scala/scala/xml/include/sax/EncodingHeuristics.scala
+++ b/shared/src/main/scala/scala/xml/include/sax/EncodingHeuristics.scala
@@ -15,6 +15,7 @@ package xml
package include.sax
import java.io.InputStream
+import scala.util.matching.Regex
/**
* `EncodingHeuristics` reads from a stream
@@ -29,13 +30,13 @@ import java.io.InputStream
object EncodingHeuristics {
object EncodingNames {
// UCS-4 isn't yet implemented in java releases anyway...
- val bigUCS4 = "UCS-4"
- val littleUCS4 = "UCS-4"
- val unusualUCS4 = "UCS-4"
- val bigUTF16 = "UTF-16BE"
- val littleUTF16 = "UTF-16LE"
- val utf8 = "UTF-8"
- val default = utf8
+ val bigUCS4: String = "UCS-4"
+ val littleUCS4: String = "UCS-4"
+ val unusualUCS4: String = "UCS-4"
+ val bigUTF16: String = "UTF-16BE"
+ val littleUTF16: String = "UTF-16LE"
+ val utf8: String = "UTF-8"
+ val default: String = utf8
}
import EncodingNames._
@@ -50,13 +51,13 @@ object EncodingHeuristics {
*/
def readEncodingFromStream(in: InputStream): String = {
var ret: String = null
- val bytesToRead = 1024 // enough to read most XML encoding declarations
- def resetAndRet = { in.reset(); ret }
+ val bytesToRead: Int = 1024 // enough to read most XML encoding declarations
+ def resetAndRet: String = { in.reset(); ret }
// This may fail if there are a lot of space characters before the end
// of the encoding declaration
in mark bytesToRead
- val bytes = (in.read, in.read, in.read, in.read)
+ val bytes: (Int, Int, Int, Int) = (in.read, in.read, in.read, in.read)
// first look for byte order mark
ret = bytes match {
@@ -73,12 +74,12 @@ object EncodingHeuristics {
return resetAndRet
def readASCIIEncoding: String = {
- val data = new Array[Byte](bytesToRead - 4)
- val length = in.read(data, 0, bytesToRead - 4)
+ val data: Array[Byte] = new Array[Byte](bytesToRead - 4)
+ val length: Int = in.read(data, 0, bytesToRead - 4)
// Use Latin-1 (ISO-8859-1) because all byte sequences are legal.
- val declaration = new String(data, 0, length, "ISO-8859-1")
- val regexp = """(?m).*?encoding\s*=\s*["'](.+?)['"]""".r
+ val declaration: String = new String(data, 0, length, "ISO-8859-1")
+ val regexp: Regex = """(?m).*?encoding\s*=\s*["'](.+?)['"]""".r
regexp.findFirstMatchIn(declaration) match {
case None => default
case Some(md) => md.subgroups(0)
diff --git a/shared/src/main/scala/scala/xml/include/sax/XIncludeFilter.scala b/shared/src/main/scala/scala/xml/include/sax/XIncludeFilter.scala
index e7929d93d..c7b22125b 100644
--- a/shared/src/main/scala/scala/xml/include/sax/XIncludeFilter.scala
+++ b/shared/src/main/scala/scala/xml/include/sax/XIncludeFilter.scala
@@ -15,13 +15,11 @@ package xml
package include.sax
import scala.xml.include._
-
import org.xml.sax.{Attributes, Locator, XMLReader}
import org.xml.sax.helpers.{AttributesImpl, NamespaceSupport, XMLFilterImpl, XMLReaderFactory}
import java.io.{BufferedInputStream, IOException, InputStreamReader, UnsupportedEncodingException}
-import java.util.Stack
-import java.net.{MalformedURLException, URL}
+import java.net.{MalformedURLException, URL, URLConnection}
/**
* This is a SAX filter which resolves all XInclude include elements before
@@ -72,10 +70,10 @@ import java.net.{MalformedURLException, URL}
*/
class XIncludeFilter extends XMLFilterImpl {
- final val XINCLUDE_NAMESPACE = "http://www.w3.org/2001/XInclude"
+ final val XINCLUDE_NAMESPACE: String = "http://www.w3.org/2001/XInclude"
- private val bases = new Stack[URL]()
- private val locators = new Stack[Locator]()
+ private val bases: java.util.Stack[URL] = new java.util.Stack[URL]()
+ private val locators: java.util.Stack[Locator] = new java.util.Stack[Locator]()
/* private EntityResolver resolver;
@@ -92,7 +90,7 @@ class XIncludeFilter extends XMLFilterImpl {
// there????
override def setDocumentLocator(locator: Locator): Unit = {
locators push locator
- val base = locator.getSystemId
+ val base: String = locator.getSystemId
try {
bases.push(new URL(base))
} catch {
@@ -103,7 +101,7 @@ class XIncludeFilter extends XMLFilterImpl {
}
// necessary to throw away contents of non-empty XInclude elements
- private var level = 0
+ private var level: Int = 0
/**
* This utility method returns true if and only if this reader is
@@ -118,14 +116,14 @@ class XIncludeFilter extends XMLFilterImpl {
def insideIncludeElement(): Boolean = level != 0
override def startElement(uri: String, localName: String, qName: String, atts1: Attributes): Unit = {
- var atts = atts1
+ var atts: Attributes = atts1
if (level == 0) { // We're not inside an xi:include element
// Adjust bases stack by pushing either the new
// value of xml:base or the base of the parent
- val base = atts.getValue(NamespaceSupport.XMLNS, "base")
- val parentBase = bases.peek()
- var currentBase = parentBase
+ val base: String = atts.getValue(NamespaceSupport.XMLNS, "base")
+ val parentBase: URL = bases.peek()
+ var currentBase: URL = parentBase
if (base != null) {
try {
currentBase = new URL(parentBase, base)
@@ -139,17 +137,17 @@ class XIncludeFilter extends XMLFilterImpl {
if (uri.equals(XINCLUDE_NAMESPACE) && localName.equals("include")) {
// include external document
- val href = atts.getValue("href")
+ val href: String = atts.getValue("href")
// Verify that there is an href attribute
if (href == null) {
throw new SAXException("Missing href attribute")
}
- var parse = atts getValue "parse"
+ var parse: String = atts getValue "parse"
if (parse == null) parse = "xml"
if (parse equals "text") {
- val encoding = atts getValue "encoding"
+ val encoding: String = atts getValue "encoding"
includeTextDocument(href, encoding)
} else if (parse equals "xml") {
includeXMLDocument(href)
@@ -162,7 +160,7 @@ class XIncludeFilter extends XMLFilterImpl {
} else {
if (atRoot) {
// add xml:base attribute if necessary
- val attsImpl = new AttributesImpl(atts)
+ val attsImpl: AttributesImpl = new AttributesImpl(atts)
attsImpl.addAttribute(NamespaceSupport.XMLNS, "base",
"xml:base", "CDATA", currentBase.toExternalForm)
atts = attsImpl
@@ -183,7 +181,7 @@ class XIncludeFilter extends XMLFilterImpl {
}
}
- private var depth = 0
+ private var depth: Int = 0
override def startDocument(): Unit = {
level = 0
@@ -225,12 +223,12 @@ class XIncludeFilter extends XMLFilterImpl {
// convenience method for error messages
private def getLocation(): String = {
- var locationString = ""
- val locator = locators.peek()
- var publicID = ""
- var systemID = ""
- var column = -1
- var line = -1
+ var locationString: String = ""
+ val locator: Locator = locators.peek()
+ var publicID: String = ""
+ var systemID: String = ""
+ var column: Int = -1
+ var line: Int = -1
if (locator != null) {
publicID = locator.getPublicId
systemID = locator.getSystemId
@@ -257,25 +255,25 @@ class XIncludeFilter extends XMLFilterImpl {
* or if the encoding is not recognized
*/
private def includeTextDocument(url: String, encoding1: String): Unit = {
- var encoding = encoding1
+ var encoding: String = encoding1
if (encoding == null || encoding.trim().equals("")) encoding = "UTF-8"
var source: URL = null
try {
- val base = bases.peek()
+ val base: URL = bases.peek()
source = new URL(base, url)
} catch {
case e: MalformedURLException =>
- val ex = new UnavailableResourceException("Unresolvable URL " + url
+ val ex: UnavailableResourceException = new UnavailableResourceException("Unresolvable URL " + url
+ getLocation())
ex.setRootCause(e)
throw new SAXException("Unresolvable URL " + url + getLocation(), ex)
}
try {
- val uc = source.openConnection()
- val in = new BufferedInputStream(uc.getInputStream)
- val encodingFromHeader = uc.getContentEncoding
- var contentType = uc.getContentType
+ val uc: URLConnection = source.openConnection()
+ val in: BufferedInputStream = new BufferedInputStream(uc.getInputStream)
+ val encodingFromHeader: String = uc.getContentEncoding
+ var contentType: String = uc.getContentType
if (encodingFromHeader != null)
encoding = encodingFromHeader
else {
@@ -292,8 +290,8 @@ class XIncludeFilter extends XMLFilterImpl {
}
}
}
- val reader = new InputStreamReader(in, encoding)
- val c = new Array[Char](1024)
+ val reader: InputStreamReader = new InputStreamReader(in, encoding)
+ val c: Array[Char] = new Array[Char](1024)
var charsRead: Int = 0 // bogus init value
while ({ {
charsRead = reader.read(c, 0, 1024)
@@ -310,7 +308,7 @@ class XIncludeFilter extends XMLFilterImpl {
}
- private var atRoot = false
+ private var atRoot: Boolean = false
/**
* This utility method reads a document at a specified URL
@@ -323,11 +321,11 @@ class XIncludeFilter extends XMLFilterImpl {
* be downloaded from the specified URL.
*/
private def includeXMLDocument(url: String): Unit = {
- val source =
+ val source: URL =
try new URL(bases.peek(), url)
catch {
case e: MalformedURLException =>
- val ex = new UnavailableResourceException("Unresolvable URL " + url + getLocation())
+ val ex: UnavailableResourceException = new UnavailableResourceException("Unresolvable URL " + url + getLocation())
ex setRootCause e
throw new SAXException("Unresolvable URL " + url + getLocation(), ex)
}
@@ -342,12 +340,12 @@ class XIncludeFilter extends XMLFilterImpl {
}
parser setContentHandler this
- val resolver = this.getEntityResolver
+ val resolver: EntityResolver = this.getEntityResolver
if (resolver != null)
parser setEntityResolver resolver
// save old level and base
- val previousLevel = level
+ val previousLevel: Int = level
this.level = 0
if (bases contains source)
throw new SAXException(
diff --git a/shared/src/main/scala/scala/xml/include/sax/XIncluder.scala b/shared/src/main/scala/scala/xml/include/sax/XIncluder.scala
index 986b14364..061d4933a 100644
--- a/shared/src/main/scala/scala/xml/include/sax/XIncluder.scala
+++ b/shared/src/main/scala/scala/xml/include/sax/XIncluder.scala
@@ -26,9 +26,9 @@ import java.io.{ OutputStream, OutputStreamWriter, IOException }
*/
class XIncluder(outs: OutputStream, encoding: String) extends ContentHandler with LexicalHandler {
- var out = new OutputStreamWriter(outs, encoding)
+ var out: OutputStreamWriter = new OutputStreamWriter(outs, encoding)
- override def setDocumentLocator(locator: Locator): Unit = {}
+ override def setDocumentLocator(locator: Locator): Unit = ()
override def startDocument(): Unit = {
try {
@@ -49,18 +49,19 @@ class XIncluder(outs: OutputStream, encoding: String) extends ContentHandler wit
}
}
- override def startPrefixMapping(prefix: String, uri: String): Unit = {}
+ override def startPrefixMapping(prefix: String, uri: String): Unit = ()
- override def endPrefixMapping(prefix: String): Unit = {}
+ override def endPrefixMapping(prefix: String): Unit = ()
- override def startElement(namespaceURI: String, localName: String, qualifiedName: String, atts: Attributes) = {
+ override def startElement(namespaceURI: String, localName: String, qualifiedName: String, atts: Attributes): Unit = {
try {
out.write("<" + qualifiedName)
- var i = 0; while (i < atts.getLength) {
+ var i: Int = 0
+ while (i < atts.getLength) {
out.write(" ")
out.write(atts.getQName(i))
out.write("='")
- val value = atts.getValue(i)
+ val value: String = atts.getValue(i)
// @todo Need to use character references if the encoding
// can't support the character
out.write(scala.xml.Utility.escape(value))
@@ -87,8 +88,9 @@ class XIncluder(outs: OutputStream, encoding: String) extends ContentHandler wit
// encoding using character references????
override def characters(ch: Array[Char], start: Int, length: Int): Unit = {
try {
- var i = 0; while (i < length) {
- val c = ch(start + i)
+ var i: Int = 0
+ while (i < length) {
+ val c: Char = ch(start + i)
if (c == '&') out.write("&")
else if (c == '<') out.write("<")
// This next fix is normally not necessary.
@@ -135,7 +137,7 @@ class XIncluder(outs: OutputStream, encoding: String) extends ContentHandler wit
inDTD = true
// if this is the source document, output a DOCTYPE declaration
if (entities.isEmpty) {
- var id = ""
+ var id: String = ""
if (publicID != null) id = " PUBLIC \"" + publicID + "\" \"" + systemID + '"'
else if (systemID != null) id = " SYSTEM \"" + systemID + '"'
try {
@@ -146,7 +148,7 @@ class XIncluder(outs: OutputStream, encoding: String) extends ContentHandler wit
}
}
}
- override def endDTD(): Unit = {}
+ override def endDTD(): Unit = ()
override def startEntity(name: String): Unit = {
entities = name :: entities
@@ -156,12 +158,12 @@ class XIncluder(outs: OutputStream, encoding: String) extends ContentHandler wit
entities = entities.tail
}
- override def startCDATA(): Unit = {}
- override def endCDATA(): Unit = {}
+ override def startCDATA(): Unit = ()
+ override def endCDATA(): Unit = ()
// Just need this reference so we can ask if a comment is
// inside an include element or not
- private var filter: XIncludeFilter = null
+ private var filter: XIncludeFilter = _
def setFilter(filter: XIncludeFilter): Unit = {
this.filter = filter
diff --git a/shared/src/main/scala/scala/xml/package.scala b/shared/src/main/scala/scala/xml/package.scala
index d25a80e27..80fbb5f15 100644
--- a/shared/src/main/scala/scala/xml/package.scala
+++ b/shared/src/main/scala/scala/xml/package.scala
@@ -74,7 +74,7 @@ package scala
* transform XML data with a [[scala.xml.transform.RuleTransformer]].
*/
package object xml {
- val XercesClassName = "org.apache.xerces.parsers.SAXParser"
+ val XercesClassName: String = "org.apache.xerces.parsers.SAXParser"
type SAXException = org.xml.sax.SAXException
type SAXParseException = org.xml.sax.SAXParseException
diff --git a/shared/src/main/scala/scala/xml/parsing/ConstructingHandler.scala b/shared/src/main/scala/scala/xml/parsing/ConstructingHandler.scala
index 4e0000f6c..226668219 100755
--- a/shared/src/main/scala/scala/xml/parsing/ConstructingHandler.scala
+++ b/shared/src/main/scala/scala/xml/parsing/ConstructingHandler.scala
@@ -26,10 +26,8 @@ abstract class ConstructingHandler extends MarkupHandler {
pscope: NamespaceBinding, empty: Boolean, nodes: NodeSeq): NodeSeq =
Elem(pre, label, attrs, pscope, empty, nodes: _*)
- override def procInstr(pos: Int, target: String, txt: String) =
- ProcInstr(target, txt)
-
- override def comment(pos: Int, txt: String) = Comment(txt)
- override def entityRef(pos: Int, n: String) = EntityRef(n)
- override def text(pos: Int, txt: String) = Text(txt)
+ override def procInstr(pos: Int, target: String, txt: String): ProcInstr = ProcInstr(target, txt)
+ override def comment(pos: Int, txt: String): Comment = Comment(txt)
+ override def entityRef(pos: Int, n: String): EntityRef = EntityRef(n)
+ override def text(pos: Int, txt: String): Text = Text(txt)
}
diff --git a/shared/src/main/scala/scala/xml/parsing/ConstructingParser.scala b/shared/src/main/scala/scala/xml/parsing/ConstructingParser.scala
index cbc8aa583..994ec87b5 100644
--- a/shared/src/main/scala/scala/xml/parsing/ConstructingParser.scala
+++ b/shared/src/main/scala/scala/xml/parsing/ConstructingParser.scala
@@ -18,10 +18,10 @@ import java.io.File
import scala.io.Source
object ConstructingParser {
- def fromFile(inp: File, preserveWS: Boolean) =
+ def fromFile(inp: File, preserveWS: Boolean): ConstructingParser =
new ConstructingParser(Source.fromFile(inp), preserveWS).initialize
- def fromSource(inp: Source, preserveWS: Boolean) =
+ def fromSource(inp: Source, preserveWS: Boolean): ConstructingParser =
new ConstructingParser(inp, preserveWS).initialize
}
diff --git a/shared/src/main/scala/scala/xml/parsing/DefaultMarkupHandler.scala b/shared/src/main/scala/scala/xml/parsing/DefaultMarkupHandler.scala
index a8d3b493f..03ee009d0 100755
--- a/shared/src/main/scala/scala/xml/parsing/DefaultMarkupHandler.scala
+++ b/shared/src/main/scala/scala/xml/parsing/DefaultMarkupHandler.scala
@@ -18,14 +18,13 @@ package parsing
abstract class DefaultMarkupHandler extends MarkupHandler {
override def elem(pos: Int, pre: String, label: String, attrs: MetaData,
- scope: NamespaceBinding, empty: Boolean, args: NodeSeq) = NodeSeq.Empty
+ scope: NamespaceBinding, empty: Boolean, args: NodeSeq): NodeSeq = NodeSeq.Empty
- override def procInstr(pos: Int, target: String, txt: String) = NodeSeq.Empty
+ override def procInstr(pos: Int, target: String, txt: String): NodeSeq = NodeSeq.Empty
override def comment(pos: Int, comment: String): NodeSeq = NodeSeq.Empty
- override def entityRef(pos: Int, n: String) = NodeSeq.Empty
-
- override def text(pos: Int, txt: String) = NodeSeq.Empty
+ override def entityRef(pos: Int, n: String): NodeSeq = NodeSeq.Empty
+ override def text(pos: Int, txt: String): NodeSeq = NodeSeq.Empty
}
diff --git a/shared/src/main/scala/scala/xml/parsing/FactoryAdapter.scala b/shared/src/main/scala/scala/xml/parsing/FactoryAdapter.scala
index eaa43afd0..689932b24 100644
--- a/shared/src/main/scala/scala/xml/parsing/FactoryAdapter.scala
+++ b/shared/src/main/scala/scala/xml/parsing/FactoryAdapter.scala
@@ -21,13 +21,13 @@ import org.xml.sax.ext.DefaultHandler2
// can be mixed into FactoryAdapter if desired
trait ConsoleErrorHandler extends DefaultHandler2 {
// ignore warning, crimson warns even for entity resolution!
- override def warning(ex: SAXParseException): Unit = {}
+ override def warning(ex: SAXParseException): Unit = ()
override def error(ex: SAXParseException): Unit = printError("Error", ex)
override def fatalError(ex: SAXParseException): Unit = printError("Fatal Error", ex)
protected def printError(errtype: String, ex: SAXParseException): Unit =
Console.withOut(Console.err) {
- val s = "[%s]:%d:%d: %s".format(
+ val s: String = "[%s]:%d:%d: %s".format(
errtype, ex.getLineNumber, ex.getColumnNumber, ex.getMessage)
Console.println(s)
Console.flush()
@@ -139,10 +139,10 @@ abstract class FactoryAdapter extends DefaultHandler2 with factory.XMLLoader[Nod
else if (!normalizeWhitespace) buffer.appendAll(ch, offset, length)
// normalizing whitespace is not compliant, but useful
else {
- var it = ch.slice(offset, offset + length).iterator
+ var it: Iterator[Char] = ch.slice(offset, offset + length).iterator
while (it.hasNext) {
- val c = it.next()
- val isSpace = c.isWhitespace
+ val c: Char = it.next()
+ val isSpace: Boolean = c.isWhitespace
buffer append (if (isSpace) ' ' else c)
if (isSpace)
it = it dropWhile (_.isWhitespace)
@@ -163,10 +163,11 @@ abstract class FactoryAdapter extends DefaultHandler2 with factory.XMLLoader[Nod
*/
override def endCDATA(): Unit = captureText()
- private def splitName(s: String): (String, String) = {
- val idx = s indexOf ':'
- if (idx < 0) (null, s)
- else (s take idx, s drop (idx + 1))
+ // TODO move into Utility
+ private def splitName(s: String): (Option[String], String) = {
+ val idx: Int = s indexOf ':'
+ if (idx < 0) (None, s)
+ else (Some(s take idx), s drop (idx + 1))
}
/* ContentHandler methods */
@@ -189,7 +190,7 @@ abstract class FactoryAdapter extends DefaultHandler2 with factory.XMLLoader[Nod
tagStack = curTag :: tagStack
curTag = qname
- val localName = splitName(qname)._2
+ val localName: String = splitName(qname)._2
capture = nodeContainsText(localName)
hStack = null :: hStack
@@ -199,16 +200,16 @@ abstract class FactoryAdapter extends DefaultHandler2 with factory.XMLLoader[Nod
else scopeStack.head
for (i <- (0 until attributes.getLength).reverse) {
- val qname = attributes getQName i
- val value = attributes getValue i
- val (pre, key) = splitName(qname)
+ val qname: String = attributes getQName i
+ val value: String = attributes getValue i
+ val (pre: Option[String], key: String) = splitName(qname)
def nullIfEmpty(s: String): String = if (s == "") null else s
- if (pre == "xmlns" || (pre == null && qname == "xmlns")) {
- val arg = if (pre == null) null else key
+ if (pre.contains("xmlns") || (pre.isEmpty && qname == "xmlns")) {
+ val arg: String = if (pre.isEmpty) null else key
scpe = NamespaceBinding(arg, nullIfEmpty(value), scpe)
} else
- m = Attribute(Option(pre), key, Text(value), m)
+ m = Attribute(pre, key, Text(value), m)
}
// Add namespace bindings for the prefix mappings declared by this element
@@ -253,21 +254,21 @@ abstract class FactoryAdapter extends DefaultHandler2 with factory.XMLLoader[Nod
*/
override def endElement(uri: String, _localName: String, qname: String): Unit = {
captureText()
- val metaData = attribStack.head
+ val metaData: MetaData = attribStack.head
attribStack = attribStack.tail
// reverse order to get it right
- val v = hStack.takeWhile(_ != null).reverse
+ val v: List[Node] = hStack.takeWhile(_ != null).reverse
hStack = hStack.dropWhile(_ != null) match {
case null :: hs => hs
case hs => hs
}
- val (pre, localName) = splitName(qname)
- val scp = scopeStack.head
+ val (pre: Option[String], localName: String) = splitName(qname)
+ val scp: NamespaceBinding = scopeStack.head
scopeStack = scopeStack.tail
// create element
- rootElem = createNode(pre, localName, metaData, scp, v)
+ rootElem = createNode(pre.orNull, localName, metaData, scp, v)
hStack = rootElem :: hStack
curTag = tagStack.head
tagStack = tagStack.tail
diff --git a/shared/src/main/scala/scala/xml/parsing/MarkupHandler.scala b/shared/src/main/scala/scala/xml/parsing/MarkupHandler.scala
index 88e30d048..065e834ba 100755
--- a/shared/src/main/scala/scala/xml/parsing/MarkupHandler.scala
+++ b/shared/src/main/scala/scala/xml/parsing/MarkupHandler.scala
@@ -114,7 +114,7 @@ abstract class MarkupHandler {
edef match {
case _: ExtDef if !isValidating => // ignore (cf REC-xml 4.4.1)
case _ =>
- val y = f(name, edef)
+ val y: EntityDecl = f(name, edef)
decls ::= y
ent.update(name, y)
}
diff --git a/shared/src/main/scala/scala/xml/parsing/MarkupParser.scala b/shared/src/main/scala/scala/xml/parsing/MarkupParser.scala
index 4a9d53524..de56029dd 100755
--- a/shared/src/main/scala/scala/xml/parsing/MarkupParser.scala
+++ b/shared/src/main/scala/scala/xml/parsing/MarkupParser.scala
@@ -40,9 +40,9 @@ trait MarkupParser extends MarkupParserCommon with TokenTests {
override type NamespaceType = NamespaceBinding
override def truncatedError(msg: String): Nothing = throw FatalError(msg)
- override def errorNoEnd(tag: String) = throw FatalError("expected closing tag of " + tag)
+ override def errorNoEnd(tag: String): Nothing = throw FatalError("expected closing tag of " + tag)
- override def xHandleError(that: Char, msg: String) = reportSyntaxError(msg)
+ override def xHandleError(that: Char, msg: String): Unit = reportSyntaxError(msg)
val input: Source
@@ -62,17 +62,17 @@ trait MarkupParser extends MarkupParserCommon with TokenTests {
// https://github.com/scala/scala-xml/issues/541 ; the broader access is necessary,
// for now anyway, to work around https://github.com/lampepfl/dotty/issues/13096
private[parsing] class WithLookAhead(underlying: Source) extends Source {
- private val queue = scala.collection.mutable.Queue[Char]()
+ private val queue: scala.collection.mutable.Queue[Char] = scala.collection.mutable.Queue[Char]()
def lookahead(): BufferedIterator[Char] = {
- val iter = queue.iterator ++ new Iterator[Char] {
- override def hasNext = underlying.hasNext
- override def next() = { val x = underlying.next(); queue += x; x }
+ val iter: Iterator[Char] = queue.iterator ++ new Iterator[Char] {
+ override def hasNext: Boolean = underlying.hasNext
+ override def next(): Char = { val x: Char = underlying.next(); queue += x; x }
}
iter.buffered
}
- override val iter = new Iterator[Char] {
- override def hasNext = underlying.hasNext || queue.nonEmpty
- override def next() = if (queue.nonEmpty) queue.dequeue() else underlying.next()
+ override val iter: Iterator[Char] = new Iterator[Char] {
+ override def hasNext: Boolean = underlying.hasNext || queue.nonEmpty
+ override def next(): Char = if (queue.nonEmpty) queue.dequeue() else underlying.next()
}
}
@@ -80,7 +80,7 @@ trait MarkupParser extends MarkupParserCommon with TokenTests {
case curInputWLA: WithLookAhead =>
curInputWLA.lookahead()
case _ =>
- val newInput = new WithLookAhead(curInput)
+ val newInput: WithLookAhead = new WithLookAhead(curInput)
curInput = newInput
newInput.lookahead()
}
@@ -95,7 +95,7 @@ trait MarkupParser extends MarkupParserCommon with TokenTests {
var pos: Int = _
/* used when reading external subset */
- var extIndex = -1
+ var extIndex: Int = -1
/** holds temporary values of pos */
// Note: if marked as an override, this causes a "...cannot override a mutable variable" error with Scala 3;
@@ -113,7 +113,7 @@ trait MarkupParser extends MarkupParserCommon with TokenTests {
lastChRead = curInput.next()
pos = curInput.pos
} else {
- val ilen = inpStack.length
+ val ilen: Int = inpStack.length
//Console.println(" ilen = "+ilen+ " extIndex = "+extIndex);
if ((ilen != extIndex) && (ilen > 0)) {
/* for external source, inpStack == Nil ! need notify of eof! */
@@ -129,11 +129,11 @@ trait MarkupParser extends MarkupParserCommon with TokenTests {
}
/** character buffer, for names */
- protected val cbuf = new StringBuilder()
+ protected val cbuf: StringBuilder = new StringBuilder()
- var dtd: DTD = null
+ var dtd: DTD = _
- protected var doc: Document = null
+ protected var doc: Document = _
override def eof: Boolean = { ch; reachedEof }
@@ -149,7 +149,7 @@ trait MarkupParser extends MarkupParserCommon with TokenTests {
def xmlProcInstr(): MetaData = {
xToken("xml")
xSpace()
- val (md, scp) = xAttributes(TopScope)
+ val (md: MetaData, scp: NamespaceBinding) = xAttributes(TopScope)
if (scp != TopScope)
reportSyntaxError("no xmlns definitions here, please.")
xToken('?')
@@ -165,8 +165,8 @@ trait MarkupParser extends MarkupParserCommon with TokenTests {
var info_enc: Option[String] = None
var info_stdl: Option[Boolean] = None
- val m = xmlProcInstr()
- var n = 0
+ val m: MetaData = xmlProcInstr()
+ var n: Int = 0
if (isProlog)
xSpaceOpt()
@@ -201,7 +201,7 @@ trait MarkupParser extends MarkupParserCommon with TokenTests {
}
if (m.length - n != 0) {
- val s = if (isProlog) "SDDecl? " else ""
+ val s: String = if (isProlog) "SDDecl? " else ""
reportSyntaxError("VersionInfo EncodingDecl? %sor '?>' expected!" format s)
}
@@ -252,13 +252,13 @@ trait MarkupParser extends MarkupParserCommon with TokenTests {
children = content(TopScope) // DTD handled as side effect
} else {
- val ts = new NodeBuffer()
+ val ts: NodeBuffer = new NodeBuffer()
content1(TopScope, ts) // DTD handled as side effect
ts &+ content(TopScope)
children = NodeSeq.fromSeq(ts)
}
//println("[MarkupParser::document] children now: "+children.toList)
- var elemCount = 0
+ var elemCount: Int = 0
var theNode: Node = null
for (c <- children) c match {
case _: ProcInstr =>
@@ -283,7 +283,7 @@ trait MarkupParser extends MarkupParserCommon with TokenTests {
}
/** append Unicode character to name buffer*/
- protected def putChar(c: Char) = cbuf append c
+ protected def putChar(c: Char): StringBuilder = cbuf append c
/**
* As the current code requires you to call nextch once manually
@@ -294,7 +294,7 @@ trait MarkupParser extends MarkupParserCommon with TokenTests {
this
}
- override protected def ch_returning_nextch: Char = { val res = ch; nextch(); res }
+ override protected def ch_returning_nextch: Char = { val res: Char = ch; nextch(); res }
override def mkAttributes(name: String, pscope: NamespaceBinding): AttributesType =
if (isNameStart (ch)) xAttributes(pscope)
@@ -322,17 +322,17 @@ trait MarkupParser extends MarkupParserCommon with TokenTests {
var scope: NamespaceBinding = pscope
var aMap: MetaData = Null
while (isNameStart(ch)) {
- val qname = xName
+ val qname: String = xName
xEQ() // side effect
- val value = xAttributeValue()
+ val value: String = xAttributeValue()
Utility.prefix(qname) match {
case Some("xmlns") =>
- val prefix = qname.substring(6 /*xmlns:*/ , qname.length)
+ val prefix: String = qname.substring(6 /*xmlns:*/ , qname.length)
scope = NamespaceBinding(prefix, value, scope)
case Some(prefix) =>
- val key = qname.substring(prefix.length + 1, qname.length)
+ val key: String = qname.substring(prefix.length + 1, qname.length)
aMap = new PrefixedAttribute(prefix, key, Text(value), aMap)
case _ =>
@@ -360,14 +360,14 @@ trait MarkupParser extends MarkupParserCommon with TokenTests {
* }}}
*/
def xEntityValue(): String = {
- val endch = ch
+ val endch: Char = ch
nextch()
while (ch != endch && !eof) {
putChar(ch)
nextch()
}
nextch()
- val str = cbuf.toString()
+ val str: String = cbuf.toString()
cbuf.setLength(0)
str
}
@@ -449,10 +449,10 @@ trait MarkupParser extends MarkupParserCommon with TokenTests {
* }}}
*/
def content(pscope: NamespaceBinding): NodeSeq = {
- val ts = new NodeBuffer
- var exit = eof
+ val ts: NodeBuffer = new NodeBuffer
+ var exit: Boolean = eof
// todo: optimize seq repr.
- def done = NodeSeq.fromSeq(ts.toList)
+ def done: NodeSeq = NodeSeq.fromSeq(ts.toList)
while (!exit) {
tmppos = pos
@@ -473,11 +473,11 @@ trait MarkupParser extends MarkupParserCommon with TokenTests {
nextch(); ch match {
case '#' => // CharacterRef
nextch()
- val theChar = handle.text(tmppos, xCharRef(() => ch, () => nextch()))
+ val theChar: NodeSeq = handle.text(tmppos, xCharRef(() => ch, () => nextch()))
xToken(';')
ts &+ theChar
case _ => // EntityRef
- val n = xName
+ val n: String = xName
xToken(';')
if (unescape contains n) {
@@ -503,14 +503,14 @@ trait MarkupParser extends MarkupParserCommon with TokenTests {
nextch()
xToken("YSTEM")
xSpace()
- val sysID = systemLiteral()
+ val sysID: String = systemLiteral()
SystemID(sysID)
case 'P' =>
nextch(); xToken("UBLIC")
xSpace()
- val pubID = pubidLiteral()
+ val pubID: String = pubidLiteral()
xSpace()
- val sysID = systemLiteral()
+ val sysID: String = systemLiteral()
PublicID(pubID, sysID)
}
@@ -527,7 +527,7 @@ trait MarkupParser extends MarkupParserCommon with TokenTests {
reportSyntaxError("unexpected character (DOCTYPE already defined")
xToken("DOCTYPE")
xSpace()
- val n = xName
+ val n: String = xName
xSpaceOpt()
//external ID
if ('S' == ch || 'P' == ch) {
@@ -580,27 +580,28 @@ trait MarkupParser extends MarkupParserCommon with TokenTests {
* }}}
*/
def element1(pscope: NamespaceBinding): NodeSeq = {
- val pos = this.pos
- val (qname, (aMap, scope)) = xTag(pscope)
- val (pre, local) = Utility.prefix(qname) match {
- case Some(p) => (p, qname drop p.length + 1)
- case _ => (null, qname)
- }
- val ts = {
+ val pos: Int = this.pos
+ val (qname: String, (aMap: MetaData, scope: NamespaceBinding)) = xTag(pscope)
+ // TODO move into Utility
+ val (pre: Option[String], local: String) = Utility.prefix(qname) match {
+ case Some(p) => (Some(p), qname drop p.length + 1)
+ case _ => (None, qname)
+ }
+ val ts: NodeSeq = {
if (ch == '/') { // empty element
xToken("/>")
- handle.elemStart(pos, pre, local, aMap, scope)
+ handle.elemStart(pos, pre.orNull, local, aMap, scope)
NodeSeq.Empty
} else { // element with content
xToken('>')
- handle.elemStart(pos, pre, local, aMap, scope)
- val tmp = content(scope)
+ handle.elemStart(pos, pre.orNull, local, aMap, scope)
+ val tmp: NodeSeq = content(scope)
xEndTag(qname)
tmp
}
}
- val res = handle.elem(pos, pre, local, aMap, scope, ts == NodeSeq.Empty, ts)
- handle.elemEnd(pos, pre, local)
+ val res: NodeSeq = handle.elem(pos, pre.orNull, local, aMap, scope, ts == NodeSeq.Empty, ts)
+ handle.elemEnd(pos, pre.orNull, local)
res
}
@@ -610,14 +611,14 @@ trait MarkupParser extends MarkupParserCommon with TokenTests {
* precondition: `xEmbeddedBlock == false` (we are not in a scala block)
*/
private def xText: String = {
- var exit = false
+ var exit: Boolean = false
while (!exit) {
putChar(ch)
nextch()
exit = eof || (ch == '<') || (ch == '&')
}
- val str = cbuf.toString
+ val str: String = cbuf.toString
cbuf.setLength(0)
str
}
@@ -630,7 +631,7 @@ trait MarkupParser extends MarkupParserCommon with TokenTests {
* }}}
*/
def systemLiteral(): String = {
- val endch = ch
+ val endch: Char = ch
if (ch != '\'' && ch != '"')
reportSyntaxError("quote ' or \" expected")
nextch()
@@ -639,7 +640,7 @@ trait MarkupParser extends MarkupParserCommon with TokenTests {
nextch()
}
nextch()
- val str = cbuf.toString()
+ val str: String = cbuf.toString()
cbuf.setLength(0)
str
}
@@ -650,7 +651,7 @@ trait MarkupParser extends MarkupParserCommon with TokenTests {
* }}}
*/
def pubidLiteral(): String = {
- val endch = ch
+ val endch: Char = ch
if (ch != '\'' && ch != '"')
reportSyntaxError("quote ' or \" expected")
nextch()
@@ -662,7 +663,7 @@ trait MarkupParser extends MarkupParserCommon with TokenTests {
nextch()
}
nextch()
- val str = cbuf.toString
+ val str: String = cbuf.toString
cbuf.setLength(0)
str
}
@@ -685,11 +686,11 @@ trait MarkupParser extends MarkupParserCommon with TokenTests {
markupDecl()
}
- def markupDecl1() = {
- def doInclude() = {
+ def markupDecl1(): Any = {
+ def doInclude(): Unit = {
xToken('['); while (']' != ch && !eof) markupDecl(); nextch() // ']'
}
- def doIgnore() = {
+ def doIgnore(): Unit = {
xToken('['); while (']' != ch && !eof) nextch(); nextch() // ']'
}
if ('?' == ch) {
@@ -723,13 +724,13 @@ trait MarkupParser extends MarkupParserCommon with TokenTests {
ch match {
case '%' =>
nextch()
- val ent = xName
+ val ent: String = xName
xToken(';')
xSpaceOpt()
push(ent)
xSpaceOpt()
- val stmt = xName
+ val stmt: String = xName
xSpaceOpt()
stmt match {
@@ -765,7 +766,7 @@ trait MarkupParser extends MarkupParserCommon with TokenTests {
def markupDecl(): Unit = ch match {
case '%' => // parameter entity reference
nextch()
- val ent = xName
+ val ent: String = xName
xToken(';')
if (!isValidating)
handle.peReference(ent) // n-v: just create PE-reference
@@ -799,7 +800,7 @@ trait MarkupParser extends MarkupParserCommon with TokenTests {
def elementDecl(): Unit = {
xToken("EMENT")
xSpace()
- val n = xName
+ val n: String = xName
xSpace()
while ('>' != ch && !eof) {
//Console.println("["+ch+"]")
@@ -808,7 +809,7 @@ trait MarkupParser extends MarkupParserCommon with TokenTests {
}
//Console.println("END["+ch+"]")
nextch()
- val cmstr = cbuf.toString()
+ val cmstr: String = cbuf.toString()
cbuf.setLength(0)
handle.elemDecl(n, cmstr)
}
@@ -818,16 +819,16 @@ trait MarkupParser extends MarkupParserCommon with TokenTests {
* ' != ch && !eof) {
- val aname = xName
+ val aname: String = xName
xSpace()
// could be enumeration (foo,bar) parse this later :-/
while ('"' != ch && '\'' != ch && '#' != ch && '<' != ch) {
@@ -835,7 +836,7 @@ trait MarkupParser extends MarkupParserCommon with TokenTests {
cbuf.append(ch)
nextch()
}
- val atpe = cbuf.toString
+ val atpe: String = cbuf.toString
cbuf.setLength(0)
val defdecl: DefaultDecl = ch match {
@@ -867,8 +868,8 @@ trait MarkupParser extends MarkupParserCommon with TokenTests {
* //sy
- val extID = externalID()
+ val extID: ExternalID = externalID()
if (isParameterEntity) {
xSpaceOpt()
xToken('>')
@@ -890,7 +891,7 @@ trait MarkupParser extends MarkupParserCommon with TokenTests {
if ('>' != ch) {
xToken("NDATA")
xSpace()
- val notat = xName
+ val notat: String = xName
xSpaceOpt()
xToken('>')
handle.unparsedEntityDecl(n, extID, notat)
@@ -901,7 +902,7 @@ trait MarkupParser extends MarkupParserCommon with TokenTests {
}
case '"' | '\'' =>
- val av = xEntityValue()
+ val av: String = xEntityValue()
xSpaceOpt()
xToken('>')
if (isParameterEntity)
@@ -920,18 +921,18 @@ trait MarkupParser extends MarkupParserCommon with TokenTests {
def notationDecl(): Unit = {
xToken("OTATION")
xSpace()
- val notat = xName
+ val notat: String = xName
xSpace()
- val extID = if (ch == 'S') {
+ val extID: ExternalID = if (ch == 'S') {
externalID()
} else if (ch == 'P') {
/* PublicID (without system, only used in NOTATION) */
nextch()
xToken("UBLIC")
xSpace()
- val pubID = pubidLiteral()
+ val pubID: String = pubidLiteral()
xSpaceOpt()
- val sysID = if (ch != '>')
+ val sysID: String = if (ch != '>')
systemLiteral()
else
null
diff --git a/shared/src/main/scala/scala/xml/parsing/MarkupParserCommon.scala b/shared/src/main/scala/scala/xml/parsing/MarkupParserCommon.scala
index c967a5f02..2606b98ff 100644
--- a/shared/src/main/scala/scala/xml/parsing/MarkupParserCommon.scala
+++ b/shared/src/main/scala/scala/xml/parsing/MarkupParserCommon.scala
@@ -23,7 +23,7 @@ import Utility.SU
* All members should be accessed through those.
*/
private[scala] trait MarkupParserCommon extends TokenTests {
- protected def unreachable = truncatedError("Cannot be reached.")
+ protected def unreachable: Nothing = truncatedError("Cannot be reached.")
// type HandleType // MarkupHandler, SymbolicXMLBuilder
type InputType // Source, CharArrayReader
@@ -41,7 +41,7 @@ private[scala] trait MarkupParserCommon extends TokenTests {
* [44] EmptyElemTag ::= '<' Name { S Attribute } [S]
*/
protected def xTag(pscope: NamespaceType): (String, AttributesType) = {
- val name = xName
+ val name: String = xName
xSpaceOpt()
(name, mkAttributes(name, pscope))
@@ -53,7 +53,7 @@ private[scala] trait MarkupParserCommon extends TokenTests {
* see [15]
*/
def xProcInstr: ElementType = {
- val n = xName
+ val n: String = xName
xSpaceOpt()
xTakeUntil(mkProcInstr(_, n, _), () => tmppos, "?>")
}
@@ -63,7 +63,7 @@ private[scala] trait MarkupParserCommon extends TokenTests {
* @param endCh either `'` or `"`
*/
def xAttributeValue(endCh: Char): String = {
- val buf = new StringBuilder
+ val buf: StringBuilder = new StringBuilder
while (ch != endCh && !eof) {
// well-formedness constraint
if (ch == '<') reportSyntaxError("'<' not allowed in attrib value")
@@ -76,13 +76,13 @@ private[scala] trait MarkupParserCommon extends TokenTests {
}
def xAttributeValue(): String = {
- val str = xAttributeValue(ch_returning_nextch)
+ val str: String = xAttributeValue(ch_returning_nextch)
// well-formedness constraint
normalizeAttributeValue(str)
}
private def takeUntilChar(it: Iterator[Char], end: Char): String = {
- val buf = new StringBuilder
+ val buf: StringBuilder = new StringBuilder
while (it.hasNext) it.next() match {
case `end` => return buf.toString
case ch => buf append ch
@@ -117,7 +117,7 @@ private[scala] trait MarkupParserCommon extends TokenTests {
else if (!isNameStart(ch))
return errorAndResult("name expected, but char '%s' cannot start a name" format ch, "")
- val buf = new StringBuilder
+ val buf: StringBuilder = new StringBuilder
while ({ buf append ch_returning_nextch
; isNameChar(ch)}) ()
@@ -128,7 +128,7 @@ private[scala] trait MarkupParserCommon extends TokenTests {
} else buf.toString
}
- private def attr_unescape(s: String) = s match {
+ private def attr_unescape(s: String): String = s match {
case "lt" => "<"
case "gt" => ">"
case "amp" => "&"
@@ -143,8 +143,8 @@ private[scala] trait MarkupParserCommon extends TokenTests {
* see spec 3.3.3
*/
private def normalizeAttributeValue(attval: String): String = {
- val buf = new StringBuilder
- val it = attval.iterator.buffered
+ val buf: StringBuilder = new StringBuilder
+ val it: BufferedIterator[Char] = attval.iterator.buffered
while (it.hasNext) buf append (it.next() match {
case ' ' | '\t' | '\n' | '\r' => " "
@@ -167,7 +167,7 @@ private[scala] trait MarkupParserCommon extends TokenTests {
Utility.parseCharRef(ch, nextch, reportSyntaxError, truncatedError)
def xCharRef(it: Iterator[Char]): String = {
- var c = it.next()
+ var c: Char = it.next()
Utility.parseCharRef(() => c, () => { c = it.next() }, reportSyntaxError, truncatedError)
}
@@ -211,13 +211,13 @@ private[scala] trait MarkupParserCommon extends TokenTests {
def xToken(that: Seq[Char]): Unit = { that foreach xToken }
/** scan [S] '=' [S]*/
- def xEQ() = { xSpaceOpt(); xToken('='); xSpaceOpt() }
+ def xEQ(): Unit = { xSpaceOpt(); xToken('='); xSpaceOpt() }
/** skip optional space S? */
- def xSpaceOpt() = while (isSpace(ch) && !eof) nextch()
+ def xSpaceOpt(): Unit = while (isSpace(ch) && !eof) nextch()
/** scan [3] S ::= (#x20 | #x9 | #xD | #xA)+ */
- def xSpace() =
+ def xSpace(): Unit =
if (isSpace(ch)) { nextch(); xSpaceOpt() }
else xHandleError(ch, "whitespace expected")
@@ -226,7 +226,7 @@ private[scala] trait MarkupParserCommon extends TokenTests {
/** Execute body with a variable saved and restored after execution */
def saving[A, B](getter: A, setter: A => Unit)(body: => B): B = {
- val saved = getter
+ val saved: A = getter
try body
finally setter(saved)
}
@@ -241,9 +241,9 @@ private[scala] trait MarkupParserCommon extends TokenTests {
positioner: () => PositionType,
until: String): T =
{
- val sb = new StringBuilder
- val head = until.head
- val rest = until.tail
+ val sb: StringBuilder = new StringBuilder
+ val head: Char = until.head
+ val rest: String = until.tail
while (!eof) {
if (ch == head && peek(rest))
diff --git a/shared/src/main/scala/scala/xml/parsing/NoBindingFactoryAdapter.scala b/shared/src/main/scala/scala/xml/parsing/NoBindingFactoryAdapter.scala
index 9e5e0a5c0..bd57b40c7 100644
--- a/shared/src/main/scala/scala/xml/parsing/NoBindingFactoryAdapter.scala
+++ b/shared/src/main/scala/scala/xml/parsing/NoBindingFactoryAdapter.scala
@@ -23,7 +23,7 @@ import factory.NodeFactory
*/
class NoBindingFactoryAdapter extends FactoryAdapter with NodeFactory[Elem] {
/** True. Every XML node may contain text that the application needs */
- override def nodeContainsText(label: String) = true
+ override def nodeContainsText(label: String): Boolean = true
/** From NodeFactory. Constructs an instance of scala.xml.Elem -- TODO: deprecate as in Elem */
override protected def create(pre: String, label: String, attrs: MetaData, scope: NamespaceBinding, children: Seq[Node]): Elem =
diff --git a/shared/src/main/scala/scala/xml/parsing/TokenTests.scala b/shared/src/main/scala/scala/xml/parsing/TokenTests.scala
index 8b8a539a4..ec3ad851a 100644
--- a/shared/src/main/scala/scala/xml/parsing/TokenTests.scala
+++ b/shared/src/main/scala/scala/xml/parsing/TokenTests.scala
@@ -38,8 +38,8 @@ trait TokenTests {
final def isSpace(cs: Seq[Char]): Boolean = cs.nonEmpty && (cs forall isSpace)
/** These are 99% sure to be redundant but refactoring on the safe side. */
- def isAlpha(c: Char) = (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z')
- def isAlphaDigit(c: Char) = isAlpha(c) || (c >= '0' && c <= '9')
+ def isAlpha(c: Char): Boolean = (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z')
+ def isAlphaDigit(c: Char): Boolean = isAlpha(c) || (c >= '0' && c <= '9')
/**
* {{{
@@ -48,7 +48,7 @@ trait TokenTests {
* }}}
* See [4] and [4a] of Appendix B of XML 1.0 specification.
*/
- def isNameChar(ch: Char) = {
+ def isNameChar(ch: Char): Boolean = {
import java.lang.Character._
// The constants represent groups Mc, Me, Mn, Lm, and Nd.
@@ -70,7 +70,7 @@ trait TokenTests {
* We do not allow a name to start with `:`.
* See [4] and Appendix B of XML 1.0 specification
*/
- def isNameStart(ch: Char) = {
+ def isNameStart(ch: Char): Boolean = {
import java.lang.Character._
getType(ch).toByte match {
@@ -87,7 +87,7 @@ trait TokenTests {
* }}}
* See [5] of XML 1.0 specification.
*/
- def isName(s: String) =
+ def isName(s: String): Boolean =
s.nonEmpty && isNameStart(s.head) && (s.tail forall isNameChar)
def isPubIDChar(ch: Char): Boolean =
@@ -102,13 +102,13 @@ trait TokenTests {
*
* @param ianaEncoding The IANA encoding name.
*/
- def isValidIANAEncoding(ianaEncoding: Seq[Char]) = {
- def charOK(c: Char) = isAlphaDigit(c) || ("._-" contains c)
+ def isValidIANAEncoding(ianaEncoding: Seq[Char]): Boolean = {
+ def charOK(c: Char): Boolean = isAlphaDigit(c) || ("._-" contains c)
ianaEncoding.nonEmpty && isAlpha(ianaEncoding.head) &&
(ianaEncoding.tail forall charOK)
}
- def checkSysID(s: String) = List('"', '\'') exists (c => !(s contains c))
- def checkPubID(s: String) = s forall isPubIDChar
+ def checkSysID(s: String): Boolean = List('"', '\'') exists (c => !(s contains c))
+ def checkPubID(s: String): Boolean = s forall isPubIDChar
}
diff --git a/shared/src/main/scala/scala/xml/parsing/XhtmlEntities.scala b/shared/src/main/scala/scala/xml/parsing/XhtmlEntities.scala
index c3649f8c6..ff593d3e2 100644
--- a/shared/src/main/scala/scala/xml/parsing/XhtmlEntities.scala
+++ b/shared/src/main/scala/scala/xml/parsing/XhtmlEntities.scala
@@ -21,7 +21,7 @@ import scala.xml.dtd.{ IntDef, ParsedEntityDecl }
*
*/
object XhtmlEntities {
- val entList = List(("quot", 34), ("amp", 38), ("lt", 60), ("gt", 62), ("nbsp", 160), ("iexcl", 161), ("cent", 162), ("pound", 163), ("curren", 164), ("yen", 165),
+ val entList: List[(String, Int)] = List(("quot", 34), ("amp", 38), ("lt", 60), ("gt", 62), ("nbsp", 160), ("iexcl", 161), ("cent", 162), ("pound", 163), ("curren", 164), ("yen", 165),
("euro", 8364), ("brvbar", 166), ("sect", 167), ("uml", 168), ("copy", 169), ("ordf", 170), ("laquo", 171), ("shy", 173), ("reg", 174), ("trade", 8482),
("macr", 175), ("deg", 176), ("plusmn", 177), ("sup2", 178), ("sup3", 179), ("acute", 180), ("micro", 181), ("para", 182), ("middot", 183), ("cedil", 184),
("sup1", 185), ("ordm", 186), ("raquo", 187), ("frac14", 188), ("frac12", 189), ("frac34", 190), ("iquest", 191), ("times", 215), ("divide", 247),
@@ -51,8 +51,8 @@ object XhtmlEntities {
val entMap: Map[String, Char] = Map.empty[String, Char] ++ entList.map { case (name, value) => (name, value.toChar) }
- val entities = entList.
+ val entities: List[(String, ParsedEntityDecl)] = entList.
map { case (name, value) => (name, ParsedEntityDecl(name, IntDef(value.toChar.toString))) }
- def apply() = entities
+ def apply(): List[(String, ParsedEntityDecl)] = entities
}
diff --git a/shared/src/main/scala/scala/xml/parsing/XhtmlParser.scala b/shared/src/main/scala/scala/xml/parsing/XhtmlParser.scala
index b21ddec75..accc65d6b 100644
--- a/shared/src/main/scala/scala/xml/parsing/XhtmlParser.scala
+++ b/shared/src/main/scala/scala/xml/parsing/XhtmlParser.scala
@@ -23,7 +23,7 @@ import scala.io.Source
* @author (c) David Pollak, 2007 WorldWide Conferencing, LLC.
*/
class XhtmlParser(override val input: Source) extends ConstructingHandler with MarkupParser with ExternalSources {
- override val preserveWS = true
+ override val preserveWS: Boolean = true
ent ++= XhtmlEntities()
}
diff --git a/shared/src/main/scala/scala/xml/transform/BasicTransformer.scala b/shared/src/main/scala/scala/xml/transform/BasicTransformer.scala
index 397c5fb31..ebbc92a54 100644
--- a/shared/src/main/scala/scala/xml/transform/BasicTransformer.scala
+++ b/shared/src/main/scala/scala/xml/transform/BasicTransformer.scala
@@ -21,8 +21,8 @@ import scala.collection.Seq
*
* @author Burak Emir
*/
-abstract class BasicTransformer extends Function1[Node, Node] {
- protected def unchanged(n: Node, ns: Seq[Node]) =
+abstract class BasicTransformer extends (Node => Node) {
+ protected def unchanged(n: Node, ns: Seq[Node]): Boolean =
ns.length == 1 && (ns.head == n)
/**
@@ -37,7 +37,7 @@ abstract class BasicTransformer extends Function1[Node, Node] {
* otherwise a new sequence of concatenated results.
*/
def transform(ns: Seq[Node]): Seq[Node] = {
- val changed = ns flatMap transform
+ val changed: Seq[Node] = ns flatMap transform
if (changed.length != ns.length || changed.zip(ns).exists(p => p._1 != p._2)) changed
else ns
}
@@ -46,8 +46,8 @@ abstract class BasicTransformer extends Function1[Node, Node] {
if (n.doTransform) n match {
case Group(xs) => Group(transform(xs)) // un-group the hack Group tag
case _ =>
- val ch = n.child
- val nch = transform(ch)
+ val ch: Seq[Node] = n.child
+ val nch: Seq[Node] = transform(ch)
if (ch eq nch) n
else Elem(n.prefix, n.label, n.attributes, n.scope, nch.isEmpty, nch: _*)
@@ -56,7 +56,7 @@ abstract class BasicTransformer extends Function1[Node, Node] {
}
override def apply(n: Node): Node = {
- val seq = transform(n)
+ val seq: Seq[Node] = transform(n)
if (seq.length > 1)
throw new UnsupportedOperationException("transform must return single node for root")
else seq.head
diff --git a/shared/src/main/scala/scala/xml/transform/RuleTransformer.scala b/shared/src/main/scala/scala/xml/transform/RuleTransformer.scala
index 45fddc1f4..657b1b73c 100644
--- a/shared/src/main/scala/scala/xml/transform/RuleTransformer.scala
+++ b/shared/src/main/scala/scala/xml/transform/RuleTransformer.scala
@@ -17,7 +17,7 @@ package transform
import scala.collection.Seq
class RuleTransformer(rules: RewriteRule*) extends BasicTransformer {
- private val transformers = rules.map(new NestingTransformer(_))
+ private val transformers: Seq[NestingTransformer] = rules.map(new NestingTransformer(_))
override def transform(n: Node): Seq[Node] = {
if (transformers.isEmpty) n
else transformers.tail.foldLeft(transformers.head.transform(n)) { (res, transformer) => transformer.transform(res) }
diff --git a/shared/src/test/scala-2.x/scala/xml/ShouldCompile.scala b/shared/src/test/scala-2.x/scala/xml/ShouldCompile.scala
index 2a0d621c8..21f06210f 100644
--- a/shared/src/test/scala-2.x/scala/xml/ShouldCompile.scala
+++ b/shared/src/test/scala-2.x/scala/xml/ShouldCompile.scala
@@ -5,6 +5,6 @@ package scala.xml
// t1626
object o {
- val n =
+ val n: Elem =
n.namespace == null
}
diff --git a/shared/src/test/scala-2.x/scala/xml/TransformersTest.scala b/shared/src/test/scala-2.x/scala/xml/TransformersTest.scala
index ae1ae1463..c67453e0e 100644
--- a/shared/src/test/scala-2.x/scala/xml/TransformersTest.scala
+++ b/shared/src/test/scala-2.x/scala/xml/TransformersTest.scala
@@ -8,8 +8,7 @@ import org.junit.Assert.assertEquals
class TransformersTest {
-
- def transformer = new RuleTransformer(new RewriteRule {
+ def transformer: RuleTransformer = new RuleTransformer(new RewriteRule {
override def transform(n: Node): NodeSeq = n match {
case { _* } =>
case n => n
@@ -17,17 +16,17 @@ class TransformersTest {
})
@Test
- def transform = // SI-2124
+ def transform(): Unit = // SI-2124
assertEquals(transformer.transform(
),
)
@Test
- def transformNamespaced = // SI-2125
+ def transformNamespaced(): Unit = // SI-2125
assertEquals(transformer.transform(
),
Group(
))
@Test
- def rewriteRule = { // SI-2276
+ def rewriteRule(): Unit = { // SI-2276
val inputXml: Node =
@@ -45,7 +44,7 @@ class TransformersTest {
}
}
- val ruleTransformer = new RuleTransformer(t1)
+ val ruleTransformer: RuleTransformer = new RuleTransformer(t1)
JUnitAssertsForXML.assertEquals(ruleTransformer(inputXml).toString, // TODO: why do we need toString?
@@ -58,10 +57,10 @@ class TransformersTest {
}
@Test
- def preserveReferentialComplexityInLinearComplexity = { // SI-4528
- var i = 0
+ def preserveReferentialComplexityInLinearComplexity(): Unit = { // SI-4528
+ var i: Int = 0
- val xmlNode = Hello Example
+ val xmlNode: Elem = Hello Example
new RuleTransformer(new RewriteRule {
override def transform(n: Node): Seq[Node] = {
@@ -78,15 +77,15 @@ class TransformersTest {
}
@Test
- def appliesRulesRecursivelyOnPreviousChanges = { // #257
- def add(outer: Elem, inner: Node) = new RewriteRule {
+ def appliesRulesRecursivelyOnPreviousChanges(): Unit = { // #257
+ def add(outer: Elem, inner: Node): RewriteRule = new RewriteRule {
override def transform(n: Node): Seq[Node] = n match {
case e: Elem if e.label == outer.label => e.copy(child = e.child ++ inner)
case other => other
}
}
- def transformer = new RuleTransformer(add(, ), add(, ))
+ def transformer: RuleTransformer = new RuleTransformer(add(, ), add(, ))
assertEquals(, transformer())
}
diff --git a/shared/src/test/scala-2.x/scala/xml/XMLTest2x.scala b/shared/src/test/scala-2.x/scala/xml/XMLTest2x.scala
index 21835506f..f844165aa 100644
--- a/shared/src/test/scala-2.x/scala/xml/XMLTest2x.scala
+++ b/shared/src/test/scala-2.x/scala/xml/XMLTest2x.scala
@@ -13,19 +13,19 @@ class XMLTest2x {
@UnitTest
- def wsdl = {
+ def wsdl(): Unit = {
assertEquals("""
""", wsdlTemplate3("service3") toString)
}
@UnitTest
- def t5154: Unit = {
+ def t5154(): Unit = {
// extra space made the pattern OK
- def f = {{3}} match { case {{3}} => true }
+ def f: Boolean = {{3}} match { case {{3}} => true }
// lack of space used to error: illegal start of simple pattern
- def g = {{3}} match { case {{3}} => true }
+ def g: Boolean = {{3}} match { case {{3}} => true }
assertTrue(f)
assertTrue(g)
diff --git a/shared/src/test/scala/scala/xml/AttributeTest.scala b/shared/src/test/scala/scala/xml/AttributeTest.scala
index 4e151224e..bae4be959 100644
--- a/shared/src/test/scala/scala/xml/AttributeTest.scala
+++ b/shared/src/test/scala/scala/xml/AttributeTest.scala
@@ -6,21 +6,22 @@ import org.junit.Assert.assertEquals
class AttributeTest {
@Test
- def unprefixedAttribute: Unit = {
- val x = new UnprefixedAttribute("foo","bar", Null)
+ def unprefixedAttribute(): Unit = {
+ val x: UnprefixedAttribute = new UnprefixedAttribute("foo","bar", Null)
assertEquals(Some(Text("bar")), x.get("foo"))
assertEquals(Text("bar"), x("foo"))
assertEquals(None, x.get("no_foo"))
assertEquals(null, x("no_foo"))
- val y = x.remove("foo")
+ val y: MetaData = x.remove("foo")
assertEquals(Null, y)
- val z = new UnprefixedAttribute("foo", null:NodeSeq, x)
+ val z: UnprefixedAttribute = new UnprefixedAttribute("foo", null:NodeSeq, x)
assertEquals(None, z.get("foo"))
- var appended = x append x append x append x
- var len = 0; while (appended ne Null) {
+ var appended: MetaData = x append x append x append x
+ var len: Int = 0
+ while (appended ne Null) {
appended = appended.next
len = len + 1
}
@@ -28,154 +29,154 @@ class AttributeTest {
}
@Test
- def attributeWithOption: Unit = {
- val x = new UnprefixedAttribute("foo", Some(Text("bar")), Null)
+ def attributeWithOption(): Unit = {
+ val x: UnprefixedAttribute = new UnprefixedAttribute("foo", Some(Text("bar")), Null)
assertEquals(Some(Text("bar")), x.get("foo"))
assertEquals(Text("bar"), x("foo"))
assertEquals(None, x.get("no_foo"))
assertEquals(null, x("no_foo"))
- val attr1 = Some(Text("foo value"))
- val attr2 = None
- val y =
+ val attr1: Option[Text] = Some(Text("foo value"))
+ val attr2: Option[Text] = None
+ val y: Elem =
assertEquals(Some(Text("foo value")), y.attributes.get("foo"))
assertEquals(Text("foo value"), y.attributes("foo"))
assertEquals(None, y.attributes.get("bar"))
assertEquals(null, y.attributes("bar"))
- val z = new UnprefixedAttribute("foo", None, x)
+ val z: UnprefixedAttribute = new UnprefixedAttribute("foo", None, x)
assertEquals(None, z.get("foo"))
}
@Test
- def attributeOrder: Unit = {
- val x =
+ def attributeOrder(): Unit = {
+ val x: Elem =
assertEquals("""""", x.toString)
}
- def attributeToString: Unit = {
+ def attributeToString(): Unit = {
val expected: String = """"""
assertEquals(expected, .toString)
assertEquals(expected, .toString)
}
@Test
- def attributeOperator: Unit = {
- val xml =
+ def attributeOperator(): Unit = {
+ val xml: Elem =
assertEquals("apple", xml \@ "bar")
}
@Test
- def attributePathRootNoAttribute: Unit = {
- val xml =
+ def attributePathRootNoAttribute(): Unit = {
+ val xml: Elem =
assertEquals(NodeSeq.Empty, xml \ "@bar")
}
@Test(expected=classOf[IllegalArgumentException])
- def attributePathIllegalEmptyAttribute: Unit = {
- val xml =
+ def attributePathIllegalEmptyAttribute(): Unit = {
+ val xml: Elem =
xml \ "@"
}
@Test
- def attributePathRootWithOneAttribute: Unit = {
- val xml =
+ def attributePathRootWithOneAttribute(): Unit = {
+ val xml: Elem =
assertEquals(Group(Text("apple")), xml \ "@bar")
// assertEquals(NodeSeq.fromSeq(Seq(Text("apple"))), xml \ "@bar")
}
@Test
- def attributePathRootWithMissingAttributes: Unit = {
- val xml =
+ def attributePathRootWithMissingAttributes(): Unit = {
+ val xml: Elem =
assertEquals(NodeSeq.Empty, xml \ "@oops")
}
@Test
- def attributePathDuplicateAttribute: Unit = {
- val xml = Elem(null, "foo",
+ def attributePathDuplicateAttribute(): Unit = {
+ val xml: Elem = Elem(null, "foo",
Attribute("bar", Text("apple"),
- Attribute("bar", Text("orange"), Null)), TopScope, true)
+ Attribute("bar", Text("orange"), Null)), TopScope, minimizeEmpty = true)
assertEquals(Group(Text("apple")), xml \ "@bar")
}
@Test
- def attributePathDescendantAttributes: Unit = {
- val xml =
+ def attributePathDescendantAttributes(): Unit = {
+ val xml: Elem =
assertEquals(NodeSeq.fromSeq(Seq(Text("1"), Text("2"))), xml \\ "@bar")
}
@Test
- def attributeDescendantPathChildAttributes: Unit = {
- val xml =
+ def attributeDescendantPathChildAttributes(): Unit = {
+ val xml: Elem =
assertEquals(NodeSeq.fromSeq(Seq(Text("1"), Text("2"))), xml \ "b" \\ "@bar")
}
@Test
- def attributeDescendantPathDescendantAttributes: Unit = {
- val xml =
+ def attributeDescendantPathDescendantAttributes(): Unit = {
+ val xml: Elem =
assertEquals(NodeSeq.fromSeq(Seq(Text("1"), Text("2"))), xml \\ "b" \\ "@bar")
}
@Test
- def attributeChildDescendantPathDescendantAttributes: Unit = {
- val xml =
+ def attributeChildDescendantPathDescendantAttributes(): Unit = {
+ val xml: Elem =
assertEquals(NodeSeq.fromSeq(Seq(Text("1"), Text("2"))), xml \ "a" \\ "@bar")
}
@Test
- def attributeDescendantDescendantPathDescendantAttributes: Unit = {
- val xml =
+ def attributeDescendantDescendantPathDescendantAttributes(): Unit = {
+ val xml: Elem =
assertEquals(NodeSeq.fromSeq(Seq(Text("1"), Text("2"))), xml \\ "b" \\ "@bar")
}
@Test(expected=classOf[IllegalArgumentException])
- def attributePathDescendantIllegalEmptyAttribute: Unit = {
- val xml =
+ def attributePathDescendantIllegalEmptyAttribute(): Unit = {
+ val xml: Elem =
xml \\ "@"
}
@Test
- def attributePathNoDescendantAttributes: Unit = {
- val xml =
+ def attributePathNoDescendantAttributes(): Unit = {
+ val xml: Elem =
assertEquals(NodeSeq.Empty, xml \\ "@oops")
}
@Test
- def attributePathOneChildWithAttributes: Unit = {
- val xml = >
+ def attributePathOneChildWithAttributes(): Unit = {
+ val xml: Elem = >
assertEquals(Group(Seq(Text("1"))), xml \ "b" \ "@bar")
}
@Test
- def attributePathTwoChildrenWithAttributes: Unit = {
- val xml =
- val b = xml \ "b"
+ def attributePathTwoChildrenWithAttributes(): Unit = {
+ val xml: Elem =
+ val b: NodeSeq = xml \ "b"
assertEquals(2, b.length.toLong)
assertEquals(NodeSeq.fromSeq(Seq(, )), b)
- val barFail = b \ "@bar"
- val barList = b.map(_ \ "@bar")
+ val barFail: NodeSeq = b \ "@bar"
+ val barList: Seq[NodeSeq] = b.map(_ \ "@bar")
assertEquals(NodeSeq.Empty, barFail)
assertEquals(List(Group(Seq(Text("1"))), Group(Seq(Text("2")))), barList)
}
@Test(expected=classOf[IllegalArgumentException])
- def invalidAttributeFailForOne: Unit = {
+ def invalidAttributeFailForOne(): Unit = {
\ "@"
}
@Test(expected=classOf[IllegalArgumentException])
- def invalidAttributeFailForMany: Unit = {
+ def invalidAttributeFailForMany(): Unit = {
.child \ "@"
}
@Test(expected=classOf[IllegalArgumentException])
- def invalidEmptyAttributeFailForOne: Unit = {
+ def invalidEmptyAttributeFailForOne(): Unit = {
\@ ""
}
@Test(expected=classOf[IllegalArgumentException])
- def invalidEmptyAttributeFailForMany: Unit = {
+ def invalidEmptyAttributeFailForMany(): Unit = {
.child \@ ""
}
}
diff --git a/shared/src/test/scala/scala/xml/CommentTest.scala b/shared/src/test/scala/scala/xml/CommentTest.scala
index b1a6cfe34..7ad4fd695 100644
--- a/shared/src/test/scala/scala/xml/CommentTest.scala
+++ b/shared/src/test/scala/scala/xml/CommentTest.scala
@@ -6,23 +6,23 @@ import org.junit.Test
final class CommentTest {
@Test(expected=classOf[IllegalArgumentException])
- def invalidCommentWithTwoDashes: Unit = {
+ def invalidCommentWithTwoDashes(): Unit = {
Comment("invalid--comment")
}
@Test(expected=classOf[IllegalArgumentException])
- def invalidCommentWithFinalDash: Unit = {
+ def invalidCommentWithFinalDash(): Unit = {
Comment("invalid comment-")
}
@Test
- def validCommentWithDash: Unit = {
+ def validCommentWithDash(): Unit = {
val valid: String = "valid-comment"
assertEquals(s"", Comment(valid).toString)
}
@Test
- def validEmptyComment: Unit = {
+ def validEmptyComment(): Unit = {
val valid: String = ""
assertEquals(s"", Comment(valid).toString)
}
diff --git a/shared/src/test/scala/scala/xml/JUnitAssertsForXML.scala b/shared/src/test/scala/scala/xml/JUnitAssertsForXML.scala
index 374ed704d..4eedd88fe 100644
--- a/shared/src/test/scala/scala/xml/JUnitAssertsForXML.scala
+++ b/shared/src/test/scala/scala/xml/JUnitAssertsForXML.scala
@@ -4,5 +4,4 @@ object JUnitAssertsForXML {
private[xml] def assertEquals(expected: String, actual: NodeSeq): Unit =
org.junit.Assert.assertEquals(expected, actual.toString)
-
}
diff --git a/shared/src/test/scala/scala/xml/MetaDataTest.scala b/shared/src/test/scala/scala/xml/MetaDataTest.scala
index 44c9454d6..039382fad 100644
--- a/shared/src/test/scala/scala/xml/MetaDataTest.scala
+++ b/shared/src/test/scala/scala/xml/MetaDataTest.scala
@@ -6,22 +6,22 @@ import org.junit.Assert.assertEquals
class MetaDataTest {
@Test
- def absentElementPrefixed1: Unit = {
+ def absentElementPrefixed1(): Unit = {
// type ascription to help overload resolution pick the right variant
assertEquals(null: Object, Null("za://foo.com", TopScope, "bar"))
assertEquals(null, Null("bar"))
}
@Test
- def absentElementPrefixed2: Unit = {
+ def absentElementPrefixed2(): Unit = {
assertEquals(Option.empty, Null.get("za://foo.com", TopScope, "bar" ))
assertEquals(Option.empty, Null.get("bar"))
}
@Test
- def presentElement1: Unit = {
- val x = new PrefixedAttribute("zo","bar", new Atom(42), Null)
- val s = NamespaceBinding("zo","za://foo.com", TopScope)
+ def presentElement1(): Unit = {
+ val x: PrefixedAttribute = new PrefixedAttribute("zo","bar", new Atom(42), Null)
+ val s: NamespaceBinding = NamespaceBinding("zo","za://foo.com", TopScope)
assertEquals(new Atom(42), x("za://foo.com", s, "bar" ))
assertEquals(null, x("bar"))
assertEquals(Some(new Atom(42)), x.get("za://foo.com", s, "bar"))
@@ -29,10 +29,10 @@ class MetaDataTest {
}
@Test
- def presentElement2: Unit = {
- val s = NamespaceBinding("zo","za://foo.com", TopScope)
- val x1 = new PrefixedAttribute("zo","bar", new Atom(42), Null)
- val x = new UnprefixedAttribute("bar","meaning", x1)
+ def presentElement2(): Unit = {
+ val s: NamespaceBinding = NamespaceBinding("zo","za://foo.com", TopScope)
+ val x1: PrefixedAttribute = new PrefixedAttribute("zo","bar", new Atom(42), Null)
+ val x: UnprefixedAttribute = new UnprefixedAttribute("bar","meaning", x1)
assertEquals(null, x(null, s, "bar"))
assertEquals(Text("meaning"), x("bar"))
assertEquals(None, x.get(null, s, "bar" ))
@@ -40,25 +40,24 @@ class MetaDataTest {
}
@Test
- def attributeExtractor: Unit = {
- def domatch(x:Node): Node = {
+ def attributeExtractor(): Unit = {
+ def domatch(x: Node): Node = {
x match {
case Node("foo", md @ UnprefixedAttribute(_, value, _), _*) if value.nonEmpty =>
md("bar")(0)
case _ => new Atom(3)
}
}
- val z =
- val z2 =
+ val z: Elem =
+ val z2: Elem =
assertEquals(Text("gar"), domatch(z))
assertEquals(new Atom(3), domatch(z2))
}
@Test
- def reverseTest: Unit = {
+ def reverseTest(): Unit = {
assertEquals("", Null.reverse.toString)
assertEquals(""" b="c"""", .attributes.reverse.toString)
assertEquals(""" d="e" b="c"""", .attributes.reverse.toString)
}
-
}
diff --git a/shared/src/test/scala/scala/xml/NodeBufferTest.scala b/shared/src/test/scala/scala/xml/NodeBufferTest.scala
index 93fcb7a5f..5b3e69eb7 100644
--- a/shared/src/test/scala/scala/xml/NodeBufferTest.scala
+++ b/shared/src/test/scala/scala/xml/NodeBufferTest.scala
@@ -6,8 +6,8 @@ import org.junit.Assert.assertEquals
class NodeBufferTest {
@Test
- def testToString: Unit = {
- val nodeBuffer = new NodeBuffer
+ def testToString(): Unit = {
+ val nodeBuffer: NodeBuffer = new NodeBuffer
assertEquals("NodeBuffer()", nodeBuffer.toString)
}
}
diff --git a/shared/src/test/scala/scala/xml/NodeSeqTest.scala b/shared/src/test/scala/scala/xml/NodeSeqTest.scala
index 8fa427363..d639855ce 100644
--- a/shared/src/test/scala/scala/xml/NodeSeqTest.scala
+++ b/shared/src/test/scala/scala/xml/NodeSeqTest.scala
@@ -1,43 +1,44 @@
package scala.xml
import scala.xml.NodeSeq.seqToNodeSeq
-
import org.junit.Test
import org.junit.Assert.assertEquals
import org.junit.Assert.fail
+import scala.collection.immutable
+
class NodeSeqTest {
@Test
- def testAppend: Unit = { // Bug #392.
+ def testAppend(): Unit = { // Bug #392.
val a: NodeSeq = Hello
- val b = Hi
+ val b: Elem = Hi
a ++ Hi match {
case res: NodeSeq => assertEquals(2, res.size.toLong)
case res: Seq[Node] => fail("Should be NodeSeq was Seq[Node]") // Unreachable code?
}
val res: NodeSeq = a ++ b
- val exp = NodeSeq.fromSeq(Seq(Hello, Hi))
+ val exp: NodeSeq = NodeSeq.fromSeq(Seq(Hello, Hi))
assertEquals(exp, res)
}
@Test
- def testAppendedAll: Unit = { // Bug #392.
+ def testAppendedAll(): Unit = { // Bug #392.
val a: NodeSeq = Hello
- val b = Hi
+ val b: Elem = Hi
a :+ Hi match {
case res: Seq[Node] => assertEquals(2, res.size.toLong)
case res: NodeSeq => fail("Should be Seq[Node] was NodeSeq") // Unreachable code?
}
val res: NodeSeq = a :+ b
- val exp = NodeSeq.fromSeq(Seq(Hello, Hi))
+ val exp: NodeSeq = NodeSeq.fromSeq(Seq(Hello, Hi))
assertEquals(exp, res)
}
@Test
- def testPrepended: Unit = {
+ def testPrepended(): Unit = {
val a: NodeSeq = Hello
- val b = Hi
+ val b: Elem = Hi
a +: Hi match {
case res: Seq[Node] => assertEquals(2, res.size.toLong)
case res: NodeSeq => fail("Should be Seq[Node] was NodeSeq") // Unreachable code?
@@ -50,21 +51,21 @@ class NodeSeqTest {
}
@Test
- def testPrependedAll: Unit = {
+ def testPrependedAll(): Unit = {
val a: NodeSeq = Hello
- val b = Hi
- val c = Hey
+ val b: Elem = Hi
+ val c: Elem = Hey
a ++: Hi ++: Hey match {
case res: Seq[Node] => assertEquals(3, res.size.toLong)
case res: NodeSeq => fail("Should be Seq[Node] was NodeSeq") // Unreachable code?
}
val res: NodeSeq = a ++: b ++: c
- val exp = NodeSeq.fromSeq(Seq(Hello, Hi, Hey))
+ val exp: NodeSeq = NodeSeq.fromSeq(Seq(Hello, Hi, Hey))
assertEquals(exp, res)
}
@Test
- def testMap: Unit = {
+ def testMap(): Unit = {
val a: NodeSeq = Hello
val exp: NodeSeq = Seq(Hi)
assertEquals(exp, a.map(_ => Hi))
@@ -72,7 +73,7 @@ class NodeSeqTest {
}
@Test
- def testFlatMap: Unit = {
+ def testFlatMap(): Unit = {
val a: NodeSeq = Hello
val exp: NodeSeq = Seq(Hi)
assertEquals(exp, a.flatMap(_ => Seq(Hi)))
@@ -81,8 +82,8 @@ class NodeSeqTest {
}
@Test
- def testStringProjection: Unit = {
- val a =
+ def testStringProjection(): Unit = {
+ val a: Elem =
b
@@ -93,7 +94,7 @@ class NodeSeqTest {
c
- val res = for {
+ val res: Seq[String] = for {
b <- a \ "b"
c <- b.child
e <- (c \ "e").headOption
diff --git a/shared/src/test/scala/scala/xml/PCDataTest.scala b/shared/src/test/scala/scala/xml/PCDataTest.scala
index 78fd494fb..3dce2f60c 100644
--- a/shared/src/test/scala/scala/xml/PCDataTest.scala
+++ b/shared/src/test/scala/scala/xml/PCDataTest.scala
@@ -5,33 +5,23 @@ import org.junit.Assert.assertEquals
class PCDataTest {
- @Test
- def emptyTest = {
- val pcdata = new PCData("")
- assertEquals("", pcdata.toString)
+ def check(pcdata: String, expected: String): Unit = {
+ val actual: PCData = new PCData(pcdata)
+ assertEquals(expected, actual.toString)
}
@Test
- def bracketTest = {
- val pcdata = new PCData("[]")
- assertEquals("", pcdata.toString)
- }
+ def emptyTest(): Unit = check("", "")
@Test
- def hellaBracketingTest = {
- val pcdata = new PCData("[[[[[[[[]]]]]]]]")
- assertEquals("", pcdata.toString)
- }
+ def bracketTest(): Unit = check("[]", "")
@Test
- def simpleNestingTest = {
- val pcdata = new PCData("]]>")
- assertEquals("]]>", pcdata.toString)
- }
+ def hellaBracketingTest(): Unit = check("[[[[[[[[]]]]]]]]", "")
@Test
- def recursiveNestingTest = {
- val pcdata = new PCData("")
- assertEquals("]]>", pcdata.toString)
- }
+ def simpleNestingTest(): Unit = check("]]>", "]]>")
+
+ @Test
+ def recursiveNestingTest(): Unit = check("", "]]>")
}
diff --git a/shared/src/test/scala/scala/xml/PatternMatchingTest.scala b/shared/src/test/scala/scala/xml/PatternMatchingTest.scala
index b2892c9cb..d2d809c93 100644
--- a/shared/src/test/scala/scala/xml/PatternMatchingTest.scala
+++ b/shared/src/test/scala/scala/xml/PatternMatchingTest.scala
@@ -7,39 +7,39 @@ import org.junit.Assert.assertEquals
class PatternMatchingTest {
@Test
- def unprefixedAttribute: Unit = {
- val li = List("1", "2", "3", "4")
+ def unprefixedAttribute(): Unit = {
+ val li: List[String] = List("1", "2", "3", "4")
assertTrue(matchSeq(li))
assertTrue(matchList(li))
}
- def matchSeq(args: Seq[String]) = args match {
+ def matchSeq(args: Seq[String]): Boolean = args match {
case Seq(a, b, c, d @ _*) => true
}
- def matchList(args: List[String]) =
+ def matchList(args: List[String]): Boolean =
Elem(null, "bla", Null, TopScope, minimizeEmpty = true, args.map { x => Text(x) }: _*) match {
case Elem(_, _, _, _, Text("1"), _*) => true
}
@Test
- def simpleNode =
+ def simpleNode(): Unit =
assertTrue( match {
case => true
})
@Test
- def nameSpaced =
+ def nameSpaced(): Unit =
assertTrue( match {
case => true
})
- val cx =
- crazy text world
-
+ val cx: Elem =
+ crazy text world
+
@Test
- def nodeContents = {
+ def nodeContents(): Unit = {
assertTrue(Utility.trim(cx) match {
case n @ crazy text world if (n \ "@foo") xml_== "bar" => true
})
@@ -47,13 +47,12 @@ class PatternMatchingTest {
case n @ crazy text world if (n \ "@foo") xml_== "bar" => true
})
assertTrue( match {
- case scala.xml.QNode("gaga", "foo", md, child @ _*) => true
+ case QNode("gaga", "foo", md, child @ _*) => true
})
assertTrue( match {
- case scala.xml.Node("foo", md, child @ _*) => true
+ case Node("foo", md, child @ _*) => true
})
-
}
object SafeNodeSeq {
@@ -67,10 +66,8 @@ class PatternMatchingTest {
}
@Test
- def nodeSeq = { // t0646
- import scala.xml.NodeSeq
-
- val books =
+ def nodeSeq(): Unit = { // t0646
+ val books: Elem =
Blabla
Blubabla
@@ -90,7 +87,7 @@ class PatternMatchingTest {
}
@Test
- def SI_4124 = {
+ def SI_4124(): Unit = {
val body: Node = hi
assertTrue((body: AnyRef, "foo") match {
diff --git a/shared/src/test/scala/scala/xml/PrintEmptyElementsTest.scala b/shared/src/test/scala/scala/xml/PrintEmptyElementsTest.scala
index a1d9b11cc..e61e195d7 100644
--- a/shared/src/test/scala/scala/xml/PrintEmptyElementsTest.scala
+++ b/shared/src/test/scala/scala/xml/PrintEmptyElementsTest.scala
@@ -6,7 +6,7 @@ import JUnitAssertsForXML.assertEquals
class PrintEmptyElementsTest {
@Test
- def representEmptyXMLElementsInShortForm: Unit = {
+ def representEmptyXMLElementsInShortForm(): Unit = {
val expected: String =
"""|
|
@@ -29,27 +29,26 @@ class PrintEmptyElementsTest {
}
@Test
- def programmaticLong: Unit = {
+ def programmaticLong(): Unit = {
assertEquals(" ",
- Elem(null, "emptiness", Null, TopScope, false) ++ Text(" ") ++ Comment("programmatic long"))
+ Elem(null, "emptiness", Null, TopScope, minimizeEmpty = false) ++ Text(" ") ++ Comment("programmatic long"))
}
@Test
- def programmaticShort: Unit = {
+ def programmaticShort(): Unit = {
assertEquals(" ",
- Elem(null, "vide", Null, TopScope, true) ++ Text(" ") ++ Comment("programmatic short"))
+ Elem(null, "vide", Null, TopScope, minimizeEmpty = true) ++ Text(" ") ++ Comment("programmatic short"))
}
@Test
- def programmaticShortWithAttribute: Unit = {
+ def programmaticShortWithAttribute(): Unit = {
assertEquals(""" """,
- Elem(null, "elem", Attribute("attr", Text("value"), Null), TopScope, true) ++ Text(" ") ++ Comment ("programmatic short with attribute"))
+ Elem(null, "elem", Attribute("attr", Text("value"), Null), TopScope, minimizeEmpty = true) ++ Text(" ") ++ Comment ("programmatic short with attribute"))
}
@Test
- def programmaticLongWithAttribute: Unit = {
+ def programmaticLongWithAttribute(): Unit = {
assertEquals(""" """,
- Elem(null, "elem2", Attribute("attr2", Text("value2"), Null), TopScope, false) ++ Text(" ") ++ Comment ("programmatic long with attribute"))
+ Elem(null, "elem2", Attribute("attr2", Text("value2"), Null), TopScope, minimizeEmpty = false) ++ Text(" ") ++ Comment ("programmatic long with attribute"))
}
-
}
diff --git a/shared/src/test/scala/scala/xml/Properties.scala b/shared/src/test/scala/scala/xml/Properties.scala
index 92a819903..b160e3023 100644
--- a/shared/src/test/scala/scala/xml/Properties.scala
+++ b/shared/src/test/scala/scala/xml/Properties.scala
@@ -14,6 +14,6 @@ package scala
package xml
object Properties extends util.PropertiesTrait {
- override protected def propCategory = "scala-xml"
- override protected def pickJarBasedOn = classOf[scala.xml.Node]
+ override protected def propCategory: String = "scala-xml"
+ override protected def pickJarBasedOn: Class[Node] = classOf[Node]
}
diff --git a/shared/src/test/scala/scala/xml/ShouldCompile.scala b/shared/src/test/scala/scala/xml/ShouldCompile.scala
index e394b4b90..12c1e841b 100644
--- a/shared/src/test/scala/scala/xml/ShouldCompile.scala
+++ b/shared/src/test/scala/scala/xml/ShouldCompile.scala
@@ -17,15 +17,15 @@ class Foo {
// t2281
class t2281A {
- def f(x: Boolean) = if (x)
else
+ def f(x: Boolean): Seq[Node] = if (x)
else
}
class t2281B {
def splitSentences(text: String): ArrayBuffer[String] = {
- val outarr = new ArrayBuffer[String]
- var outstr = new StringBuffer
- var prevspace = false
- val ctext = text.replaceAll("\n+", "\n")
+ val outarr: ArrayBuffer[String] = new ArrayBuffer[String]
+ var outstr: StringBuffer = new StringBuffer
+ var prevspace: Boolean = false
+ val ctext: String = text.replaceAll("\n+", "\n")
ctext foreach { c =>
outstr append c
if (c == '.' || c == '!' || c == '?' || c == '\n' || c == ':' || c == ';' || (prevspace && c == '-')) {
@@ -43,15 +43,15 @@ class t2281B {
outarr
}
- def spanForSentence(x: String, picktext: String) =
+ def spanForSentence(x: String, picktext: String): Seq[Node] =
if (x == "\n\n") {
} else {
{ x }
}
- def selectableSentences(text: String, picktext: String) = {
- val sentences = splitSentences(text)
+ def selectableSentences(text: String, picktext: String): ArrayBuffer[Seq[Node]] = {
+ val sentences: ArrayBuffer[String] = splitSentences(text)
sentences.map(x => spanForSentence(x, picktext))
}
}
@@ -62,7 +62,7 @@ object SI_5858 {
}
class Floozy {
- def fooz(x: Node => String) = {}
+ def fooz(x: Node => String): Unit = ()
def foo(m: Node): Unit = fooz {
case Elem(_, _, _, _, n, _*) if n == m => "gaga"
}
@@ -82,7 +82,7 @@ object guardedMatch { // SI-3705
// SI-6897
object shouldCompile {
- val html = (null: Any) match {
+ val html: Seq[Node] = (null: Any) match {
case 1 =>
case 2 =>
}
diff --git a/shared/src/test/scala/scala/xml/UtilityTest.scala b/shared/src/test/scala/scala/xml/UtilityTest.scala
index 73d4a85a4..219dbdd2a 100644
--- a/shared/src/test/scala/scala/xml/UtilityTest.scala
+++ b/shared/src/test/scala/scala/xml/UtilityTest.scala
@@ -9,45 +9,45 @@ import org.junit.Assert.assertNotEquals
class UtilityTest {
@Test
- def isNameStart: Unit = {
+ def isNameStart(): Unit = {
assertTrue(Utility.isNameStart('b'))
assertTrue(Utility.isNameStart(':'))
}
@Test
- def trim: Unit = {
- val x =
-
-
- val y = xml.Utility.trim(x)
+ def trim(): Unit = {
+ val x: Elem =
+
+
+ val y: Node = Utility.trim(x)
assertTrue(y match { case => true })
- val x2 =
+ val x2: Elem =
a b b a
- val y2 = xml.Utility.trim(x2)
+ val y2: Node = Utility.trim(x2)
assertTrue(y2 match { case a b b a => true })
}
@Test
- def aposEscaping: Unit = {
- val z = ''
- val z1 = z.toString
+ def aposEscaping(): Unit = {
+ val z: Elem = ''
+ val z1: String = z.toString
assertEquals("''", z1)
}
@Test
- def sort: Unit = {
- assertEquals("", xml.Utility.sort(.attributes).toString)
- assertEquals(""" b="c"""", xml.Utility.sort(.attributes).toString)
- val q = xml.Utility.sort()
- assertEquals(" a=\"2\" g=\"3\" j=\"2\" oo=\"2\"", xml.Utility.sort(q.attributes).toString)
- val pp = new xml.PrettyPrinter(80,5)
+ def sort(): Unit = {
+ assertEquals("", Utility.sort(.attributes).toString)
+ assertEquals(""" b="c"""", Utility.sort(.attributes).toString)
+ val q: Node = Utility.sort()
+ assertEquals(" a=\"2\" g=\"3\" j=\"2\" oo=\"2\"", Utility.sort(q.attributes).toString)
+ val pp: PrettyPrinter = new PrettyPrinter(80,5)
assertEquals("", pp.format(q))
}
@Test
- def issue777: Unit = {
+ def issue777(): Unit = {
@@ -55,14 +55,14 @@ class UtilityTest {
}
@Test
- def issue90: Unit = {
- val x =
+ def issue90(): Unit = {
+ val x: Elem =
assertEquals("", Utility.serialize(x, minimizeTags = MinimizeMode.Always).toString)
}
@Test
- def issue183: Unit = {
- val x =
+ def issue183(): Unit = {
+ val x: Elem =
assertEquals("", Utility.serialize(x, stripComments = true).toString)
assertEquals("", Utility.serialize(x, stripComments = false).toString)
}
@@ -81,7 +81,7 @@ class UtilityTest {
Utility.Escapes.escMap.keys.toSeq
@Test
- def escapePrintablesTest: Unit = {
+ def escapePrintablesTest(): Unit = {
for {
char <- printableAscii.diff(escapedChars)
} yield {
@@ -90,7 +90,7 @@ class UtilityTest {
}
@Test
- def escapeEscapablesTest: Unit = {
+ def escapeEscapablesTest(): Unit = {
for {
char <- escapedChars
} yield {
@@ -99,7 +99,7 @@ class UtilityTest {
}
@Test
- def escapeAsciiControlCharsTest: Unit = {
+ def escapeAsciiControlCharsTest(): Unit = {
/* Escapes that Scala (Java) doesn't support.
* \u0007 -> \a (bell)
@@ -107,18 +107,18 @@ class UtilityTest {
* \u000B -> \v (vertical tab)
* \u007F -> DEL (delete)
*/
- val input = " \u0007\b\u001B\f\n\r\t\u000B\u007F"
+ val input: String = " \u0007\b\u001B\f\n\r\t\u000B\u007F"
- val expect = " \n\r\t\u007F"
+ val expect: String = " \n\r\t\u007F"
- val result = Utility.escape(input)
+ val result: String = Utility.escape(input)
assertEquals(printfc(expect), printfc(result)) // Pretty,
assertEquals(expect, result) // but verify.
}
@Test
- def escapeUnicodeExtendedControlCodesTest: Unit = {
+ def escapeUnicodeExtendedControlCodesTest(): Unit = {
for {
char <- '\u0080' to '\u009f' // Extended control codes (C1)
} yield {
@@ -127,7 +127,7 @@ class UtilityTest {
}
@Test
- def escapeUnicodeTwoBytesTest: Unit = {
+ def escapeUnicodeTwoBytesTest(): Unit = {
for {
char <- '\u00A0' to '\u07FF' // Two bytes (cont.)
} yield {
@@ -136,7 +136,7 @@ class UtilityTest {
}
@Test
- def escapeUnicodeThreeBytesTest: Unit = {
+ def escapeUnicodeThreeBytesTest(): Unit = {
for {
char <- '\u0800' to '\uFFFF' // Three bytes
} yield {
@@ -151,7 +151,7 @@ class UtilityTest {
*
* Or think of `printf("%c", i)` in C, but a little better.
*/
- def printfc(str: String) = {
+ def printfc(str: String): String = {
str.map(prettyChar).mkString
}
@@ -197,26 +197,26 @@ class UtilityTest {
(key: Char) => key.toString
}
- def issue73StartsWithAndEndsWithWSInFirst: Unit = {
- val x = {Text(" My name is ")}{Text("Harry")}
+ def issue73StartsWithAndEndsWithWSInFirst(): Unit = {
+ val x: Elem = {Text(" My name is ")}{Text("Harry")}
assertEquals(My name is Harry
, Utility.trim(x))
}
@Test
- def issue73EndsWithWSInLast: Unit = {
- val x = {Text("My name is ")}{Text("Harry ")}
+ def issue73EndsWithWSInLast(): Unit = {
+ val x: Elem = {Text("My name is ")}{Text("Harry ")}
assertEquals(My name is Harry
, Utility.trim(x))
}
@Test
- def issue73HasWSInMiddle: Unit = {
- val x = {Text("My name is")}{Text(" ")}{Text("Harry")}
+ def issue73HasWSInMiddle(): Unit = {
+ val x: Elem = {Text("My name is")}{Text(" ")}{Text("Harry")}
assertEquals(My name is Harry
, Utility.trim(x))
}
@Test
- def issue73HasWSEverywhere: Unit = {
- val x = {Text(" My name ")}{Text(" is ")}{Text(" Harry ")}
+ def issue73HasWSEverywhere(): Unit = {
+ val x: Elem = {Text(" My name ")}{Text(" is ")}{Text(" Harry ")}
assertEquals(My name is Harry
, Utility.trim(x))
}
}
diff --git a/shared/src/test/scala/scala/xml/XMLEmbeddingTest.scala b/shared/src/test/scala/scala/xml/XMLEmbeddingTest.scala
index 398ab6dde..746513ee1 100644
--- a/shared/src/test/scala/scala/xml/XMLEmbeddingTest.scala
+++ b/shared/src/test/scala/scala/xml/XMLEmbeddingTest.scala
@@ -6,13 +6,12 @@ import org.junit.Assert.assertEquals
class XMLEmbeddingTest {
@Test
- def basic: Unit = {
- val ya = {{
+ def basic(): Unit = {
+ val ya: Elem = {{
assertEquals("{", ya.text)
- val ua = }}
+ val ua: Elem = }}
assertEquals("}", ua.text)
- val za = {{}}{{}}{{}}
+ val za: Elem = {{}}{{}}{{}}
assertEquals("{}{}{}", za.text)
}
-
}
diff --git a/shared/src/test/scala/scala/xml/XMLSyntaxTest.scala b/shared/src/test/scala/scala/xml/XMLSyntaxTest.scala
index 700709f29..9f873abc3 100644
--- a/shared/src/test/scala/scala/xml/XMLSyntaxTest.scala
+++ b/shared/src/test/scala/scala/xml/XMLSyntaxTest.scala
@@ -14,37 +14,37 @@ class XMLSyntaxTest {
@Test
def test1(): Unit = {
- val xNull = {null} // these used to be Atom(unit), changed to empty children
+ val xNull: Elem = {null} // these used to be Atom(unit), changed to empty children
assertTrue(xNull.child sameElements Nil)
- val x0 = {} // these used to be Atom(unit), changed to empty children
- val x00 = { } // dto.
- val xa = { "world" }
+ val x0: Elem = {} // these used to be Atom(unit), changed to empty children
+ val x00: Elem = { } // dto.
+ val xa: Elem = { "world" }
assertTrue(x0.child sameElements Nil)
assertTrue(x00.child sameElements Nil)
assertEquals("world", handle[String](xa))
- val xb = { 1.5 }
+ val xb: Elem = { 1.5 }
assertEquals(1.5, handle[Double](xb), 0.0)
- val xc = { 5 }
+ val xc: Elem = { 5 }
assertEquals(5, handle[Int](xc).toLong)
- val xd = { true }
+ val xd: Elem = { true }
assertEquals(true, handle[Boolean](xd))
- val xe = { 5:Short }
+ val xe: Elem = { 5:Short }
assertEquals((5:Short).toLong, handle[Short](xe).toLong)
- val xf = { val x = 27; x }
+ val xf: Elem = { val x = 27; x }
assertEquals(27, handle[Int](xf).toLong)
- val xg = { List(1,2,3,4) }
+ val xg: Elem = { List(1,2,3,4) }
assertEquals("1 2 3 4", xg.toString)
assertFalse(xg.child.map(_.isInstanceOf[Text]).exists(identity))
- val xh = { for(x <- List(1,2,3,4) if x % 2 == 0) yield x }
+ val xh: Elem = { for(x <- List(1,2,3,4) if x % 2 == 0) yield x }
assertEquals("2 4", xh.toString)
assertFalse(xh.child.map(_.isInstanceOf[Text]).exists(identity))
}
@@ -55,12 +55,11 @@ class XMLSyntaxTest {
@Test
def test2(): Unit = {
val x1: Option[Seq[Node]] = Some(hello)
- val n1 =
+ val n1: Elem =
assertEquals(x1, n1.attribute("key"))
val x2: Option[Seq[Node]] = None
- val n2 =
+ val n2: Elem =
assertEquals(x2, n2.attribute("key"))
}
-
}
diff --git a/shared/src/test/scala/scala/xml/XMLTest.scala b/shared/src/test/scala/scala/xml/XMLTest.scala
index f57aeb2fa..4de79b799 100644
--- a/shared/src/test/scala/scala/xml/XMLTest.scala
+++ b/shared/src/test/scala/scala/xml/XMLTest.scala
@@ -6,45 +6,45 @@ import org.junit.{Test => UnitTest}
import org.junit.Assert.assertTrue
import org.junit.Assert.assertFalse
import org.junit.Assert.assertEquals
-// import scala.xml.parsing.ConstructingParser
import java.io.StringWriter
import scala.collection.Iterable
import scala.collection.Seq
+import scala.xml.dtd.{DocType, PublicID}
import scala.xml.Utility.sort
object XMLTest {
- val e: scala.xml.MetaData = Null //Node.NoAttributes
- val sc: scala.xml.NamespaceBinding = TopScope
+ val e: MetaData = Null //Node.NoAttributes
+ val sc: NamespaceBinding = TopScope
}
class XMLTest {
@UnitTest
- def nodeSeq: Unit = {
- val p =
-
-
-
-
+ def nodeSeq(): Unit = {
+ val p: Elem =
+
+
+
+
- val pelems_1 = for (x <- p \ "bar"; y <- p \ "baz") yield {
+ val pelems_1: NodeSeq = for (x <- p \ "bar"; y <- p \ "baz") yield {
Text(x.attributes("value").toString + y.attributes("bazValue").toString + "!")
}
- val pelems_2 = NodeSeq.fromSeq(List(Text("38!"), Text("58!")))
+ val pelems_2: NodeSeq = NodeSeq.fromSeq(List(Text("38!"), Text("58!")))
assertTrue(pelems_1 sameElements pelems_2)
assertTrue(Text("8") sameElements (p \\ "@bazValue"))
}
@UnitTest
- def queryBooks: Unit = {
- val books =
+ def queryBooks(): Unit = {
+ val books: Elem =
Blabla
Blubabla
Baaaaaaalabla
- val reviews =
+ val reviews: Elem =
Blabla
@@ -66,7 +66,7 @@ class XMLTest {
- val results1 = new scala.xml.PrettyPrinter(80, 5).formatNodes(
+ val results1: String = new PrettyPrinter(80, 5).formatNodes(
for {
t <- books \\ "title"
r <- reviews \\ "entry" if (r \ "title") xml_== t
@@ -74,7 +74,7 @@ class XMLTest {
{ t }
{ r \ "remarks" }
)
- val results1Expected = """
+ val results1Expected: String = """
| Blabla
| Hallo Welt.
|
@@ -87,17 +87,16 @@ class XMLTest {
assertEquals(results1Expected, results1)
{
- val actual = for (t @ Blabla <- NodeSeq.fromSeq(books.child).toList)
+ val actual: List[Node] = for (t @ Blabla <- NodeSeq.fromSeq(books.child).toList)
yield t
- val expected = List(Blabla)
+ val expected: List[Elem] = List(Blabla)
assertEquals(expected, actual)
}
-
}
@UnitTest
- def queryPhoneBook: Unit = {
- val phoneBook =
+ def queryPhoneBook(): Unit = {
+ val phoneBook: Elem =
This is thephonebook
@@ -112,7 +111,7 @@ class XMLTest {
- val addrBook =
+ val addrBook: Elem =
This is theaddressbook
@@ -127,7 +126,7 @@ class XMLTest {
- val actual: String = new scala.xml.PrettyPrinter(80, 5).formatNodes(
+ val actual: String = new PrettyPrinter(80, 5).formatNodes(
for {
t <- addrBook \\ "entry"
r <- phoneBook \\ "entry" if (t \ "name") xml_== (r \ "name")
@@ -135,32 +134,33 @@ class XMLTest {
{ t.child }
{ r \ "phone" }
)
- val expected = """|
- | John
- | Elm Street
- | Dolphin City
- | +41 21 693 68 67
- | +41 79 602 23 23
- |""".stripMargin
+ val expected: String =
+ """|
+ | John
+ | Elm Street
+ | Dolphin City
+ | +41 21 693 68 67
+ | +41 79 602 23 23
+ |""".stripMargin
assertEquals(expected, actual)
}
@UnitTest(expected=classOf[IllegalArgumentException])
- def failEmptyStringChildren: Unit = {
+ def failEmptyStringChildren(): Unit = {
\ ""
}
@UnitTest(expected=classOf[IllegalArgumentException])
- def failEmptyStringDescendants: Unit = {
+ def failEmptyStringDescendants(): Unit = {
\\ ""
}
@UnitTest
- def namespaces: Unit = {
- val cuckoo =
-
-
-
+ def namespaces(): Unit = {
+ val cuckoo: Elem =
+
+
+
assertEquals("http://cuckoo.com", cuckoo.namespace)
for (n <- cuckoo \ "_") {
assertEquals("http://cuckoo.com", n.namespace)
@@ -168,11 +168,11 @@ class XMLTest {
}
@UnitTest
- def namespacesWithNestedXmls: Unit = {
- val foo =
- val bar = {foo}
- val expected = """"""
- val actual = bar.toString
+ def namespacesWithNestedXmls(): Unit = {
+ val foo: Elem =
+ val bar: Elem = {foo}
+ val expected: String = """"""
+ val actual: String = bar.toString
assertEquals(expected, actual)
}
@@ -180,7 +180,7 @@ class XMLTest {
scala.xml.Elem.apply(prefix, label, attributes, scope, minimizeEmpty = true, child: _*)
@UnitTest
- def groupNode = {
+ def groupNode(): Unit = {
val zx1: Node = Group { }
val zy1: Node = { zx1 }
assertEquals("", zy1.toString)
@@ -188,39 +188,39 @@ class XMLTest {
assertEquals("",
Group { List(, zy1, zx1) }.toString)
- val zz1 =
+ val zz1: Group =
assertTrue(zx1 xml_== zz1)
assertTrue(zz1.length == 3)
}
@UnitTest
- def dodgyNamespace = {
- val x =
+ def dodgyNamespace(): Unit = {
+ val x: Elem =
assertTrue(x.toString.matches(".*xmlns:dog=\"http://dog.com\".*"))
}
- val ax =
-
-
+ val ax: Elem =
+
+
- val cx =
- crazy text world
-
+ val cx: Elem =
+ crazy text world
+
- val bx =
+ val bx: Elem =
@UnitTest
- def XmlEx = {
+ def XmlEx(): Unit = {
assertTrue((ax \ "@foo") xml_== "bar") // uses NodeSeq.view!
- assertTrue((ax \ "@foo") xml_== xml.Text("bar")) // dto.
+ assertTrue((ax \ "@foo") xml_== Text("bar")) // dto.
assertTrue((bx \ "@foo") xml_== "bar&x") // dto.
- assertTrue((bx \ "@foo") xml_sameElements List(xml.Text("bar&x")))
+ assertTrue((bx \ "@foo") xml_sameElements List(Text("bar&x")))
assertTrue("" == bx.toString)
}
@UnitTest
- def XmlEy: Unit = {
+ def XmlEy(): Unit = {
assertTrue((ax \ "@{the namespace from outer space}foo") xml_== "baz")
assertTrue((cx \ "@{the namespace from outer space}foo") xml_== "baz")
@@ -246,15 +246,15 @@ class XMLTest {
}
@UnitTest
- def comment =
+ def comment(): Unit =
assertEquals("", toString)
@UnitTest
- def weirdElem =
+ def weirdElem(): Unit =
assertEquals("", toString)
@UnitTest
- def escape =
+ def escape(): Unit =
assertEquals("""
"Come, come again, whoever you are, come!
Heathen, fire worshipper or idolatrous, come!
@@ -268,23 +268,23 @@ Ours is the portal of hope, come as you are."
Mevlana Celaleddin Rumi]]> toString) // this guy will escaped, and rightly so
@UnitTest
- def unparsed2 = {
- object myBreak extends scala.xml.Unparsed("
")
+ def unparsed2(): Unit = {
+ object myBreak extends Unparsed("
")
assertEquals("
", { myBreak } toString) // shows use of unparsed
}
@UnitTest
- def justDontFail = {
+ def justDontFail(): Unit = {
match {
- case scala.xml.QNode("gaga", "foo", md, child @ _*) =>
+ case QNode("gaga", "foo", md, child @ _*) =>
}
match {
- case scala.xml.Node("foo", md, child @ _*) =>
+ case Node("foo", md, child @ _*) =>
}
}
- def f(s: String) = {
+ def f(s: String): Elem = {
{
for (item <- s split ',') yield { item }
@@ -293,7 +293,7 @@ Ours is the portal of hope, come as you are."
}
@UnitTest
- def nodeBuffer =
+ def nodeBuffer(): Unit =
assertEquals(
"""
abc
@@ -313,7 +313,7 @@ Ours is the portal of hope, come as you are."
@UnitTest
- def wsdl = {
+ def wsdl(): Unit = {
assertEquals("""
""", wsdlTemplate1("service1") toString)
assertEquals("""
@@ -323,30 +323,28 @@ Ours is the portal of hope, come as you are."
}
@UnitTest
- def t547: Unit = {
+ def t547(): Unit = {
// ambiguous toString problem from #547
- val atom: scala.xml.Atom[Unit] = new scala.xml.Atom(())
+ val atom: Atom[Unit] = new Atom(())
assertEquals(().toString, atom.toString)
}
@UnitTest
- def t1079 = assertFalse( == )
-
- import dtd.{ DocType, PublicID }
+ def t1079(): Unit = assertFalse( == )
@UnitTest
- def t1620 = {
- val dt = DocType("foo", PublicID("-//Foo Corp//DTD 1.0//EN", "foo.dtd"), Seq())
- var pw = new StringWriter()
- XML.write(pw, , "utf-8", true, dt)
+ def t1620(): Unit = {
+ val dt: DocType = DocType("foo", PublicID("-//Foo Corp//DTD 1.0//EN", "foo.dtd"), Seq())
+ var pw: StringWriter = new StringWriter()
+ XML.write(pw, , "utf-8", xmlDecl = true, dt)
pw.flush()
assertEquals("""
""", pw.toString)
pw = new StringWriter()
- val dt2 = DocType("foo", PublicID("-//Foo Corp//DTD 1.0//EN", null), Seq())
- XML.write(pw, , "utf-8", true, dt2)
+ val dt2: DocType = DocType("foo", PublicID("-//Foo Corp//DTD 1.0//EN", null), Seq())
+ XML.write(pw, , "utf-8", xmlDecl = true, dt2)
pw.flush()
assertEquals("""
@@ -354,11 +352,11 @@ Ours is the portal of hope, come as you are."
}
@UnitTest
- def t1773 = {
- val xs = List(
+ def t1773(): Unit = {
+ val xs: List[Elem] = List(
,
,
- { xml.NodeSeq.Empty },
+ { NodeSeq.Empty },
{ "" },
{ if (true) "" else "I like turtles" })
@@ -366,7 +364,7 @@ Ours is the portal of hope, come as you are."
}
@UnitTest
- def t3886 = {
+ def t3886(): Unit = {
assertTrue( == )
assertTrue( != )
assertTrue( != )
@@ -377,7 +375,7 @@ Ours is the portal of hope, come as you are."
}
@UnitTest
- def t4124: Unit = {
+ def t4124(): Unit = {
val body: Node = hi
assertEquals("hi", ((body: AnyRef, "foo"): @unchecked) match {
case (node: Node, "bar") => "bye"
@@ -401,7 +399,7 @@ Ours is the portal of hope, come as you are."
}
@UnitTest
- def t5052: Unit = {
+ def t5052(): Unit = {
assertTrue( xml_== )
assertTrue( xml_== )
assertTrue( xml_== )
@@ -409,8 +407,8 @@ Ours is the portal of hope, come as you are."
}
@UnitTest
- def t5115 = {
- def assertHonorsIterableContract(i: Iterable[_]) = assertEquals(i.size.toLong, i.iterator.size.toLong)
+ def t5115(): Unit = {
+ def assertHonorsIterableContract(i: Iterable[_]): Unit = assertEquals(i.size.toLong, i.iterator.size.toLong)
assertHonorsIterableContract(.attributes)
assertHonorsIterableContract(.attributes)
@@ -423,24 +421,24 @@ Ours is the portal of hope, come as you are."
}
@UnitTest
- def t5843: Unit = {
- val foo = scala.xml.Attribute(null, "foo", "1", scala.xml.Null)
- val bar = scala.xml.Attribute(null, "bar", "2", foo)
- val ns = scala.xml.NamespaceBinding(null, "uri", scala.xml.TopScope)
+ def t5843(): Unit = {
+ val foo: Attribute = Attribute(null, "foo", "1", Null)
+ val bar: Attribute = Attribute(null, "bar", "2", foo)
+ val ns: NamespaceBinding = NamespaceBinding(null, "uri", TopScope)
assertEquals(""" foo="1"""", foo toString)
- assertEquals(null, scala.xml.TopScope.getURI(foo.pre))
+ assertEquals(null, TopScope.getURI(foo.pre))
assertEquals(""" bar="2"""", bar remove "foo" toString)
assertEquals(""" foo="1"""", bar remove "bar" toString)
- assertEquals(""" bar="2"""", bar remove (null, scala.xml.TopScope, "foo") toString)
- assertEquals(""" foo="1"""", bar remove (null, scala.xml.TopScope, "bar") toString)
+ assertEquals(""" bar="2"""", bar remove (null, TopScope, "foo") toString)
+ assertEquals(""" foo="1"""", bar remove (null, TopScope, "bar") toString)
assertEquals(""" bar="2" foo="1"""", bar toString)
assertEquals(""" bar="2" foo="1"""", bar remove (null, ns, "foo") toString)
assertEquals(""" bar="2" foo="1"""", bar remove (null, ns, "bar") toString)
}
@UnitTest
- def t7074: Unit = {
+ def t7074(): Unit = {
assertEquals("""""", sort() toString)
assertEquals("""""", sort() toString)
assertEquals("""""", sort() toString)
@@ -453,20 +451,20 @@ Ours is the portal of hope, come as you are."
}
@UnitTest
- def attributes = {
- val noAttr =
- val attrNull =
- val attrNone =
- val preAttrNull =
- val preAttrNone =
+ def attributes(): Unit = {
+ val noAttr: Elem =
+ val attrNull: Elem =
+ val attrNone: Elem =
+ val preAttrNull: Elem =
+ val preAttrNone: Elem =
assertEquals(noAttr, attrNull)
assertEquals(noAttr, attrNone)
assertEquals(noAttr, preAttrNull)
assertEquals(noAttr, preAttrNone)
- val xml1 =
- val xml2 =
- val xml3 =
+ val xml1: Elem =
+ val xml2: Elem =
+ val xml3: Elem =
assertEquals(xml1, xml2)
assertEquals(xml1, xml3)
@@ -487,11 +485,11 @@ Ours is the portal of hope, come as you are."
}
@UnitTest
- def issue28: Unit = {
- val x =
+ def issue28(): Unit = {
+ val x: Elem =
// val ns = new NamespaceBinding("x", "gaga", sc)
// val x = Elem("x", "foo", e, ns)
- val pp = new xml.PrettyPrinter(80, 2)
+ val pp: PrettyPrinter = new PrettyPrinter(80, 2)
// This assertion passed
assertEquals("""""", x.toString)
// This was the bug, producing an errant xmlns attribute
@@ -499,35 +497,35 @@ Ours is the portal of hope, come as you are."
}
@UnitTest
- def nodeSeqNs: Unit = {
- val x = {
+ def nodeSeqNs(): Unit = {
+ val x: NodeBuffer = {
}
- val pp = new PrettyPrinter(80, 2)
- val expected = """"""
+ val pp: PrettyPrinter = new PrettyPrinter(80, 2)
+ val expected: String = """"""
assertEquals(expected, pp.formatNodes(x))
}
@UnitTest
- def nodeStringBuilder: Unit = {
- val x = {
+ def nodeStringBuilder(): Unit = {
+ val x: Elem = {
}
- val pp = new PrettyPrinter(80, 2)
- val expected = """"""
- val sb = new StringBuilder
+ val pp: PrettyPrinter = new PrettyPrinter(80, 2)
+ val expected: String = """"""
+ val sb: StringBuilder = new StringBuilder
pp.format(x, sb)
assertEquals(expected, sb.toString)
}
@UnitTest
- def i1976: Unit = {
- val node = { "whatever " }
+ def i1976(): Unit = {
+ val node: Elem = { "whatever " }
assertEquals("whatever ", node.child.text)
}
@UnitTest
- def i6547: Unit = {
+ def i6547(): Unit = {
}
}
diff --git a/shared/src/test/scala/scala/xml/dtd/DeclTest.scala b/shared/src/test/scala/scala/xml/dtd/DeclTest.scala
index a41542897..5b01fb2fc 100644
--- a/shared/src/test/scala/scala/xml/dtd/DeclTest.scala
+++ b/shared/src/test/scala/scala/xml/dtd/DeclTest.scala
@@ -7,7 +7,7 @@ import org.junit.Assert.assertEquals
class DeclTest {
@Test
- def elemDeclToString: Unit = {
+ def elemDeclToString(): Unit = {
assertEquals(
"",
ElemDecl("x", PCDATA).toString
@@ -15,14 +15,14 @@ class DeclTest {
}
@Test
- def attListDeclToString: Unit = {
+ def attListDeclToString(): Unit = {
- val expected =
+ val expected: String =
"""|""".stripMargin
- val actual = AttListDecl("x",
+ val actual: String = AttListDecl("x",
List(
AttrDecl("y", "CDATA", REQUIRED),
AttrDecl("z", "CDATA", REQUIRED)
@@ -33,7 +33,7 @@ class DeclTest {
}
@Test
- def parsedEntityDeclToString: Unit = {
+ def parsedEntityDeclToString(): Unit = {
assertEquals(
"""""",
ParsedEntityDecl("foo", ExtDef(SystemID("bar"))).toString
diff --git a/shared/src/test/scala/scala/xml/parsing/PiParsingTest.scala b/shared/src/test/scala/scala/xml/parsing/PiParsingTest.scala
index cca701b31..6bbff668a 100644
--- a/shared/src/test/scala/scala/xml/parsing/PiParsingTest.scala
+++ b/shared/src/test/scala/scala/xml/parsing/PiParsingTest.scala
@@ -6,15 +6,14 @@ import scala.xml.JUnitAssertsForXML.assertEquals
class PiParsingTest {
@Test
- def piNoWSLiteral: Unit = {
- val expected = "ab"
+ def piNoWSLiteral(): Unit = {
+ val expected: String = "ab"
assertEquals(expected, ab)
}
@Test
- def piLiteral: Unit = {
- val expected = " a b "
+ def piLiteral(): Unit = {
+ val expected: String = " a b "
assertEquals(expected, a b )
}
-
}
diff --git a/shared/src/test/scala/scala/xml/parsing/Ticket0632Test.scala b/shared/src/test/scala/scala/xml/parsing/Ticket0632Test.scala
index 8adbd2503..b35bc4d36 100644
--- a/shared/src/test/scala/scala/xml/parsing/Ticket0632Test.scala
+++ b/shared/src/test/scala/scala/xml/parsing/Ticket0632Test.scala
@@ -6,24 +6,23 @@ import scala.xml.JUnitAssertsForXML.assertEquals
class Ticket0632Test {
@Test
- def singleAmp: Unit = {
- val expected = ""
+ def singleAmp(): Unit = {
+ val expected: String = ""
assertEquals(expected, )
assertEquals(expected, )
}
@Test
- def oneAndHalfAmp: Unit = {
- val expected = ""
+ def oneAndHalfAmp(): Unit = {
+ val expected: String = ""
assertEquals(expected, )
assertEquals(expected, )
}
@Test
- def doubleAmp: Unit = {
- val expected = ""
+ def doubleAmp(): Unit = {
+ val expected: String = ""
assertEquals(expected, )
assertEquals(expected, )
}
-
}