@@ -119,10 +119,12 @@ object GenerateFunctionConverters {
119
119
def text = Predef .augmentString(showCode(t).replace(" $" , " " )).lines.toVector
120
120
}
121
121
122
+ /** Blocks of code with priority (lower priority has higher precedence in implicit search). */
122
123
case class Prioritized (lines : Vector [String ], priority : Int ) {
123
124
def withPriority (i : Int ) = copy(priority = i)
124
125
}
125
126
127
+ /** Contains code for conversion between functions and SAMs (single abstract methods). */
126
128
case class SamConversionCode (
127
129
base : String ,
128
130
wrappedAsScala : Vector [String ],
@@ -140,20 +142,21 @@ object GenerateFunctionConverters {
140
142
}
141
143
object SamConversionCode {
142
144
def apply (scc : SamConversionCode * ): (Vector [String ], Vector [String ], Vector [Vector [String ]]) = {
143
- val sccDepthSet = scc.map(_.implicitToJava.priority).toSet
145
+ val sccDepthSet = scc.map(_.implicitToJava.priority).to[collection. SortedSet ]
144
146
val codes =
145
147
{
146
- if (sccDepthSet != (0 to sccDepthSet.max).toSet) {
147
- val sccDepthMap = sccDepthSet.toList.sorted.zipWithIndex.toMap
148
+ val size = sccDepthSet.size
149
+ // normalize the elements to a fix [0..size-1] range
150
+ if (sccDepthSet.firstKey != 0 || sccDepthSet.lastKey != size - 1 ) {
151
+ val sccDepthMap = sccDepthSet.iterator.zipWithIndex.toMap
148
152
scc.map(x => x.withPriority(sccDepthMap(x.implicitToJava.priority)))
149
153
}
150
154
else scc
151
155
}.toVector.sortBy(_.base)
152
- def priorityName (n : Int , pure : Boolean = false ): String = {
153
- val pre =
154
- if (pure) s " Priority ${n}FunctionExtensions "
155
- else s " trait ${priorityName(n, pure = true )}"
156
- if (! pure && n < (sccDepthSet.size- 1 )) s " $pre extends ${priorityName(n+ 1 , pure = true )}" else pre
156
+ def priorityName (n : Int ): String = s " Priority ${n}FunctionExtensions "
157
+ def priorityHeader (n : Int ): String = {
158
+ val pre = s " trait ${priorityName(n)}"
159
+ if (n < sccDepthSet.size - 1 ) s " $pre extends ${priorityName(n+ 1 )}" else pre
157
160
}
158
161
val impls =
159
162
" object FunctionWrappers {" +: {
@@ -163,7 +166,7 @@ object GenerateFunctionConverters {
163
166
val traits = codes.groupBy(_.implicitToJava.priority).toVector.sortBy(- _._1).map{ case (k,vs) =>
164
167
s " import language.implicitConversions " +:
165
168
" " +:
166
- s " ${priorityName (k)} { " +:
169
+ s " ${priorityHeader (k)} { " +:
167
170
s " import FunctionWrappers._ " +:
168
171
s " " +:
169
172
{
0 commit comments