Load Java parameter names correctly in BinaryJavaMethod
PSI-based implementation (accessible via `-Xuse-old-class-files-reading`) loads parameter names from the "MethodParameters" attribute if it's present, so our own implementation should as well. This metadata doesn't seem supported in the java.lang.model.element API though, so SymbolBasedValueParameter (which is used in `-Xuse-javac`) will continue to have incorrect behavior for now #KT-25193 Fixed
This commit is contained in:
+17
-1
@@ -25,18 +25,34 @@ import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||
import org.jetbrains.org.objectweb.asm.*
|
||||
import java.lang.reflect.Array
|
||||
|
||||
internal class AnnotationsCollectorMethodVisitor(
|
||||
internal class AnnotationsAndParameterCollectorMethodVisitor(
|
||||
private val member: BinaryJavaMethodBase,
|
||||
private val context: ClassifierResolutionContext,
|
||||
private val signatureParser: BinaryClassSignatureParser,
|
||||
private val parametersToSkipNumber: Int
|
||||
) : MethodVisitor(ASM_API_VERSION_FOR_CLASS_READING) {
|
||||
private var parameterIndex = 0
|
||||
|
||||
override fun visitAnnotationDefault(): AnnotationVisitor? {
|
||||
member.safeAs<BinaryJavaMethod>()?.hasAnnotationParameterDefaultValue = true
|
||||
// We don't store default value in Java model
|
||||
return null
|
||||
}
|
||||
|
||||
override fun visitParameter(name: String?, access: Int) {
|
||||
if (name != null) {
|
||||
val index = parameterIndex - parametersToSkipNumber
|
||||
if (index >= 0) {
|
||||
val parameter = member.valueParameters.getOrNull(index) ?: error(
|
||||
"No parameter with index $parameterIndex-$parametersToSkipNumber (name=$name access=$access) " +
|
||||
"in method ${member.containingClass.fqName}.${member.name}"
|
||||
)
|
||||
parameter.updateName(Name.identifier(name))
|
||||
}
|
||||
}
|
||||
parameterIndex++
|
||||
}
|
||||
|
||||
override fun visitAnnotation(desc: String, visible: Boolean) =
|
||||
BinaryJavaAnnotation.addAnnotation(
|
||||
member.annotations as MutableCollection<JavaAnnotation>,
|
||||
|
||||
+6
-6
@@ -31,7 +31,7 @@ import java.text.StringCharacterIterator
|
||||
abstract class BinaryJavaMethodBase(
|
||||
override val access: Int,
|
||||
override val containingClass: JavaClass,
|
||||
val valueParameters: List<JavaValueParameter>,
|
||||
val valueParameters: List<BinaryJavaValueParameter>,
|
||||
val typeParameters: List<JavaTypeParameter>,
|
||||
override val name: Name
|
||||
) : JavaMember, MapBasedJavaAnnotationOwner, BinaryJavaModifierListOwner {
|
||||
@@ -80,13 +80,13 @@ abstract class BinaryJavaMethodBase(
|
||||
}
|
||||
|
||||
val parameterTypes = info.valueParameterTypes
|
||||
val parameterList = ContainerUtil.newArrayList<JavaValueParameter>()
|
||||
val parameterList = ContainerUtil.newArrayList<BinaryJavaValueParameter>()
|
||||
val paramCount = parameterTypes.size
|
||||
for (i in 0..paramCount - 1) {
|
||||
val type = parameterTypes[i]
|
||||
val isEllipsisParam = isVarargs && i == paramCount - 1
|
||||
|
||||
parameterList.add(BinaryJavaValueParameter(null, type, isEllipsisParam))
|
||||
parameterList.add(BinaryJavaValueParameter(type, isEllipsisParam))
|
||||
}
|
||||
|
||||
val member: BinaryJavaMethodBase =
|
||||
@@ -106,7 +106,7 @@ abstract class BinaryJavaMethodBase(
|
||||
else -> 0
|
||||
}
|
||||
|
||||
return member to AnnotationsCollectorMethodVisitor(member, parentContext, signatureParser, paramIgnoreCount)
|
||||
return member to AnnotationsAndParameterCollectorMethodVisitor(member, parentContext, signatureParser, paramIgnoreCount)
|
||||
}
|
||||
|
||||
private fun parseMethodDescription(
|
||||
@@ -155,7 +155,7 @@ abstract class BinaryJavaMethodBase(
|
||||
class BinaryJavaMethod(
|
||||
flags: Int,
|
||||
containingClass: JavaClass,
|
||||
valueParameters: List<JavaValueParameter>,
|
||||
valueParameters: List<BinaryJavaValueParameter>,
|
||||
typeParameters: List<JavaTypeParameter>,
|
||||
name: Name,
|
||||
override val returnType: JavaType
|
||||
@@ -168,7 +168,7 @@ class BinaryJavaMethod(
|
||||
class BinaryJavaConstructor(
|
||||
flags: Int,
|
||||
containingClass: JavaClass,
|
||||
valueParameters: List<JavaValueParameter>,
|
||||
valueParameters: List<BinaryJavaValueParameter>,
|
||||
typeParameters: List<JavaTypeParameter>
|
||||
) : BinaryJavaMethodBase(
|
||||
flags, containingClass, valueParameters, typeParameters,
|
||||
|
||||
+7
-1
@@ -50,12 +50,18 @@ class BinaryJavaTypeParameter(
|
||||
}
|
||||
|
||||
class BinaryJavaValueParameter(
|
||||
override val name: Name?,
|
||||
override val type: JavaType,
|
||||
override val isVararg: Boolean
|
||||
) : JavaValueParameter, MapBasedJavaAnnotationOwner {
|
||||
override val annotations: MutableCollection<JavaAnnotation> = ContainerUtil.newSmartList()
|
||||
override val annotationsByFqName by buildLazyValueForMap()
|
||||
|
||||
override var name: Name? = null
|
||||
|
||||
internal fun updateName(newName: Name) {
|
||||
assert(name == null) { "Parameter can't have two names: $name and $newName" }
|
||||
name = newName
|
||||
}
|
||||
}
|
||||
|
||||
fun isNotTopLevelClass(classContent: ByteArray): Boolean {
|
||||
|
||||
Reference in New Issue
Block a user