Skip to content

Commit 0902c3b

Browse files
committed
Parse parameter names from classfiles
1 parent a406225 commit 0902c3b

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

compiler/src/dotty/tools/dotc/core/StdNames.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@ object StdNames {
257257
final val DeprecatedATTR: N = "Deprecated"
258258
final val ExceptionsATTR: N = "Exceptions"
259259
final val InnerClassesATTR: N = "InnerClasses"
260+
final val MethodParametersATTR: N = "MethodParameters"
260261
final val LineNumberTableATTR: N = "LineNumberTable"
261262
final val LocalVariableTableATTR: N = "LocalVariableTable"
262263
final val RuntimeVisibleAnnotationATTR: N = "RuntimeVisibleAnnotations" // RetentionPolicy.RUNTIME

compiler/src/dotty/tools/dotc/core/classfile/ClassfileParser.scala

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -657,6 +657,7 @@ class ClassfileParser(
657657
var constant: Constant = null
658658
var exceptions: List[NameOrString] = Nil
659659
var annotations: List[Annotation] = Nil
660+
var namedParams: Map[Int, TermName] = Map.empty
660661
def complete(tp: Type, isVarargs: Boolean = false)(using Context): Type = {
661662
val updatedType =
662663
if sig == null then tp
@@ -680,7 +681,14 @@ class ClassfileParser(
680681
sym.addAnnotation(ThrowsAnnotation(cls.asClass))
681682
}
682683

683-
cook.apply(newType)
684+
def fillInParamNames(t: Type): Type = t match
685+
case mt @ MethodType(oldp) if namedParams.nonEmpty =>
686+
mt.derivedLambdaType(List.tabulate(oldp.size)(n => namedParams.getOrElse(n, oldp(n))))
687+
case pt: PolyType if namedParams.nonEmpty =>
688+
pt.derivedLambdaType(pt.paramNames, pt.paramInfos, fillInParamNames(pt.resultType))
689+
case _ => t
690+
691+
cook.apply(fillInParamNames(newType))
684692
}
685693
}
686694

@@ -714,6 +722,14 @@ class ClassfileParser(
714722
if (c ne null) res.constant = c
715723
else report.warning(s"Invalid constant in attribute of ${sym.showLocated} while parsing ${classfile}")
716724

725+
case tpnme.MethodParametersATTR =>
726+
val paramCount = in.nextByte
727+
for i <- 0 until paramCount do
728+
val name = pool.getName(in.nextChar)
729+
val flags = in.nextChar
730+
if (flags & JAVA_ACC_SYNTHETIC) == 0 then
731+
res.namedParams += (i -> name.name)
732+
717733
case tpnme.AnnotationDefaultATTR =>
718734
sym.addAnnotation(Annotation(defn.AnnotationDefaultAnnot, Nil))
719735

0 commit comments

Comments
 (0)