FIR: consider Java default constructors as primary ones
This commit is contained in:
@@ -210,11 +210,14 @@ class JavaSymbolProvider(
|
||||
val javaClassDeclaredConstructors = javaClass.constructors
|
||||
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 classTypeParameters = javaClass.typeParameters.convertTypeParameters(javaTypeParameterStack)
|
||||
val firJavaConstructor = FirJavaConstructor(
|
||||
this@JavaSymbolProvider.session, constructorSymbol, visibility,
|
||||
this@JavaSymbolProvider.session, constructorSymbol, visibility, isPrimary,
|
||||
FirResolvedTypeRefImpl(
|
||||
this@JavaSymbolProvider.session, null,
|
||||
firSymbol.constructType(
|
||||
@@ -230,7 +233,7 @@ class JavaSymbolProvider(
|
||||
}
|
||||
|
||||
if (javaClassDeclaredConstructors.isEmpty() && javaClass.classKind == ClassKind.CLASS) {
|
||||
addJavaConstructor()
|
||||
addJavaConstructor(isPrimary = true)
|
||||
}
|
||||
for (javaConstructor in javaClassDeclaredConstructors) {
|
||||
addJavaConstructor(javaConstructor.visibility).apply {
|
||||
|
||||
@@ -21,6 +21,7 @@ class FirJavaConstructor(
|
||||
session: FirSession,
|
||||
override val symbol: FirConstructorSymbol,
|
||||
visibility: Visibility,
|
||||
override val isPrimary: Boolean,
|
||||
delegatedSelfTypeRef: FirTypeRef
|
||||
) : FirAbstractCallableMember<FirConstructor>(
|
||||
session,
|
||||
|
||||
+20
-6
@@ -180,12 +180,26 @@ class JavaClassEnhancementScope(
|
||||
}
|
||||
}
|
||||
val function: FirMemberFunction<*> = when (firMethod) {
|
||||
is FirJavaConstructor -> FirConstructorImpl(
|
||||
this@JavaClassEnhancementScope.session, null, FirConstructorSymbol(methodId),
|
||||
newReceiverTypeRef, newReturnTypeRef
|
||||
).apply {
|
||||
this.valueParameters += newValueParameters
|
||||
this.typeParameters += firMethod.typeParameters
|
||||
is FirJavaConstructor -> {
|
||||
val symbol = FirConstructorSymbol(methodId)
|
||||
if (firMethod.isPrimary) {
|
||||
FirPrimaryConstructorImpl(
|
||||
this@JavaClassEnhancementScope.session, null, symbol,
|
||||
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(
|
||||
this@JavaClassEnhancementScope.session, null,
|
||||
|
||||
Reference in New Issue
Block a user