aboutsummaryrefslogtreecommitdiff
path: root/plugins/kotlin-as-java/src/main
diff options
context:
space:
mode:
authorPaweł Marks <pmarks@virtuslab.com>2020-03-11 16:55:40 +0100
committerPaweł Marks <Kordyjan@users.noreply.github.com>2020-03-11 18:25:01 +0100
commit8e4ffa367b43cdc57c3921fab2182a4209913a51 (patch)
treee4e03996eab0372b642978f0540079efdb6da191 /plugins/kotlin-as-java/src/main
parent93b8ae8a552ed88f50e4f17a5906ddeedb77e639 (diff)
downloaddokka-8e4ffa367b43cdc57c3921fab2182a4209913a51.tar.gz
dokka-8e4ffa367b43cdc57c3921fab2182a4209913a51.tar.bz2
dokka-8e4ffa367b43cdc57c3921fab2182a4209913a51.zip
Use Bounds instead of Wrappers to describe types
Diffstat (limited to 'plugins/kotlin-as-java/src/main')
-rw-r--r--plugins/kotlin-as-java/src/main/kotlin/converters/KotlinToJavaConverter.kt41
-rw-r--r--plugins/kotlin-as-java/src/main/kotlin/signatures/JavaSignatureProvider.kt10
2 files changed, 9 insertions, 42 deletions
diff --git a/plugins/kotlin-as-java/src/main/kotlin/converters/KotlinToJavaConverter.kt b/plugins/kotlin-as-java/src/main/kotlin/converters/KotlinToJavaConverter.kt
index 3b0f69f6..cf777e67 100644
--- a/plugins/kotlin-as-java/src/main/kotlin/converters/KotlinToJavaConverter.kt
+++ b/plugins/kotlin-as-java/src/main/kotlin/converters/KotlinToJavaConverter.kt
@@ -75,7 +75,7 @@ internal fun Property.asJava(isTopLevel: Boolean = false, relocateToClass: Strin
visibility = visibility.copy(
map = visibility.mapValues { JavaVisibility.Private }
),
- type = type.asJava(isTopLevel), // TODO: check
+ type = type.asJava(), // TODO: check
setter = null,
getter = null, // Removing getters and setters as they will be available as functions
extra = if (isTopLevel) extra.plus(extra.mergeAdditionalModifiers(setOf(ExtraModifiers.STATIC))) else extra
@@ -98,7 +98,7 @@ internal fun Property.javaAccessors(isTopLevel: Boolean = false, relocateToClass
visibility = visibility.copy(
map = visibility.mapValues { JavaVisibility.Public }
),
- type = type.asJava(isTopLevel), // TODO: check
+ type = type.asJava(), // TODO: check
extra = if (isTopLevel) getter!!.extra.plus(getter!!.extra.mergeAdditionalModifiers(setOf(ExtraModifiers.STATIC))) else getter!!.extra
),
setter?.copy(
@@ -116,7 +116,7 @@ internal fun Property.javaAccessors(isTopLevel: Boolean = false, relocateToClass
visibility = visibility.copy(
map = visibility.mapValues { JavaVisibility.Public }
),
- type = type.asJava(isTopLevel), // TODO: check
+ type = type.asJava(), // TODO: check
extra = if (isTopLevel) setter!!.extra.plus(setter!!.extra.mergeAdditionalModifiers(setOf(ExtraModifiers.STATIC))) else setter!!.extra
)
)
@@ -204,13 +204,7 @@ internal fun Object.asJava(): Object = copy(
it to JavaVisibility.Public
}.toMap()
),
- type = JavaTypeWrapper(
- dri.packageName?.split(".").orEmpty() +
- dri.classNames?.split(".").orEmpty(),
- emptyList(),
- dri,
- false
- ),
+ type = TypeConstructor(dri, emptyList()),
setter = null,
getter = null,
platformData = platformData,
@@ -250,36 +244,9 @@ internal fun String.getAsPrimitive(): JvmPrimitiveType? = org.jetbrains.kotlin.b
.find { it.typeFqName.asString() == this }
?.let { JvmPrimitiveType.get(it) }
-internal fun TypeWrapper.getAsType(classId: ClassId, fqName: String, top: Boolean): TypeWrapper {
- val fqNameSplit = fqName
- .takeIf { top }
- ?.getAsPrimitive()
- ?.name?.toLowerCase()
- ?.let(::listOf)
- ?: classId.asString().split("/")
-
- return JavaTypeWrapper(
- fqNameSplit,
- arguments.map { it.asJava(false) },
- classId.toDRI(dri),
- fqNameSplit.last()[0].isLowerCase()
- )
-}
-
private fun DRI.partialFqName() = packageName?.let { "$it." } + classNames
private fun DRI.possiblyAsJava() = this.partialFqName().mapToJava()?.toDRI(this) ?: this
-internal fun TypeWrapper.asJava(top: Boolean = true): TypeWrapper = constructorFqName
- ?.let { if (it.endsWith(".Unit")) return VoidTypeWrapper() else it }
- ?.let { fqName -> fqName.mapToJava()?.let { getAsType(it, fqName, top) } } ?: this
-
-private data class VoidTypeWrapper(
- override val constructorFqName: String = "void",
- override val constructorNamePathSegments: List<String> = listOf("void"),
- override val arguments: List<TypeWrapper> = emptyList(),
- override val dri: DRI = DRI("java.lang", "Void")
-) : TypeWrapper
-
private fun String.mapToJava(): ClassId? =
JavaToKotlinClassMap.mapKotlinToJava(FqName(this).toUnsafe())
diff --git a/plugins/kotlin-as-java/src/main/kotlin/signatures/JavaSignatureProvider.kt b/plugins/kotlin-as-java/src/main/kotlin/signatures/JavaSignatureProvider.kt
index 91e5164d..265e05cd 100644
--- a/plugins/kotlin-as-java/src/main/kotlin/signatures/JavaSignatureProvider.kt
+++ b/plugins/kotlin-as-java/src/main/kotlin/signatures/JavaSignatureProvider.kt
@@ -62,9 +62,7 @@ class JavaSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLogge
private fun signature(f: Function) = contentBuilder.contentFor(f, ContentKind.Symbol) {
text(f.modifier.takeIf { it !in ignoredModifiers }?.name.orEmpty() + " ")
val returnType = f.type
- if (!f.isConstructor && returnType.constructorFqName != Unit::class.qualifiedName) {
- type(returnType)
- }
+ signatureForProjection(returnType)
text(" ")
link(f.name, f.dri)
list(f.generics, prefix = "<", suffix = ">") {
@@ -72,7 +70,7 @@ class JavaSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLogge
}
text("(")
list(f.parameters) {
- type(it.type)
+ signatureForProjection(it.type)
text(" ")
link(it.name!!, it.dri)
}
@@ -98,12 +96,14 @@ class JavaSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLogge
}
is Variance -> group {
- text(p.kind.toString() + " ")
+ text(p.kind.toString() + " ") // TODO: "super" && "extends"
signatureForProjection(p.inner)
}
is Star -> text("?")
is Nullable -> signatureForProjection(p.inner)
+
+ is PrimitiveJavaType -> text(p.name)
}
} \ No newline at end of file