@@ -46,77 +46,82 @@ object factories {
46
46
}
47
47
48
48
def expandTpe (t : Type , params : List [Reference ] = Nil ): Reference = t match {
49
- case tl : PolyType =>
50
- // FIXME: should be handled correctly
51
- // example, in `Option`:
52
- //
53
- // {{{
54
- // def companion: GenericCompanion[collection.Iterable]
55
- // }}}
56
- //
57
- // Becomes: def companion: [+X0] -> collection.Iterable[X0]
58
- typeRef(tl.show + " (not handled)" )
59
- case AppliedType (tycon, args) =>
49
+ case AppliedType (tycon, args) => {
60
50
val cls = tycon.typeSymbol
61
- if (tycon.isRepeatedParam)
62
- expandTpe(args.head)
63
- else if (defn.isFunctionClass(cls))
51
+
52
+ if (defn.isFunctionClass(cls))
64
53
FunctionReference (args.init.map(expandTpe(_, Nil )), expandTpe(args.last))
65
54
else if (defn.isTupleClass(cls))
66
55
TupleReference (args.map(expandTpe(_, Nil )))
67
56
else {
68
- val query = tycon.show
69
- val name = query.split( " \\ . " ).last
57
+ val query = cls.showFullName
58
+ val name = cls.name.show
70
59
typeRef(name, query, params = args.map(expandTpe(_, Nil )))
71
60
}
61
+ }
72
62
73
- case ref @ RefinedType (parent, rn, info) =>
74
- expandTpe(parent) // FIXME: will be a refined HK, aka class Foo[X] { def bar: List[X] } or similar
75
- case ref @ HKApply (tycon, args) =>
76
- expandTpe(tycon, args.map(expandTpe(_, params)))
77
- case TypeRef (_, n) =>
78
- val name = n.decode.toString.split(" \\ $" ).last
79
- typeRef(name, params = params)
80
- case ta : TypeAlias =>
81
- expandTpe(ta.alias.widenDealias)
82
- case OrType (left, right) =>
83
- OrTypeReference (expandTpe(left), expandTpe(right))
84
- case AndType (left, right) =>
85
- AndTypeReference (expandTpe(left), expandTpe(right))
86
- case tb @ TypeBounds (lo, hi) =>
63
+ case t : TypeRef => {
64
+ val cls = t.typeSymbol
65
+ typeRef(cls.name.show.split(" \\ $\\ $" ).last, query = cls.showFullName, params = params)
66
+ }
67
+
68
+ case TypeBounds (lo, hi) =>
87
69
BoundsReference (expandTpe(lo), expandTpe(hi))
88
- case AnnotatedType (tpe, _) =>
89
- expandTpe(tpe)
70
+
71
+ case t : PolyParam =>
72
+ typeRef(t.paramName.show, params = params)
73
+
90
74
case ExprType (tpe) =>
91
75
expandTpe(tpe)
92
- case c : ConstantType =>
93
- ConstantReference (c.show)
94
- case tt : ThisType =>
95
- expandTpe(tt.underlying)
96
- case ci : ClassInfo =>
97
- val query = path(ci.typeSymbol).mkString(" ." )
98
- typeRef(ci.cls.name.show, query = query)
99
- case mt : MethodType =>
100
- expandTpe(mt.resultType)
101
- case pp : PolyParam =>
102
- val paramName = pp.paramName.show
103
- val name =
104
- if (paramName.contains('$' ))
105
- paramName.split(" \\ $\\ $" ).last
106
- else paramName
107
-
108
- typeRef(name)
109
- case tr : TermRef =>
76
+
77
+ case t : ThisType =>
78
+ expandTpe(t.underlying)
79
+
80
+ case AnnotatedType (t, _) =>
81
+ expandTpe(t)
82
+
83
+ case t : MethodType =>
84
+ expandTpe(t.finalResultType)
85
+
86
+ case t : TermRef => {
110
87
/** A `TermRef` appears in the return type in e.g:
111
88
* ```
112
89
* def id[T](t: T): t.type = t
113
90
* ```
114
91
*/
115
- val name = tr .show
92
+ val name = t .show
116
93
if (! name.endsWith(" .type" ))
117
- ctx.warning(s " unhandled return type found: $tr" )
94
+ ctx.warning(s " unhandled return type found: $t" )
95
+
96
+ typeRef(name, query = t.typeSymbol.showFullName, params = params)
97
+ }
98
+
99
+ case ci : ClassInfo =>
100
+ typeRef(ci.cls.name.show, query = ci.typeSymbol.showFullName)
101
+
102
+ case tl : PolyType => {
103
+ // FIXME: should be handled correctly
104
+ // example, in `Option`:
105
+ //
106
+ // ```scala
107
+ // def companion: GenericCompanion[collection.Iterable]
108
+ // ```
109
+ //
110
+ // Becomes: def companion: [+X0] -> collection.Iterable[X0]
111
+ typeRef(tl.show + " (not handled)" )
112
+ }
118
113
119
- typeRef(name, params = params)
114
+ case OrType (left, right) =>
115
+ OrTypeReference (expandTpe(left), expandTpe(right))
116
+
117
+ case AndType (left, right) =>
118
+ AndTypeReference (expandTpe(left), expandTpe(right))
119
+
120
+ case c : ConstantType =>
121
+ ConstantReference (c.show)
122
+
123
+ case ref @ RefinedType (parent, rn, info) =>
124
+ expandTpe(parent) // FIXME: will be a refined HK, aka class Foo[X] { def bar: List[X] } or similar
120
125
}
121
126
122
127
expandTpe(t)
0 commit comments