diff options
17 files changed, 897 insertions, 247 deletions
diff --git a/core/src/main/kotlin/model/Documentable.kt b/core/src/main/kotlin/model/Documentable.kt index 17b49f97..90958210 100644 --- a/core/src/main/kotlin/model/Documentable.kt +++ b/core/src/main/kotlin/model/Documentable.kt @@ -114,7 +114,7 @@ data class DPackage( ) : Documentable(), WithScope, WithExtraProperties<DPackage> { override val name = dri.packageName.orEmpty() override val children: List<Documentable> - get() = (properties + functions + classlikes) as List<Documentable> + get() = (properties + functions + classlikes) override fun withNewExtras(newExtras: PropertyContainer<DPackage>) = copy(extra = newExtras) } @@ -140,7 +140,7 @@ data class DClass( WithExtraProperties<DClass> { override val children: List<Documentable> - get() = (functions + properties + classlikes + constructors) as List<Documentable> + get() = (functions + properties + classlikes + constructors) override fun withNewExtras(newExtras: PropertyContainer<DClass>) = copy(extra = newExtras) } @@ -163,7 +163,7 @@ data class DEnum( override val extra: PropertyContainer<DEnum> = PropertyContainer.empty() ) : DClasslike(), WithCompanion, WithConstructors, WithSupertypes, WithExtraProperties<DEnum> { override val children: List<Documentable> - get() = (entries + functions + properties + classlikes + constructors) as List<Documentable> + get() = (entries + functions + properties + classlikes + constructors) override fun withNewExtras(newExtras: PropertyContainer<DEnum>) = copy(extra = newExtras) } @@ -180,7 +180,7 @@ data class DEnumEntry( override val extra: PropertyContainer<DEnumEntry> = PropertyContainer.empty() ) : Documentable(), WithScope, WithExtraProperties<DEnumEntry> { override val children: List<Documentable> - get() = (functions + properties + classlikes) as List<Documentable> + get() = (functions + properties + classlikes) override fun withNewExtras(newExtras: PropertyContainer<DEnumEntry>) = copy(extra = newExtras) } @@ -224,7 +224,7 @@ data class DInterface( override val extra: PropertyContainer<DInterface> = PropertyContainer.empty() ) : DClasslike(), WithCompanion, WithGenerics, WithSupertypes, WithExtraProperties<DInterface> { override val children: List<Documentable> - get() = (functions + properties + classlikes) as List<Documentable> + get() = (functions + properties + classlikes) override fun withNewExtras(newExtras: PropertyContainer<DInterface>) = copy(extra = newExtras) } @@ -266,7 +266,7 @@ data class DAnnotation( override val extra: PropertyContainer<DAnnotation> = PropertyContainer.empty() ) : DClasslike(), WithCompanion, WithConstructors, WithExtraProperties<DAnnotation>, WithGenerics { override val children: List<Documentable> - get() = (functions + properties + classlikes + constructors) as List<Documentable> + get() = (functions + properties + classlikes + constructors) override fun withNewExtras(newExtras: PropertyContainer<DAnnotation>) = copy(extra = newExtras) } diff --git a/core/src/main/kotlin/model/documentableProperties.kt b/core/src/main/kotlin/model/documentableProperties.kt index f630ba3b..699a1df1 100644 --- a/core/src/main/kotlin/model/documentableProperties.kt +++ b/core/src/main/kotlin/model/documentableProperties.kt @@ -1,13 +1,28 @@ package org.jetbrains.dokka.model +import org.jetbrains.dokka.links.DRI import org.jetbrains.dokka.model.properties.ExtraProperty import org.jetbrains.dokka.model.properties.MergeStrategy -data class InheritedFunction(val isInherited: Boolean): ExtraProperty<DFunction> { +data class InheritedFunction(val inheritedFrom: DRI?): ExtraProperty<DFunction> { companion object : ExtraProperty.Key<DFunction, InheritedFunction> { override fun mergeStrategyFor(left: InheritedFunction, right: InheritedFunction) = MergeStrategy.Fail { throw IllegalArgumentException("Function inheritance should be consistent!") } } + + val isInherited: Boolean + get() = inheritedFrom != null + override val key: ExtraProperty.Key<DFunction, *> = InheritedFunction +} + +data class ImplementedInterfaces(val interfaces: List<DRI>): ExtraProperty<Documentable> { + companion object : ExtraProperty.Key<Documentable, ImplementedInterfaces> { + override fun mergeStrategyFor(left: ImplementedInterfaces, right: ImplementedInterfaces) = MergeStrategy.Fail { + throw IllegalArgumentException("Implemented interfaces should be consistent!") + } + } + + override val key: ExtraProperty.Key<Documentable, *> = ImplementedInterfaces }
\ No newline at end of file diff --git a/core/src/main/kotlin/pages/PageNodes.kt b/core/src/main/kotlin/pages/PageNodes.kt index 42ca25cc..b9f1025f 100644 --- a/core/src/main/kotlin/pages/PageNodes.kt +++ b/core/src/main/kotlin/pages/PageNodes.kt @@ -1,9 +1,7 @@ package org.jetbrains.dokka.pages -import org.jetbrains.dokka.DokkaConfiguration -import org.jetbrains.dokka.model.Documentable -import org.jetbrains.dokka.Platform import org.jetbrains.dokka.links.DRI +import org.jetbrains.dokka.model.Documentable import java.util.* interface PageNode { diff --git a/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt b/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt index dfa7b480..4f292ca1 100644 --- a/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt +++ b/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt @@ -147,7 +147,8 @@ private class DokkaDescriptorVisitor( sourceSets = setOf(sourceSet), extra = PropertyContainer.withAll( descriptor.additionalExtras().toSourceSetDependent().toAdditionalModifiers(), - descriptor.getAnnotations().toSourceSetDependent().toAnnotations() + descriptor.getAnnotations().toSourceSetDependent().toAnnotations(), + ImplementedInterfaces(info.interfaces) ) ) } @@ -173,7 +174,8 @@ private class DokkaDescriptorVisitor( sourceSets = setOf(sourceSet), extra = PropertyContainer.withAll( descriptor.additionalExtras().toSourceSetDependent().toAdditionalModifiers(), - descriptor.getAnnotations().toSourceSetDependent().toAnnotations() + descriptor.getAnnotations().toSourceSetDependent().toAnnotations(), + ImplementedInterfaces(info.interfaces) ) ) } @@ -201,7 +203,8 @@ private class DokkaDescriptorVisitor( sourceSets = setOf(sourceSet), extra = PropertyContainer.withAll( descriptor.additionalExtras().toSourceSetDependent().toAdditionalModifiers(), - descriptor.getAnnotations().toSourceSetDependent().toAnnotations() + descriptor.getAnnotations().toSourceSetDependent().toAnnotations(), + ImplementedInterfaces(info.interfaces) ) ) } @@ -284,7 +287,8 @@ private class DokkaDescriptorVisitor( sourceSets = setOf(sourceSet), extra = PropertyContainer.withAll( descriptor.additionalExtras().toSourceSetDependent().toAdditionalModifiers(), - descriptor.getAnnotations().toSourceSetDependent().toAnnotations() + descriptor.getAnnotations().toSourceSetDependent().toAnnotations(), + ImplementedInterfaces(info.interfaces) ) ) } @@ -322,14 +326,14 @@ private class DokkaDescriptorVisitor( ) } - fun CallableMemberDescriptor.createDRI(wasOverriden: Boolean = false): Pair<DRI, Boolean> = + fun CallableMemberDescriptor.createDRI(wasOverridenBy: DRI? = null): Pair<DRI, DRI?> = if (kind == CallableMemberDescriptor.Kind.DECLARATION || overriddenDescriptors.isEmpty()) - Pair(DRI.from(this), wasOverriden) + Pair(DRI.from(this), wasOverridenBy) else - overriddenDescriptors.first().createDRI(true) + overriddenDescriptors.first().createDRI(DRI.from(this)) override fun visitFunctionDescriptor(descriptor: FunctionDescriptor, parent: DRIWithPlatformInfo): DFunction { - val (dri, isInherited) = descriptor.createDRI() + val (dri, inheritedFrom) = descriptor.createDRI() val isExpect = descriptor.isExpect val actual = descriptor.createSources() @@ -352,7 +356,7 @@ private class DokkaDescriptorVisitor( type = descriptor.returnType!!.toBound(), sourceSets = setOf(sourceSet), extra = PropertyContainer.withAll( - InheritedFunction(isInherited), + InheritedFunction(inheritedFrom), descriptor.additionalExtras().toSourceSetDependent().toAdditionalModifiers(), descriptor.getAnnotations().toSourceSetDependent().toAnnotations() ) @@ -550,8 +554,17 @@ private class DokkaDescriptorVisitor( getDocumentation()?.toSourceSetDependent() ?: emptyMap() private fun ClassDescriptor.resolveClassDescriptionData(): ClassInfo { + val superClasses = hashSetOf<ClassDescriptor>() + + fun processSuperClasses(supers: List<ClassDescriptor>) { + supers.forEach { + superClasses.add(it) + processSuperClasses(it.getSuperInterfaces() + it.getAllSuperclassesWithoutAny()) + } + } + processSuperClasses(getSuperInterfaces() + getAllSuperclassesWithoutAny()) return ClassInfo( - (getSuperInterfaces() + getAllSuperclassesWithoutAny()).map { DRI.from(it) }, + superClasses.map { Supertype(DRI.from(it), it.kind == ClassKind.INTERFACE) }.toList(), resolveDescriptorData() ) } @@ -726,7 +739,13 @@ private class DokkaDescriptorVisitor( private fun ValueArgument.childrenAsText() = this.safeAs<KtValueArgument>()?.children?.map {it.text }.orEmpty() - private data class ClassInfo(val supertypes: List<DRI>, val docs: SourceSetDependent<DocumentationNode>) + private data class ClassInfo(private val allSupertypes: List<Supertype>, val docs: SourceSetDependent<DocumentationNode>){ + val supertypes: List<DRI> + get() = allSupertypes.map { it.dri } + + val interfaces: List<DRI> + get() = allSupertypes.filter { it.isInterface }.map { it.dri } + } private fun Visibility.toDokkaVisibility(): org.jetbrains.dokka.model.Visibility = when (this) { Visibilities.PUBLIC -> KotlinVisibility.Public @@ -740,6 +759,8 @@ private class DokkaDescriptorVisitor( "${this.enumClassId.relativeClassName.asString()}.${this.enumEntryName.identifier}" private fun fallbackPackageName(): String = "[${sourceSet.displayName} root]"// TODO: error-prone, find a better way to do it + + private data class Supertype(val dri: DRI, val isInterface: Boolean) } private fun DRI.withPackageFallbackTo(fallbackPackage: String): DRI { diff --git a/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt b/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt index 6ec5c4f5..8b397859 100644 --- a/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt +++ b/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt @@ -1,18 +1,20 @@ package org.jetbrains.dokka.base.translators.psi -import com.intellij.icons.AllIcons.Nodes.Static -import com.intellij.lang.jvm.annotation.JvmAnnotationAttribute import com.intellij.lang.jvm.JvmModifier +import com.intellij.lang.jvm.annotation.JvmAnnotationAttribute import com.intellij.lang.jvm.types.JvmReferenceType import com.intellij.openapi.vfs.VirtualFileManager import com.intellij.psi.* import com.intellij.psi.impl.source.PsiClassReferenceType import com.intellij.psi.impl.source.PsiImmediateClassType -import com.intellij.psi.impl.source.tree.java.PsiArrayInitializerMemberValueImpl import org.jetbrains.dokka.links.DRI import org.jetbrains.dokka.links.nextTarget import org.jetbrains.dokka.links.withClass import org.jetbrains.dokka.model.* +import org.jetbrains.dokka.model.doc.DocumentationLink +import org.jetbrains.dokka.model.doc.DocumentationNode +import org.jetbrains.dokka.model.doc.Param +import org.jetbrains.dokka.model.doc.Text import org.jetbrains.dokka.model.properties.PropertyContainer import org.jetbrains.dokka.plugability.DokkaContext import org.jetbrains.dokka.transformers.sources.SourceToDocumentableTranslator @@ -27,9 +29,9 @@ import org.jetbrains.kotlin.load.java.propertyNamesBySetMethodName import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.psi.psiUtil.getChildOfType import org.jetbrains.kotlin.resolve.DescriptorUtils +import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull import org.jetbrains.kotlin.utils.addToStdlib.safeAs import java.io.File -import java.lang.ClassValue object DefaultPsiToDocumentableTranslator : SourceToDocumentableTranslator { @@ -120,23 +122,24 @@ object DefaultPsiToDocumentableTranslator : SourceToDocumentableTranslator { fun parseClasslike(psi: PsiClass, parent: DRI): DClasslike = with(psi) { val dri = parent.withClass(name.toString()) - val ancestorsSet = hashSetOf<DRI>() + val ancestorsSet = hashSetOf<Ancestor>() val superMethodsKeys = hashSetOf<Int>() - val superMethods = mutableListOf<PsiMethod>() + val superMethods = mutableListOf<Pair<PsiMethod, DRI>>() methods.forEach { superMethodsKeys.add(it.hash) } fun parseSupertypes(superTypes: Array<PsiClassType>) { superTypes.forEach { type -> (type as? PsiClassType)?.takeUnless { type.shouldBeIgnored }?.resolve()?.let { + val definedAt = DRI.from(it) it.methods.forEach { method -> val hash = method.hash if (!method.isConstructor && !superMethodsKeys.contains(hash) && method.getVisibility() != Visibilities.PRIVATE ) { superMethodsKeys.add(hash) - superMethods.add(method) + superMethods.add(Pair(method, definedAt)) } } - ancestorsSet.add(DRI.from(it)) + ancestorsSet.add(Ancestor(DRI.from(it), it.isInterface)) parseSupertypes(it.superTypes) } } @@ -145,12 +148,13 @@ object DefaultPsiToDocumentableTranslator : SourceToDocumentableTranslator { val (regularFunctions, accessors) = splitFunctionsAndAccessors() val documentation = javadocParser.parseDocumentation(this).toSourceSetDependent() val allFunctions = regularFunctions.mapNotNull { if (!it.isConstructor) parseFunction(it) else null } + - superMethods.map { parseFunction(it, isInherited = true) } + superMethods.map { parseFunction(it.first, inheritedFrom = it.second) } val source = PsiDocumentableSource(this).toSourceSetDependent() val classlikes = innerClasses.map { parseClasslike(it, dri) } val visibility = getVisibility().toSourceSetDependent() - val ancestors = ancestorsSet.toList().toSourceSetDependent() + val ancestors = ancestorsSet.toList().map { it.dri }.toSourceSetDependent() val modifiers = getModifier().toSourceSetDependent() + val implementedInterfacesExtra = ImplementedInterfaces(ancestorsSet.filter { it.isInterface }.map { it.dri }.toList()) return when { isAnnotationType -> DAnnotation( @@ -167,8 +171,8 @@ object DefaultPsiToDocumentableTranslator : SourceToDocumentableTranslator { constructors.map { parseFunction(it, true) }, mapTypeParameters(dri), setOf(sourceSetData), - PropertyContainer.empty<DAnnotation>() + annotations.toList().getAnnotations() - .toSourceSetDependent().toAnnotations() + PropertyContainer.withAll(implementedInterfacesExtra, annotations.toList().toListOfAnnotations().toSourceSetDependent() + .toAnnotations()) ) isEnum -> DEnum( dri, @@ -183,8 +187,8 @@ object DefaultPsiToDocumentableTranslator : SourceToDocumentableTranslator { emptyList(), emptyList(), setOf(sourceSetData), - PropertyContainer.empty<DEnumEntry>() + entry.annotations.toList().getAnnotations() - .toSourceSetDependent().toAnnotations() + PropertyContainer.withAll(implementedInterfacesExtra, annotations.toList().toListOfAnnotations().toSourceSetDependent() + .toAnnotations()) ) }, documentation, @@ -198,8 +202,8 @@ object DefaultPsiToDocumentableTranslator : SourceToDocumentableTranslator { constructors.map { parseFunction(it, true) }, ancestors, setOf(sourceSetData), - PropertyContainer.empty<DEnum>() + annotations.toList().getAnnotations().toSourceSetDependent() - .toAnnotations() + PropertyContainer.withAll(implementedInterfacesExtra, annotations.toList().toListOfAnnotations().toSourceSetDependent() + .toAnnotations()) ) isInterface -> DInterface( dri, @@ -215,8 +219,8 @@ object DefaultPsiToDocumentableTranslator : SourceToDocumentableTranslator { mapTypeParameters(dri), ancestors, setOf(sourceSetData), - PropertyContainer.empty<DInterface>() + annotations.toList().getAnnotations().toSourceSetDependent() - .toAnnotations() + PropertyContainer.withAll(implementedInterfacesExtra, annotations.toList().toListOfAnnotations().toSourceSetDependent() + .toAnnotations()) ) else -> DClass( dri, @@ -234,8 +238,8 @@ object DefaultPsiToDocumentableTranslator : SourceToDocumentableTranslator { null, modifiers, setOf(sourceSetData), - PropertyContainer.empty<DClass>() + annotations.toList().getAnnotations().toSourceSetDependent() - .toAnnotations() + PropertyContainer.withAll(implementedInterfacesExtra, annotations.toList().toListOfAnnotations().toSourceSetDependent() + .toAnnotations()) ) } } @@ -243,9 +247,10 @@ object DefaultPsiToDocumentableTranslator : SourceToDocumentableTranslator { private fun parseFunction( psi: PsiMethod, isConstructor: Boolean = false, - isInherited: Boolean = false + inheritedFrom: DRI? = null ): DFunction { val dri = DRI.from(psi) + val docs = javadocParser.parseDocumentation(psi).toSourceSetDependent() return DFunction( dri, if (isConstructor) "<init>" else psi.name, @@ -254,13 +259,13 @@ object DefaultPsiToDocumentableTranslator : SourceToDocumentableTranslator { DParameter( dri.copy(target = dri.target.nextTarget()), psiParameter.name, - javadocParser.parseDocumentation(psiParameter).toSourceSetDependent(), + DocumentationNode(docs.entries.mapNotNull { it.value.children.filterIsInstance<Param>().firstOrNull { it.root.children.firstIsInstanceOrNull<DocumentationLink>()?.children?.firstIsInstanceOrNull<Text>()?.body == psiParameter.name } }).toSourceSetDependent(), null, getBound(psiParameter.type), setOf(sourceSetData) ) }, - javadocParser.parseDocumentation(psi).toSourceSetDependent(), + docs, null, PsiDocumentableSource(psi).toSourceSetDependent(), psi.getVisibility().toSourceSetDependent(), @@ -271,9 +276,9 @@ object DefaultPsiToDocumentableTranslator : SourceToDocumentableTranslator { setOf(sourceSetData), psi.additionalExtras().let { PropertyContainer.withAll( - InheritedFunction(isInherited), + InheritedFunction(inheritedFrom), it.toSourceSetDependent().toAdditionalModifiers(), - (psi.annotations.toList().getAnnotations() + it.getAnnotations()).toSourceSetDependent() + (psi.annotations.toList().toListOfAnnotations() + it.toListOfAnnotations()).toSourceSetDependent() .toAnnotations() ) } @@ -291,7 +296,7 @@ object DefaultPsiToDocumentableTranslator : SourceToDocumentableTranslator { ).toSet() - private fun Set<ExtraModifiers>.getAnnotations() = map { + private fun Set<ExtraModifiers>.toListOfAnnotations() = map { if (it !is ExtraModifiers.JavaOnlyModifiers.Static) Annotations.Annotation(DRI("kotlin.jvm", it.name.toLowerCase().capitalize()), emptyMap()) else @@ -398,14 +403,14 @@ object DefaultPsiToDocumentableTranslator : SourceToDocumentableTranslator { psi.additionalExtras().let { PropertyContainer.withAll<DProperty>( it.toSourceSetDependent().toAdditionalModifiers(), - (psi.annotations.toList().getAnnotations() + it.getAnnotations()).toSourceSetDependent() + (psi.annotations.toList().toListOfAnnotations() + it.toListOfAnnotations()).toSourceSetDependent() .toAnnotations() ) } ) } - private fun Collection<PsiAnnotation>.getAnnotations() = + private fun Collection<PsiAnnotation>.toListOfAnnotations() = filter { it !is KtLightAbstractAnnotation }.mapNotNull { it.toAnnotation() } private fun JvmAnnotationAttribute.toValue(): AnnotationParameterValue = when (this) { @@ -436,4 +441,6 @@ object DefaultPsiToDocumentableTranslator : SourceToDocumentableTranslator { DRI.from(it) } } + + private data class Ancestor(val dri: DRI, val isInterface: Boolean) } diff --git a/plugins/base/src/test/kotlin/content/params/ContentForParamsTest.kt b/plugins/base/src/test/kotlin/content/params/ContentForParamsTest.kt index 335d834e..f66f88db 100644 --- a/plugins/base/src/test/kotlin/content/params/ContentForParamsTest.kt +++ b/plugins/base/src/test/kotlin/content/params/ContentForParamsTest.kt @@ -1,8 +1,18 @@ package content.params import matchers.content.* +import org.jetbrains.dokka.Platform +import org.jetbrains.dokka.model.DFunction +import org.jetbrains.dokka.model.Documentable +import org.jetbrains.dokka.model.SourceSetData +import org.jetbrains.dokka.model.doc.DocumentationNode +import org.jetbrains.dokka.model.doc.Param +import org.jetbrains.dokka.model.doc.Text import org.jetbrains.dokka.pages.ContentPage +import org.jetbrains.dokka.pages.MemberPageNode +import org.jetbrains.dokka.pages.dfs import org.jetbrains.dokka.testApi.testRunner.AbstractCoreTest +import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull import org.junit.jupiter.api.Test import utils.* @@ -558,4 +568,45 @@ class ContentForParamsTest : AbstractCoreTest() { } } } + + @Test + fun javaDocCommentWithDocumentedParameters(){ + testInline( + """ + |/src/main/java/test/Main.java + |package test + | public class Main { + | + | /** + | * comment to function + | * @param first comment to first param + | * @param second comment to second param + | */ + | public void sample(String first, String second) { + | + | } + | } + """.trimIndent(), testConfiguration + ){ + pagesTransformationStage = { + module -> + val sampleFunction = module.dfs { + it is MemberPageNode && it.dri.first().toString() == "test/Main/sample/#java.lang.String#java.lang.String/PointingToDeclaration/" + } as MemberPageNode + val forJvm = (sampleFunction.documentable as DFunction).parameters.mapNotNull { + val jvm = it.documentation.keys.first { it.platform == Platform.jvm } + it.documentation[jvm] + } + + assert(forJvm.size == 2) + val (first, second) = forJvm.map { it.paramsDescription() } + assert(first == "comment to first param") + assert(second == "comment to second param") + } + } + } + + private fun DocumentationNode.paramsDescription(): String = + children.firstIsInstanceOrNull<Param>()?.root?.children?.firstIsInstanceOrNull<Text>()?.body.orEmpty() + }
\ No newline at end of file diff --git a/plugins/base/src/test/kotlin/model/ClassesTest.kt b/plugins/base/src/test/kotlin/model/ClassesTest.kt index 5616a6c3..9121f9ae 100644 --- a/plugins/base/src/test/kotlin/model/ClassesTest.kt +++ b/plugins/base/src/test/kotlin/model/ClassesTest.kt @@ -1,6 +1,7 @@ package model import org.jetbrains.dokka.links.DRI +import org.jetbrains.dokka.links.sureClassNames import org.jetbrains.dokka.model.* import org.jetbrains.dokka.model.KotlinModifier.* import org.junit.jupiter.api.Assertions.assertNull @@ -425,7 +426,7 @@ class ClassesTest : AbstractModelTest("/src/main/kotlin/classes/Test.kt", "class """@Suppress("abc") class Foo() {}""" ) { with((this / "classes" / "Foo").cast<DClass>()) { - with(extra[Annotations]!!.content.entries.single().value.firstOrNull().assertNotNull("annotations")) { + with(extra[Annotations]?.content?.firstOrNull().assertNotNull("annotations")) { dri.toString() equals "kotlin/Suppress///PointingToDeclaration/" (params["names"].assertNotNull("param") as ArrayValue).value equals listOf(StringValue("\"abc\"")) } @@ -483,4 +484,20 @@ class ClassesTest : AbstractModelTest("/src/main/kotlin/classes/Test.kt", "class } } } + + @Test fun allImplementedInterfaces() { + inlineModelTest( + """ + | interface Highest { } + | open class HighestImpl: Highest { } + | interface Lower { } + | interface LowerImplInterface: Lower { } + | class Tested : HighestImpl(), LowerImplInterface { } + """.trimIndent() + ){ + with((this / "classes" / "Tested").cast<DClass>()){ + extra[ImplementedInterfaces]?.interfaces?.map { it.sureClassNames }?.sorted() equals listOf("Highest", "Lower", "LowerImplInterface").sorted() + } + } + } }
\ No newline at end of file diff --git a/plugins/base/src/test/kotlin/model/JavaTest.kt b/plugins/base/src/test/kotlin/model/JavaTest.kt index 8f52fcc8..77fcc666 100644 --- a/plugins/base/src/test/kotlin/model/JavaTest.kt +++ b/plugins/base/src/test/kotlin/model/JavaTest.kt @@ -2,16 +2,22 @@ package model import org.jetbrains.dokka.base.transformers.documentables.InheritorsInfo import org.jetbrains.dokka.links.DRI +import org.jetbrains.dokka.links.sureClassNames import org.jetbrains.dokka.model.* +import org.jetbrains.dokka.model.doc.Param +import org.jetbrains.dokka.model.doc.Text +import org.jetbrains.dokka.pages.dfs +import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull import org.junit.jupiter.api.Assertions.assertTrue import org.junit.jupiter.api.Test import utils.AbstractModelTest import utils.assertNotNull +import utils.docs import utils.name class JavaTest : AbstractModelTest("/src/main/kotlin/java/Test.java", "java") { - @Test //todo params in comments + @Test fun function() { inlineModelTest( """ @@ -30,12 +36,27 @@ class JavaTest : AbstractModelTest("/src/main/kotlin/java/Test.java", "java") { children counts 1 with((this / "fn").cast<DFunction>()) { name equals "fn" - this + val params = parameters.map { it.documentation.values.first().children.first() as Param } + params.mapNotNull { it.root.children.firstIsInstanceOrNull<Text>()?.body } equals listOf("is String parameter", "is int parameter") } } } } + @Test fun allImplementedInterfacesInJava() { + inlineModelTest( + """ + |interface Highest { } + |interface Lower extends Highest { } + |class Extendable { } + |class Tested extends Extendable implements Lower { } + """){ + with((this / "java" / "Tested").cast<DClass>()){ + extra[ImplementedInterfaces]?.interfaces?.map { it.sureClassNames }?.sorted() equals listOf("Highest", "Lower").sorted() + } + } + } + //@Test fun function() { // verifyJavaPackageMember("testdata/java/member.java", defaultModelConfig) { cls -> // assertEquals("Test", cls.name) diff --git a/plugins/javadoc/src/main/kotlin/javadoc/JavadocLocationProvider.kt b/plugins/javadoc/src/main/kotlin/javadoc/JavadocLocationProvider.kt index 520486f6..a92320dd 100644 --- a/plugins/javadoc/src/main/kotlin/javadoc/JavadocLocationProvider.kt +++ b/plugins/javadoc/src/main/kotlin/javadoc/JavadocLocationProvider.kt @@ -91,7 +91,7 @@ class JavadocLocationProvider(pageRoot: RootPageNode, private val context: Dokka } }?.joinToString("/")?.let {if (skipExtension) "$it.html" else it}?.let { Paths.get(dir).relativize(Paths.get(it)).toString() - } ?: run {throw IllegalStateException("Page for ${link.name} not found")} + } ?: run {""} //TODO just a glue to compile it on HMPP override fun resolveRoot(node: PageNode): String { TODO("Not yet implemented") diff --git a/plugins/javadoc/src/main/kotlin/javadoc/JavadocPageCreator.kt b/plugins/javadoc/src/main/kotlin/javadoc/JavadocPageCreator.kt index 64fc539f..a3bef099 100644 --- a/plugins/javadoc/src/main/kotlin/javadoc/JavadocPageCreator.kt +++ b/plugins/javadoc/src/main/kotlin/javadoc/JavadocPageCreator.kt @@ -3,14 +3,21 @@ package javadoc import javadoc.pages.* import org.jetbrains.dokka.Platform import org.jetbrains.dokka.base.signatures.SignatureProvider +import org.jetbrains.dokka.base.signatures.function import org.jetbrains.dokka.base.transformers.pages.comments.CommentsToContentConverter import org.jetbrains.dokka.base.transformers.pages.comments.DocTagToContentConverter import org.jetbrains.dokka.model.* import org.jetbrains.dokka.model.doc.Description +import org.jetbrains.dokka.model.doc.Param +import org.jetbrains.dokka.model.doc.TagWrapper +import org.jetbrains.dokka.model.doc.Text +import org.jetbrains.dokka.model.properties.PropertyContainer +import org.jetbrains.dokka.model.properties.WithExtraProperties import org.jetbrains.dokka.pages.ContentKind import org.jetbrains.dokka.pages.DCI import org.jetbrains.dokka.utilities.DokkaLogger import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull +import org.jetbrains.kotlin.utils.addToStdlib.safeAs open class JavadocPageCreator( commentsToContentConverter: CommentsToContentConverter, @@ -28,21 +35,28 @@ open class JavadocPageCreator( fun pageForPackage(p: DPackage) = JavadocPackagePageNode(p.name, contentForPackage(p), setOf(p.dri), p, - p.classlikes.map { pageForClasslike(it) } // TODO: nested classlikes - ).also { - it - } + p.classlikes.mapNotNull { pageForClasslike(it) } // TODO: nested classlikes + ) - fun pageForClasslike(c: DClasslike): JavadocClasslikePageNode { - val constructors = when (c) { - is DClass -> c.constructors - is DEnum -> c.constructors - else -> emptyList() + fun pageForClasslike(c: DClasslike): JavadocClasslikePageNode? = + c.sourceSets.firstOrNull { it.platform == Platform.jvm }?.let {jvm -> + JavadocClasslikePageNode( + name = c.name.orEmpty(), + content = contentForClasslike(c), + dri = setOf(c.dri), + modifiers = listOfNotNull(c.visibility[jvm]?.name), + signature = signatureProvider.signature(c), + description = c.description(jvm), + constructors = c.safeAs<WithConstructors>()?.constructors?.map { it.toJavadocFunction(jvm) }.orEmpty(), + methods = c.functions.map { it.toJavadocFunction(jvm) }, + entries = c.safeAs<DEnum>()?.entries?.map { JavadocEntryNode(signatureProvider.signature(it), it.description(jvm)) }.orEmpty(), + classlikes = c.classlikes.mapNotNull { pageForClasslike(it) }, + properties = c.properties.map { JavadocPropertyNode(signatureProvider.signature(it), TextNode(it.description(jvm), setOf(jvm))) }, + documentable = c, + extras = c.safeAs<WithExtraProperties<Documentable>>()?.extra ?: PropertyContainer.empty() + ) } - return JavadocClasslikePageNode(c.name.orEmpty(), contentForClasslike(c), setOf(c.dri), c, emptyList()) - } - fun contentForModule(m: DModule): JavadocContentNode = JavadocContentGroup( setOf(m.dri), @@ -96,5 +110,48 @@ open class JavadocPageCreator( kind = JavadocContentKind.Class ) } + + private fun signatureForProjection(p: Projection): String = + when (p) { + is OtherParameter -> p.name + is TypeConstructor -> if (p.function) + "TODO" + else { + val other = if(p.projections.isNotEmpty()){ + p.projections.joinToString(prefix = "<", postfix = ">") { signatureForProjection(it) } + } else { + "" + } + "${p.dri.classNames.orEmpty()} $other" + } + + is Variance -> "${p.kind} ${signatureForProjection(p.inner)}" + is Star -> "*" + is Nullable -> "${signatureForProjection(p.inner)}?" + is JavaObject -> "Object" + is Void -> "Void" + is PrimitiveJavaType -> p.name + is Dynamic -> "dynamic" + is UnresolvedBound -> p.name + } + + private fun DFunction.toJavadocFunction(sourceSetData: SourceSetData) = JavadocFunctionNode( + name = name, + signature = signatureProvider.signature(this), + brief = TextNode(description(sourceSetData), setOf(sourceSetData)), + parameters = parameters.map { + JavadocParameterNode( + name = it.name.orEmpty(), + type = signatureForProjection(it.type), + description = TextNode(it.findNodeInDocumentation<Param>(sourceSetData), setOf(sourceSetData)) + ) + }, + extras = extra + ) + + private fun Documentable.description(sourceSetData: SourceSetData): String = findNodeInDocumentation<Description>(sourceSetData) + + private inline fun <reified T: TagWrapper> Documentable.findNodeInDocumentation(sourceSetData: SourceSetData): String = + documentation[sourceSetData]?.children?.firstIsInstanceOrNull<T>()?.root?.children?.firstIsInstanceOrNull<Text>()?.body.orEmpty() } diff --git a/plugins/javadoc/src/main/kotlin/javadoc/KorteJavadocRenderer.kt b/plugins/javadoc/src/main/kotlin/javadoc/KorteJavadocRenderer.kt index aa7c2dfe..1026ea5c 100644 --- a/plugins/javadoc/src/main/kotlin/javadoc/KorteJavadocRenderer.kt +++ b/plugins/javadoc/src/main/kotlin/javadoc/KorteJavadocRenderer.kt @@ -8,13 +8,19 @@ import kotlinx.coroutines.launch import kotlinx.coroutines.runBlocking import org.jetbrains.dokka.base.renderers.OutputWriter import org.jetbrains.dokka.links.DRI +import org.jetbrains.dokka.links.sureClassNames +import org.jetbrains.dokka.model.ImplementedInterfaces +import org.jetbrains.dokka.model.InheritedFunction import org.jetbrains.dokka.pages.* import org.jetbrains.dokka.plugability.DokkaContext import org.jetbrains.dokka.renderers.Renderer +import org.jetbrains.kotlin.utils.addToStdlib.safeAs import java.nio.file.Path import java.nio.file.Paths import java.time.LocalDate +typealias PageContent = Map<String, Any?> + class KorteJavadocRenderer(val outputWriter: OutputWriter, val context: DokkaContext, val resourceDir: String) : Renderer { private lateinit var locationProvider: JavadocLocationProvider @@ -67,8 +73,7 @@ class KorteJavadocRenderer(val outputWriter: OutputWriter, val context: DokkaCon "docName" to "docName", // todo docname "pathToRoot" to pathToRoot, "dir" to dir - ) + node.contentMap -// DokkaConsoleLogger.info("${node::class.java.canonicalName}::${node.name} - $link") + ) + renderContentNodes(node) writeFromTemplate(outputWriter, link, templateForNode(node), contentMap.toList()) node.children.forEach { renderNode(it, link.toNormalized()) } } @@ -120,11 +125,11 @@ class KorteJavadocRenderer(val outputWriter: OutputWriter, val context: DokkaCon ) } - private fun renderContentNode(content: ContentNode) = when(content) { - is ContentText -> content.text - is ContentComposite -> renderContent(content.children) - else -> "" - } +// private fun renderContentNode(content: ContentNode) = when(content) { +// is ContentText -> content.text +// is ContentComposite -> renderContent(content.children) +// else -> "" +// } private fun renderContent(content: List<ContentNode>): String = content.joinToString("") { renderContentNode(it) } @@ -179,7 +184,10 @@ class KorteJavadocRenderer(val outputWriter: OutputWriter, val context: DokkaCon } rootNodes.joinToString{ drawRec(it) } }, - Filter("length") { subject.dynamicLength() } + Filter("length") { subject.dynamicLength() }, + TeFunction("hasAnyDescription"){ args -> + args.first().safeAs<List<HashMap<String, String>>>()?.any { it["description"]?.trim()?.isNotEmpty() ?: false } + } ).forEach { when (it) { is TeFunction -> config.register(it) @@ -197,4 +205,94 @@ class KorteJavadocRenderer(val outputWriter: OutputWriter, val context: DokkaCon javaClass.classLoader.getResourceAsStream("$basePath/$template")?.bufferedReader()?.lines()?.toArray() ?.joinToString("\n") ?: throw IllegalStateException("Template not found: $basePath/$template") } + + private fun renderContentNodes(node: JavadocPageNode): PageContent = + when(node){ + is JavadocClasslikePageNode -> renderClasslikeNode(node) + is JavadocFunctionNode -> renderFunctionNode(node) + else -> node.contentMap + } + + private fun renderFunctionNode(node: JavadocFunctionNode): PageContent { + val (modifiers, signature) = node.modifiersAndSignature + return mapOf( + "signature" to renderContentNode(node.signature), + "brief" to renderContentNode(node.brief), + "parameters" to node.parameters.map { renderParameterNode(it) }, + "inlineParameters" to node.parameters.joinToString { "${it.type} ${it.name}" }, + "modifiers" to renderContentNode(modifiers), + "signatureWithoutModifiers" to renderContentNode(signature)) + node.contentMap + } + + private fun renderParameterNode(node: JavadocParameterNode): PageContent = + mapOf( + "description" to renderContentNode(node.description), + ) + node.contentMap + + private fun renderClasslikeNode(node: JavadocClasslikePageNode): PageContent = + mapOf( + "constructors" to node.constructors.map { renderContentNodes(it) }, + "signature" to renderContentNode(node.signature), + "methods" to renderClasslikeMethods(node.methods), + "entries" to node.entries.map { renderEntryNode(it) }, + "properties" to node.properties.map { renderPropertyNode(it)}, + "classlikes" to node.classlikes.map { renderNestedClasslikeNode(it) }, + "implementedInterfaces" to renderImplementedInterfaces(node) + ) + node.contentMap + + private fun renderImplementedInterfaces(node: JavadocClasslikePageNode) = + node.extras[ImplementedInterfaces]?.interfaces?.map { it.displayable() }.orEmpty() + + private fun renderClasslikeMethods(nodes: List<JavadocFunctionNode>): PageContent { + val (inherited, own) = nodes.partition { it.extras[InheritedFunction]?.isInherited ?: false } + return mapOf( + "own" to own.map { renderContentNodes(it) }, + "inherited" to inherited.map { renderInheritedMethod(it) }.groupBy { it["inheritedFrom"] as String }.entries.map { + mapOf("inheritedFrom" to it.key, "names" to it.value.map{ it["name"] as String }.sorted().joinToString() ) + } + ) + } + + private fun renderInheritedMethod(node: JavadocFunctionNode): PageContent { + val inheritedFrom = node.extras[InheritedFunction]?.inheritedFrom + return mapOf( + "inheritedFrom" to inheritedFrom?.displayable().orEmpty(), + "name" to node.name + ) + } + + private fun renderNestedClasslikeNode(node: JavadocClasslikePageNode): PageContent { + return mapOf( + "modifiers" to (node.modifiers + "static" + node.contentMap["kind"]).joinToString(separator = " "), + "signature" to node.name, + "description" to node.description + ) + } + + private fun renderPropertyNode(node: JavadocPropertyNode): PageContent { + val (modifiers, signature) = node.modifiersAndSignature + return mapOf( + "modifiers" to renderContentNode(modifiers), + "signature" to renderContentNode(signature), + "description" to renderContentNode(node.brief) + ) + } + + private fun renderEntryNode(node: JavadocEntryNode): PageContent = + mapOf( + "signature" to renderContentNode(node.signature), + ) + node.contentMap + + + //TODO is it possible to use html renderer? + private fun renderContentNode(node: ContentNode): String = + when(node){ + is ContentGroup -> node.children.joinToString(separator = "") { renderContentNode(it) } + is ContentText -> node.text + is TextNode -> node.text + is ContentLink -> """<a href="TODO">${node.children.joinToString { renderContentNode(it) }} </a>""" + else -> "" + } + + private fun DRI.displayable(): String = "${packageName}.${sureClassNames}" }
\ No newline at end of file diff --git a/plugins/javadoc/src/main/kotlin/javadoc/pages/JavadocContentNodes.kt b/plugins/javadoc/src/main/kotlin/javadoc/pages/JavadocContentNodes.kt index 031ce970..1c42adb3 100644 --- a/plugins/javadoc/src/main/kotlin/javadoc/pages/JavadocContentNodes.kt +++ b/plugins/javadoc/src/main/kotlin/javadoc/pages/JavadocContentNodes.kt @@ -37,6 +37,8 @@ class EmptyNode( override fun withNewExtras(newExtras: PropertyContainer<ContentNode>): ContentNode = EmptyNode(dci.dri.first(), dci.kind, sourceSets, newExtras) + + override fun hasAnyContent(): Boolean = false } class JavadocContentGroup( @@ -56,6 +58,8 @@ class JavadocContentGroup( ): JavadocContentGroup = JavadocContentGroup(dri, kind, sourceSets, JavaContentGroupBuilder(sourceSets).apply(block).list) } + + override fun hasAnyContent(): Boolean = children.isNotEmpty() } class JavaContentGroupBuilder(val sourceSets: Set<SourceSetData>) { @@ -71,6 +75,8 @@ class TitleNode( sourceSets: Set<SourceSetData> ) : JavadocContentNode(dri, kind, sourceSets) { + override fun hasAnyContent(): Boolean = !title.isBlank() || !version.isBlank() + override val contentMap: Map<String, Any?> by lazy { mapOf( "title" to title, @@ -78,8 +84,6 @@ class TitleNode( "packageName" to parent ) } - -// override fun withNewExtras(newExtras: PropertyContainer<ContentNode>): ContentNode = TODO() } fun JavaContentGroupBuilder.title( @@ -92,6 +96,18 @@ fun JavaContentGroupBuilder.title( list.add(TitleNode(title, version, parent, dri, kind, sourceSets)) } +data class TextNode( + val text: String, + override val sourceSets: Set<SourceSetData> +) : JavadocContentNode(emptySet(), ContentKind.Main, sourceSets) { + + override fun hasAnyContent(): Boolean = !text.isBlank() + + override val contentMap: Map<String, Any?> = mapOf( + "text" to text, + ) +} + class ListNode( val tabTitle: String, val colTitle: String, @@ -100,6 +116,9 @@ class ListNode( val kind: Kind, sourceSets: Set<SourceSetData> ) : JavadocContentNode(dri, kind, sourceSets) { + + override fun hasAnyContent(): Boolean = children.isNotEmpty() + override val contentMap: Map<String, Any?> by lazy { mapOf( "tabTitle" to tabTitle, diff --git a/plugins/javadoc/src/main/kotlin/javadoc/pages/JavadocPageNodes.kt b/plugins/javadoc/src/main/kotlin/javadoc/pages/JavadocPageNodes.kt index 118bc4d3..7f6abb15 100644 --- a/plugins/javadoc/src/main/kotlin/javadoc/pages/JavadocPageNodes.kt +++ b/plugins/javadoc/src/main/kotlin/javadoc/pages/JavadocPageNodes.kt @@ -6,10 +6,12 @@ import org.jetbrains.dokka.Platform import org.jetbrains.dokka.base.renderers.platforms import org.jetbrains.dokka.links.DRI import org.jetbrains.dokka.model.* +import org.jetbrains.dokka.model.properties.PropertyContainer import org.jetbrains.dokka.pages.* import org.jetbrains.kotlin.descriptors.ClassDescriptor import org.jetbrains.kotlin.descriptors.ClassKind import org.jetbrains.kotlin.resolve.DescriptorUtils.getClassDescriptorForType +import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstance interface JavadocPageNode : ContentPage { val contentMap: Map<String, Any?> @@ -79,20 +81,98 @@ class JavadocPackagePageNode( ) } +data class JavadocEntryNode( + val signature: ContentNode, + val brief: String +) { + val contentMap: Map<String, Any?> = mapOf( + "brief" to brief + ) +} + +data class JavadocParameterNode( + val name: String, + val type: String, + val description: ContentNode +) { + val contentMap: Map<String, Any?> = mapOf( + "name" to name, + "type" to type + ) +} + +data class JavadocPropertyNode( + val signature: ContentNode, + val brief: ContentNode +){ + val modifiersAndSignature: Pair<ContentNode, ContentNode> + get() = (signature as ContentGroup).splitSignatureIntoModifiersAndName() +} + +data class JavadocFunctionNode( + val signature: ContentNode, + val brief: ContentNode, + val parameters: List<JavadocParameterNode>, + override val name: String, + override val dri: Set<DRI> = emptySet(), + override val content: ContentNode = EmptyNode(DRI.topLevel, ContentKind.Classlikes, emptySet()), + override val children: List<PageNode> = emptyList(), + override val documentable: Documentable? = null, + override val embeddedResources: List<String> = emptyList(), + val extras: PropertyContainer<DFunction> = PropertyContainer.empty() +): JavadocPageNode { + override val contentMap: Map<String, Any?> = mapOf( + "name" to name + ) + + override fun modified( + name: String, + children: List<PageNode> + ): PageNode = TODO() + + override fun modified( + name: String, + content: ContentNode, + dri: Set<DRI>, + embeddedResources: List<String>, + children: List<PageNode> + ): ContentPage = TODO() + + val modifiersAndSignature: Pair<ContentNode, ContentNode> + get() = (signature as ContentGroup).splitSignatureIntoModifiersAndName() + +} + class JavadocClasslikePageNode( override val name: String, override val content: JavadocContentNode, override val dri: Set<DRI>, - + val modifiers: List<String>, + val signature: ContentNode, + val description: String, + val constructors: List<JavadocFunctionNode>, + val methods: List<JavadocFunctionNode>, + val entries: List<JavadocEntryNode>, + val classlikes: List<JavadocClasslikePageNode>, + val properties: List<JavadocPropertyNode>, override val documentable: Documentable? = null, override val children: List<PageNode> = emptyList(), - override val embeddedResources: List<String> = listOf() + override val embeddedResources: List<String> = listOf(), + val extras: PropertyContainer<Documentable>, ) : JavadocPageNode { - override val contentMap: Map<String, Any?> by lazy { mapOf("kind" to "class") + content.contentMap } + override val contentMap: Map<String, Any?> by lazy { + mapOf( + "kind" to documentable?.kind(), + "name" to name, + "package" to dri.first().packageName, + "classlikeDocumentation" to description + ) + content.contentMap + } + override fun modified( name: String, children: List<PageNode> - ): PageNode = JavadocClasslikePageNode(name, content, dri, documentable, children, embeddedResources) + ): PageNode = JavadocClasslikePageNode(name, content, dri, modifiers, signature, description, constructors, methods, entries, classlikes, properties, documentable, children, embeddedResources, extras) override fun modified( name: String, @@ -101,7 +181,7 @@ class JavadocClasslikePageNode( embeddedResources: List<String>, children: List<PageNode> ): ContentPage = - JavadocClasslikePageNode(name, content as JavadocContentNode, dri, documentable, children, embeddedResources) + JavadocClasslikePageNode(name, content as JavadocContentNode, dri, modifiers, signature, description, constructors, methods, entries, classlikes, properties, documentable, children, embeddedResources, extras) } class AllClassesPage(val classes: List<JavadocClasslikePageNode>) : JavadocPageNode { @@ -295,10 +375,8 @@ class TreeViewPage( descriptorInheritanceTree.forEach { addToMap(it, mergeMap) } psiInheritanceTree.forEach { addToMap(it, mergeMap) } - val g = mergeMap.entries.find { it.key.classNames == "Any" || it.key.classNames == "Object" }?.value?.dri?.let(::collect) - val rootClasses = listOf("Any", "Object") val rootNodes = mergeMap.entries.filter { - it.key.classNames in rootClasses //TODO: Probably should be matched by DRI, not just className + it.key.classNames in setOf("Any", "Object") //TODO: Probably should be matched by DRI, not just className }.map { collect(it.value.dri) } @@ -350,4 +428,20 @@ class TreeViewPage( interface ContentValue data class StringValue(val text: String) : ContentValue -data class ListValue(val list: List<String>) : ContentValue
\ No newline at end of file +data class ListValue(val list: List<String>) : ContentValue + +private fun ContentGroup.splitSignatureIntoModifiersAndName(): Pair<ContentNode, ContentNode> { + val signature = children.firstIsInstance<ContentGroup>() + val modifiers = signature.children.takeWhile { it !is ContentLink } + return Pair(signature.copy(children = modifiers), signature.copy(children = signature.children.drop(modifiers.size))) +} + +private fun Documentable.kind(): String? = + when(this){ + is DClass -> "class" + is DEnum -> "enum" + is DAnnotation -> "annotation" + is DObject -> "object" + is DInterface -> "interface" + else -> null + }
\ No newline at end of file diff --git a/plugins/javadoc/src/main/kotlin/javadoc/pages/OverviewSummary.kt b/plugins/javadoc/src/main/kotlin/javadoc/pages/OverviewSummary.kt deleted file mode 100644 index ae573007..00000000 --- a/plugins/javadoc/src/main/kotlin/javadoc/pages/OverviewSummary.kt +++ /dev/null @@ -1,161 +0,0 @@ -package javadoc.pages - -import java.time.LocalDate - -internal fun overviewSummary(title: String, version: String) = """ -<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> -<!-- NewPage --> -<html lang="en"> -<head> -<title>Overview ($title $version API)</title> -<meta name="date" content="${LocalDate.now()}"> -<link rel="stylesheet" type="text/css" href="stylesheet.css" title="Style"> -<script type="text/javascript" src="script.js"></script> -</head> -<body> -<script type="text/javascript"><!-- - try { - if (location.href.indexOf('is-external=true') == -1) { - parent.document.title="Overview ($title $version API)"; - } - } - catch(err) { - } -//--> -</script> -<noscript> -<div>JavaScript is disabled on your browser.</div> -</noscript> -<!-- ========= START OF TOP NAVBAR ======= --> -<div class="topNav"><a name="navbar.top"> -<!-- --> -</a> -<div class="skipNav"><a href="#skip.navbar.top" title="Skip navigation links">Skip navigation links</a></div> -<a name="navbar.top.firstrow"> -<!-- --> -</a> -<ul class="navList" title="Navigation"> -<li class="navBarCell1Rev">Overview</li> -<li>Package</li> -<li>Class</li> -<li><a href="overview-tree.html">Tree</a></li> -<li><a href="deprecated-list.html">Deprecated</a></li> -<li><a href="index-all.html">Index</a></li> -<li><a href="help-doc.html">Help</a></li> -</ul> -</div> -<div class="subNav"> -<ul class="navList"> -<li>Prev</li> -<li>Next</li> -</ul> -<ul class="navList"> -<li><a href="index.html?overview-summary.html" target="_top">Frames</a></li> -<li><a href="overview-summary.html" target="_top">No Frames</a></li> -</ul> -<ul class="navList" id="allclasses_navbar_top"> -<li><a href="allclasses-noframe.html">All Classes</a></li> -</ul> -<div> -<script type="text/javascript"><!-- - allClassesLink = document.getElementById("allclasses_navbar_top"); - if(window==top) { - allClassesLink.style.display = "block"; - } - else { - allClassesLink.style.display = "none"; - } - //--> -</script> -</div> -<a name="skip.navbar.top"> -<!-- --> -</a></div> -<!-- ========= END OF TOP NAVBAR ========= --> -<div class="header"> -<h1 class="title">terrain-generator 0.0.1 API</h1> -</div> -<div class="contentContainer"> -<table class="overviewSummary" border="0" cellpadding="3" cellspacing="0" summary="Packages table, listing packages, and an explanation"> -<caption><span>Packages</span><span class="tabEnd"> </span></caption> -<tr> -<th class="colFirst" scope="col">Package</th> -<th class="colLast" scope="col">Description</th> -</tr> -<tbody> -<tr class="altColor"> -<td class="colFirst"><a href="adaptation/package-summary.html">adaptation</a></td> -<td class="colLast"> </td> -</tr> -<tr class="rowColor"> -<td class="colFirst"><a href="app/package-summary.html">app</a></td> -<td class="colLast"> </td> -</tr> -<tr class="altColor"> -<td class="colFirst"><a href="common/package-summary.html">common</a></td> -<td class="colLast"> </td> -</tr> -<tr class="rowColor"> -<td class="colFirst"><a href="model/package-summary.html">model</a></td> -<td class="colLast"> </td> -</tr> -<tr class="altColor"> -<td class="colFirst"><a href="processor/package-summary.html">processor</a></td> -<td class="colLast"> </td> -</tr> -<tr class="rowColor"> -<td class="colFirst"><a href="transformation/package-summary.html">transformation</a></td> -<td class="colLast"> </td> -</tr> -</tbody> -</table> -</div> -<!-- ======= START OF BOTTOM NAVBAR ====== --> -<div class="bottomNav"><a name="navbar.bottom"> -<!-- --> -</a> -<div class="skipNav"><a href="#skip.navbar.bottom" title="Skip navigation links">Skip navigation links</a></div> -<a name="navbar.bottom.firstrow"> -<!-- --> -</a> -<ul class="navList" title="Navigation"> -<li class="navBarCell1Rev">Overview</li> -<li>Package</li> -<li>Class</li> -<li><a href="overview-tree.html">Tree</a></li> -<li><a href="deprecated-list.html">Deprecated</a></li> -<li><a href="index-all.html">Index</a></li> -<li><a href="help-doc.html">Help</a></li> -</ul> -</div> -<div class="subNav"> -<ul class="navList"> -<li>Prev</li> -<li>Next</li> -</ul> -<ul class="navList"> -<li><a href="index.html?overview-summary.html" target="_top">Frames</a></li> -<li><a href="overview-summary.html" target="_top">No Frames</a></li> -</ul> -<ul class="navList" id="allclasses_navbar_bottom"> -<li><a href="allclasses-noframe.html">All Classes</a></li> -</ul> -<div> -<script type="text/javascript"><!-- - allClassesLink = document.getElementById("allclasses_navbar_bottom"); - if(window==top) { - allClassesLink.style.display = "block"; - } - else { - allClassesLink.style.display = "none"; - } - //--> -</script> -</div> -<a name="skip.navbar.bottom"> -<!-- --> -</a></div> -<!-- ======== END OF BOTTOM NAVBAR ======= --> -</body> -</html> -"""
\ No newline at end of file diff --git a/plugins/javadoc/src/main/resources/static_res/script.js b/plugins/javadoc/src/main/resources/static_res/script.js new file mode 100644 index 00000000..15fe6ac1 --- /dev/null +++ b/plugins/javadoc/src/main/resources/static_res/script.js @@ -0,0 +1,139 @@ +/* + * Copyright (c) 2013, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +var moduleSearchIndex; +var packageSearchIndex; +var typeSearchIndex; +var memberSearchIndex; +var tagSearchIndex; +function loadScripts(doc, tag) { + createElem(doc, tag, 'jquery/jszip/dist/jszip.js'); + createElem(doc, tag, 'jquery/jszip-utils/dist/jszip-utils.js'); + if (window.navigator.userAgent.indexOf('MSIE ') > 0 || window.navigator.userAgent.indexOf('Trident/') > 0 || + window.navigator.userAgent.indexOf('Edge/') > 0) { + createElem(doc, tag, 'jquery/jszip-utils/dist/jszip-utils-ie.js'); + } + createElem(doc, tag, 'search.js'); + + $.get(pathtoroot + "module-search-index.zip") + .done(function() { + JSZipUtils.getBinaryContent(pathtoroot + "module-search-index.zip", function(e, data) { + var zip = new JSZip(data); + zip.load(data); + moduleSearchIndex = JSON.parse(zip.file("module-search-index.json").asText()); + }); + }); + $.get(pathtoroot + "package-search-index.zip") + .done(function() { + JSZipUtils.getBinaryContent(pathtoroot + "package-search-index.zip", function(e, data) { + var zip = new JSZip(data); + zip.load(data); + packageSearchIndex = JSON.parse(zip.file("package-search-index.json").asText()); + }); + }); + $.get(pathtoroot + "type-search-index.zip") + .done(function() { + JSZipUtils.getBinaryContent(pathtoroot + "type-search-index.zip", function(e, data) { + var zip = new JSZip(data); + zip.load(data); + typeSearchIndex = JSON.parse(zip.file("type-search-index.json").asText()); + }); + }); + $.get(pathtoroot + "member-search-index.zip") + .done(function() { + JSZipUtils.getBinaryContent(pathtoroot + "member-search-index.zip", function(e, data) { + var zip = new JSZip(data); + zip.load(data); + memberSearchIndex = JSON.parse(zip.file("member-search-index.json").asText()); + }); + }); + $.get(pathtoroot + "tag-search-index.zip") + .done(function() { + JSZipUtils.getBinaryContent(pathtoroot + "tag-search-index.zip", function(e, data) { + var zip = new JSZip(data); + zip.load(data); + tagSearchIndex = JSON.parse(zip.file("tag-search-index.json").asText()); + }); + }); + if (!moduleSearchIndex) { + createElem(doc, tag, 'module-search-index.js'); + } + if (!packageSearchIndex) { + createElem(doc, tag, 'package-search-index.js'); + } + if (!typeSearchIndex) { + createElem(doc, tag, 'type-search-index.js'); + } + if (!memberSearchIndex) { + createElem(doc, tag, 'member-search-index.js'); + } + if (!tagSearchIndex) { + createElem(doc, tag, 'tag-search-index.js'); + } + $(window).resize(function() { + $('.navPadding').css('padding-top', $('.fixedNav').css("height")); + }); +} + +function createElem(doc, tag, path) { + var script = doc.createElement(tag); + var scriptElement = doc.getElementsByTagName(tag)[0]; + script.src = pathtoroot + path; + scriptElement.parentNode.insertBefore(script, scriptElement); +} + +function show(type) { + count = 0; + for (var key in data) { + var row = document.getElementById(key); + if ((data[key] & type) !== 0) { + row.style.display = ''; + row.className = (count++ % 2) ? rowColor : altColor; + } + else + row.style.display = 'none'; + } + updateTabs(type); +} + +function updateTabs(type) { + for (var value in tabs) { + var sNode = document.getElementById(tabs[value][0]); + var spanNode = sNode.firstChild; + if (value == type) { + sNode.className = activeTableTab; + spanNode.innerHTML = tabs[value][1]; + } + else { + sNode.className = tableTab; + spanNode.innerHTML = "<a href=\"javascript:show("+ value + ");\">" + tabs[value][1] + "</a>"; + } + } +} + +function updateModuleFrame(pFrame, cFrame) { + top.packageFrame.location = pFrame; + top.classFrame.location = cFrame; +} diff --git a/plugins/javadoc/src/main/resources/views/class.korte b/plugins/javadoc/src/main/resources/views/class.korte index 9b19df08..a9120fb2 100644 --- a/plugins/javadoc/src/main/resources/views/class.korte +++ b/plugins/javadoc/src/main/resources/views/class.korte @@ -1,2 +1,274 @@ {% extends "components/base.korte" %} -{% block content %} default {% end %}
\ No newline at end of file +{% block content %} + +<main role="main"> + <div class="header"> + <div class="subTitle"><span class="packageLabelInType">Package</span> <a href="package-summary.html">{{ package }}</a></div> + <h2 title="{{ kind|capitalize }} {{ name }}" class="title">{{ kind|capitalize }} {{ name }}</h2> + </div> + <div class="contentContainer"> + <!-- <ul class="inheritance"> + <li>java.lang.Object</li> + <li> + <ul class="inheritance"> + <li>adaptation.Adaptation</li> + </ul> + </li> + </ul> TODO inheritance tree --> + <div class="description"> + <ul class="blockList"> + <li class="blockList"> + {% if implementedInterfaces.size != 0 %} + <dl> + <dt>All Implemented Interfaces:</dt> + <dd> + {% for name in implementedInterfaces %} + <code>{{ name }}</code> + {% if !loop.last %} + , + {% endif %} + {% endfor %} + </dd> + </dl> + {% endif %} + <hr> + <pre>{{ signature|raw }}</pre> + <div class="block">{{ classlikeDocumentation }}</div> + </li> + </ul> + </div> + <div class="summary"> + <ul class="blockList"> + <li class="blockList"> + <!-- ======== NESTED CLASS SUMMARY ======== --> + {% if classlikes.size != 0 %} + <section role="region"> + <ul class="blockList"> + <li class="blockList"><a id="nested.class.summary"> + <!-- --> + </a> + <h3>Nested Class Summary</h3> + <table class="memberSummary"> + <caption><span>Nested Classes</span><span class="tabEnd"> </span></caption> + <tr> + <th class="colFirst" scope="col">Modifier and Type</th> + <th class="colSecond" scope="col">Class</th> + <th class="colLast" scope="col">Description</th> + </tr> + {% for classlike in classlikes %} + <tr class="{{ rowColor(loop.index0) }}"> + <td class="colFirst"><code>{{ classlike.modifiers }}</code></td> + <th class="colSecond" scope="row"><code>{{ classlike.signature }}</span></code> + </th> + <td class="colLast">{{ classlike.description }}</td> + </tr> + {% endfor %} + </table> + </li> + </ul> + </section> + {% endif %} + <!-- =========== FIELD SUMMARY =========== --> + {% if properties.size != 0 %} + <section role="region"> + <ul class="blockList"> + <li class="blockList"><a id="field.summary"> + <!-- --> + </a> + <h3>Field Summary</h3> + <table class="memberSummary"> + <caption><span>Fields</span><span class="tabEnd"> </span></caption> + <tr> + <th class="colFirst" scope="col">Modifier and Type</th> + <th class="colSecond" scope="col">Field</th> + <th class="colLast" scope="col">Description</th> + </tr> + {% for property in properties %} + <tr class="{{ rowColor(loop.index0) }}"> + <td class="colFirst"><code>{{ property.modifiers|raw }}</code></td> + <th class="colSecond" scope="row"><code>{{ property.signature|raw }}</code></th> + <td class="colLast">{{ description|raw }}</td> + </tr> + {% endfor %} + </table> + </li> + </ul> + </section> + {% endif %} + <!-- ======== CONSTRUCTOR SUMMARY ======== --> + {% if constructors.size != 0 %} + <section role="region"> + <ul class="blockList"> + <li class="blockList"><a id="constructor.summary"> + <!-- --> + </a> + <h3>Constructor Summary</h3> + <table class="memberSummary"> + <caption><span>Constructors</span><span class="tabEnd"> </span></caption> + <tbody> + <tr> + <th class="colFirst" scope="col">Constructor</th> + <th class="colLast" scope="col">Description</th> + </tr> + + {% for constructor in constructors %} + <tr class="{{ rowColor(loop.index0) }}"> + <th class="colConstructorName" scope="row"><code><span class="memberNameLink"><a + href="#%3Cinit%3E({{ constructor.inlineParameters }})">{{ constructor.name }}</a></span>({{ constructor.inlineParameters }})</code></th> + <td class="colLast">{{ constructor.brief }}</td> + </tr> + {% endfor %} + + </tbody> + </table> + </li> + </ul> + </section> + {% endif %} + <!-- =========== ENUM CONSTANT SUMMARY =========== --> + {% if entries.size != 0 %} + <section role="region"> + <ul class="blockList"> + <li class="blockList"><a id="enum.constant.summary"> + <!-- --> + </a> + <h3>Enum Constant Summary</h3> + <table class="memberSummary"> + <caption><span>Enum Constants</span><span class="tabEnd"> </span></caption> + <tr> + <th class="colFirst" scope="col">Enum Constant</th> + <th class="colLast" scope="col">Description</th> + </tr> + {% for entry in entries %} + <tr class="{{ rowColor(loop.index0) }}"> + <th class="colFirst" scope="row"><code><span class="memberNameLink"><a + href="TODO">{{ entry.signature|raw }}</a></span></code></th> + <td class="colLast">{{ entry.brief }}</td> + </tr> + {% endfor %} + </table> + </li> + </ul> + </section> + {% endif %} + <!-- ========== METHOD SUMMARY =========== --> + {% if methods.own.size !=0 || methods.inherited.size != 0 %} + <section role="region"> + <ul class="blockList"> + <li class="blockList"><a id="method.summary"> + <!-- --> + </a> + <h3>Method Summary</h3> + <table class="memberSummary"> + <caption><span id="t0" class="activeTableTab"><span>All Methods</span><span + class="tabEnd"> </span></span><span id="t1" class="tableTab"><span><a + href="javascript:show(1);">Static Methods</a></span><span class="tabEnd"> </span></span><span + id="t4" class="tableTab"><span><a href="javascript:show(8);">Concrete Methods</a></span><span + class="tabEnd"> </span></span></caption> + <tbody> + <tr> + <th class="colFirst" scope="col">Modifier and Type</th> + <th class="colSecond" scope="col">Method</th> + <th class="colLast" scope="col">Description</th> + </tr> + {% for method in methods.own %} + <tr id="i{{ loop.index0 }}" class="{{ rowColor(loop.index0) }}"> + <td class="colFirst"><code>{{ method.modifiers|raw }}</code> + </td> + <th class="colSecond" scope="row"><code>{{ method.signatureWithoutModifiers|raw }} </code> + </th> + <td class="colLast">{{ method.brief|raw }}</td> + </tr> + {% endfor %} + </tbody> + </table> + <ul class="blockList"> + {% for method in methods.inherited %} + <li class="blockList"><a id="methods.inherited.from.class.{{ method.inheritedFrom}}"> + <!-- --> + </a> + <h3>Methods inherited from class {{ method.inheritedFrom}}</h3> + <code>{{ method.names }}</code></li> + {% endfor %} + <li class="blockList"><a id="methods.inherited.from.class.java.lang.Object"> + <!-- --> + </a> + <h3>Methods inherited from class java.lang.Object</h3> + <code>clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, + wait, wait, wait</code></li> + </ul> + </li> + </ul> + </section> + {% endif %} + </li> + </ul> + </div> + <div class="details"> + <ul class="blockList"> + <li class="blockList"> + <!-- ========= CONSTRUCTOR DETAIL ======== --> + {% if constructors.size != 0 %} + <section role="region"> + <ul class="blockList"> + <li class="blockList"><a id="constructor.detail"> + <!-- --> + </a> + <h3>Constructor Detail</h3> + {% for constructor in constructors %} + <a id="<{{ constructor.name }}>({{ constructor.inlineParameters }})"> + <!-- --> + </a> + <ul class="blockList"> + <li class="blockList"> + <h4>{{ constructor.name }}</h4> + <pre>{{ constructor.name }}({{ constructor.inlineParameters }})</pre> + <div class="block">{{ constructor.brief }}</div> + {% if constructor.parameters.size != 0 && hasAnyDescription(constructor.parameters) %} + <dl> + <dt><span class="paramLabel">Parameters:</span></dt> + {% for parameter in constructor.parameters %} + {% if parameter.description != "" %} + <dd><code>{{ parameter.name }}</code> - {{ parameter.description }}</dd> + {% endif %} + {% endfor %} + </dl> + {% endif %} + </li> + </ul> + {% endfor %} + </li> + </ul> + </section> + {% endif %} + <!-- ============ METHOD DETAIL ========== --> + {% if methods.own.size != 0 %} + <section role="region"> + <ul class="blockList"> + <li class="blockList"><a id="method.detail"> + <!-- --> + </a> + <h3>Method Detail</h3> + {% for method in methods.own %} + <a id="transform(model.ModelGraph,transformation.Transformation)"> + <!-- TODO --> + </a> + <ul class="blockListLast"> + <li class="blockList"> + <h4>{{ method.name }}</h4> + <pre class="methodSignature">{{ method.signature|raw }}</pre> + <div class="block">{{ method.brief|raw }}</div> + <!-- TODO missing return annotation --> + </li> + </ul> + {% endfor %} + </li> + </ul> + </section> + {% endif %} + </li> + </ul> + </div> + </div> +</main> +{% end %}
\ No newline at end of file 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 94eda40f..07636071 100644 --- a/plugins/kotlin-as-java/src/main/kotlin/signatures/JavaSignatureProvider.kt +++ b/plugins/kotlin-as-java/src/main/kotlin/signatures/JavaSignatureProvider.kt @@ -33,7 +33,9 @@ class JavaSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLogge ) } - private fun signature(e: DEnumEntry) = contentBuilder.contentFor(e, ContentKind.Symbol, setOf(TextStyle.Monospace)) + private fun signature(e: DEnumEntry) = contentBuilder.contentFor(e, ContentKind.Symbol, setOf(TextStyle.Monospace)){ + link(e.name, e.dri) + } private fun signature(c: DClasslike) = contentBuilder.contentFor(c, ContentKind.Symbol, setOf(TextStyle.Monospace)) { |