[ObjCExport] Fix kdoc primary constructor
KT-66387
This commit is contained in:
committed by
Space Team
parent
c04a8fc3b8
commit
16d53a0e34
+3
@@ -11,6 +11,9 @@ import org.jetbrains.kotlin.analysis.api.symbols.markers.KtPossiblyNamedSymbol
|
|||||||
import org.jetbrains.kotlin.backend.konan.objcexport.ObjCExportStubOrigin
|
import org.jetbrains.kotlin.backend.konan.objcexport.ObjCExportStubOrigin
|
||||||
import org.jetbrains.kotlin.objcexport.analysisApiUtils.getKDocString
|
import org.jetbrains.kotlin.objcexport.analysisApiUtils.getKDocString
|
||||||
|
|
||||||
|
/**
|
||||||
|
* [org.jetbrains.kotlin.backend.konan.objcexport.ObjCExportStubFactoriesKt.ObjCExportStubOrigin]
|
||||||
|
*/
|
||||||
context(KtAnalysisSession)
|
context(KtAnalysisSession)
|
||||||
fun KtSymbol.getObjCExportStubOrigin(): ObjCExportStubOrigin {
|
fun KtSymbol.getObjCExportStubOrigin(): ObjCExportStubOrigin {
|
||||||
// TODO: Differentiate origins
|
// TODO: Differentiate origins
|
||||||
|
|||||||
+1
-1
@@ -21,7 +21,7 @@ fun KtClassOrObjectSymbol.translateToObjCClass(): ObjCClass? {
|
|||||||
val attributes = (if (enumKind || final) listOf(OBJC_SUBCLASSING_RESTRICTED) else emptyList()) + name.toNameAttributes()
|
val attributes = (if (enumKind || final) listOf(OBJC_SUBCLASSING_RESTRICTED) else emptyList()) + name.toNameAttributes()
|
||||||
|
|
||||||
val comment: ObjCComment? = annotationsList.translateToObjCComment()
|
val comment: ObjCComment? = annotationsList.translateToObjCComment()
|
||||||
val origin: ObjCExportStubOrigin = getObjCExportStubOrigin()
|
val origin = getObjCExportStubOrigin()
|
||||||
|
|
||||||
val superClass = translateSuperClass()
|
val superClass = translateSuperClass()
|
||||||
val superProtocols: List<String> = superProtocols()
|
val superProtocols: List<String> = superProtocols()
|
||||||
|
|||||||
+27
-24
@@ -3,6 +3,7 @@ package org.jetbrains.kotlin.objcexport
|
|||||||
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
|
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
|
||||||
import org.jetbrains.kotlin.analysis.api.symbols.KtClassKind
|
import org.jetbrains.kotlin.analysis.api.symbols.KtClassKind
|
||||||
import org.jetbrains.kotlin.analysis.api.symbols.KtClassOrObjectSymbol
|
import org.jetbrains.kotlin.analysis.api.symbols.KtClassOrObjectSymbol
|
||||||
|
import org.jetbrains.kotlin.analysis.api.symbols.KtFunctionLikeSymbol
|
||||||
import org.jetbrains.kotlin.backend.konan.descriptors.arrayTypes
|
import org.jetbrains.kotlin.backend.konan.descriptors.arrayTypes
|
||||||
import org.jetbrains.kotlin.backend.konan.objcexport.ObjCInstanceType
|
import org.jetbrains.kotlin.backend.konan.objcexport.ObjCInstanceType
|
||||||
import org.jetbrains.kotlin.backend.konan.objcexport.ObjCMethod
|
import org.jetbrains.kotlin.backend.konan.objcexport.ObjCMethod
|
||||||
@@ -14,14 +15,18 @@ import org.jetbrains.kotlin.objcexport.analysisApiUtils.isVisibleInObjC
|
|||||||
|
|
||||||
context(KtAnalysisSession, KtObjCExportSession)
|
context(KtAnalysisSession, KtObjCExportSession)
|
||||||
fun KtClassOrObjectSymbol.translateToObjCConstructors(): List<ObjCMethod> {
|
fun KtClassOrObjectSymbol.translateToObjCConstructors(): List<ObjCMethod> {
|
||||||
val result = mutableListOf<ObjCMethod>()
|
|
||||||
|
|
||||||
/* Translate declared constructors */
|
/* Translate declared constructors */
|
||||||
result += getDeclaredMemberScope().getConstructors()
|
val result = getDeclaredMemberScope()
|
||||||
|
.getConstructors()
|
||||||
.filter { !it.hasExportForCompilerAnnotation }
|
.filter { !it.hasExportForCompilerAnnotation }
|
||||||
.filter { it.isVisibleInObjC() }
|
.filter { it.isVisibleInObjC() }
|
||||||
.sortedWith(StableCallableOrder)
|
.sortedWith(StableCallableOrder)
|
||||||
.map { it.buildObjCMethod() }
|
.flatMap { constructor ->
|
||||||
|
val objCConstructor = constructor.buildObjCMethod()
|
||||||
|
listOf(objCConstructor) + if (objCConstructor.name == "init") listOf(buildNewInitConstructor(constructor)) else emptyList()
|
||||||
|
}
|
||||||
|
.toMutableList()
|
||||||
|
|
||||||
/* Create special 'alloc' constructors */
|
/* Create special 'alloc' constructors */
|
||||||
if (this.classIdIfNonLocal?.asFqNameString() in arrayTypes ||
|
if (this.classIdIfNonLocal?.asFqNameString() in arrayTypes ||
|
||||||
@@ -30,7 +35,7 @@ fun KtClassOrObjectSymbol.translateToObjCConstructors(): List<ObjCMethod> {
|
|||||||
result.add(
|
result.add(
|
||||||
ObjCMethod(
|
ObjCMethod(
|
||||||
comment = null,
|
comment = null,
|
||||||
origin = getObjCExportStubOrigin(),
|
origin = null,
|
||||||
isInstanceMethod = false,
|
isInstanceMethod = false,
|
||||||
returnType = ObjCInstanceType,
|
returnType = ObjCInstanceType,
|
||||||
selectors = listOf("alloc"),
|
selectors = listOf("alloc"),
|
||||||
@@ -62,25 +67,23 @@ fun KtClassOrObjectSymbol.translateToObjCConstructors(): List<ObjCMethod> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val initIndex = result.indexOfFirst { it.name == "init" }
|
|
||||||
if (initIndex > -1) {
|
|
||||||
/**
|
|
||||||
* If there is "init" we need always add this special constructor
|
|
||||||
*/
|
|
||||||
result.add(
|
|
||||||
initIndex + 1, ObjCMethod(
|
|
||||||
comment = null,
|
|
||||||
origin = getObjCExportStubOrigin(),
|
|
||||||
isInstanceMethod = false,
|
|
||||||
returnType = ObjCInstanceType,
|
|
||||||
selectors = listOf("new"),
|
|
||||||
parameters = emptyList(),
|
|
||||||
attributes = listOf(
|
|
||||||
"availability(swift, unavailable, message=\"use object initializers instead\")"
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Additional primary constructor which goes always after primary constructor ([ObjCMethod.name] == "init")
|
||||||
|
*/
|
||||||
|
context(KtAnalysisSession)
|
||||||
|
private fun buildNewInitConstructor(constructor: KtFunctionLikeSymbol): ObjCMethod {
|
||||||
|
return ObjCMethod(
|
||||||
|
comment = null,
|
||||||
|
origin = constructor.getObjCExportStubOrigin(),
|
||||||
|
isInstanceMethod = false,
|
||||||
|
returnType = ObjCInstanceType,
|
||||||
|
selectors = listOf("new"),
|
||||||
|
parameters = emptyList(),
|
||||||
|
attributes = listOf(
|
||||||
|
"availability(swift, unavailable, message=\"use object initializers instead\")"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
+1
-1
@@ -22,7 +22,7 @@ fun KtClassOrObjectSymbol.translateToObjCObject(): ObjCClass? {
|
|||||||
val name = getObjCClassOrProtocolName()
|
val name = getObjCClassOrProtocolName()
|
||||||
val attributes = (if (enumKind || final) listOf(OBJC_SUBCLASSING_RESTRICTED) else emptyList()) + name.toNameAttributes()
|
val attributes = (if (enumKind || final) listOf(OBJC_SUBCLASSING_RESTRICTED) else emptyList()) + name.toNameAttributes()
|
||||||
val comment: ObjCComment? = annotationsList.translateToObjCComment()
|
val comment: ObjCComment? = annotationsList.translateToObjCComment()
|
||||||
val origin: ObjCExportStubOrigin = getObjCExportStubOrigin()
|
val origin = getObjCExportStubOrigin()
|
||||||
val superProtocols: List<String> = superProtocols()
|
val superProtocols: List<String> = superProtocols()
|
||||||
val categoryName: String? = null
|
val categoryName: String? = null
|
||||||
val generics: List<ObjCGenericTypeDeclaration> = emptyList()
|
val generics: List<ObjCGenericTypeDeclaration> = emptyList()
|
||||||
|
|||||||
-1
@@ -152,7 +152,6 @@ class ObjCExportHeaderGeneratorTest(private val generator: HeaderGenerator) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TodoAnalysisApi
|
|
||||||
fun `test - kdocWithBlockTags`() {
|
fun `test - kdocWithBlockTags`() {
|
||||||
doTest(headersTestDataDir.resolve("kdocWithBlockTags"))
|
doTest(headersTestDataDir.resolve("kdocWithBlockTags"))
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user