Skip to content

Commit cf5763e

Browse files
authored
Merge pull request #654 from dubinsky/very-minor-cleanup
cleanup
2 parents d93eb46 + 16374df commit cf5763e

31 files changed

+131
-146
lines changed

build.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ lazy val xml = crossProject(JSPlatform, JVMPlatform, NativePlatform)
150150
retrieveDir,
151151
log
152152
)
153-
.fold(w => throw w.resolveException, identity(_))
153+
.fold(w => throw w.resolveException, identity)
154154
val jarPath = cp
155155
.find(_.toString.contains("junit-plugin"))
156156
.getOrElse(throw new Exception("Can't find Scala Native junit-plugin jar"))

jvm/src/test/scala/scala/xml/XMLTest.scala

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class XMLTestJVM {
3333
def equality(): Unit = {
3434
val c: Node = new Node {
3535
override def label: String = "hello"
36-
override def hashCode(): Int =
36+
override def hashCode: Int =
3737
Utility.hashCode(prefix, label, this.attributes.hashCode(), scope.hashCode(), child)
3838
override def child: Seq[Node] = Elem(null, "world", e, sc)
3939
//def attributes = e
@@ -54,7 +54,6 @@ class XMLTestJVM {
5454
Elem(null, "author", e, sc, Text("Peter Buneman")),
5555
Elem(null, "author", e, sc, Text("Dan Suciu")),
5656
Elem(null, "title", e, sc, Text("Data on ze web"))), x2p)
57-
5857
}
5958

6059
@UnitTest
@@ -640,7 +639,7 @@ class XMLTestJVM {
640639
parserFactory.setNamespaceAware(namespaceAware)
641640
parserFactory.setXIncludeAware(namespaceAware)
642641

643-
assertEquals(xml, XML.withSAXParser(parserFactory.newSAXParser).loadString(xml).toString())
642+
assertEquals(xml, XML.withSAXParser(parserFactory.newSAXParser).loadString(xml).toString)
644643
}
645644

646645
@UnitTest

shared/src/main/scala/scala/xml/Attribute.scala

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,19 +65,19 @@ trait Attribute extends MetaData {
6565

6666
override def remove(key: String): MetaData =
6767
if (!isPrefixed && this.key == key) next
68-
else copy(next remove key)
68+
else copy(next.remove(key))
6969

7070
override def remove(namespace: String, scope: NamespaceBinding, key: String): MetaData =
71-
if (this.key == key && (scope getURI pre) == namespace) next
71+
if (this.key == key && scope.getURI(pre) == namespace) next
7272
else copy(next.remove(namespace, scope, key))
7373

7474
override def isPrefixed: Boolean = pre != null
7575

7676
override def getNamespace(owner: Node): String
7777

7878
override def wellformed(scope: NamespaceBinding): Boolean = {
79-
val arg: String = if (isPrefixed) scope getURI pre else null
80-
(next(arg, scope, key) == null) && (next wellformed scope)
79+
val arg: String = if (isPrefixed) scope.getURI(pre) else null
80+
(next(arg, scope, key) == null) && next.wellformed(scope)
8181
}
8282

8383
/** Returns an iterator on attributes */
@@ -98,9 +98,9 @@ trait Attribute extends MetaData {
9898
if (value == null)
9999
return
100100
if (isPrefixed)
101-
sb append pre append ':'
101+
sb.append(pre).append(':')
102102

103-
sb append key append '='
103+
sb.append(key).append('=')
104104
val sb2: StringBuilder = new StringBuilder()
105105
Utility.sequenceToXML(value, TopScope, sb2, stripComments = true)
106106
Utility.appendQuoted(sb2.toString, sb)

shared/src/main/scala/scala/xml/Equality.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ trait Equality extends scala.Equals {
8585
* which heads off a lot of inconsistency up front.
8686
*/
8787
override def canEqual(other: Any): Boolean = other match {
88-
case x: Equality => true
88+
case _: Equality => true
8989
case _ => false
9090
}
9191

@@ -96,7 +96,7 @@ trait Equality extends scala.Equals {
9696
* are final since clearly individual classes cannot be trusted
9797
* to maintain a semblance of order.
9898
*/
99-
override def hashCode(): Int = basisForHashCode.##
99+
override def hashCode: Int = basisForHashCode.##
100100
override def equals(other: Any): Boolean = doComparison(other, blithe = false)
101101
final def xml_==(other: Any): Boolean = doComparison(other, blithe = true)
102102
final def xml_!=(other: Any): Boolean = !xml_==(other)

shared/src/main/scala/scala/xml/Group.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ final case class Group(nodes: Seq[Node]) extends Node {
2424
override def theSeq: Seq[Node] = nodes
2525

2626
override def canEqual(other: Any): Boolean = other match {
27-
case x: Group => true
27+
case _: Group => true
2828
case _ => false
2929
}
3030

shared/src/main/scala/scala/xml/MetaData.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ object MetaData {
7575
* attributes. Every instance of this class is either
7676
* - an instance of `UnprefixedAttribute key,value` or
7777
* - an instance of `PrefixedAttribute namespace_prefix,key,value` or
78-
* - `Null, the empty attribute list.
78+
* - `Null`, the empty attribute list.
7979
*
8080
* Namespace URIs are obtained by using the namespace scope of the element
8181
* owning this attribute (see `getNamespace`).
@@ -204,17 +204,17 @@ abstract class MetaData
204204
* @param uri namespace of key
205205
* @param scope a namespace scp (usually of the element owning this attribute list)
206206
* @param key to be looked fore
207-
* @return value as Some[Seq[Node]] if key is found, None otherwise
207+
* @return value as `Some[Seq[Node]]` if key is found, None otherwise
208208
*/
209209
final def get(uri: String, scope: NamespaceBinding, key: String): Option[Seq[Node]] =
210210
Option(apply(uri, scope, key))
211211

212-
protected def toString1(): String = sbToString(toString1)
212+
protected def toString1: String = sbToString(toString1)
213213

214214
// appends string representations of single attribute to StringBuilder
215215
protected def toString1(sb: StringBuilder): Unit
216216

217-
override def toString(): String = sbToString(buildString)
217+
override def toString: String = sbToString(buildString)
218218

219219
def buildString(sb: StringBuilder): StringBuilder = {
220220
sb append ' '

shared/src/main/scala/scala/xml/Node.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,8 @@ abstract class Node extends NodeSeq {
140140
def descendant_or_self: List[Node] = this :: descendant
141141

142142
override def canEqual(other: Any): Boolean = other match {
143-
case x: Group => false
144-
case x: Node => true
143+
case _: Group => false
144+
case _: Node => true
145145
case _ => false
146146
}
147147

@@ -178,7 +178,7 @@ abstract class Node extends NodeSeq {
178178
/**
179179
* Same as `toString('''false''')`.
180180
*/
181-
override def toString(): String = buildString(stripComments = false)
181+
override def toString: String = buildString(stripComments = false)
182182

183183
/**
184184
* Appends qualified name of this node to `StringBuilder`.
@@ -194,7 +194,7 @@ abstract class Node extends NodeSeq {
194194
/**
195195
* Returns a type symbol (e.g. DTD, XSD), default `'''null'''`.
196196
*/
197-
def xmlType(): TypeSymbol = null
197+
def xmlType: TypeSymbol = null
198198

199199
/**
200200
* Returns a text representation of this node. Note that this is not equivalent to

shared/src/main/scala/scala/xml/NodeSeq.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ abstract class NodeSeq extends AbstractSeq[Node] with immutable.Seq[Node] with S
102102
else if (that(1) == '{') {
103103
val i: Int = that indexOf '}'
104104
if (i == -1) fail
105-
val (uri: String, key: String) = (that.substring(2, i), that.substring(i + 1, that.length()))
105+
val (uri: String, key: String) = (that.substring(2, i), that.substring(i + 1, that.length))
106106
if (uri == "" || key == "") fail
107107
else y.attribute(uri, key)
108108
} else y.attribute(that drop 1)
@@ -128,7 +128,7 @@ abstract class NodeSeq extends AbstractSeq[Node] with immutable.Seq[Node] with S
128128
/**
129129
* Projection function, which returns elements of `this` sequence and of
130130
* all its subsequences, based on the string `that`. Use:
131-
* - `this \\ "foo" to get a list of all elements that are labelled with `"foo"`,
131+
* - `this \\ "foo"` to get a list of all elements that are labelled with "foo"`,
132132
* including `this`;
133133
* - `this \\ "_"` to get a list of all elements (wildcard), including `this`;
134134
* - `this \\ "@foo"` to get all unprefixed attributes `"foo"`;
@@ -159,7 +159,7 @@ abstract class NodeSeq extends AbstractSeq[Node] with immutable.Seq[Node] with S
159159
*/
160160
def \@(attributeName: String): String = (this \ ("@" + attributeName)).text
161161

162-
override def toString(): String = theSeq.mkString
162+
override def toString: String = theSeq.mkString
163163

164164
def text: String = (this map (_.text)).mkString
165165
}

shared/src/main/scala/scala/xml/Null.scala

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
package scala
1414
package xml
1515

16-
import Utility.isNameStart
1716
import scala.collection.Iterator
1817
import scala.collection.Seq
1918

@@ -50,13 +49,13 @@ case object Null extends MetaData {
5049

5150
override def apply(namespace: String, scope: NamespaceBinding, key: String) /* TODO type annotation */ = null
5251
override def apply(key: String) /* TODO type annotation */ =
53-
if (isNameStart(key.head)) null
52+
if (Utility.isNameStart(key.head)) null
5453
else throw new IllegalArgumentException("not a valid attribute name '" + key + "', so can never match !")
5554

5655
override protected def toString1(sb: StringBuilder): Unit = ()
57-
override protected def toString1(): String = ""
56+
override protected def toString1: String = ""
5857

59-
override def toString(): String = ""
58+
override def toString: String = ""
6059

6160
override def buildString(sb: StringBuilder): StringBuilder = sb
6261

shared/src/main/scala/scala/xml/PrettyPrinter.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,11 @@ class PrettyPrinter(width: Int, step: Int, minimizeEmpty: Boolean) {
150150

151151
protected def traverse(node: Node, pscope: NamespaceBinding, ind: Int): Unit = node match {
152152

153-
case Text(s) if s.trim() == "" =>
153+
case Text(s) if s.trim == "" =>
154154

155155
case _: Atom[_] | _: Comment | _: EntityRef | _: ProcInstr =>
156-
makeBox(ind, node.toString().trim())
157-
case g@Group(xs) =>
156+
makeBox(ind, node.toString.trim)
157+
case Group(xs) =>
158158
traverse(xs.iterator, pscope, ind)
159159
case _ =>
160160
val test: String = {

shared/src/main/scala/scala/xml/SpecialNode.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ abstract class SpecialNode extends Node {
2424
/** always empty */
2525
final override def attributes: Null.type = Null
2626

27-
/** always Node.EmptyNamespace */
27+
/** always Node.EmptyNamespace - TODO not really: Node.EmptyNamespace is "", but this is null. */
2828
final override def namespace: scala.Null = null
2929

3030
/** always empty */

shared/src/main/scala/scala/xml/TopScope.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ object TopScope extends NamespaceBinding(null, null, null) {
2828
override def getPrefix(uri1: String): String =
2929
if (uri1 == namespace) xml else null
3030

31-
override def toString(): String = ""
31+
override def toString: String = ""
3232

3333
override def buildString(stop: NamespaceBinding): String = ""
3434
override def buildString(sb: StringBuilder, ignore: NamespaceBinding): Unit = ()

shared/src/main/scala/scala/xml/Utility.scala

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ object Utility extends AnyRef with parsing.TokenTests {
2828

2929
// [Martin] This looks dubious. We don't convert StringBuilders to
3030
// Strings anywhere else, why do it here?
31-
implicit def implicitSbToString(sb: StringBuilder): String = sb.toString()
31+
implicit def implicitSbToString(sb: StringBuilder): String = sb.toString
3232

3333
// helper for the extremely oft-repeated sequence of creating a
3434
// StringBuilder, passing it around, and then grabbing its String.
@@ -50,7 +50,7 @@ object Utility extends AnyRef with parsing.TokenTests {
5050
*/
5151
def trim(x: Node): Node = x match {
5252
case Elem(pre, lab, md, scp, child@_*) =>
53-
val children: Seq[Node] = combineAdjacentTextNodes(child) flatMap trimProper
53+
val children: Seq[Node] = combineAdjacentTextNodes(child).flatMap(trimProper)
5454
Elem(pre, lab, md, scp, children.isEmpty, children: _*)
5555
}
5656

@@ -67,7 +67,7 @@ object Utility extends AnyRef with parsing.TokenTests {
6767
*/
6868
def trimProper(x: Node): Seq[Node] = x match {
6969
case Elem(pre, lab, md, scp, child@_*) =>
70-
val children: Seq[Node] = combineAdjacentTextNodes(child) flatMap trimProper
70+
val children: Seq[Node] = combineAdjacentTextNodes(child).flatMap(trimProper)
7171
Elem(pre, lab, md, scp, children.isEmpty, children: _*)
7272
case Text(s) =>
7373
new TextBuffer().append(s).toText
@@ -173,7 +173,7 @@ object Utility extends AnyRef with parsing.TokenTests {
173173
// minimizeTags: Boolean = false): String =
174174
// {
175175
// toXMLsb(x, pscope, sb, stripComments, decodeEntities, preserveWhitespace, minimizeTags)
176-
// sb.toString()
176+
// sb.toString
177177
// }
178178

179179
/**
@@ -263,13 +263,16 @@ object Utility extends AnyRef with parsing.TokenTests {
263263
} else children foreach { serialize(_, pscope, sb, stripComments, decodeEntities, preserveWhitespace, minimizeTags) }
264264
}
265265

266+
def splitName(name: String): (Option[String], String) = {
267+
val colon: Int = name.indexOf(':')
268+
if (colon < 0) (None, name)
269+
else (Some(name.take(colon)), name.drop(colon + 1))
270+
}
271+
266272
/**
267273
* Returns prefix of qualified name if any.
268274
*/
269-
final def prefix(name: String): Option[String] = name.indexOf(':') match {
270-
case -1 => None
271-
case i => Some(name.substring(0, i))
272-
}
275+
final def prefix(name: String): Option[String] = splitName(name)._1
273276

274277
/**
275278
* Returns a hashcode for the given constituents of a node
@@ -357,12 +360,12 @@ object Utility extends AnyRef with parsing.TokenTests {
357360
rfb.append(c)
358361
c = it.next()
359362
}
360-
val ref: String = rfb.toString()
363+
val ref: String = rfb.toString
361364
rfb.clear()
362365
unescape(ref, sb) match {
363366
case null =>
364367
if (sb.nonEmpty) { // flush buffer
365-
nb += Text(sb.toString())
368+
nb += Text(sb.toString)
366369
sb.clear()
367370
}
368371
nb += EntityRef(ref) // add entityref
@@ -372,7 +375,7 @@ object Utility extends AnyRef with parsing.TokenTests {
372375
} else sb append c
373376
}
374377
if (sb.nonEmpty) { // flush buffer
375-
val x: Text = Text(sb.toString())
378+
val x: Text = Text(sb.toString)
376379
if (nb.isEmpty)
377380
return x
378381
else

shared/src/main/scala/scala/xml/XML.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ object XML extends XMLLoader[Elem] {
117117
final def write(w: java.io.Writer, node: Node, enc: String, xmlDecl: Boolean, doctype: dtd.DocType, minimizeTags: MinimizeMode.Value = MinimizeMode.Default): Unit = {
118118
/* TODO: optimize by giving writer parameter to toXML*/
119119
if (xmlDecl) w.write("<?xml version='1.0' encoding='" + enc + "'?>\n")
120-
if (doctype ne null) w.write(doctype.toString() + "\n")
120+
if (doctype ne null) w.write(doctype.toString + "\n")
121121
w.write(Utility.serialize(node, minimizeTags = minimizeTags).toString)
122122
}
123123
}

shared/src/main/scala/scala/xml/dtd/Decl.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,22 +150,22 @@ case class PEReference(ent: String) extends MarkupDecl {
150150
// default declarations for attributes
151151

152152
sealed abstract class DefaultDecl {
153-
override def toString(): String
153+
def toString: String
154154
def buildString(sb: StringBuilder): StringBuilder
155155
}
156156

157157
case object REQUIRED extends DefaultDecl {
158-
override def toString(): String = "#REQUIRED"
158+
override def toString: String = "#REQUIRED"
159159
override def buildString(sb: StringBuilder): StringBuilder = sb append "#REQUIRED"
160160
}
161161

162162
case object IMPLIED extends DefaultDecl {
163-
override def toString(): String = "#IMPLIED"
163+
override def toString: String = "#IMPLIED"
164164
override def buildString(sb: StringBuilder): StringBuilder = sb append "#IMPLIED"
165165
}
166166

167167
case class DEFAULT(fixed: Boolean, attValue: String) extends DefaultDecl {
168-
override def toString(): String = sbToString(buildString)
168+
override def toString: String = sbToString(buildString)
169169
override def buildString(sb: StringBuilder): StringBuilder = {
170170
if (fixed) sb append "#FIXED "
171171
Utility.appendEscapedQuoted(attValue, sb)

shared/src/main/scala/scala/xml/dtd/DocType.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ case class DocType(name: String, extID: ExternalID, intSubset: Seq[dtd.Decl]) {
3535
if (intSubset.isEmpty) ""
3636
else intSubset.mkString("[", "", "]")
3737

38-
"""<!DOCTYPE %s %s%s>""".format(name, extID.toString(), intString)
38+
"""<!DOCTYPE %s %s%s>""".format(name, extID.toString, intString)
3939
}
4040
}
4141

shared/src/main/scala/scala/xml/dtd/ExternalID.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ sealed abstract class ExternalID extends parsing.TokenTests {
3636
(if (systemId == null) "" else " " + quotedSystemLiteral)
3737
}
3838
def buildString(sb: StringBuilder): StringBuilder =
39-
sb.append(this.toString())
39+
sb.append(this.toString)
4040

4141
def systemId: String
4242
def publicId: String

shared/src/main/scala/scala/xml/dtd/ValidationException.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ object MakeValidationException {
3737
val sb: StringBuilder = new StringBuilder("missing value for REQUIRED attribute")
3838
if (allKeys.size > 1) sb.append('s')
3939
allKeys foreach (k => sb append "'%s'".format(k))
40-
ValidationException(sb.toString())
40+
ValidationException(sb.toString)
4141
}
4242

4343
def fromMissingAttribute(key: String, tpe: String): ValidationException =

shared/src/main/scala/scala/xml/dtd/impl/BaseBerrySethi.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import scala.collection.Seq
2020

2121
/**
2222
* This class turns a regular expression over `A` into a
23-
* [[scala.util.automata.NondetWordAutom]] over `A` using the celebrated
23+
* [[scala.xml.dtd.impl.NondetWordAutom]] over `A` using the celebrated
2424
* position automata construction (also called ''Berry-Sethi'' or ''Glushkov'').
2525
*/
2626
@deprecated("This class will be removed", "2.10.0")

0 commit comments

Comments
 (0)