mirror of
https://github.com/sbt/sbt.git
synced 2026-09-07 11:01:08 +02:00
handle constant types
This commit is contained in:
@@ -119,7 +119,8 @@ class SameAPI(tagsA: TypeVars, tagsB: TypeVars, includePrivate: Boolean, include
|
||||
debug(sameDefinitions(byName(atypes), byName(btypes)), "Type definitions differed")
|
||||
}
|
||||
def sameDefinitions(a: scala.collection.Map[String, List[Definition]], b: scala.collection.Map[String, List[Definition]]): Boolean =
|
||||
debug(sameStrings(a.keySet, b.keySet), "\tDefinition strings differed") && zippedEntries(a,b).forall(tupled(sameNamedDefinitions))
|
||||
debug(sameStrings(a.keySet, b.keySet), "\tDefinition strings differed (a: " + a.keySet + ", b: " + b.keySet + ")") &&
|
||||
zippedEntries(a,b).forall(tupled(sameNamedDefinitions))
|
||||
|
||||
/** Removes definitions that should not be considered for API equality.
|
||||
* All top-level definitions are always considered: 'private' only means package-private.
|
||||
@@ -303,6 +304,7 @@ class SameAPI(tagsA: TypeVars, tagsB: TypeVars, includePrivate: Boolean, include
|
||||
(a, b) match
|
||||
{
|
||||
case (sa: SimpleType, sb: SimpleType) => debug(sameSimpleType(sa, sb), "Different simple types: " + DefaultShowAPI(sa) + " and " + DefaultShowAPI(sb))
|
||||
case (ca: Constant, cb: Constant) => debug(sameConstantType(ca, cb), "Different constant types: " + DefaultShowAPI(ca) + " and " + DefaultShowAPI(cb))
|
||||
case (aa: Annotated, ab: Annotated) => debug(sameAnnotatedType(aa, ab), "Different annotated types")
|
||||
case (sa: Structure, sb: Structure) => debug(sameStructure(sa, sb), "Different structure type")
|
||||
case (ea: Existential, eb: Existential) => debug(sameExistentialType(ea, eb), "Different existential type")
|
||||
@@ -310,6 +312,9 @@ class SameAPI(tagsA: TypeVars, tagsB: TypeVars, includePrivate: Boolean, include
|
||||
case _ => false
|
||||
}
|
||||
|
||||
def sameConstantType(ca: Constant, cb: Constant): Boolean =
|
||||
sameType(ca.baseType, cb.baseType) &&
|
||||
ca.value == cb.value
|
||||
def sameExistentialType(a: Existential, b: Existential): Boolean =
|
||||
sameTypeParameters(a.clause, b.clause) &&
|
||||
sameType(a.baseType, b.baseType)
|
||||
|
||||
@@ -169,13 +169,14 @@ trait ShowDefinition
|
||||
}
|
||||
trait ShowType
|
||||
{
|
||||
implicit def showType(implicit s: Show[SimpleType], a: Show[Annotated], st: Show[Structure], e: Show[Existential], po: Show[Polymorphic]): Show[Type] =
|
||||
implicit def showType(implicit s: Show[SimpleType], a: Show[Annotated], st: Show[Structure], c: Show[Constant], e: Show[Existential], po: Show[Polymorphic]): Show[Type] =
|
||||
new Show[Type]
|
||||
{
|
||||
def show(t: Type) =
|
||||
t match
|
||||
{
|
||||
case q: SimpleType => s.show(q)
|
||||
case q: Constant => c.show(q)
|
||||
case q: Annotated => a.show(q)
|
||||
case q: Structure => st.show(q)
|
||||
case q: Existential => e.show(q)
|
||||
@@ -219,6 +220,8 @@ trait ShowTypes
|
||||
new Show[Projection] { def show(p: Projection) = t.show(p.prefix) + "#" + p.id }
|
||||
implicit def showParameterized(implicit t: Show[Type]): Show[Parameterized] =
|
||||
new Show[Parameterized] { def show(p: Parameterized) = t.show(p.baseType) + mapSeq(p.typeArguments, t).mkString("[", ", ", "]") }
|
||||
implicit def showConstant(implicit t: Show[Type]): Show[Constant] =
|
||||
new Show[Constant] { def show(c: Constant) = t.show(c.baseType) + "(" + c.value + ")" }
|
||||
implicit def showExistential(implicit t: Show[Type], tp: Show[TypeParameter]): Show[Existential] =
|
||||
new Show[Existential] {
|
||||
def show(e: Existential) =
|
||||
@@ -291,6 +294,7 @@ object DefaultShowAPI extends ShowBase with ShowBasicTypes with ShowValueParamet
|
||||
implicit lazy val showSimple: Show[SimpleType] = new ShowLazy(Cyclic.showSimpleType)
|
||||
implicit lazy val showAnnotated: Show[Annotated] = Cyclic.showAnnotated
|
||||
implicit lazy val showExistential: Show[Existential] = Cyclic.showExistential
|
||||
implicit lazy val showConstant: Show[Constant] = Cyclic.showConstant
|
||||
implicit lazy val showParameterized: Show[Parameterized] = Cyclic.showParameterized
|
||||
|
||||
implicit lazy val showTypeParameters: Show[Seq[TypeParameter]] = new ShowLazy(Cyclic.showTypeParameters)
|
||||
|
||||
@@ -95,6 +95,7 @@ private class TagTypeVariables
|
||||
{
|
||||
case s: Structure => tagStructure(s)
|
||||
case e: Existential => tagExistential(e)
|
||||
case c: Constant => tagConstant(c)
|
||||
case p: Polymorphic => tagPolymorphic(p)
|
||||
case a: Annotated => tagAnnotated(a)
|
||||
case p: Parameterized => tagParameterized(p)
|
||||
@@ -102,7 +103,8 @@ private class TagTypeVariables
|
||||
case _: EmptyType | _: Singleton | _: ParameterRef => ()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
def tagConstant(c: Constant) = tagType(c.baseType)
|
||||
def tagExistential(e: Existential) = tagParameters(e.clause, e.baseType)
|
||||
def tagPolymorphic(p: Polymorphic) = tagParameters(p.parameters, p.baseType)
|
||||
def tagProjection(p: Projection) = tagType(p.prefix)
|
||||
|
||||
@@ -144,6 +144,7 @@ class Visit
|
||||
{
|
||||
case s: Structure => visitStructure(s)
|
||||
case e: Existential => visitExistential(e)
|
||||
case c: Constant => visitConstant(c)
|
||||
case p: Polymorphic => visitPolymorphic(p)
|
||||
case a: Annotated => visitAnnotated(a)
|
||||
case p: Parameterized => visitParameterized(p)
|
||||
@@ -169,6 +170,11 @@ class Visit
|
||||
def visitIdPath(id: Id) { visitString(id.id) }
|
||||
|
||||
|
||||
def visitConstant(c: Constant) =
|
||||
{
|
||||
visitString(c.value)
|
||||
visitType(c.baseType)
|
||||
}
|
||||
def visitExistential(e: Existential) = visitParameters(e.clause, e.baseType)
|
||||
def visitPolymorphic(p: Polymorphic) = visitParameters(p.parameters, p.baseType)
|
||||
def visitProjection(p: Projection) =
|
||||
|
||||
Reference in New Issue
Block a user