@@ -3,7 +3,6 @@ package transform
3
3
4
4
import java .io .{PrintWriter , StringWriter }
5
5
import java .lang .reflect .Method
6
- import java .net .URLClassLoader
7
6
8
7
import dotty .tools .dotc .ast .tpd
9
8
import dotty .tools .dotc .core .Contexts ._
@@ -14,6 +13,7 @@ import dotty.tools.dotc.core.Names.Name
14
13
import dotty .tools .dotc .core .quoted ._
15
14
import dotty .tools .dotc .core .Types ._
16
15
import dotty .tools .dotc .core .Symbols ._
16
+ import dotty .tools .dotc .core .TypeErasure
17
17
18
18
import scala .util .control .NonFatal
19
19
import dotty .tools .dotc .util .Positions .Position
@@ -170,28 +170,49 @@ object Splicer {
170
170
171
171
/** List of classes of the parameters of the signature of `sym` */
172
172
private def paramsSig (sym : Symbol ): List [Class [_]] = {
173
- sym.signature.paramsSig.map { param =>
174
- defn.valueTypeNameToJavaType(param) match {
175
- case Some (clazz) => clazz
176
- case None =>
177
- def javaArraySig (name : String ): String = {
178
- if (name.endsWith(" []" )) " [" + javaArraySig(name.dropRight(2 ))
179
- else name match {
180
- case " scala.Boolean" => " Z"
181
- case " scala.Byte" => " B"
182
- case " scala.Short" => " S"
183
- case " scala.Int" => " I"
184
- case " scala.Long" => " J"
185
- case " scala.Float" => " F"
186
- case " scala.Double" => " D"
187
- case " scala.Char" => " C"
188
- case paramName => " L" + paramName + " ;"
189
- }
173
+ TypeErasure .erasure(sym.info) match {
174
+ case meth : MethodType =>
175
+ meth.paramInfos.map { param =>
176
+ def arrayDepth (tpe : Type , depth : Int ): (Type , Int ) = tpe match {
177
+ case JavaArrayType (elemType) => arrayDepth(elemType, depth + 1 )
178
+ case _ => (tpe, depth)
190
179
}
191
- def javaSig (name : String ): String =
192
- if (name.endsWith(" []" )) javaArraySig(name) else name
193
- java.lang.Class .forName(javaSig(param.toString), false , classLoader)
194
- }
180
+ def javaArraySig (tpe : Type ): String = {
181
+ val (elemType, depth) = arrayDepth(tpe, 0 )
182
+ val sym = elemType.classSymbol
183
+ val suffix =
184
+ if (sym == defn.BooleanClass ) " Z"
185
+ else if (sym == defn.ByteClass ) " B"
186
+ else if (sym == defn.ShortClass ) " S"
187
+ else if (sym == defn.IntClass ) " I"
188
+ else if (sym == defn.LongClass ) " J"
189
+ else if (sym == defn.FloatClass ) " F"
190
+ else if (sym == defn.DoubleClass ) " D"
191
+ else if (sym == defn.CharClass ) " C"
192
+ else " L" + javaSig(elemType) + " ;"
193
+ (" [" * depth) + suffix
194
+ }
195
+ def javaSig (tpe : Type ): String = tpe match {
196
+ case tpe : JavaArrayType => javaArraySig(tpe)
197
+ case _ =>
198
+ // Take the flatten name of the class and the full package name
199
+ val pack = tpe.classSymbol.topLevelClass.owner
200
+ val packageName = if (pack == defn.EmptyPackageClass ) " " else pack.fullName + " ."
201
+ packageName + tpe.classSymbol.fullNameSeparated(FlatName ).toString
202
+ }
203
+
204
+ val sym = param.classSymbol
205
+ if (sym == defn.BooleanClass ) classOf [Boolean ]
206
+ else if (sym == defn.ByteClass ) classOf [Byte ]
207
+ else if (sym == defn.CharClass ) classOf [Char ]
208
+ else if (sym == defn.ShortClass ) classOf [Short ]
209
+ else if (sym == defn.IntClass ) classOf [Int ]
210
+ else if (sym == defn.LongClass ) classOf [Long ]
211
+ else if (sym == defn.FloatClass ) classOf [Float ]
212
+ else if (sym == defn.DoubleClass ) classOf [Double ]
213
+ else java.lang.Class .forName(javaSig(param), false , classLoader)
214
+ }
215
+ case _ => Nil
195
216
}
196
217
}
197
218
0 commit comments