FIR: consider Java default constructors as primary ones
This commit is contained in:
@@ -210,11 +210,14 @@ class JavaSymbolProvider(
|
|||||||
val javaClassDeclaredConstructors = javaClass.constructors
|
val javaClassDeclaredConstructors = javaClass.constructors
|
||||||
val constructorId = CallableId(classId.packageFqName, classId.relativeClassName, classId.shortClassName)
|
val constructorId = CallableId(classId.packageFqName, classId.relativeClassName, classId.shortClassName)
|
||||||
|
|
||||||
fun addJavaConstructor(visibility: Visibility = this.visibility): FirJavaConstructor {
|
fun addJavaConstructor(
|
||||||
|
visibility: Visibility = this.visibility,
|
||||||
|
isPrimary: Boolean = false
|
||||||
|
): FirJavaConstructor {
|
||||||
val constructorSymbol = FirConstructorSymbol(constructorId)
|
val constructorSymbol = FirConstructorSymbol(constructorId)
|
||||||
val classTypeParameters = javaClass.typeParameters.convertTypeParameters(javaTypeParameterStack)
|
val classTypeParameters = javaClass.typeParameters.convertTypeParameters(javaTypeParameterStack)
|
||||||
val firJavaConstructor = FirJavaConstructor(
|
val firJavaConstructor = FirJavaConstructor(
|
||||||
this@JavaSymbolProvider.session, constructorSymbol, visibility,
|
this@JavaSymbolProvider.session, constructorSymbol, visibility, isPrimary,
|
||||||
FirResolvedTypeRefImpl(
|
FirResolvedTypeRefImpl(
|
||||||
this@JavaSymbolProvider.session, null,
|
this@JavaSymbolProvider.session, null,
|
||||||
firSymbol.constructType(
|
firSymbol.constructType(
|
||||||
@@ -230,7 +233,7 @@ class JavaSymbolProvider(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (javaClassDeclaredConstructors.isEmpty() && javaClass.classKind == ClassKind.CLASS) {
|
if (javaClassDeclaredConstructors.isEmpty() && javaClass.classKind == ClassKind.CLASS) {
|
||||||
addJavaConstructor()
|
addJavaConstructor(isPrimary = true)
|
||||||
}
|
}
|
||||||
for (javaConstructor in javaClassDeclaredConstructors) {
|
for (javaConstructor in javaClassDeclaredConstructors) {
|
||||||
addJavaConstructor(javaConstructor.visibility).apply {
|
addJavaConstructor(javaConstructor.visibility).apply {
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ class FirJavaConstructor(
|
|||||||
session: FirSession,
|
session: FirSession,
|
||||||
override val symbol: FirConstructorSymbol,
|
override val symbol: FirConstructorSymbol,
|
||||||
visibility: Visibility,
|
visibility: Visibility,
|
||||||
|
override val isPrimary: Boolean,
|
||||||
delegatedSelfTypeRef: FirTypeRef
|
delegatedSelfTypeRef: FirTypeRef
|
||||||
) : FirAbstractCallableMember<FirConstructor>(
|
) : FirAbstractCallableMember<FirConstructor>(
|
||||||
session,
|
session,
|
||||||
|
|||||||
+20
-6
@@ -180,12 +180,26 @@ class JavaClassEnhancementScope(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
val function: FirMemberFunction<*> = when (firMethod) {
|
val function: FirMemberFunction<*> = when (firMethod) {
|
||||||
is FirJavaConstructor -> FirConstructorImpl(
|
is FirJavaConstructor -> {
|
||||||
this@JavaClassEnhancementScope.session, null, FirConstructorSymbol(methodId),
|
val symbol = FirConstructorSymbol(methodId)
|
||||||
newReceiverTypeRef, newReturnTypeRef
|
if (firMethod.isPrimary) {
|
||||||
).apply {
|
FirPrimaryConstructorImpl(
|
||||||
this.valueParameters += newValueParameters
|
this@JavaClassEnhancementScope.session, null, symbol,
|
||||||
this.typeParameters += firMethod.typeParameters
|
firMethod.visibility,
|
||||||
|
isExpect = false,
|
||||||
|
isActual = false,
|
||||||
|
delegatedSelfTypeRef = newReturnTypeRef,
|
||||||
|
delegatedConstructor = null
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
FirConstructorImpl(
|
||||||
|
this@JavaClassEnhancementScope.session, null, symbol,
|
||||||
|
newReceiverTypeRef, newReturnTypeRef
|
||||||
|
)
|
||||||
|
}.apply {
|
||||||
|
this.valueParameters += newValueParameters
|
||||||
|
this.typeParameters += firMethod.typeParameters
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else -> FirMemberFunctionImpl(
|
else -> FirMemberFunctionImpl(
|
||||||
this@JavaClassEnhancementScope.session, null,
|
this@JavaClassEnhancementScope.session, null,
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ FILE fqName:<root> fileName:/Derived.kt
|
|||||||
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.Derived
|
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.Derived
|
||||||
CONSTRUCTOR visibility:public <> () returnType:<root>.Derived [primary]
|
CONSTRUCTOR visibility:public <> () returnType:<root>.Derived [primary]
|
||||||
BLOCK_BODY
|
BLOCK_BODY
|
||||||
DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () declared in <root>.Base'
|
DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in <root>.Base'
|
||||||
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:Derived modality:FINAL visibility:public superTypes:[<root>.Base]'
|
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:Derived modality:FINAL visibility:public superTypes:[<root>.Base]'
|
||||||
ANONYMOUS_INITIALIZER isStatic=false
|
ANONYMOUS_INITIALIZER isStatic=false
|
||||||
BLOCK_BODY
|
BLOCK_BODY
|
||||||
|
|||||||
+1
-1
@@ -98,7 +98,7 @@ FILE fqName:<root> fileName:/kt16904.kt
|
|||||||
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.Test2
|
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.Test2
|
||||||
CONSTRUCTOR visibility:public <> () returnType:<root>.Test2 [primary]
|
CONSTRUCTOR visibility:public <> () returnType:<root>.Test2 [primary]
|
||||||
BLOCK_BODY
|
BLOCK_BODY
|
||||||
DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () declared in <root>.J'
|
DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in <root>.J'
|
||||||
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:Test2 modality:FINAL visibility:public superTypes:[<root>.J]'
|
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:Test2 modality:FINAL visibility:public superTypes:[<root>.J]'
|
||||||
ANONYMOUS_INITIALIZER isStatic=false
|
ANONYMOUS_INITIALIZER isStatic=false
|
||||||
BLOCK_BODY
|
BLOCK_BODY
|
||||||
|
|||||||
+1
-1
@@ -82,5 +82,5 @@ FILE fqName:<root> fileName:/samConversionsWithSmartCasts.kt
|
|||||||
FUN name:test9 visibility:public modality:FINAL <> () returnType:kotlin.Unit
|
FUN name:test9 visibility:public modality:FINAL <> () returnType:kotlin.Unit
|
||||||
BLOCK_BODY
|
BLOCK_BODY
|
||||||
CALL 'public open fun run1 (r: java.lang.Runnable?): kotlin.Unit declared in <root>.J' type=kotlin.Unit origin=null
|
CALL 'public open fun run1 (r: java.lang.Runnable?): kotlin.Unit declared in <root>.J' type=kotlin.Unit origin=null
|
||||||
$this: CONSTRUCTOR_CALL 'public constructor <init> () declared in <root>.J' type=<root>.J origin=null
|
$this: CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in <root>.J' type=<root>.J origin=null
|
||||||
r: ERROR_CALL 'Unresolved reference: <Unresolved name: test9>#' type=IrErrorType
|
r: ERROR_CALL 'Unresolved reference: <Unresolved name: test9>#' type=IrErrorType
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ FILE fqName:<root> fileName:/Derived.kt
|
|||||||
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.Derived
|
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.Derived
|
||||||
CONSTRUCTOR visibility:public <> () returnType:<root>.Derived [primary]
|
CONSTRUCTOR visibility:public <> () returnType:<root>.Derived [primary]
|
||||||
BLOCK_BODY
|
BLOCK_BODY
|
||||||
DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () declared in <root>.Base'
|
DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in <root>.Base'
|
||||||
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:Derived modality:FINAL visibility:public superTypes:[<root>.Base]'
|
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:Derived modality:FINAL visibility:public superTypes:[<root>.Base]'
|
||||||
FUN name:setValue visibility:public modality:FINAL <> ($this:<root>.Derived, v:kotlin.Any) returnType:kotlin.Unit
|
FUN name:setValue visibility:public modality:FINAL <> ($this:<root>.Derived, v:kotlin.Any) returnType:kotlin.Unit
|
||||||
$this: VALUE_PARAMETER name:<this> type:<root>.Derived
|
$this: VALUE_PARAMETER name:<this> type:<root>.Derived
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ FILE fqName:<root> fileName:/javaInnerClass.kt
|
|||||||
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.Test1
|
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.Test1
|
||||||
CONSTRUCTOR visibility:public <> () returnType:<root>.Test1 [primary]
|
CONSTRUCTOR visibility:public <> () returnType:<root>.Test1 [primary]
|
||||||
BLOCK_BODY
|
BLOCK_BODY
|
||||||
DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () declared in <root>.J'
|
DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in <root>.J'
|
||||||
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:Test1 modality:FINAL visibility:public superTypes:[<root>.J]'
|
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:Test1 modality:FINAL visibility:public superTypes:[<root>.J]'
|
||||||
PROPERTY name:test visibility:public modality:FINAL [val]
|
PROPERTY name:test visibility:public modality:FINAL [val]
|
||||||
FIELD PROPERTY_BACKING_FIELD name:test type:IrErrorType visibility:public [final]
|
FIELD PROPERTY_BACKING_FIELD name:test type:IrErrorType visibility:public [final]
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ FILE fqName:<root> fileName:/javaSyntheticProperty.kt
|
|||||||
FIELD PROPERTY_BACKING_FIELD name:test type:kotlin.String? visibility:public [final,static]
|
FIELD PROPERTY_BACKING_FIELD name:test type:kotlin.String? visibility:public [final,static]
|
||||||
EXPRESSION_BODY
|
EXPRESSION_BODY
|
||||||
CALL 'public open fun getFoo (): kotlin.String? declared in <root>.J' type=kotlin.String? origin=null
|
CALL 'public open fun getFoo (): kotlin.String? declared in <root>.J' type=kotlin.String? origin=null
|
||||||
$this: CONSTRUCTOR_CALL 'public/*package*/ constructor <init> () declared in <root>.J' type=<root>.J origin=null
|
$this: CONSTRUCTOR_CALL 'public/*package*/ constructor <init> () [primary] declared in <root>.J' type=<root>.J origin=null
|
||||||
FUN DEFAULT_PROPERTY_ACCESSOR name:<get-test> visibility:public modality:FINAL <> () returnType:kotlin.String?
|
FUN DEFAULT_PROPERTY_ACCESSOR name:<get-test> visibility:public modality:FINAL <> () returnType:kotlin.String?
|
||||||
correspondingProperty: PROPERTY name:test visibility:public modality:FINAL [val]
|
correspondingProperty: PROPERTY name:test visibility:public modality:FINAL [val]
|
||||||
BLOCK_BODY
|
BLOCK_BODY
|
||||||
|
|||||||
Reference in New Issue
Block a user