in rsc/src/main/scala/rsc/classpath/scalacp/Types.scala [15:81]
def loop(tpe: Type): s.Type = {
tpe match {
case NoType =>
s.NoType
case NoPrefix =>
s.NoType
case ThisType(sym) =>
val ssym = sym.sym.ssym
s.ThisType(ssym)
case SingleType(pre, sym) =>
val spre = pre.tpe.stpe
val ssym = sym.sym.ssym
s.SingleType(spre, ssym)
case ConstantType(lit) =>
def classOf(tpe: Ref): s.Type = {
loop(tpe.tpe) match {
case s.NoType => s.NoType
case sarg =>
val ssym = "java/lang/Class#"
val sargs = sarg :: Nil
s.TypeRef(s.NoType, ssym, sargs)
}
}
val sconst = lit.lit match {
case UnitLit => s.UnitConstant()
case BooleanLit(value: Boolean) => s.BooleanConstant(value)
case ByteLit(value: Byte) => s.ByteConstant(value)
case ShortLit(value: Short) => s.ShortConstant(value)
case CharLit(value: Char) => s.CharConstant(value)
case IntLit(value: Int) => s.IntConstant(value)
case LongLit(value: Long) => s.LongConstant(value)
case FloatLit(value: Float) => s.FloatConstant(value)
case DoubleLit(value: Double) => s.DoubleConstant(value)
case StringLit(name: Ref) => s.StringConstant(name.name.value)
case NullLit => s.NullConstant()
case ClassLit(tpe: Ref) => return classOf(tpe)
case EnumLit(sym: Ref) => crash(tpe.toString)
}
s.ConstantType(sconst)
case TypeRef(pre, sym, targs) =>
val spre = pre.tpe.stpe
val ssym = sym.sym.ssym
val stargs = targs.map(_.tpe.stpe)
s.TypeRef(spre, ssym, stargs)
case RefinedType(sym, parents) =>
val stpe = s.WithType(parents.map(_.tpe).map(loop))
val sdecls = sym.sym.sdecls(HardlinkChildren)
s.StructuralType(stpe, sdecls)
case PolyType(tpe, params) =>
loop(tpe.tpe) match {
case s.NoType =>
s.NoType
case stpe =>
val stparams = params.map(_.sym).sscope(HardlinkChildren)
s.UniversalType(stparams, stpe)
}
case AnnotatedType(tpe, _) =>
// FIXME: https://github.com/twitter/rsc/issues/93
loop(tpe.tpe)
case ExistentialType(tpe, decls) =>
val stpe = loop(tpe.tpe)
val sdecls = decls.map(_.sym).sscope(HardlinkChildren)
s.ExistentialType(stpe, sdecls)
case _ =>
crash(tpe.toString)
}
}