Skip to content

Commit 3742370

Browse files
committed
Added all missing type annotations.
- introduced `ScalaVersionSpecificReturnTypes`; - split MIMA exclusions by Scala version; - removed exclusions that are no longer needed; - made Circle CI task names not mention the exact Scala version; - provisioned for Scala 2.13-specific code; - Scala 2.13- is only Scala 2.12 now that Scala 11 is no longer supported :) - marked classes used by the compiler.
1 parent 26af21d commit 3742370

26 files changed

+161
-58
lines changed

.circleci/config.yml

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -92,56 +92,56 @@ workflows:
9292
build:
9393
jobs:
9494
- scala_job:
95-
name: 2.12.18
95+
name: 2.12.x
9696
java_version: jdk8
9797
scala_version: 2.12.18
9898
- scala_job:
99-
name: 2.13.11
99+
name: 2.13.x
100100
java_version: jdk8
101101
scala_version: 2.13.11
102102
- scala_job:
103-
name: 3.3.0
103+
name: 3.x
104104
java_version: jdk8
105105
scala_version: 3.3.0
106106
- scala_job:
107-
name: jdk11_2.12
107+
name: jdk11_2.12.x
108108
java_version: jdk11
109109
scala_version: 2.12.18
110110
- scala_job:
111-
name: jdk11_2.13
111+
name: jdk11_2.13.x
112112
java_version: jdk11
113113
scala_version: 2.13.11
114114
- scala_job:
115-
name: jdk11_3.1
115+
name: jdk11_3.x
116116
java_version: jdk11
117117
scala_version: 3.3.0
118118
- scala_job:
119-
name: jdk17_2.12
119+
name: jdk17_2.12.x
120120
java_version: jdk17
121121
scala_version: 2.12.18
122122
- scala_job:
123-
name: jdk17_2.13
123+
name: jdk17_2.13.x
124124
java_version: jdk17
125125
scala_version: 2.13.11
126126
- scala_job:
127-
name: jdk17_3.3
127+
name: jdk17_3.x
128128
java_version: jdk17
129129
scala_version: 3.3.0
130130
- scalajs_job:
131-
name: sjs1.0_2.12
131+
name: sjs1.0_2.12.x
132132
scala_version: 2.12.18
133133
- scalajs_job:
134-
name: sjs1.0_2.13
134+
name: sjs1.0_2.13.x
135135
scala_version: 2.13.11
136136
- scalajs_job:
137-
name: sjs1.0_3.3
137+
name: sjs1.0_3.x
138138
scala_version: 3.3.0
139139
- scalanative_job:
140-
name: native0.4_2.12
140+
name: native0.4_2.12.x
141141
scala_version: 2.12.18
142142
- scalanative_job:
143-
name: native0.4_2.13
143+
name: native0.4_2.13.x
144144
scala_version: 2.13.11
145145
- scalanative_job:
146-
name: native0.4_3
146+
name: native0.4_3.x
147147
scala_version: 3.3.0

build.sbt

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,20 @@ ThisBuild / licenses += (("Apache-2.0", url("https://www.apache.org/licenses/LIC
99
ThisBuild / libraryDependencySchemes += "org.scala-js" %% "scalajs-library" % "semver-spec"
1010
ThisBuild / apiURL := Some(url("https://javadoc.io/doc/org.scala-lang.modules/scala-xml_2.13/"))
1111

12-
lazy val configSettings: Seq[Setting[_]] = Seq(
12+
lazy val configSettings: Seq[Setting[?]] = Seq(
1313
unmanagedSourceDirectories ++= {
1414
unmanagedSourceDirectories.value.flatMap { dir =>
15-
val sv = scalaVersion.value
16-
Seq(
17-
CrossVersion.partialVersion(sv) match {
18-
case Some((major, minor)) if major > 2 || (major == 2 && minor >= 13) => file(dir.getPath ++ "-2.13+")
19-
case _ => file(dir.getPath ++ "-2.13-")
20-
},
21-
CrossVersion.partialVersion(sv) match {
22-
case Some((2, _)) => file(dir.getPath ++ "-2.x")
23-
case _ => file(dir.getPath ++ "-3.x")
24-
}
25-
)
15+
def forVersion(version: String): File = file(dir.getPath ++ "-" ++ version)
16+
CrossVersion.partialVersion(scalaVersion.value) match {
17+
case Some((3, _)) => Seq(forVersion("3"), forVersion("2.13+"))
18+
case Some((2, minor)) =>
19+
Seq(forVersion("2")) ++ (minor match {
20+
case 13 => Seq(forVersion("2.13"), forVersion("2.13+"))
21+
case 12 => Seq(forVersion("2.12"))
22+
case _ => Seq()
23+
})
24+
case _ => Seq()
25+
}
2626
}
2727
}
2828
)
@@ -65,13 +65,21 @@ lazy val xml = crossProject(JSPlatform, JVMPlatform, NativePlatform)
6565
versionPolicyIntention := Compatibility.BinaryCompatible,
6666
// Note: See discussion on non-JVM Mima in https://github.com/scala/scala-xml/pull/517
6767
mimaBinaryIssueFilters ++= {
68-
import com.typesafe.tools.mima.core._
69-
import com.typesafe.tools.mima.core.ProblemFilters._
70-
Seq(
71-
// necessitated by the introduction of new abstract methods in FactoryAdapter:
72-
exclude[ReversedMissingMethodProblem]("scala.xml.parsing.FactoryAdapter.createComment"), // see #549
73-
exclude[ReversedMissingMethodProblem]("scala.xml.parsing.FactoryAdapter.createPCData") // see #558
74-
)
68+
//import com.typesafe.tools.mima.core.{}
69+
//import com.typesafe.tools.mima.core.ProblemFilters
70+
Seq( // exclusions for all Scala versions
71+
) ++ (CrossVersion.partialVersion(scalaVersion.value) match {
72+
case Some((3, _)) => Seq( // Scala 3-specific exclusions
73+
)
74+
case Some((2, minor)) => Seq( // Scala 2-specific exclusions
75+
) ++ (minor match {
76+
case 13 => Seq( // Scala 2.13-specific exclusions
77+
)
78+
case 12 => Seq( // Scala 2.12-specific exclusions
79+
)
80+
})
81+
case _ => Seq()
82+
})
7583
},
7684
// Mima signature checking stopped working after 3.0.2 upgrade, see #557
7785
mimaReportSignatureProblems := (CrossVersion.partialVersion(scalaVersion.value) match {

shared/src/main/scala-2.13-/scala/xml/ScalaVersionSpecific.scala renamed to shared/src/main/scala-2.12/scala/xml/ScalaVersionSpecific.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ private[xml] object ScalaVersionSpecific {
2222
override def apply(from: Coll): mutable.Builder[Node, NodeSeq] = NodeSeq.newBuilder
2323
override def apply(): mutable.Builder[Node, NodeSeq] = NodeSeq.newBuilder
2424
}
25+
type SeqNodeUnapplySeq = scala.collection.Seq[Node]
2526
}
2627

2728
private[xml] trait ScalaVersionSpecificNodeSeq extends SeqLike[Node, NodeSeq] { self: NodeSeq =>

shared/src/main/scala-2.13+/scala/xml/ScalaVersionSpecific.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ private[xml] object ScalaVersionSpecific {
2424
def newBuilder(from: Coll): Builder[Node, NodeSeq] = NodeSeq.newBuilder
2525
def fromSpecific(from: Coll)(it: IterableOnce[Node]): NodeSeq = (NodeSeq.newBuilder ++= from).result()
2626
}
27+
type SeqNodeUnapplySeq = scala.collection.immutable.Seq[Node]
2728
}
2829

2930
private[xml] trait ScalaVersionSpecificNodeSeq
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Scala (https://www.scala-lang.org)
3+
*
4+
* Copyright EPFL and Lightbend, Inc.
5+
*
6+
* Licensed under Apache License 2.0
7+
* (http://www.apache.org/licenses/LICENSE-2.0).
8+
*
9+
* See the NOTICE file distributed with this work for
10+
* additional information regarding copyright ownership.
11+
*/
12+
13+
package scala.xml
14+
15+
/*
16+
Unlike other Scala-version-specific things, this class is not filling any gaps in capabilities
17+
between different versions of Scala; instead, it mostly documents the types that different versions of the
18+
Scala compiler inferred in the unfortunate absence of the explicit type annotations.
19+
What should have been specified explicitly is given in the comments;
20+
next time we break binary compatibility the types should be changed in the code and this class removed.
21+
*/
22+
private[xml] object ScalaVersionSpecificReturnTypes { // should be
23+
type ExternalIDAttribute = MetaData // Null.type
24+
type NoExternalIDId = scala.Null
25+
type NodeNoAttributes = MetaData // Null.type
26+
type NullFilter = MetaData // Null.type
27+
type NullGetNamespace = scala.Null
28+
type NullNext = scala.Null
29+
type NullKey = scala.Null
30+
type NullValue = scala.Null
31+
type NullApply1 = scala.collection.Seq[Node] // scala.Null
32+
type NullApply3 = scala.Null
33+
type NullRemove = Null.type
34+
type SpecialNodeChild = Nil.type
35+
type GroupChild = Nothing
36+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Scala (https://www.scala-lang.org)
3+
*
4+
* Copyright EPFL and Lightbend, Inc.
5+
*
6+
* Licensed under Apache License 2.0
7+
* (http://www.apache.org/licenses/LICENSE-2.0).
8+
*
9+
* See the NOTICE file distributed with this work for
10+
* additional information regarding copyright ownership.
11+
*/
12+
13+
package scala.xml
14+
15+
/*
16+
Unlike other Scala-version-specific things, this class is not filling any gaps in capabilities
17+
between different versions of Scala; instead, it mostly documents the types that different versions of the
18+
Scala compiler inferred in the unfortunate absence of the explicit type annotations.
19+
What should have been specified explicitly is given in the comments;
20+
next time we break binary compatibility the types should be changed in the code and this class removed.
21+
*/
22+
private[xml] object ScalaVersionSpecificReturnTypes { // should be
23+
type ExternalIDAttribute = MetaData // Null.type
24+
type NoExternalIDId = String // scala.Null
25+
type NodeNoAttributes = MetaData // Null.type
26+
type NullFilter = MetaData // Null.type
27+
type NullGetNamespace = String // scala.Null
28+
type NullNext = MetaData // scala.Null
29+
type NullKey = String // scala.Null
30+
type NullValue = scala.collection.Seq[Node] // scala.Null
31+
type NullApply1 = scala.collection.Seq[Node] // scala.Null
32+
type NullApply3 = scala.collection.Seq[Node] // scala.Null
33+
type NullRemove = MetaData // Null.type
34+
type SpecialNodeChild = scala.collection.Seq[Node] // Nil.type
35+
type GroupChild = scala.collection.Seq[Node] // Nothing
36+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import scala.collection.Seq
2222
* @author Burak Emir
2323
*/
2424
object Attribute {
25-
def unapply(x: Attribute) /* TODO type annotation */ = x match {
25+
def unapply(x: Attribute): Option[(String, Seq[Node], MetaData)] = x match {
2626
case PrefixedAttribute(_, key, value, next) => Some((key, value, next))
2727
case UnprefixedAttribute(key, value, next) => Some((key, value, next))
2828
case _ => None

shared/src/main/scala/scala/xml/Comment.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ package xml
2121
* and the final character may not be `-` to prevent a closing span of `-->`
2222
* which is invalid. [[https://www.w3.org/TR/xml11//#IDA5CES]]
2323
*/
24+
// Note: used by the Scala compiler.
2425
case class Comment(commentText: String) extends SpecialNode {
2526

2627
override def label: String = "#REM"

shared/src/main/scala/scala/xml/Elem.scala

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,17 @@ import scala.collection.Seq
2121
* any `Node` instance (that is not a `SpecialNode` or a `Group`) using the
2222
* syntax `case Elem(prefix, label, attribs, scope, child @ _*) => ...`
2323
*/
24+
// Note: used by the Scala compiler.
2425
object Elem {
2526

2627
def apply(prefix: String, label: String, attributes: MetaData, scope: NamespaceBinding, minimizeEmpty: Boolean, child: Node*): Elem =
2728
new Elem(prefix, label, attributes, scope, minimizeEmpty, child: _*)
2829

29-
def unapplySeq(n: Node) /* TODO type annotation */ = n match {
30-
case _: SpecialNode | _: Group => None
31-
case _ => Some((n.prefix, n.label, n.attributes, n.scope, n.child.toSeq))
32-
}
30+
def unapplySeq(n: Node): Option[(String, String, MetaData, NamespaceBinding, ScalaVersionSpecific.SeqNodeUnapplySeq)] =
31+
n match {
32+
case _: SpecialNode | _: Group => None
33+
case _ => Some((n.prefix, n.label, n.attributes, n.scope, n.child.toSeq))
34+
}
3335
}
3436

3537
/**
@@ -51,6 +53,7 @@ object Elem {
5153
* empty; `false` if it should be written out in long form.
5254
* @param child the children of this node
5355
*/
56+
// Note: used by the Scala compiler.
5457
class Elem(
5558
override val prefix: String,
5659
override val label: String,

shared/src/main/scala/scala/xml/EntityRef.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package xml
1919
* @author Burak Emir
2020
* @param entityName the name of the entity reference, for example `amp`.
2121
*/
22+
// Note: used by the Scala compiler.
2223
case class EntityRef(entityName: String) extends SpecialNode {
2324
final override def doCollectNamespaces: Boolean = false
2425
final override def doTransform: Boolean = false

0 commit comments

Comments
 (0)