FIR Java: fix creation & handling of type parameter symbols

Before this commit, we created type parameter symbols each time
when type parameter was referenced or created.
In this commit, we introduced class-bound Java type parameter stack
and use it to find referenced type parameter symbol.
So now they are created only when Java type parameter is created
This commit is contained in:
Mikhail Glukhikh
2019-04-18 20:02:31 +03:00
parent f8bb1d161a
commit 092d10b1a8
38 changed files with 249 additions and 130 deletions
@@ -9,6 +9,8 @@ import com.intellij.openapi.project.Project
import com.intellij.psi.search.GlobalSearchScope import com.intellij.psi.search.GlobalSearchScope
import org.jetbrains.kotlin.fir.FirSession import org.jetbrains.kotlin.fir.FirSession
import org.jetbrains.kotlin.fir.declarations.FirRegularClass import org.jetbrains.kotlin.fir.declarations.FirRegularClass
import org.jetbrains.kotlin.fir.declarations.FirTypeParameter
import org.jetbrains.kotlin.fir.declarations.impl.FirTypeParameterImpl
import org.jetbrains.kotlin.fir.java.declarations.FirJavaClass import org.jetbrains.kotlin.fir.java.declarations.FirJavaClass
import org.jetbrains.kotlin.fir.java.declarations.FirJavaConstructor import org.jetbrains.kotlin.fir.java.declarations.FirJavaConstructor
import org.jetbrains.kotlin.fir.java.declarations.FirJavaField import org.jetbrains.kotlin.fir.java.declarations.FirJavaField
@@ -26,16 +28,19 @@ import org.jetbrains.kotlin.fir.symbols.ConeClassLikeSymbol
import org.jetbrains.kotlin.fir.symbols.impl.FirClassSymbol import org.jetbrains.kotlin.fir.symbols.impl.FirClassSymbol
import org.jetbrains.kotlin.fir.symbols.impl.FirFieldSymbol import org.jetbrains.kotlin.fir.symbols.impl.FirFieldSymbol
import org.jetbrains.kotlin.fir.symbols.impl.FirFunctionSymbol import org.jetbrains.kotlin.fir.symbols.impl.FirFunctionSymbol
import org.jetbrains.kotlin.fir.symbols.impl.FirTypeParameterSymbol
import org.jetbrains.kotlin.fir.types.ConeClassErrorType import org.jetbrains.kotlin.fir.types.ConeClassErrorType
import org.jetbrains.kotlin.fir.types.impl.ConeTypeParameterTypeImpl import org.jetbrains.kotlin.fir.types.impl.ConeTypeParameterTypeImpl
import org.jetbrains.kotlin.fir.types.impl.FirResolvedTypeRefImpl import org.jetbrains.kotlin.fir.types.impl.FirResolvedTypeRefImpl
import org.jetbrains.kotlin.load.java.JavaClassFinder import org.jetbrains.kotlin.load.java.JavaClassFinder
import org.jetbrains.kotlin.load.java.JvmAnnotationNames import org.jetbrains.kotlin.load.java.JvmAnnotationNames
import org.jetbrains.kotlin.load.java.structure.JavaClass import org.jetbrains.kotlin.load.java.structure.JavaClass
import org.jetbrains.kotlin.load.java.structure.JavaTypeParameter
import org.jetbrains.kotlin.name.ClassId import org.jetbrains.kotlin.name.ClassId
import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.resolve.jvm.KotlinJavaPsiFacade import org.jetbrains.kotlin.resolve.jvm.KotlinJavaPsiFacade
import org.jetbrains.kotlin.types.Variance.INVARIANT
class JavaSymbolProvider( class JavaSymbolProvider(
val session: FirSession, val session: FirSession,
@@ -98,6 +103,35 @@ class JavaSymbolProvider(
} }
} }
private fun JavaTypeParameter.toFirTypeParameter(javaTypeParameterStack: JavaTypeParameterStack): FirTypeParameter {
val stored = javaTypeParameterStack.safeGet(this)
if (stored != null) return stored.fir
val firSymbol = FirTypeParameterSymbol()
val result = FirTypeParameterImpl(session, null, firSymbol, name, variance = INVARIANT, isReified = false)
javaTypeParameterStack.add(this, result)
return result
}
private fun FirTypeParameter.addBounds(
javaTypeParameter: JavaTypeParameter,
stack: JavaTypeParameterStack
) {
require(this is FirTypeParameterImpl)
for (upperBound in javaTypeParameter.upperBounds) {
bounds += upperBound.toFirResolvedTypeRef(this@JavaSymbolProvider.session, stack)
}
}
private fun List<JavaTypeParameter>.convertTypeParameters(stack: JavaTypeParameterStack): List<FirTypeParameter> {
return this
.map { it.toFirTypeParameter(stack) }
.also {
it.forEachIndexed { index, typeParameter ->
typeParameter.addBounds(this[index], stack)
}
}
}
override fun getClassLikeSymbolByFqName(classId: ClassId): ConeClassLikeSymbol? { override fun getClassLikeSymbolByFqName(classId: ClassId): ConeClassLikeSymbol? {
if (!hasTopLevelClassOf(classId)) return null if (!hasTopLevelClassOf(classId)) return null
return classCache.lookupCacheOrCalculateWithPostCompute(classId, { return classCache.lookupCacheOrCalculateWithPostCompute(classId, {
@@ -109,18 +143,28 @@ class JavaSymbolProvider(
} }
}) { firSymbol, foundClass -> }) { firSymbol, foundClass ->
foundClass?.let { javaClass -> foundClass?.let { javaClass ->
val javaTypeParameterStack = JavaTypeParameterStack()
val parentFqName = classId.relativeClassName.parent()
val isTopLevel = parentFqName.isRoot
if (!isTopLevel) {
val parentId = ClassId(classId.packageFqName, parentFqName, false)
val parentClassSymbol = getClassLikeSymbolByFqName(parentId) as? FirClassSymbol
val parentClass = parentClassSymbol?.fir
if (parentClass is FirJavaClass) {
javaTypeParameterStack.addStack(parentClass.javaTypeParameterStack)
}
}
FirJavaClass( FirJavaClass(
session, firSymbol as FirClassSymbol, javaClass.name, session, firSymbol as FirClassSymbol, javaClass.name,
javaClass.visibility, javaClass.modality, javaClass.visibility, javaClass.modality,
javaClass.classKind, javaClass.classKind, isTopLevel = isTopLevel,
isTopLevel = classId.relativeClassName.parent().isRoot, isStatic = javaClass.isStatic isStatic = javaClass.isStatic,
javaTypeParameterStack = javaTypeParameterStack
).apply { ).apply {
for (typeParameter in javaClass.typeParameters) { this.typeParameters += foundClass.typeParameters.convertTypeParameters(javaTypeParameterStack)
typeParameters += createTypeParameterSymbol(this@JavaSymbolProvider.session, typeParameter.name).fir addAnnotationsFrom(this@JavaSymbolProvider.session, javaClass, javaTypeParameterStack)
}
addAnnotationsFrom(this@JavaSymbolProvider.session, javaClass)
for (supertype in javaClass.supertypes) { for (supertype in javaClass.supertypes) {
superTypeRefs += supertype.toFirResolvedTypeRef(this@JavaSymbolProvider.session) superTypeRefs += supertype.toFirResolvedTypeRef(this@JavaSymbolProvider.session, javaTypeParameterStack)
} }
// TODO: may be we can process fields & methods later. // TODO: may be we can process fields & methods later.
// However, they should be built up to override resolve stage // However, they should be built up to override resolve stage
@@ -132,11 +176,11 @@ class JavaSymbolProvider(
val firJavaField = FirJavaField( val firJavaField = FirJavaField(
this@JavaSymbolProvider.session, fieldSymbol, fieldName, this@JavaSymbolProvider.session, fieldSymbol, fieldName,
javaField.visibility, javaField.modality, javaField.visibility, javaField.modality,
returnTypeRef = returnType.toFirJavaTypeRef(this@JavaSymbolProvider.session), returnTypeRef = returnType.toFirJavaTypeRef(this@JavaSymbolProvider.session, javaTypeParameterStack),
isVar = !javaField.isFinal, isVar = !javaField.isFinal,
isStatic = javaField.isStatic isStatic = javaField.isStatic
).apply { ).apply {
addAnnotationsFrom(this@JavaSymbolProvider.session, javaField) addAnnotationsFrom(this@JavaSymbolProvider.session, javaField, javaTypeParameterStack)
} }
declarations += firJavaField declarations += firJavaField
} }
@@ -148,15 +192,15 @@ class JavaSymbolProvider(
val firJavaMethod = FirJavaMethod( val firJavaMethod = FirJavaMethod(
this@JavaSymbolProvider.session, methodSymbol, methodName, this@JavaSymbolProvider.session, methodSymbol, methodName,
javaMethod.visibility, javaMethod.modality, javaMethod.visibility, javaMethod.modality,
returnTypeRef = returnType.toFirJavaTypeRef(this@JavaSymbolProvider.session), returnTypeRef = returnType.toFirJavaTypeRef(this@JavaSymbolProvider.session, javaTypeParameterStack),
isStatic = javaMethod.isStatic isStatic = javaMethod.isStatic
).apply { ).apply {
for (typeParameter in javaMethod.typeParameters) { this.typeParameters += javaMethod.typeParameters.convertTypeParameters(javaTypeParameterStack)
typeParameters += createTypeParameterSymbol(this@JavaSymbolProvider.session, typeParameter.name).fir addAnnotationsFrom(this@JavaSymbolProvider.session, javaMethod, javaTypeParameterStack)
}
addAnnotationsFrom(this@JavaSymbolProvider.session, javaMethod)
for (valueParameter in javaMethod.valueParameters) { for (valueParameter in javaMethod.valueParameters) {
valueParameters += valueParameter.toFirValueParameters(this@JavaSymbolProvider.session) valueParameters += valueParameter.toFirValueParameters(
this@JavaSymbolProvider.session, javaTypeParameterStack
)
} }
} }
declarations += firJavaMethod declarations += firJavaMethod
@@ -164,12 +208,8 @@ class JavaSymbolProvider(
for (javaConstructor in javaClass.constructors) { for (javaConstructor in javaClass.constructors) {
val constructorId = CallableId(classId.packageFqName, classId.relativeClassName, classId.shortClassName) val constructorId = CallableId(classId.packageFqName, classId.relativeClassName, classId.shortClassName)
val constructorSymbol = FirFunctionSymbol(constructorId) val constructorSymbol = FirFunctionSymbol(constructorId)
val classTypeParameters = typeParameters.map { val classTypeParameters = javaClass.typeParameters.convertTypeParameters(javaTypeParameterStack)
createTypeParameterSymbol(this@JavaSymbolProvider.session, it.name).fir val constructorTypeParameters = javaConstructor.typeParameters.convertTypeParameters(javaTypeParameterStack)
}
val constructorTypeParameters = javaConstructor.typeParameters.map {
createTypeParameterSymbol(this@JavaSymbolProvider.session, it.name).fir
}
val typeParameters = classTypeParameters + constructorTypeParameters val typeParameters = classTypeParameters + constructorTypeParameters
val firJavaConstructor = FirJavaConstructor( val firJavaConstructor = FirJavaConstructor(
this@JavaSymbolProvider.session, constructorSymbol, javaConstructor.visibility, this@JavaSymbolProvider.session, constructorSymbol, javaConstructor.visibility,
@@ -182,9 +222,11 @@ class JavaSymbolProvider(
) )
).apply { ).apply {
this.typeParameters += typeParameters this.typeParameters += typeParameters
addAnnotationsFrom(this@JavaSymbolProvider.session, javaConstructor) addAnnotationsFrom(this@JavaSymbolProvider.session, javaConstructor, javaTypeParameterStack)
for (valueParameter in javaConstructor.valueParameters) { for (valueParameter in javaConstructor.valueParameters) {
valueParameters += valueParameter.toFirValueParameters(this@JavaSymbolProvider.session) valueParameters += valueParameter.toFirValueParameters(
this@JavaSymbolProvider.session, javaTypeParameterStack
)
} }
} }
declarations += firJavaConstructor declarations += firJavaConstructor
@@ -0,0 +1,38 @@
/*
* Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.fir.java
import org.jetbrains.kotlin.fir.declarations.FirTypeParameter
import org.jetbrains.kotlin.fir.symbols.impl.FirTypeParameterSymbol
import org.jetbrains.kotlin.load.java.structure.JavaTypeParameter
internal class JavaTypeParameterStack {
private val typeParameterMap = mutableMapOf<JavaTypeParameter, FirTypeParameterSymbol>()
fun add(javaTypeParameter: JavaTypeParameter, firTypeParameter: FirTypeParameter) {
typeParameterMap[javaTypeParameter] = firTypeParameter.symbol
}
fun addStack(javaTypeParameterStack: JavaTypeParameterStack) {
typeParameterMap += javaTypeParameterStack.typeParameterMap
}
fun remove(javaTypeParameter: JavaTypeParameter) {
typeParameterMap.remove(javaTypeParameter)
}
operator fun get(javaTypeParameter: JavaTypeParameter): FirTypeParameterSymbol {
return safeGet(javaTypeParameter)
?: throw IllegalArgumentException("Cannot find Java type parameter $javaTypeParameter in stack")
}
fun safeGet(javaTypeParameter: JavaTypeParameter) = typeParameterMap[javaTypeParameter]
companion object {
val EMPTY: JavaTypeParameterStack = JavaTypeParameterStack()
}
}
@@ -10,7 +10,6 @@ import org.jetbrains.kotlin.descriptors.Modality
import org.jetbrains.kotlin.fir.FirSession import org.jetbrains.kotlin.fir.FirSession
import org.jetbrains.kotlin.fir.declarations.FirTypeParameter import org.jetbrains.kotlin.fir.declarations.FirTypeParameter
import org.jetbrains.kotlin.fir.declarations.FirValueParameter import org.jetbrains.kotlin.fir.declarations.FirValueParameter
import org.jetbrains.kotlin.fir.declarations.impl.FirTypeParameterImpl
import org.jetbrains.kotlin.fir.expressions.FirAnnotationCall import org.jetbrains.kotlin.fir.expressions.FirAnnotationCall
import org.jetbrains.kotlin.fir.expressions.FirArrayOfCall import org.jetbrains.kotlin.fir.expressions.FirArrayOfCall
import org.jetbrains.kotlin.fir.expressions.FirExpression import org.jetbrains.kotlin.fir.expressions.FirExpression
@@ -26,7 +25,6 @@ import org.jetbrains.kotlin.fir.service
import org.jetbrains.kotlin.fir.symbols.ConeClassLikeLookupTagImpl import org.jetbrains.kotlin.fir.symbols.ConeClassLikeLookupTagImpl
import org.jetbrains.kotlin.fir.symbols.StandardClassIds import org.jetbrains.kotlin.fir.symbols.StandardClassIds
import org.jetbrains.kotlin.fir.symbols.impl.FirClassSymbol import org.jetbrains.kotlin.fir.symbols.impl.FirClassSymbol
import org.jetbrains.kotlin.fir.symbols.impl.FirTypeParameterSymbol
import org.jetbrains.kotlin.fir.types.* import org.jetbrains.kotlin.fir.types.*
import org.jetbrains.kotlin.fir.types.impl.ConeClassTypeImpl import org.jetbrains.kotlin.fir.types.impl.ConeClassTypeImpl
import org.jetbrains.kotlin.fir.types.impl.ConeTypeParameterTypeImpl import org.jetbrains.kotlin.fir.types.impl.ConeTypeParameterTypeImpl
@@ -34,7 +32,6 @@ import org.jetbrains.kotlin.fir.types.impl.FirResolvedTypeRefImpl
import org.jetbrains.kotlin.ir.expressions.IrConstKind import org.jetbrains.kotlin.ir.expressions.IrConstKind
import org.jetbrains.kotlin.load.java.structure.* import org.jetbrains.kotlin.load.java.structure.*
import org.jetbrains.kotlin.name.ClassId import org.jetbrains.kotlin.name.ClassId
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.types.Variance.* import org.jetbrains.kotlin.types.Variance.*
@@ -61,37 +58,48 @@ internal fun ClassId.toConeKotlinType(
return ConeClassTypeImpl(lookupTag, typeArguments, isNullable) return ConeClassTypeImpl(lookupTag, typeArguments, isNullable)
} }
internal fun FirTypeRef.toNotNullConeKotlinType(session: FirSession): ConeKotlinType = internal fun FirTypeRef.toNotNullConeKotlinType(
session: FirSession, javaTypeParameterStack: JavaTypeParameterStack
): ConeKotlinType =
when (this) { when (this) {
is FirResolvedTypeRef -> type is FirResolvedTypeRef -> type
is FirJavaTypeRef -> { is FirJavaTypeRef -> {
val javaType = type val javaType = type
javaType.toNotNullConeKotlinType(session) javaType.toNotNullConeKotlinType(session, javaTypeParameterStack)
} }
else -> ConeKotlinErrorType("Unexpected type reference in JavaClassUseSiteScope: ${this::class.java}") else -> ConeKotlinErrorType("Unexpected type reference in JavaClassUseSiteScope: ${this::class.java}")
} }
internal fun JavaType?.toNotNullConeKotlinType(session: FirSession): ConeLookupTagBasedType { internal fun JavaType?.toNotNullConeKotlinType(
return toConeKotlinTypeWithNullability(session, isNullable = false) session: FirSession, javaTypeParameterStack: JavaTypeParameterStack
): ConeLookupTagBasedType {
return toConeKotlinTypeWithNullability(session, javaTypeParameterStack, isNullable = false)
} }
internal fun JavaType.toFirJavaTypeRef(session: FirSession): FirJavaTypeRef { internal fun JavaType.toFirJavaTypeRef(session: FirSession, javaTypeParameterStack: JavaTypeParameterStack): FirJavaTypeRef {
val annotations = (this as? JavaClassifierType)?.annotations.orEmpty() val annotations = (this as? JavaClassifierType)?.annotations.orEmpty()
return FirJavaTypeRef(session, annotations = annotations.map { it.toFirAnnotationCall(session) }, type = this) return FirJavaTypeRef(
} session,
annotations = annotations.map { it.toFirAnnotationCall(session, javaTypeParameterStack) }, type = this
internal fun JavaClassifierType.toFirResolvedTypeRef(session: FirSession): FirResolvedTypeRef {
val coneType = this.toConeKotlinTypeWithNullability(session, isNullable = false)
return FirResolvedTypeRefImpl(
session, psi = null, type = coneType,
isMarkedNullable = false, annotations = annotations.map { it.toFirAnnotationCall(session) }
) )
} }
internal fun JavaType?.toConeKotlinTypeWithNullability(session: FirSession, isNullable: Boolean): ConeLookupTagBasedType { internal fun JavaClassifierType.toFirResolvedTypeRef(
session: FirSession, javaTypeParameterStack: JavaTypeParameterStack
): FirResolvedTypeRef {
val coneType = this.toConeKotlinTypeWithNullability(session, javaTypeParameterStack, isNullable = false)
return FirResolvedTypeRefImpl(
session, psi = null, type = coneType, isMarkedNullable = false,
annotations = annotations.map { it.toFirAnnotationCall(session, javaTypeParameterStack) }
)
}
internal fun JavaType?.toConeKotlinTypeWithNullability(
session: FirSession, javaTypeParameterStack: JavaTypeParameterStack, isNullable: Boolean
): ConeLookupTagBasedType {
return when (this) { return when (this) {
is JavaClassifierType -> { is JavaClassifierType -> {
toConeKotlinTypeWithNullability(session, isNullable) toConeKotlinTypeWithNullability(session, isNullable, javaTypeParameterStack)
} }
is JavaPrimitiveType -> { is JavaPrimitiveType -> {
val primitiveType = type val primitiveType = type
@@ -107,8 +115,8 @@ internal fun JavaType?.toConeKotlinTypeWithNullability(session: FirSession, isNu
if (componentType !is JavaPrimitiveType) { if (componentType !is JavaPrimitiveType) {
val classId = StandardClassIds.Array val classId = StandardClassIds.Array
val argumentType = ConeFlexibleType( val argumentType = ConeFlexibleType(
componentType.toConeKotlinTypeWithNullability(session, isNullable = false), componentType.toConeKotlinTypeWithNullability(session, javaTypeParameterStack, isNullable = false),
componentType.toConeKotlinTypeWithNullability(session, isNullable = true) componentType.toConeKotlinTypeWithNullability(session, javaTypeParameterStack, isNullable = true)
) )
classId.toConeKotlinType(arrayOf(argumentType), isNullable) classId.toConeKotlinType(arrayOf(argumentType), isNullable)
} else { } else {
@@ -117,7 +125,7 @@ internal fun JavaType?.toConeKotlinTypeWithNullability(session: FirSession, isNu
classId.toConeKotlinType(emptyArray(), isNullable) classId.toConeKotlinType(emptyArray(), isNullable)
} }
} }
is JavaWildcardType -> bound?.toNotNullConeKotlinType(session) ?: run { is JavaWildcardType -> bound?.toNotNullConeKotlinType(session, javaTypeParameterStack) ?: run {
val classId = StandardClassIds.Any val classId = StandardClassIds.Any
classId.toConeKotlinType(emptyArray(), isNullable) classId.toConeKotlinType(emptyArray(), isNullable)
} }
@@ -129,7 +137,9 @@ internal fun JavaType?.toConeKotlinTypeWithNullability(session: FirSession, isNu
} }
} }
internal fun JavaClassifierType.toConeKotlinTypeWithNullability(session: FirSession, isNullable: Boolean): ConeLookupTagBasedType { internal fun JavaClassifierType.toConeKotlinTypeWithNullability(
session: FirSession, isNullable: Boolean, javaTypeParameterStack: JavaTypeParameterStack
): ConeLookupTagBasedType {
return when (val classifier = classifier) { return when (val classifier = classifier) {
is JavaClass -> { is JavaClass -> {
val classId = classifier.classId!! val classId = classifier.classId!!
@@ -137,29 +147,23 @@ internal fun JavaClassifierType.toConeKotlinTypeWithNullability(session: FirSess
lookupTag.constructClassType( lookupTag.constructClassType(
typeArguments.mapIndexed { index, argument -> typeArguments.mapIndexed { index, argument ->
argument.toConeProjection( argument.toConeProjection(
session, null session, javaTypeParameterStack, null
//symbol.fir.typeParameters.getOrNull(index) //symbol.fir.typeParameters.getOrNull(index)
) )
}.toTypedArray(), isNullable }.toTypedArray(), isNullable
) )
} }
is JavaTypeParameter -> { is JavaTypeParameter -> {
// TODO: it's unclear how to identify type parameter by the symbol val symbol = javaTypeParameterStack[classifier]
// TODO: some type parameter cache (provider?)
val symbol = createTypeParameterSymbol(session, classifier.name)
ConeTypeParameterTypeImpl(symbol, isNullable) ConeTypeParameterTypeImpl(symbol, isNullable)
} }
else -> ConeClassErrorType(reason = "Unexpected classifier: $classifier") else -> ConeClassErrorType(reason = "Unexpected classifier: $classifier")
} }
} }
internal fun createTypeParameterSymbol(session: FirSession, name: Name): FirTypeParameterSymbol { internal fun JavaAnnotation.toFirAnnotationCall(
val firSymbol = FirTypeParameterSymbol() session: FirSession, javaTypeParameterStack: JavaTypeParameterStack
FirTypeParameterImpl(session, null, firSymbol, name, variance = INVARIANT, isReified = false) ): FirAnnotationCall {
return firSymbol
}
internal fun JavaAnnotation.toFirAnnotationCall(session: FirSession): FirAnnotationCall {
return FirAnnotationCallImpl( return FirAnnotationCallImpl(
session, psi = null, useSiteTarget = null, session, psi = null, useSiteTarget = null,
annotationTypeRef = FirResolvedTypeRefImpl( annotationTypeRef = FirResolvedTypeRefImpl(
@@ -171,28 +175,34 @@ internal fun JavaAnnotation.toFirAnnotationCall(session: FirSession): FirAnnotat
) )
).apply { ).apply {
for (argument in this@toFirAnnotationCall.arguments) { for (argument in this@toFirAnnotationCall.arguments) {
arguments += argument.toFirExpression(session) arguments += argument.toFirExpression(session, javaTypeParameterStack)
} }
} }
} }
internal fun FirAbstractAnnotatedElement.addAnnotationsFrom(session: FirSession, javaAnnotationOwner: JavaAnnotationOwner) { internal fun FirAbstractAnnotatedElement.addAnnotationsFrom(
session: FirSession, javaAnnotationOwner: JavaAnnotationOwner, javaTypeParameterStack: JavaTypeParameterStack
) {
for (annotation in javaAnnotationOwner.annotations) { for (annotation in javaAnnotationOwner.annotations) {
annotations += annotation.toFirAnnotationCall(session) annotations += annotation.toFirAnnotationCall(session, javaTypeParameterStack)
} }
} }
internal fun JavaValueParameter.toFirValueParameters(session: FirSession): FirValueParameter { internal fun JavaValueParameter.toFirValueParameters(
session: FirSession, javaTypeParameterStack: JavaTypeParameterStack
): FirValueParameter {
return FirJavaValueParameter( return FirJavaValueParameter(
session, name ?: Name.special("<anonymous Java parameter>"), session, name ?: Name.special("<anonymous Java parameter>"),
returnTypeRef = type.toFirJavaTypeRef(session), returnTypeRef = type.toFirJavaTypeRef(session, javaTypeParameterStack),
isVararg = isVararg isVararg = isVararg
).apply { ).apply {
addAnnotationsFrom(session, this@toFirValueParameters) addAnnotationsFrom(session, this@toFirValueParameters, javaTypeParameterStack)
} }
} }
internal fun JavaType?.toConeProjection(session: FirSession, boundTypeParameter: FirTypeParameter?): ConeKotlinTypeProjection { internal fun JavaType?.toConeProjection(
session: FirSession, javaTypeParameterStack: JavaTypeParameterStack, boundTypeParameter: FirTypeParameter?
): ConeKotlinTypeProjection {
return when (this) { return when (this) {
null -> ConeStarProjection null -> ConeStarProjection
is JavaWildcardType -> { is JavaWildcardType -> {
@@ -202,7 +212,7 @@ internal fun JavaType?.toConeProjection(session: FirSession, boundTypeParameter:
if (bound == null || parameterVariance != INVARIANT && parameterVariance != argumentVariance) { if (bound == null || parameterVariance != INVARIANT && parameterVariance != argumentVariance) {
ConeStarProjection ConeStarProjection
} else { } else {
val boundType = bound.toConeKotlinTypeWithNullability(session, isNullable = false) val boundType = bound.toConeKotlinTypeWithNullability(session, javaTypeParameterStack, isNullable = false)
if (argumentVariance == OUT_VARIANCE) { if (argumentVariance == OUT_VARIANCE) {
ConeKotlinTypeProjectionOut(boundType) ConeKotlinTypeProjectionOut(boundType)
} else { } else {
@@ -210,12 +220,14 @@ internal fun JavaType?.toConeProjection(session: FirSession, boundTypeParameter:
} }
} }
} }
is JavaClassifierType -> toConeKotlinTypeWithNullability(session, isNullable = false) is JavaClassifierType -> toConeKotlinTypeWithNullability(session, javaTypeParameterStack, isNullable = false)
else -> ConeClassErrorType("Unexpected type argument: $this") else -> ConeClassErrorType("Unexpected type argument: $this")
} }
} }
private fun JavaAnnotationArgument.toFirExpression(session: FirSession): FirExpression { private fun JavaAnnotationArgument.toFirExpression(
session: FirSession, javaTypeParameterStack: JavaTypeParameterStack
): FirExpression {
// TODO: this.name // TODO: this.name
return when (this) { return when (this) {
is JavaLiteralAnnotationArgument -> { is JavaLiteralAnnotationArgument -> {
@@ -233,7 +245,7 @@ private fun JavaAnnotationArgument.toFirExpression(session: FirSession): FirExpr
} }
is JavaArrayAnnotationArgument -> FirArrayOfCallImpl(session, null).apply { is JavaArrayAnnotationArgument -> FirArrayOfCallImpl(session, null).apply {
for (element in getElements()) { for (element in getElements()) {
arguments += element.toFirExpression(session) arguments += element.toFirExpression(session, javaTypeParameterStack)
} }
} }
is JavaEnumValueAnnotationArgument -> { is JavaEnumValueAnnotationArgument -> {
@@ -256,9 +268,11 @@ private fun JavaAnnotationArgument.toFirExpression(session: FirSession): FirExpr
} }
is JavaClassObjectAnnotationArgument -> FirGetClassCallImpl(session, null).apply { is JavaClassObjectAnnotationArgument -> FirGetClassCallImpl(session, null).apply {
val referencedType = getReferencedType() val referencedType = getReferencedType()
arguments += FirClassReferenceExpressionImpl(session, null, referencedType.toFirResolvedTypeRef(session)) arguments += FirClassReferenceExpressionImpl(
session, null, referencedType.toFirResolvedTypeRef(session, javaTypeParameterStack)
)
} }
is JavaAnnotationAsAnnotationArgument -> getAnnotation().toFirAnnotationCall(session) is JavaAnnotationAsAnnotationArgument -> getAnnotation().toFirAnnotationCall(session, javaTypeParameterStack)
else -> FirErrorExpressionImpl(session, null, "Unknown JavaAnnotationArgument: ${this::class.java}") else -> FirErrorExpressionImpl(session, null, "Unknown JavaAnnotationArgument: ${this::class.java}")
} }
} }
@@ -289,8 +303,10 @@ private fun Any?.createConstant(session: FirSession): FirExpression {
} }
} }
private fun JavaType.toFirResolvedTypeRef(session: FirSession): FirResolvedTypeRef { private fun JavaType.toFirResolvedTypeRef(
if (this is JavaClassifierType) return toFirResolvedTypeRef(session) session: FirSession, javaTypeParameterStack: JavaTypeParameterStack
): FirResolvedTypeRef {
if (this is JavaClassifierType) return toFirResolvedTypeRef(session, javaTypeParameterStack)
return FirResolvedTypeRefImpl( return FirResolvedTypeRefImpl(
session, psi = null, type = ConeClassErrorType("Unexpected JavaType: $this"), session, psi = null, type = ConeClassErrorType("Unexpected JavaType: $this"),
isMarkedNullable = false, annotations = emptyList() isMarkedNullable = false, annotations = emptyList()
@@ -13,11 +13,12 @@ import org.jetbrains.kotlin.fir.declarations.FirDeclaration
import org.jetbrains.kotlin.fir.declarations.FirRegularClass import org.jetbrains.kotlin.fir.declarations.FirRegularClass
import org.jetbrains.kotlin.fir.declarations.impl.FirAbstractMemberDeclaration import org.jetbrains.kotlin.fir.declarations.impl.FirAbstractMemberDeclaration
import org.jetbrains.kotlin.fir.declarations.impl.FirModifiableClass import org.jetbrains.kotlin.fir.declarations.impl.FirModifiableClass
import org.jetbrains.kotlin.fir.java.JavaTypeParameterStack
import org.jetbrains.kotlin.fir.symbols.impl.FirClassSymbol import org.jetbrains.kotlin.fir.symbols.impl.FirClassSymbol
import org.jetbrains.kotlin.fir.types.FirTypeRef import org.jetbrains.kotlin.fir.types.FirTypeRef
import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.name.Name
class FirJavaClass( class FirJavaClass internal constructor(
session: FirSession, session: FirSession,
override val symbol: FirClassSymbol, override val symbol: FirClassSymbol,
name: Name, name: Name,
@@ -25,7 +26,8 @@ class FirJavaClass(
modality: Modality?, modality: Modality?,
override val classKind: ClassKind, override val classKind: ClassKind,
isTopLevel: Boolean, isTopLevel: Boolean,
isStatic: Boolean isStatic: Boolean,
internal val javaTypeParameterStack: JavaTypeParameterStack
) : FirAbstractMemberDeclaration( ) : FirAbstractMemberDeclaration(
session, psi = null, name = name, session, psi = null, name = name,
visibility = visibility, modality = modality, visibility = visibility, modality = modality,
@@ -11,6 +11,7 @@ import org.jetbrains.kotlin.fir.declarations.FirValueParameter
import org.jetbrains.kotlin.fir.expressions.FirAnnotationCall import org.jetbrains.kotlin.fir.expressions.FirAnnotationCall
import org.jetbrains.kotlin.fir.expressions.FirAnnotationContainer import org.jetbrains.kotlin.fir.expressions.FirAnnotationContainer
import org.jetbrains.kotlin.fir.expressions.resolvedFqName import org.jetbrains.kotlin.fir.expressions.resolvedFqName
import org.jetbrains.kotlin.fir.java.JavaTypeParameterStack
import org.jetbrains.kotlin.fir.java.toConeKotlinTypeWithNullability import org.jetbrains.kotlin.fir.java.toConeKotlinTypeWithNullability
import org.jetbrains.kotlin.fir.java.toFirJavaTypeRef import org.jetbrains.kotlin.fir.java.toFirJavaTypeRef
import org.jetbrains.kotlin.fir.java.toNotNullConeKotlinType import org.jetbrains.kotlin.fir.java.toNotNullConeKotlinType
@@ -30,6 +31,7 @@ import org.jetbrains.kotlin.utils.addToStdlib.safeAs
internal class EnhancementSignatureParts( internal class EnhancementSignatureParts(
private val typeQualifierResolver: FirAnnotationTypeQualifierResolver, private val typeQualifierResolver: FirAnnotationTypeQualifierResolver,
private val typeContainer: FirAnnotationContainer?, private val typeContainer: FirAnnotationContainer?,
private val javaTypeParameterStack: JavaTypeParameterStack,
private val current: FirJavaTypeRef, private val current: FirJavaTypeRef,
private val fromOverridden: Collection<FirTypeRef>, private val fromOverridden: Collection<FirTypeRef>,
private val isCovariant: Boolean, private val isCovariant: Boolean,
@@ -54,7 +56,7 @@ internal class EnhancementSignatureParts(
} }
} }
val containsFunctionN = current.toNotNullConeKotlinType(session).contains { val containsFunctionN = current.toNotNullConeKotlinType(session, javaTypeParameterStack).contains {
if (it is ConeClassErrorType) false if (it is ConeClassErrorType) false
else { else {
val classId = it.lookupTag.classId val classId = it.lookupTag.classId
@@ -63,7 +65,7 @@ internal class EnhancementSignatureParts(
} }
} }
val enhancedCurrent = current.enhance(session, qualifiersWithPredefined ?: qualifiers) val enhancedCurrent = current.enhance(session, javaTypeParameterStack, qualifiersWithPredefined ?: qualifiers)
return PartEnhancementResult( return PartEnhancementResult(
enhancedCurrent, wereChanges = true, containsFunctionN = containsFunctionN enhancedCurrent, wereChanges = true, containsFunctionN = containsFunctionN
) )
@@ -100,7 +102,7 @@ internal class EnhancementSignatureParts(
if (arg is JavaWildcardType || arg == null) { if (arg is JavaWildcardType || arg == null) {
add(null) add(null)
} else { } else {
add(arg.toFirJavaTypeRef(context.session)) add(arg.toFirJavaTypeRef(context.session, javaTypeParameterStack))
} }
} }
} else if (type != null) { } else if (type != null) {
@@ -148,8 +150,8 @@ internal class EnhancementSignatureParts(
is FirJavaTypeRef -> { is FirJavaTypeRef -> {
Pair( Pair(
// TODO: optimize // TODO: optimize
type.toConeKotlinTypeWithNullability(session, isNullable = false), type.toConeKotlinTypeWithNullability(session, javaTypeParameterStack, isNullable = false),
type.toConeKotlinTypeWithNullability(session, isNullable = true) type.toConeKotlinTypeWithNullability(session, javaTypeParameterStack, isNullable = true)
) )
} }
else -> return JavaTypeQualifiers.NONE else -> return JavaTypeQualifiers.NONE
@@ -13,7 +13,7 @@ import org.jetbrains.kotlin.fir.declarations.*
import org.jetbrains.kotlin.fir.expressions.* import org.jetbrains.kotlin.fir.expressions.*
import org.jetbrains.kotlin.fir.expressions.impl.FirConstExpressionImpl import org.jetbrains.kotlin.fir.expressions.impl.FirConstExpressionImpl
import org.jetbrains.kotlin.fir.expressions.impl.FirQualifiedAccessExpressionImpl import org.jetbrains.kotlin.fir.expressions.impl.FirQualifiedAccessExpressionImpl
import org.jetbrains.kotlin.fir.java.createTypeParameterSymbol import org.jetbrains.kotlin.fir.java.JavaTypeParameterStack
import org.jetbrains.kotlin.fir.java.declarations.FirJavaClass import org.jetbrains.kotlin.fir.java.declarations.FirJavaClass
import org.jetbrains.kotlin.fir.java.declarations.FirJavaField import org.jetbrains.kotlin.fir.java.declarations.FirJavaField
import org.jetbrains.kotlin.fir.java.toConeProjection import org.jetbrains.kotlin.fir.java.toConeProjection
@@ -51,8 +51,12 @@ internal class IndexedJavaTypeQualifiers(private val data: Array<JavaTypeQualifi
val size: Int get() = data.size val size: Int get() = data.size
} }
internal fun FirJavaTypeRef.enhance(session: FirSession, qualifiers: IndexedJavaTypeQualifiers): FirResolvedTypeRef { internal fun FirJavaTypeRef.enhance(
return type.enhancePossiblyFlexible(session, annotations, qualifiers, 0) session: FirSession,
javaTypeParameterStack: JavaTypeParameterStack,
qualifiers: IndexedJavaTypeQualifiers
): FirResolvedTypeRef {
return type.enhancePossiblyFlexible(session, javaTypeParameterStack, annotations, qualifiers, 0)
} }
// The index in the lambda is the position of the type component: // The index in the lambda is the position of the type component:
@@ -61,6 +65,7 @@ internal fun FirJavaTypeRef.enhance(session: FirSession, qualifiers: IndexedJava
// For flexible types, both bounds are indexed in the same way: `(A<B>..C<D>)` gives `0 - (A<B>..C<D>), 1 - B and D`. // For flexible types, both bounds are indexed in the same way: `(A<B>..C<D>)` gives `0 - (A<B>..C<D>), 1 - B and D`.
private fun JavaType?.enhancePossiblyFlexible( private fun JavaType?.enhancePossiblyFlexible(
session: FirSession, session: FirSession,
javaTypeParameterStack: JavaTypeParameterStack,
annotations: List<FirAnnotationCall>, annotations: List<FirAnnotationCall>,
qualifiers: IndexedJavaTypeQualifiers, qualifiers: IndexedJavaTypeQualifiers,
index: Int index: Int
@@ -70,10 +75,10 @@ private fun JavaType?.enhancePossiblyFlexible(
return when (type) { return when (type) {
is JavaClassifierType -> { is JavaClassifierType -> {
val lowerResult = type.enhanceInflexibleType( val lowerResult = type.enhanceInflexibleType(
session, annotations, arguments, TypeComponentPosition.FLEXIBLE_LOWER, qualifiers, index session, javaTypeParameterStack, annotations, arguments, TypeComponentPosition.FLEXIBLE_LOWER, qualifiers, index
) )
val upperResult = type.enhanceInflexibleType( val upperResult = type.enhanceInflexibleType(
session, annotations, arguments, TypeComponentPosition.FLEXIBLE_UPPER, qualifiers, index session, javaTypeParameterStack, annotations, arguments, TypeComponentPosition.FLEXIBLE_UPPER, qualifiers, index
) )
FirResolvedTypeRefImpl( FirResolvedTypeRefImpl(
@@ -83,7 +88,7 @@ private fun JavaType?.enhancePossiblyFlexible(
) )
} }
else -> { else -> {
val enhanced = type.toNotNullConeKotlinType(session) val enhanced = type.toNotNullConeKotlinType(session, javaTypeParameterStack)
FirResolvedTypeRefImpl(session, psi = null, type = enhanced, isMarkedNullable = false, annotations = annotations) FirResolvedTypeRefImpl(session, psi = null, type = enhanced, isMarkedNullable = false, annotations = annotations)
} }
} }
@@ -125,6 +130,7 @@ private fun ClassId.mutableToReadOnly(): ClassId? {
private fun JavaClassifierType.enhanceInflexibleType( private fun JavaClassifierType.enhanceInflexibleType(
session: FirSession, session: FirSession,
javaTypeParameterStack: JavaTypeParameterStack,
annotations: List<FirAnnotationCall>, annotations: List<FirAnnotationCall>,
arguments: List<JavaType?>, arguments: List<JavaType?>,
position: TypeComponentPosition, position: TypeComponentPosition,
@@ -143,8 +149,8 @@ private fun JavaClassifierType.enhanceInflexibleType(
val kotlinClassId = mappedId ?: classId val kotlinClassId = mappedId ?: classId
ConeClassLikeLookupTagImpl(kotlinClassId) ConeClassLikeLookupTagImpl(kotlinClassId)
} }
is JavaTypeParameter -> createTypeParameterSymbol(session, classifier.name) is JavaTypeParameter -> javaTypeParameterStack[classifier]
else -> return toNotNullConeKotlinType(session) else -> return toNotNullConeKotlinType(session, javaTypeParameterStack)
} }
val effectiveQualifiers = qualifiers(index) val effectiveQualifiers = qualifiers(index)
@@ -156,10 +162,11 @@ private fun JavaClassifierType.enhanceInflexibleType(
globalArgIndex++ globalArgIndex++
arg.toConeProjection( arg.toConeProjection(
session, session,
javaTypeParameterStack,
((originalTag as? FirBasedSymbol<*>)?.fir as? FirCallableMemberDeclaration)?.typeParameters?.getOrNull(localArgIndex) ((originalTag as? FirBasedSymbol<*>)?.fir as? FirCallableMemberDeclaration)?.typeParameters?.getOrNull(localArgIndex)
) )
} else { } else {
val argEnhancedTypeRef = arg.enhancePossiblyFlexible(session, annotations, qualifiers, globalArgIndex) val argEnhancedTypeRef = arg.enhancePossiblyFlexible(session, javaTypeParameterStack, annotations, qualifiers, globalArgIndex)
globalArgIndex += arg.subtreeSize() globalArgIndex += arg.subtreeSize()
argEnhancedTypeRef.type.type.toTypeProjection(Variance.INVARIANT) argEnhancedTypeRef.type.type.toTypeProjection(Variance.INVARIANT)
} }
@@ -11,10 +11,8 @@ import org.jetbrains.kotlin.fir.declarations.impl.*
import org.jetbrains.kotlin.fir.expressions.FirAnnotationContainer import org.jetbrains.kotlin.fir.expressions.FirAnnotationContainer
import org.jetbrains.kotlin.fir.expressions.FirExpression import org.jetbrains.kotlin.fir.expressions.FirExpression
import org.jetbrains.kotlin.fir.expressions.impl.FirConstExpressionImpl import org.jetbrains.kotlin.fir.expressions.impl.FirConstExpressionImpl
import org.jetbrains.kotlin.fir.java.declarations.FirJavaConstructor import org.jetbrains.kotlin.fir.java.JavaTypeParameterStack
import org.jetbrains.kotlin.fir.java.declarations.FirJavaField import org.jetbrains.kotlin.fir.java.declarations.*
import org.jetbrains.kotlin.fir.java.declarations.FirJavaMethod
import org.jetbrains.kotlin.fir.java.declarations.FirJavaValueParameter
import org.jetbrains.kotlin.fir.java.enhancement.* import org.jetbrains.kotlin.fir.java.enhancement.*
import org.jetbrains.kotlin.fir.java.enhancement.EnhancementSignatureParts import org.jetbrains.kotlin.fir.java.enhancement.EnhancementSignatureParts
import org.jetbrains.kotlin.fir.java.toNotNullConeKotlinType import org.jetbrains.kotlin.fir.java.toNotNullConeKotlinType
@@ -42,7 +40,10 @@ class JavaClassEnhancementScope(
private val session: FirSession, private val session: FirSession,
private val useSiteScope: JavaClassUseSiteScope private val useSiteScope: JavaClassUseSiteScope
) : FirScope { ) : FirScope {
private val owner: FirRegularClass get() = useSiteScope.symbol.fir private val owner: FirRegularClass = useSiteScope.symbol.fir
private val javaTypeParameterStack: JavaTypeParameterStack =
if (owner is FirJavaClass) owner.javaTypeParameterStack else JavaTypeParameterStack.EMPTY
private val jsr305State: Jsr305State = session.jsr305State ?: Jsr305State.DEFAULT private val jsr305State: Jsr305State = session.jsr305State ?: Jsr305State.DEFAULT
@@ -188,12 +189,14 @@ class JavaClassEnhancementScope(
newReceiverTypeRef, newReturnTypeRef newReceiverTypeRef, newReturnTypeRef
).apply { ).apply {
this.valueParameters += newValueParameters this.valueParameters += newValueParameters
this.typeParameters += firMethod.typeParameters
} }
else -> FirMemberFunctionImpl( else -> FirMemberFunctionImpl(
this@JavaClassEnhancementScope.session, null, symbol, name, this@JavaClassEnhancementScope.session, null, symbol, name,
newReceiverTypeRef, newReturnTypeRef newReceiverTypeRef, newReturnTypeRef
).apply { ).apply {
this.valueParameters += newValueParameters this.valueParameters += newValueParameters
this.typeParameters += firMethod.typeParameters
} }
} }
function.apply { function.apply {
@@ -226,7 +229,7 @@ class JavaClassEnhancementScope(
private fun StringBuilder.appendErasedType(typeRef: FirTypeRef) { private fun StringBuilder.appendErasedType(typeRef: FirTypeRef) {
when (typeRef) { when (typeRef) {
is FirResolvedTypeRef -> appendConeType(typeRef.type) is FirResolvedTypeRef -> appendConeType(typeRef.type)
is FirJavaTypeRef -> appendConeType(typeRef.toNotNullConeKotlinType(session)) is FirJavaTypeRef -> appendConeType(typeRef.toNotNullConeKotlinType(session, javaTypeParameterStack))
} }
} }
@@ -390,6 +393,7 @@ class JavaClassEnhancementScope(
return EnhancementSignatureParts( return EnhancementSignatureParts(
typeQualifierResolver, typeQualifierResolver,
typeContainer, typeContainer,
javaTypeParameterStack,
typeRef as FirJavaTypeRef, typeRef as FirJavaTypeRef,
overriddenMembers.map { overriddenMembers.map {
typeInSignature.getTypeRef(it) typeInSignature.getTypeRef(it)
@@ -9,6 +9,8 @@ import org.jetbrains.kotlin.builtins.jvm.JavaToKotlinClassMap
import org.jetbrains.kotlin.descriptors.Modality import org.jetbrains.kotlin.descriptors.Modality
import org.jetbrains.kotlin.fir.FirSession import org.jetbrains.kotlin.fir.FirSession
import org.jetbrains.kotlin.fir.declarations.* import org.jetbrains.kotlin.fir.declarations.*
import org.jetbrains.kotlin.fir.java.JavaTypeParameterStack
import org.jetbrains.kotlin.fir.java.declarations.FirJavaClass
import org.jetbrains.kotlin.fir.java.toNotNullConeKotlinType import org.jetbrains.kotlin.fir.java.toNotNullConeKotlinType
import org.jetbrains.kotlin.fir.resolve.transformers.firUnsafe import org.jetbrains.kotlin.fir.resolve.transformers.firUnsafe
import org.jetbrains.kotlin.fir.scopes.FirScope import org.jetbrains.kotlin.fir.scopes.FirScope
@@ -33,6 +35,9 @@ class JavaClassUseSiteScope(
) : FirAbstractProviderBasedScope(session, lookupInFir = true) { ) : FirAbstractProviderBasedScope(session, lookupInFir = true) {
internal val symbol = klass.symbol internal val symbol = klass.symbol
private val javaTypeParameterStack: JavaTypeParameterStack =
if (klass is FirJavaClass) klass.javaTypeParameterStack else JavaTypeParameterStack.EMPTY
//base symbol as key, overridden as value //base symbol as key, overridden as value
private val overriddenByBase = mutableMapOf<ConeCallableSymbol, ConeFunctionSymbol?>() private val overriddenByBase = mutableMapOf<ConeCallableSymbol, ConeFunctionSymbol?>()
@@ -54,7 +59,10 @@ class JavaClassUseSiteScope(
} }
private fun isEqualTypes(a: FirTypeRef, b: FirTypeRef) = private fun isEqualTypes(a: FirTypeRef, b: FirTypeRef) =
isEqualTypes(a.toNotNullConeKotlinType(session), b.toNotNullConeKotlinType(session)) isEqualTypes(
a.toNotNullConeKotlinType(session, javaTypeParameterStack),
b.toNotNullConeKotlinType(session, javaTypeParameterStack)
)
private fun isOverriddenFunCheck(overriddenInJava: FirFunction, base: FirFunction): Boolean { private fun isOverriddenFunCheck(overriddenInJava: FirFunction, base: FirFunction): Boolean {
val receiverTypeRef = (base as FirCallableMemberDeclaration).receiverTypeRef val receiverTypeRef = (base as FirCallableMemberDeclaration).receiverTypeRef
@@ -14,7 +14,7 @@ class FirJavaTypeRef(
session: FirSession, session: FirSession,
annotations: List<FirAnnotationCall>, annotations: List<FirAnnotationCall>,
val type: JavaType val type: JavaType
) : FirUserTypeRefImpl(session, psi = null,isMarkedNullable = false) { ) : FirUserTypeRefImpl(session, psi = null, isMarkedNullable = false) {
init { init {
this.annotations += annotations this.annotations += annotations
} }
@@ -1,2 +1,2 @@
public final class ClassWithTypePP<P, Q> : R|java/lang/Object| { public final class ClassWithTypePP<P, Q : R|P|> : R|java/lang/Object| {
} }
@@ -1,2 +1,2 @@
public open class ClassWithTypePRefNext<R, P> : R|java/lang/Object| { public open class ClassWithTypePRefNext<R : R|java/lang/Iterable<P>|, P> : R|java/lang/Object| {
} }
@@ -1,2 +1,2 @@
public final class ClassWithTypePRefSelf<P> : R|java/lang/Object| { public final class ClassWithTypePRefSelf<P : R|java/lang/Enum<P>|> : R|java/lang/Object| {
} }
@@ -1,2 +1,2 @@
public final class ClassWithTypePRefSelfAndClass<P> : R|java/lang/Object| { public final class ClassWithTypePRefSelfAndClass<P : R|test/ClassWithTypePRefSelfAndClass<P>|> : R|java/lang/Object| {
} }
@@ -1,4 +1,4 @@
public open class MethodTypePOneUpperBound : R|java/lang/Object| { public open class MethodTypePOneUpperBound : R|java/lang/Object| {
public open operator fun bar(): R|kotlin/Unit| public open operator fun <T : R|java/lang/Cloneable|> bar(): R|kotlin/Unit|
} }
@@ -1,4 +1,4 @@
public open class MethodTypePTwoUpperBounds : R|java/lang/Object| { public open class MethodTypePTwoUpperBounds : R|java/lang/Object| {
public open operator fun foo(): R|kotlin/Unit| public open operator fun <T : R|java/lang/Cloneable|, R|java/lang/Runnable|> foo(): R|kotlin/Unit|
} }
@@ -1,4 +1,4 @@
public final class MethodWithTypeP : R|java/lang/Object| { public final class MethodWithTypeP : R|java/lang/Object| {
public final operator fun f(): R|kotlin/Unit| public final operator fun <P> f(): R|kotlin/Unit|
} }
@@ -1,4 +1,4 @@
public final class MethodWithTypePP : R|java/lang/Object| { public final class MethodWithTypePP : R|java/lang/Object| {
public final operator fun f(): R|kotlin/Unit| public final operator fun <P, Q : R|P|> f(): R|kotlin/Unit|
} }
@@ -1,4 +1,4 @@
public open class MethodWithTypePRefClassP<P> : R|java/lang/Object| { public open class MethodWithTypePRefClassP<P> : R|java/lang/Object| {
public final operator fun f(): R|kotlin/Unit| public final operator fun <Q : R|P|> f(): R|kotlin/Unit|
} }
@@ -1,4 +1,4 @@
public final class MethosWithPRefTP : R|java/lang/Object| { public final class MethosWithPRefTP : R|java/lang/Object| {
public final operator fun f(p: R|ft<P, P?>|!): R|kotlin/Unit| public final operator fun <P> f(p: R|ft<P, P?>|!): R|kotlin/Unit|
} }
@@ -1,2 +1,2 @@
public abstract interface RawUpperBound<T> : R|java/lang/Object| { public abstract interface RawUpperBound<T : R|test/RawUpperBound<*>|> : R|java/lang/Object| {
} }
@@ -1,2 +1,2 @@
public abstract interface RecursiveRawUpperBound<T> : R|java/lang/Object| { public abstract interface RecursiveRawUpperBound<T : R|test/RecursiveRawUpperBound<*>|> : R|java/lang/Object| {
} }
@@ -1,2 +1,2 @@
public abstract interface RecursiveWildcardUpperBound<T> : R|java/lang/Object| { public abstract interface RecursiveWildcardUpperBound<T : R|test/RecursiveWildcardUpperBound<*>|> : R|java/lang/Object| {
} }
@@ -1,4 +1,4 @@
public open class ConstructorGenericDeep : R|java/lang/Object| { public open class ConstructorGenericDeep : R|java/lang/Object| {
public constructor(cl: R|ft<java/lang/Class<ft<P, P?>>, java/lang/Class<ft<P, P?>>?>|!): R|test/ConstructorGenericDeep| public constructor<P>(cl: R|ft<java/lang/Class<ft<P, P?>>, java/lang/Class<ft<P, P?>>?>|!): R|test/ConstructorGenericDeep|
} }
@@ -1,4 +1,4 @@
public open class ConstructorGenericSimple : R|java/lang/Object| { public open class ConstructorGenericSimple : R|java/lang/Object| {
public constructor(p: R|ft<P, P?>|!): R|test/ConstructorGenericSimple| public constructor<P>(p: R|ft<P, P?>|!): R|test/ConstructorGenericSimple|
} }
@@ -1,4 +1,4 @@
public open class ConstructorGenericUpperBound : R|java/lang/Object| { public open class ConstructorGenericUpperBound : R|java/lang/Object| {
public constructor(p: R|ft<P, P?>|!): R|test/ConstructorGenericUpperBound| public constructor<P : R|java/util/RandomAccess|>(p: R|ft<P, P?>|!): R|test/ConstructorGenericUpperBound|
} }
@@ -1,4 +1,4 @@
public open class AllBoundsInWhen : R|java/lang/Object| { public open class AllBoundsInWhen : R|java/lang/Object| {
public open operator fun foo(): R|kotlin/Unit| public open operator fun <T : R|java/io/Serializable|> foo(): R|kotlin/Unit|
} }
@@ -1,4 +1,4 @@
public open class ConstructorWithNewTypeParams<T> : R|java/lang/Object| { public open class ConstructorWithNewTypeParams<T> : R|java/lang/Object| {
public constructor(first: R|ft<U, U?>|!): R|test/ConstructorWithNewTypeParams<T>| public constructor<T, U>(first: R|ft<U, U?>|!): R|test/ConstructorWithNewTypeParams<T>|
} }
@@ -1,4 +1,4 @@
public open class ConstructorWithParentTypeParams<T> : R|java/lang/Object| { public open class ConstructorWithParentTypeParams<T> : R|java/lang/Object| {
public constructor(first: R|ft<T, T?>|!): R|test/ConstructorWithParentTypeParams<T>| public constructor<T>(first: R|ft<T, T?>|!): R|test/ConstructorWithParentTypeParams<T>|
} }
@@ -1,6 +1,6 @@
public open class MethodWithMappedClasses : R|java/lang/Object| { public open class MethodWithMappedClasses : R|java/lang/Object| {
public open operator fun copy(dest: R|ft<kotlin/collections/MutableList<in T>, kotlin/collections/List<in T>?>|!, src: R|ft<kotlin/collections/MutableList<ft<T, T?>>, kotlin/collections/List<ft<T, T?>>?>|!): R|kotlin/Unit| public open operator fun <T> copy(dest: R|ft<kotlin/collections/MutableList<in T>, kotlin/collections/List<in T>?>|!, src: R|ft<kotlin/collections/MutableList<ft<T, T?>>, kotlin/collections/List<ft<T, T?>>?>|!): R|kotlin/Unit|
public open operator fun copyMap(dest: R|ft<kotlin/collections/MutableMap<ft<kotlin/String, kotlin/String?>, in T>, kotlin/collections/Map<ft<kotlin/String, kotlin/String?>, in T>?>|!, src: R|ft<kotlin/collections/MutableMap<ft<kotlin/String, kotlin/String?>, ft<T, T?>>, kotlin/collections/Map<ft<kotlin/String, kotlin/String?>, ft<T, T?>>?>|!): R|kotlin/Unit| public open operator fun <T> copyMap(dest: R|ft<kotlin/collections/MutableMap<ft<kotlin/String, kotlin/String?>, in T>, kotlin/collections/Map<ft<kotlin/String, kotlin/String?>, in T>?>|!, src: R|ft<kotlin/collections/MutableMap<ft<kotlin/String, kotlin/String?>, ft<T, T?>>, kotlin/collections/Map<ft<kotlin/String, kotlin/String?>, ft<T, T?>>?>|!): R|kotlin/Unit|
} }
@@ -1,4 +1,4 @@
public open class MethodWithTypeParameters : R|java/lang/Object| { public open class MethodWithTypeParameters : R|java/lang/Object| {
public open operator fun foo(a: R|ft<A, A?>|!, b: R|ft<kotlin/collections/MutableList<out B>, kotlin/collections/List<out B>?>|!, list: R|ft<kotlin/collections/MutableList<in java/lang/String>, kotlin/collections/List<in java/lang/String>?>|!): R|kotlin/Unit| public open operator fun <A, B : R|java/lang/Runnable|, R|java/util/List<java/lang/Cloneable>|> foo(a: R|ft<A, A?>|!, b: R|ft<kotlin/collections/MutableList<out B>, kotlin/collections/List<out B>?>|!, list: R|ft<kotlin/collections/MutableList<in java/lang/String>, kotlin/collections/List<in java/lang/String>?>|!): R|kotlin/Unit|
} }
@@ -1,4 +1,4 @@
public open class WrongTypeParameterBoundStructure1 : R|java/lang/Object| { public open class WrongTypeParameterBoundStructure1 : R|java/lang/Object| {
public open operator fun foo(a: R|ft<A, A?>|!, b: R|ft<kotlin/collections/MutableList<out B>, kotlin/collections/List<out B>?>|!): R|kotlin/Unit| public open operator fun <A, B : R|java/lang/Runnable|, R|java/util/List<java/lang/Cloneable>|> foo(a: R|ft<A, A?>|!, b: R|ft<kotlin/collections/MutableList<out B>, kotlin/collections/List<out B>?>|!): R|kotlin/Unit|
} }
@@ -1,4 +1,4 @@
public open class Max : R|java/lang/Object| { public open class Max : R|java/lang/Object| {
public open operator fun max(coll: R|ft<kotlin/collections/MutableCollection<out T>, kotlin/collections/Collection<out T>?>|!): R|ft<T, T?>|! public open operator fun <T : R|java/lang/Object|, R|java/lang/Comparable<in T>|> max(coll: R|ft<kotlin/collections/MutableCollection<out T>, kotlin/collections/Collection<out T>?>|!): R|ft<T, T?>|!
} }
@@ -1,10 +1,10 @@
public abstract interface LoadIterableWithNullability<T> : R|java/lang/Object| { public abstract interface LoadIterableWithNullability<T> : R|java/lang/Object| {
@R|org/jetbrains/annotations/NotNull|() @R|kotlin/annotations/jvm/Mutable|() public abstract operator fun getIterable(): R|ft<kotlin/collections/MutableIterable<ft<T, T?>>, kotlin/collections/MutableIterable<ft<T, T?>>>| @R|org/jetbrains/annotations/NotNull|() @R|kotlin/annotations/jvm/Mutable|() public abstract operator fun getIterable(): R|kotlin/collections/MutableIterable<ft<T, T?>>|
public abstract operator fun setIterable(@R|kotlin/annotations/jvm/Mutable|() @R|org/jetbrains/annotations/NotNull|() Iterable: R|ft<kotlin/collections/MutableIterable<ft<T, T?>>, kotlin/collections/MutableIterable<ft<T, T?>>>|): R|kotlin/Unit| public abstract operator fun setIterable(@R|kotlin/annotations/jvm/Mutable|() @R|org/jetbrains/annotations/NotNull|() Iterable: R|kotlin/collections/MutableIterable<ft<T, T?>>|): R|kotlin/Unit|
@R|org/jetbrains/annotations/NotNull|() @R|kotlin/annotations/jvm/ReadOnly|() public abstract operator fun getReadOnlyIterable(): R|ft<kotlin/collections/Iterable<ft<T, T?>>, kotlin/collections/Iterable<ft<T, T?>>>| @R|org/jetbrains/annotations/NotNull|() @R|kotlin/annotations/jvm/ReadOnly|() public abstract operator fun getReadOnlyIterable(): R|kotlin/collections/Iterable<ft<T, T?>>|
public abstract operator fun setReadOnlyIterable(@R|kotlin/annotations/jvm/ReadOnly|() @R|org/jetbrains/annotations/NotNull|() Iterable: R|ft<kotlin/collections/Iterable<ft<T, T?>>, kotlin/collections/Iterable<ft<T, T?>>>|): R|kotlin/Unit| public abstract operator fun setReadOnlyIterable(@R|kotlin/annotations/jvm/ReadOnly|() @R|org/jetbrains/annotations/NotNull|() Iterable: R|kotlin/collections/Iterable<ft<T, T?>>|): R|kotlin/Unit|
} }
@@ -1,4 +1,4 @@
public abstract interface GenericInterfaceParameterWithSelfBound<T> : R|java/lang/Object| { public abstract interface GenericInterfaceParameterWithSelfBound<T : R|test/GenericInterfaceParameterWithSelfBound<T>|> : R|java/lang/Object| {
public abstract operator fun method(t: R|ft<T, T?>|!): R|ft<T, T?>|! public abstract operator fun method(t: R|ft<T, T?>|!): R|ft<T, T?>|!
} }
@@ -1,4 +1,4 @@
public abstract interface GenericInterfaceParametersWithBounds<A, B> : R|java/lang/Object| { public abstract interface GenericInterfaceParametersWithBounds<A : R|java/lang/Comparable<A>|, R|java/lang/Cloneable|, B : R|java/util/List<A>|> : R|java/lang/Object| {
public abstract operator fun method(a: R|kotlin/Array<ft<A, A?>>|, b: R|ft<B, B?>|!): R|kotlin/Unit| public abstract operator fun method(a: R|kotlin/Array<ft<A, A?>>|, b: R|ft<B, B?>|!): R|kotlin/Unit|
} }
@@ -1,4 +1,4 @@
public abstract interface GenericMethodParameters : R|java/lang/Object| { public abstract interface GenericMethodParameters : R|java/lang/Object| {
public abstract operator fun method(a: R|kotlin/Array<ft<A, A?>>|, b: R|ft<B, B?>|!): R|kotlin/Unit| public abstract operator fun <A : R|java/lang/CharSequence|, B : R|java/util/List<A>|> method(a: R|kotlin/Array<ft<A, A?>>|, b: R|ft<B, B?>|!): R|kotlin/Unit|
} }
@@ -1,8 +1,8 @@
public open class TypeParameterOfMethod : R|java/lang/Object| { public open class TypeParameterOfMethod : R|java/lang/Object| {
public open static operator fun max(comparator: R|ft<java/util/Comparator<ft<T, T?>>, java/util/Comparator<ft<T, T?>>?>|!, value1: R|ft<T, T?>|!, value2: R|ft<T, T?>|!): R|ft<T, T?>|! public open static operator fun <T> max(comparator: R|ft<java/util/Comparator<ft<T, T?>>, java/util/Comparator<ft<T, T?>>?>|!, value1: R|ft<T, T?>|!, value2: R|ft<T, T?>|!): R|ft<T, T?>|!
public open static operator fun max2(comparator: R|ft<java/util/Comparator<ft<T, T?>>, java/util/Comparator<ft<T, T?>>?>|!, value1: R|ft<T, T?>|!, value2: R|ft<T, T?>|!): R|ft<T, T?>|! public open static operator fun <T : R|java/lang/CharSequence|> max2(comparator: R|ft<java/util/Comparator<ft<T, T?>>, java/util/Comparator<ft<T, T?>>?>|!, value1: R|ft<T, T?>|!, value2: R|ft<T, T?>|!): R|ft<T, T?>|!
public open static operator fun method(a: R|ft<java/util/Comparator<ft<A, A?>>, java/util/Comparator<ft<A, A?>>?>|!, b: R|ft<B, B?>|!): R|kotlin/Unit| public open static operator fun <A : R|java/lang/CharSequence|, B : R|java/util/List<A>|> method(a: R|ft<java/util/Comparator<ft<A, A?>>, java/util/Comparator<ft<A, A?>>?>|!, b: R|ft<B, B?>|!): R|kotlin/Unit|
} }
@@ -15,6 +15,6 @@ public final enum class StaticMembersInEnum : R|java/lang/Enum<test/StaticMember
public open static operator fun valueOf(x: R|kotlin/Int|): R|kotlin/Unit| public open static operator fun valueOf(x: R|kotlin/Int|): R|kotlin/Unit|
public open static operator fun valueOf(<anonymous Java parameter>: R|ft<java/lang/Class<ft<T, T?>>, java/lang/Class<ft<T, T?>>?>|!, <anonymous Java parameter>: R|ft<kotlin/String, kotlin/String?>|!): R|ft<T, T?>|! public open static operator fun <T : R|java/lang/Enum<T>|> valueOf(<anonymous Java parameter>: R|ft<java/lang/Class<ft<T, T?>>, java/lang/Class<ft<T, T?>>?>|!, <anonymous Java parameter>: R|ft<kotlin/String, kotlin/String?>|!): R|ft<T, T?>|!
} }