Skip to content

Added all missing type annotations. #675

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,56 +92,56 @@ workflows:
build:
jobs:
- scala_job:
name: 2.12.18
name: 2.12.x
java_version: jdk8
scala_version: 2.12.18
- scala_job:
name: 2.13.11
name: 2.13.x
java_version: jdk8
scala_version: 2.13.11
- scala_job:
name: 3.3.0
name: 3.x
java_version: jdk8
scala_version: 3.3.0
- scala_job:
name: jdk11_2.12
name: jdk11_2.12.x
java_version: jdk11
scala_version: 2.12.18
- scala_job:
name: jdk11_2.13
name: jdk11_2.13.x
java_version: jdk11
scala_version: 2.13.11
- scala_job:
name: jdk11_3.1
name: jdk11_3.x
java_version: jdk11
scala_version: 3.3.0
- scala_job:
name: jdk17_2.12
name: jdk17_2.12.x
java_version: jdk17
scala_version: 2.12.18
- scala_job:
name: jdk17_2.13
name: jdk17_2.13.x
java_version: jdk17
scala_version: 2.13.11
- scala_job:
name: jdk17_3.3
name: jdk17_3.x
java_version: jdk17
scala_version: 3.3.0
- scalajs_job:
name: sjs1.0_2.12
name: sjs1.0_2.12.x
scala_version: 2.12.18
- scalajs_job:
name: sjs1.0_2.13
name: sjs1.0_2.13.x
scala_version: 2.13.11
- scalajs_job:
name: sjs1.0_3.3
name: sjs1.0_3.x
scala_version: 3.3.0
- scalanative_job:
name: native0.4_2.12
name: native0.4_2.12.x
scala_version: 2.12.18
- scalanative_job:
name: native0.4_2.13
name: native0.4_2.13.x
scala_version: 2.13.11
- scalanative_job:
name: native0.4_3
name: native0.4_3.x
scala_version: 3.3.0
46 changes: 27 additions & 19 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,20 @@ ThisBuild / licenses += (("Apache-2.0", url("https://www.apache.org/licenses/LIC
ThisBuild / libraryDependencySchemes += "org.scala-js" %% "scalajs-library" % "semver-spec"
ThisBuild / apiURL := Some(url("https://javadoc.io/doc/org.scala-lang.modules/scala-xml_2.13/"))

lazy val configSettings: Seq[Setting[_]] = Seq(
lazy val configSettings: Seq[Setting[?]] = Seq(
unmanagedSourceDirectories ++= {
unmanagedSourceDirectories.value.flatMap { dir =>
val sv = scalaVersion.value
Seq(
CrossVersion.partialVersion(sv) match {
case Some((major, minor)) if major > 2 || (major == 2 && minor >= 13) => file(dir.getPath ++ "-2.13+")
case _ => file(dir.getPath ++ "-2.13-")
},
CrossVersion.partialVersion(sv) match {
case Some((2, _)) => file(dir.getPath ++ "-2.x")
case _ => file(dir.getPath ++ "-3.x")
}
)
def forVersion(version: String): File = file(dir.getPath ++ "-" ++ version)
CrossVersion.partialVersion(scalaVersion.value) match {
case Some((3, _)) => Seq(forVersion("3"), forVersion("2.13+"))
case Some((2, minor)) =>
Seq(forVersion("2")) ++ (minor match {
case 13 => Seq(forVersion("2.13"), forVersion("2.13+"))
case 12 => Seq(forVersion("2.12"))
case _ => Seq()
})
case _ => Seq()
}
}
}
)
Expand Down Expand Up @@ -65,13 +65,21 @@ lazy val xml = crossProject(JSPlatform, JVMPlatform, NativePlatform)
versionPolicyIntention := Compatibility.BinaryCompatible,
// Note: See discussion on non-JVM Mima in https://github.com/scala/scala-xml/pull/517
mimaBinaryIssueFilters ++= {
import com.typesafe.tools.mima.core._
import com.typesafe.tools.mima.core.ProblemFilters._
Seq(
// necessitated by the introduction of new abstract methods in FactoryAdapter:
exclude[ReversedMissingMethodProblem]("scala.xml.parsing.FactoryAdapter.createComment"), // see #549
exclude[ReversedMissingMethodProblem]("scala.xml.parsing.FactoryAdapter.createPCData") // see #558
)
//import com.typesafe.tools.mima.core.{}
//import com.typesafe.tools.mima.core.ProblemFilters
Seq( // exclusions for all Scala versions
) ++ (CrossVersion.partialVersion(scalaVersion.value) match {
case Some((3, _)) => Seq( // Scala 3-specific exclusions
)
case Some((2, minor)) => Seq( // Scala 2-specific exclusions
) ++ (minor match {
case 13 => Seq( // Scala 2.13-specific exclusions
)
case 12 => Seq( // Scala 2.12-specific exclusions
)
})
case _ => Seq()
})
},
// Mima signature checking stopped working after 3.0.2 upgrade, see #557
mimaReportSignatureProblems := (CrossVersion.partialVersion(scalaVersion.value) match {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ private[xml] object ScalaVersionSpecific {
override def apply(from: Coll): mutable.Builder[Node, NodeSeq] = NodeSeq.newBuilder
override def apply(): mutable.Builder[Node, NodeSeq] = NodeSeq.newBuilder
}
type SeqNodeUnapplySeq = scala.collection.Seq[Node]
}

private[xml] trait ScalaVersionSpecificNodeSeq extends SeqLike[Node, NodeSeq] { self: NodeSeq =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ private[xml] object ScalaVersionSpecific {
def newBuilder(from: Coll): Builder[Node, NodeSeq] = NodeSeq.newBuilder
def fromSpecific(from: Coll)(it: IterableOnce[Node]): NodeSeq = (NodeSeq.newBuilder ++= from).result()
}
type SeqNodeUnapplySeq = scala.collection.immutable.Seq[Node]
}

private[xml] trait ScalaVersionSpecificNodeSeq
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Scala (https://www.scala-lang.org)
*
* Copyright EPFL and Lightbend, Inc.
*
* Licensed under Apache License 2.0
* (http://www.apache.org/licenses/LICENSE-2.0).
*
* See the NOTICE file distributed with this work for
* additional information regarding copyright ownership.
*/

package scala.xml

/*
Unlike other Scala-version-specific things, this class is not filling any gaps in capabilities
between different versions of Scala; instead, it mostly documents the types that different versions of the
Scala compiler inferred in the unfortunate absence of the explicit type annotations.
What should have been specified explicitly is given in the comments;
next time we break binary compatibility the types should be changed in the code and this class removed.
*/
private[xml] object ScalaVersionSpecificReturnTypes { // should be
type ExternalIDAttribute = MetaData // Null.type
type NoExternalIDId = scala.Null
type NodeNoAttributes = MetaData // Null.type
type NullFilter = MetaData // Null.type
type NullGetNamespace = scala.Null
type NullNext = scala.Null
type NullKey = scala.Null
type NullValue = scala.Null
type NullApply1 = scala.collection.Seq[Node] // scala.Null
type NullApply3 = scala.Null
type NullRemove = Null.type
type SpecialNodeChild = Nil.type
type GroupChild = Nothing
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Scala (https://www.scala-lang.org)
*
* Copyright EPFL and Lightbend, Inc.
*
* Licensed under Apache License 2.0
* (http://www.apache.org/licenses/LICENSE-2.0).
*
* See the NOTICE file distributed with this work for
* additional information regarding copyright ownership.
*/

package scala.xml

/*
Unlike other Scala-version-specific things, this class is not filling any gaps in capabilities
between different versions of Scala; instead, it mostly documents the types that different versions of the
Scala compiler inferred in the unfortunate absence of the explicit type annotations.
What should have been specified explicitly is given in the comments;
next time we break binary compatibility the types should be changed in the code and this class removed.
*/
private[xml] object ScalaVersionSpecificReturnTypes { // should be
type ExternalIDAttribute = MetaData // Null.type
type NoExternalIDId = String // scala.Null
type NodeNoAttributes = MetaData // Null.type
type NullFilter = MetaData // Null.type
type NullGetNamespace = String // scala.Null
type NullNext = MetaData // scala.Null
type NullKey = String // scala.Null
type NullValue = scala.collection.Seq[Node] // scala.Null
type NullApply1 = scala.collection.Seq[Node] // scala.Null
type NullApply3 = scala.collection.Seq[Node] // scala.Null
type NullRemove = MetaData // Null.type
type SpecialNodeChild = scala.collection.Seq[Node] // Nil.type
type GroupChild = scala.collection.Seq[Node] // Nothing
}
2 changes: 1 addition & 1 deletion shared/src/main/scala/scala/xml/Attribute.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import scala.collection.Seq
* @author Burak Emir
*/
object Attribute {
def unapply(x: Attribute) /* TODO type annotation */ = x match {
def unapply(x: Attribute): Option[(String, Seq[Node], MetaData)] = x match {
case PrefixedAttribute(_, key, value, next) => Some((key, value, next))
case UnprefixedAttribute(key, value, next) => Some((key, value, next))
case _ => None
Expand Down
1 change: 1 addition & 0 deletions shared/src/main/scala/scala/xml/Comment.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ package xml
* and the final character may not be `-` to prevent a closing span of `-->`
* which is invalid. [[https://www.w3.org/TR/xml11//#IDA5CES]]
*/
// Note: used by the Scala compiler.
case class Comment(commentText: String) extends SpecialNode {

override def label: String = "#REM"
Expand Down
11 changes: 7 additions & 4 deletions shared/src/main/scala/scala/xml/Elem.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,17 @@ import scala.collection.Seq
* any `Node` instance (that is not a `SpecialNode` or a `Group`) using the
* syntax `case Elem(prefix, label, attribs, scope, child @ _*) => ...`
*/
// Note: used by the Scala compiler.
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) /* TODO type annotation */ = n match {
case _: SpecialNode | _: Group => None
case _ => Some((n.prefix, n.label, n.attributes, n.scope, n.child.toSeq))
}
def unapplySeq(n: Node): Option[(String, String, MetaData, NamespaceBinding, ScalaVersionSpecific.SeqNodeUnapplySeq)] =
n match {
case _: SpecialNode | _: Group => None
case _ => Some((n.prefix, n.label, n.attributes, n.scope, n.child.toSeq))
}
}

/**
Expand All @@ -51,6 +53,7 @@ object Elem {
* empty; `false` if it should be written out in long form.
* @param child the children of this node
*/
// Note: used by the Scala compiler.
class Elem(
override val prefix: String,
override val label: String,
Expand Down
1 change: 1 addition & 0 deletions shared/src/main/scala/scala/xml/EntityRef.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package xml
* @author Burak Emir
* @param entityName the name of the entity reference, for example `amp`.
*/
// Note: used by the Scala compiler.
case class EntityRef(entityName: String) extends SpecialNode {
final override def doCollectNamespaces: Boolean = false
final override def doTransform: Boolean = false
Expand Down
3 changes: 2 additions & 1 deletion shared/src/main/scala/scala/xml/Group.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import scala.collection.Seq
*
* @author Burak Emir
*/
// Note: used by the Scala compiler.
final case class Group(nodes: Seq[Node]) extends Node {
override def theSeq: Seq[Node] = nodes

Expand All @@ -44,6 +45,6 @@ final case class Group(nodes: Seq[Node]) extends Node {
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")
override def child: ScalaVersionSpecificReturnTypes.GroupChild = fail("child")
def buildString(sb: StringBuilder): Nothing = fail("toString(StringBuilder)")
}
1 change: 1 addition & 0 deletions shared/src/main/scala/scala/xml/MetaData.scala
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ object MetaData {
* Namespace URIs are obtained by using the namespace scope of the element
* owning this attribute (see `getNamespace`).
*/
// Note: used by the Scala compiler.
abstract class MetaData
extends AbstractIterable[MetaData]
with Iterable[MetaData]
Expand Down
1 change: 1 addition & 0 deletions shared/src/main/scala/scala/xml/NamespaceBinding.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import scala.collection.Seq
*
* @author Burak Emir
*/
// Note: used by the Scala compiler.
@SerialVersionUID(0 - 2518644165573446725L)
case class NamespaceBinding(prefix: String, uri: String, parent: NamespaceBinding) extends AnyRef with Equality {
if (prefix == "")
Expand Down
5 changes: 3 additions & 2 deletions shared/src/main/scala/scala/xml/Node.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@ import scala.collection.Seq
*/
object Node {
/** the constant empty attribute sequence */
final def NoAttributes: MetaData = Null
final def NoAttributes: ScalaVersionSpecificReturnTypes.NodeNoAttributes = Null

/** the empty namespace */
val EmptyNamespace: String = ""

def unapplySeq(n: Node) /* TODO type annotation */ = Some((n.label, n.attributes, n.child.toSeq))
def unapplySeq(n: Node): Some[(String, MetaData, ScalaVersionSpecific.SeqNodeUnapplySeq)] =
Some((n.label, n.attributes, n.child.toSeq))
}

/**
Expand Down
1 change: 1 addition & 0 deletions shared/src/main/scala/scala/xml/NodeBuffer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ package xml
*
* @author Burak Emir
*/
// Note: used by the Scala compiler.
class NodeBuffer extends scala.collection.mutable.ArrayBuffer[Node] with ScalaVersionSpecificNodeBuffer {
/**
* Append given object to this buffer, returns reference on this
Expand Down
19 changes: 10 additions & 9 deletions shared/src/main/scala/scala/xml/Null.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,20 @@ import scala.collection.Seq
*
* @author Burak Emir
*/
// Note: used by the Scala compiler.
case object Null extends MetaData {
override def iterator: Iterator[Nothing] = 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 filter(f: MetaData => Boolean): ScalaVersionSpecificReturnTypes.NullFilter = this

override def copy(next: MetaData): MetaData = next
override def getNamespace(owner: Node) /* TODO type annotation */ = null
override def getNamespace(owner: Node): ScalaVersionSpecificReturnTypes.NullGetNamespace = null

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 next: ScalaVersionSpecificReturnTypes.NullNext = null
override def key: ScalaVersionSpecificReturnTypes.NullKey = null
override def value: ScalaVersionSpecificReturnTypes.NullValue = null
override def isPrefixed: Boolean = false

override def length: Int = 0
Expand All @@ -47,8 +48,8 @@ case object Null extends MetaData {
}
override protected def basisForHashCode: Seq[Any] = Nil

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

Expand All @@ -61,6 +62,6 @@ case object Null extends MetaData {

override def wellformed(scope: NamespaceBinding): Boolean = true

override def remove(key: String) /* TODO type annotation */ = this
override def remove(namespace: String, scope: NamespaceBinding, key: String) /* TODO type annotation */ = this
override def remove(key: String): ScalaVersionSpecificReturnTypes.NullRemove = this
override def remove(namespace: String, scope: NamespaceBinding, key: String): ScalaVersionSpecificReturnTypes.NullRemove = this
}
2 changes: 2 additions & 0 deletions shared/src/main/scala/scala/xml/PCData.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package xml
*
* @author Burak Emir
*/
// Note: used by the Scala compiler (before Scala 3).
class PCData(data: String) extends Atom[String](data) {

/**
Expand All @@ -39,6 +40,7 @@ class PCData(data: String) extends Atom[String](data) {
*
* @author Burak Emir
*/
// Note: used by the Scala compiler (before Scala 3).
object PCData {
def apply(data: String): PCData = new PCData(data)
def unapply(other: Any): Option[String] = other match {
Expand Down
Loading