From f3db3f313c599b84b1a9810723c6a503c0baf7a9 Mon Sep 17 00:00:00 2001 From: Simon Ogorodnik Date: Thu, 30 Nov 2017 19:04:11 +0300 Subject: New format stub --- core/src/main/resources/dokka/format/java-layout-html.properties | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 core/src/main/resources/dokka/format/java-layout-html.properties (limited to 'core/src/main/resources') diff --git a/core/src/main/resources/dokka/format/java-layout-html.properties b/core/src/main/resources/dokka/format/java-layout-html.properties new file mode 100644 index 00000000..c5c6bb15 --- /dev/null +++ b/core/src/main/resources/dokka/format/java-layout-html.properties @@ -0,0 +1,2 @@ +class=org.jetbrains.dokka.formats.JavaLayoutHtmlFormatDescriptor +description=Produces Kotlin Style Docs with Javadoc like layout \ No newline at end of file -- cgit From 1b722f7c61ea3405b8f33612044b28f0b4087406 Mon Sep 17 00:00:00 2001 From: Simon Ogorodnik Date: Thu, 30 Nov 2017 20:34:25 +0300 Subject: WIP --- build.gradle | 1 + core/build.gradle | 2 + .../main/kotlin/Formats/JavaLayoutHtmlFormat.kt | 53 ++++++++++++++++++---- .../dokka/format/java-layout-html.properties | 2 +- 4 files changed, 47 insertions(+), 11 deletions(-) (limited to 'core/src/main/resources') diff --git a/build.gradle b/build.gradle index 0002ee69..5772bc5d 100644 --- a/build.gradle +++ b/build.gradle @@ -33,6 +33,7 @@ allprojects { maven { url 'https://jitpack.io' } maven { url "https://teamcity.jetbrains.com/guestAuth/repository/download/Kotlin_dev_CompilerAllPlugins/$bundled_kotlin_compiler_version/maven" } ivy(repo) + maven { url "https://dl.bintray.com/kotlin/kotlinx.html" } } } diff --git a/core/build.gradle b/core/build.gradle index a8f0f275..d37b98b3 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -33,6 +33,8 @@ dependencies { compile intellijCoreAnalysis() + compile 'org.jetbrains.kotlinx:kotlinx-html-jvm:0.6.8' + //tools.jar def toolsJar = files(((URLClassLoader) ToolProvider.getSystemToolClassLoader()).getURLs().findAll { it.path.endsWith("jar") }) compileOnly toolsJar diff --git a/core/src/main/kotlin/Formats/JavaLayoutHtmlFormat.kt b/core/src/main/kotlin/Formats/JavaLayoutHtmlFormat.kt index c023c477..832c466e 100644 --- a/core/src/main/kotlin/Formats/JavaLayoutHtmlFormat.kt +++ b/core/src/main/kotlin/Formats/JavaLayoutHtmlFormat.kt @@ -1,7 +1,11 @@ -package org.jetbrains.dokka.formats +package org.jetbrains.dokka.Formats +import com.google.inject.Inject +import kotlinx.html.li +import kotlinx.html.stream.appendHTML +import kotlinx.html.ul import org.jetbrains.dokka.* -import org.jetbrains.dokka.Formats.KotlinFormatDescriptorBase +import java.io.File class JavaLayoutHtmlFormatDescriptor : KotlinFormatDescriptorBase() { @@ -22,24 +26,53 @@ class JavaLayoutHtmlFormatService : FormatService { class JavaLayoutHtmlFormatOutputBuilder : FormattedOutputBuilder { override fun appendNodes(nodes: Iterable) { - TODO("not implemented") + + } +} + + +class JavaLayoutHtmlFormatNavListBuilder @Inject constructor(private val locationService: LocationService) : OutlineFormatService { + override fun getOutlineFileName(location: Location): File { + TODO() + } + + override fun appendOutlineHeader(location: Location, node: DocumentationNode, to: StringBuilder) { + with(to.appendHTML()) { + //a(href = ) + li { + when { + node.kind == NodeKind.Package -> appendOutline(location, to, node.members) + } + } + } + } + + override fun appendOutlineLevel(to: StringBuilder, body: () -> Unit) { + with(to.appendHTML()) { + ul { body() } + } } + } -class JavaLayoutHtmlFormatGenerator : Generator { +class JavaLayoutHtmlFormatGenerator @Inject constructor( + private val outlineFormatService: OutlineFormatService +) : Generator { override fun buildPages(nodes: Iterable) { - TODO("not implemented") + } override fun buildOutlines(nodes: Iterable) { - TODO("not implemented") + for (node in nodes) { + if (node.kind == NodeKind.Module) { + //outlineFormatService.formatOutline() + } + } } - override fun buildSupportFiles() { - TODO("not implemented") - } + override fun buildSupportFiles() {} override fun buildPackageList(nodes: Iterable) { - TODO("not implemented") + } } \ No newline at end of file diff --git a/core/src/main/resources/dokka/format/java-layout-html.properties b/core/src/main/resources/dokka/format/java-layout-html.properties index c5c6bb15..fbb2bbed 100644 --- a/core/src/main/resources/dokka/format/java-layout-html.properties +++ b/core/src/main/resources/dokka/format/java-layout-html.properties @@ -1,2 +1,2 @@ -class=org.jetbrains.dokka.formats.JavaLayoutHtmlFormatDescriptor +class=org.jetbrains.dokka.Formats.JavaLayoutHtmlFormatDescriptor description=Produces Kotlin Style Docs with Javadoc like layout \ No newline at end of file -- cgit From 1eab9404b8ecbd51e5270af0cc0c9545e68f35f2 Mon Sep 17 00:00:00 2001 From: Simon Ogorodnik Date: Sat, 2 Dec 2017 05:20:21 +0300 Subject: Remove categories to prevent injection errors When not NodeLocationAwareGenerator used --- core/src/main/kotlin/Utilities/DokkaModules.kt | 13 ------------- core/src/main/resources/dokka/generator/default.properties | 2 -- core/src/main/resources/dokka/generator/javadoc.properties | 2 -- core/src/main/resources/dokka/language/java.properties | 1 - core/src/main/resources/dokka/language/kotlin.properties | 1 - core/src/main/resources/dokka/outline/yaml.properties | 1 - 6 files changed, 20 deletions(-) delete mode 100644 core/src/main/resources/dokka/generator/default.properties delete mode 100644 core/src/main/resources/dokka/generator/javadoc.properties delete mode 100644 core/src/main/resources/dokka/language/java.properties delete mode 100644 core/src/main/resources/dokka/language/kotlin.properties delete mode 100644 core/src/main/resources/dokka/outline/yaml.properties (limited to 'core/src/main/resources') diff --git a/core/src/main/kotlin/Utilities/DokkaModules.kt b/core/src/main/kotlin/Utilities/DokkaModules.kt index a2d720ef..fcc2f692 100644 --- a/core/src/main/kotlin/Utilities/DokkaModules.kt +++ b/core/src/main/kotlin/Utilities/DokkaModules.kt @@ -51,19 +51,6 @@ class DokkaOutputModule(val options: DocumentationOptions, binder.bind(LanguageService::class.java).to(KotlinLanguageService::class.java) binder.bind(File::class.java).annotatedWith(Names.named("outputDir")).toInstance(File(options.outputDir)) -// binder.bindNameAnnotated("singleFolder") -// binder.bindNameAnnotated("singleFolder") -// binder.bindNameAnnotated("folders") -// binder.bindNameAnnotated("folders") - - // defaults -// binder.bind(LocationService::class.java).to(FoldersLocationService::class.java) -// binder.bind(FileLocationService::class.java).to(FoldersLocationService::class.java) - - binder.registerCategory("outline") - binder.registerCategory("format") - binder.registerCategory("generator") - binder.bind().toInstance(options) binder.bind().toInstance(logger) binder.bind(StringListType).annotatedWith(Names.named(impliedPlatformsName)).toInstance(options.impliedPlatforms) diff --git a/core/src/main/resources/dokka/generator/default.properties b/core/src/main/resources/dokka/generator/default.properties deleted file mode 100644 index a4a16200..00000000 --- a/core/src/main/resources/dokka/generator/default.properties +++ /dev/null @@ -1,2 +0,0 @@ -class=org.jetbrains.dokka.FileGenerator -description=Default documentation generator \ No newline at end of file diff --git a/core/src/main/resources/dokka/generator/javadoc.properties b/core/src/main/resources/dokka/generator/javadoc.properties deleted file mode 100644 index 4075704f..00000000 --- a/core/src/main/resources/dokka/generator/javadoc.properties +++ /dev/null @@ -1,2 +0,0 @@ -class=org.jetbrains.dokka.javadoc.JavadocGenerator -description=Produces output via JDK javadoc tool \ No newline at end of file diff --git a/core/src/main/resources/dokka/language/java.properties b/core/src/main/resources/dokka/language/java.properties deleted file mode 100644 index ab42f532..00000000 --- a/core/src/main/resources/dokka/language/java.properties +++ /dev/null @@ -1 +0,0 @@ -class=org.jetbrains.dokka.JavaLanguageService \ No newline at end of file diff --git a/core/src/main/resources/dokka/language/kotlin.properties b/core/src/main/resources/dokka/language/kotlin.properties deleted file mode 100644 index 16092007..00000000 --- a/core/src/main/resources/dokka/language/kotlin.properties +++ /dev/null @@ -1 +0,0 @@ -class=org.jetbrains.dokka.KotlinLanguageService \ No newline at end of file diff --git a/core/src/main/resources/dokka/outline/yaml.properties b/core/src/main/resources/dokka/outline/yaml.properties deleted file mode 100644 index 7268af37..00000000 --- a/core/src/main/resources/dokka/outline/yaml.properties +++ /dev/null @@ -1 +0,0 @@ -class=org.jetbrains.dokka.YamlOutlineService \ No newline at end of file -- cgit From 2de8d15435c1e779a1f97c48330acf5fc9c38670 Mon Sep 17 00:00:00 2001 From: Simon Ogorodnik Date: Mon, 11 Dec 2017 18:30:42 +0300 Subject: Add description for javadoc format --- core/src/main/resources/dokka/format/javadoc.properties | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'core/src/main/resources') diff --git a/core/src/main/resources/dokka/format/javadoc.properties b/core/src/main/resources/dokka/format/javadoc.properties index a58317fc..a0d8a945 100644 --- a/core/src/main/resources/dokka/format/javadoc.properties +++ b/core/src/main/resources/dokka/format/javadoc.properties @@ -1 +1,2 @@ -class=org.jetbrains.dokka.javadoc.JavadocFormatDescriptor \ No newline at end of file +class=org.jetbrains.dokka.javadoc.JavadocFormatDescriptor +description=Produces Javadoc, with Kotlin declarations as Java view \ No newline at end of file -- cgit From f1252678883133709f13fa2d6b7adbce3156f112 Mon Sep 17 00:00:00 2001 From: Simon Ogorodnik Date: Wed, 31 Jan 2018 23:49:51 +0300 Subject: Refactor selecting of inbound link resolvers --- .../Kotlin/ExternalDocumentationLinkResolver.kt | 43 +++++++++++++++++----- core/src/main/kotlin/Utilities/ServiceLocator.kt | 16 ++++++-- .../inbound-link-resolver/dokka-default.properties | 2 + .../dokka/inbound-link-resolver/javadoc.properties | 2 + 4 files changed, 51 insertions(+), 12 deletions(-) create mode 100644 core/src/main/resources/dokka/inbound-link-resolver/dokka-default.properties create mode 100644 core/src/main/resources/dokka/inbound-link-resolver/javadoc.properties (limited to 'core/src/main/resources') diff --git a/core/src/main/kotlin/Kotlin/ExternalDocumentationLinkResolver.kt b/core/src/main/kotlin/Kotlin/ExternalDocumentationLinkResolver.kt index 400326d2..7be37177 100644 --- a/core/src/main/kotlin/Kotlin/ExternalDocumentationLinkResolver.kt +++ b/core/src/main/kotlin/Kotlin/ExternalDocumentationLinkResolver.kt @@ -4,6 +4,10 @@ import com.google.inject.Inject import com.google.inject.Singleton import com.intellij.psi.PsiMethod import com.intellij.util.io.* +import org.jetbrains.dokka.Formats.FileGeneratorBasedFormatDescriptor +import org.jetbrains.dokka.Formats.FormatDescriptor +import org.jetbrains.dokka.Utilities.ServiceLocator +import org.jetbrains.dokka.Utilities.lookup import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.descriptors.impl.EnumEntrySyntheticClassDescriptor import org.jetbrains.kotlin.load.java.descriptors.JavaCallableMemberDescriptor @@ -21,6 +25,7 @@ import java.net.URL import java.net.URLConnection import java.nio.file.Path import java.security.MessageDigest +import kotlin.reflect.full.findAnnotation fun ByteArray.toHexString() = this.joinToString(separator = "") { "%02x".format(it) } @@ -129,13 +134,22 @@ class ExternalDocumentationLinkResolver @Inject constructor( .map { (key, value) -> key to value } .toMap() - val resolver = if (format == "javadoc") { - InboundExternalLinkResolutionService.Javadoc() - } else { - val linkExtension = paramsMap["linkExtension"]?.singleOrNull() ?: - throw RuntimeException("Failed to parse package list from $packageListUrl") - InboundExternalLinkResolutionService.Dokka(linkExtension) - } + + val defaultResolverDesc = services["dokka-default"]!! + val resolverDesc = services[format] + ?: defaultResolverDesc.takeIf { format in formatsWithDefaultResolver } + ?: defaultResolverDesc.also { + logger.warn("Couldn't find InboundExternalLinkResolutionService(format = `$format`) for $link, using Dokka default") + } + + + val resolverClass = javaClass.classLoader.loadClass(resolverDesc.className).kotlin + + val constructors = resolverClass.constructors + + val constructor = constructors.singleOrNull() + ?: constructors.first { it.findAnnotation() != null } + val resolver = constructor.call(paramsMap) as InboundExternalLinkResolutionService val rootInfo = ExternalDocumentationRoot(link.url, resolver, locations) @@ -170,6 +184,15 @@ class ExternalDocumentationLinkResolver @Inject constructor( companion object { const val DOKKA_PARAM_PREFIX = "\$dokka." + val services = ServiceLocator.allServices("inbound-link-resolver").associateBy { it.name } + private val formatsWithDefaultResolver = + ServiceLocator + .allServices("format") + .filter { + val desc = ServiceLocator.lookup(it) as? FileGeneratorBasedFormatDescriptor + desc?.generatorServiceClass == FileGenerator::class + }.map { it.name } + .toSet() } } @@ -177,7 +200,7 @@ class ExternalDocumentationLinkResolver @Inject constructor( interface InboundExternalLinkResolutionService { fun getPath(symbol: DeclarationDescriptor): String? - class Javadoc : InboundExternalLinkResolutionService { + class Javadoc(paramsMap: Map>) : InboundExternalLinkResolutionService { override fun getPath(symbol: DeclarationDescriptor): String? { if (symbol is EnumEntrySyntheticClassDescriptor) { return getPath(symbol.containingDeclaration)?.let { it + "#" + symbol.name.asString() } @@ -203,7 +226,9 @@ interface InboundExternalLinkResolutionService { } } - class Dokka(val extension: String) : InboundExternalLinkResolutionService { + class Dokka(val paramsMap: Map>) : InboundExternalLinkResolutionService { + val extension = paramsMap["linkExtension"]?.singleOrNull() ?: error("linkExtension not provided for Dokka resolver") + override fun getPath(symbol: DeclarationDescriptor): String? { val leafElement = when (symbol) { is CallableDescriptor, is TypeAliasDescriptor -> true diff --git a/core/src/main/kotlin/Utilities/ServiceLocator.kt b/core/src/main/kotlin/Utilities/ServiceLocator.kt index 71bfd21b..83c4c65c 100644 --- a/core/src/main/kotlin/Utilities/ServiceLocator.kt +++ b/core/src/main/kotlin/Utilities/ServiceLocator.kt @@ -14,12 +14,21 @@ class ServiceLookupException(message: String) : Exception(message) object ServiceLocator { fun lookup(clazz: Class, category: String, implementationName: String): T { val descriptor = lookupDescriptor(category, implementationName) + return lookup(clazz, descriptor) + } + + fun lookup( + clazz: Class, + descriptor: ServiceDescriptor + ): T { val loadedClass = javaClass.classLoader.loadClass(descriptor.className) val constructor = loadedClass.constructors - .filter { it.parameterTypes.isEmpty() } - .firstOrNull() ?: throw ServiceLookupException("Class ${descriptor.className} has no corresponding constructor") + .filter { it.parameterTypes.isEmpty() } + .firstOrNull() + ?: throw ServiceLookupException("Class ${descriptor.className} has no corresponding constructor") - val implementationRawType: Any = if (constructor.parameterTypes.isEmpty()) constructor.newInstance() else constructor.newInstance(constructor) + val implementationRawType: Any = + if (constructor.parameterTypes.isEmpty()) constructor.newInstance() else constructor.newInstance(constructor) if (!clazz.isInstance(implementationRawType)) { throw ServiceLookupException("Class ${descriptor.className} is not a subtype of ${clazz.name}") @@ -79,6 +88,7 @@ object ServiceLocator { } inline fun ServiceLocator.lookup(category: String, implementationName: String): T = lookup(T::class.java, category, implementationName) +inline fun ServiceLocator.lookup(desc: ServiceDescriptor): T = lookup(T::class.java, desc) private val ZipEntry.fileName: String get() = name.substringAfterLast("/", name) diff --git a/core/src/main/resources/dokka/inbound-link-resolver/dokka-default.properties b/core/src/main/resources/dokka/inbound-link-resolver/dokka-default.properties new file mode 100644 index 00000000..c484a920 --- /dev/null +++ b/core/src/main/resources/dokka/inbound-link-resolver/dokka-default.properties @@ -0,0 +1,2 @@ +class=org.jetbrains.dokka.InboundExternalLinkResolutionService$Dokka +description=Uses Dokka Default resolver \ No newline at end of file diff --git a/core/src/main/resources/dokka/inbound-link-resolver/javadoc.properties b/core/src/main/resources/dokka/inbound-link-resolver/javadoc.properties new file mode 100644 index 00000000..0d5d7d17 --- /dev/null +++ b/core/src/main/resources/dokka/inbound-link-resolver/javadoc.properties @@ -0,0 +1,2 @@ +class=org.jetbrains.dokka.InboundExternalLinkResolutionService$Javadoc +description=Uses Javadoc Default resolver \ No newline at end of file -- cgit From 71ef970eacfab2fd948ab3fba9aa01808cb7b211 Mon Sep 17 00:00:00 2001 From: Simon Ogorodnik Date: Thu, 1 Feb 2018 19:02:33 +0300 Subject: [backport] Implement inbound links in java layout html Original: 4641470 --- .../JavaLayoutHtmlPackageListService.kt | 86 ++++++++++++++++++++++ .../java-layout-html.properties | 2 + 2 files changed, 88 insertions(+) create mode 100644 core/src/main/resources/dokka/inbound-link-resolver/java-layout-html.properties (limited to 'core/src/main/resources') diff --git a/core/src/main/kotlin/Formats/JavaLayoutHtml/JavaLayoutHtmlPackageListService.kt b/core/src/main/kotlin/Formats/JavaLayoutHtml/JavaLayoutHtmlPackageListService.kt index 398758f2..d04ed64b 100644 --- a/core/src/main/kotlin/Formats/JavaLayoutHtml/JavaLayoutHtmlPackageListService.kt +++ b/core/src/main/kotlin/Formats/JavaLayoutHtml/JavaLayoutHtmlPackageListService.kt @@ -2,8 +2,13 @@ package org.jetbrains.dokka.Formats import org.jetbrains.dokka.DocumentationModule import org.jetbrains.dokka.ExternalDocumentationLinkResolver.Companion.DOKKA_PARAM_PREFIX +import org.jetbrains.dokka.InboundExternalLinkResolutionService import org.jetbrains.dokka.NodeKind import org.jetbrains.dokka.PackageListService +import org.jetbrains.kotlin.descriptors.* +import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameUnsafe +import org.jetbrains.kotlin.resolve.descriptorUtil.isCompanionObject +import org.jetbrains.kotlin.types.KotlinType class JavaLayoutHtmlPackageListService: PackageListService { @@ -19,10 +24,91 @@ class JavaLayoutHtmlPackageListService: PackageListService { return buildString { appendParam("format", "java-layout-html") + appendParam("mode", "kotlin") for (p in packages) { appendln(p) } } } +} + +class JavaLayoutHtmlInboundLinkResolutionService(private val paramMap: Map>) : InboundExternalLinkResolutionService { + private fun getContainerPath(symbol: DeclarationDescriptor): String? { + return when (symbol) { + is PackageFragmentDescriptor -> symbol.fqName.asString() + "/" + is ClassifierDescriptor -> getContainerPath(symbol.findPackage()) + symbol.nameWithOuter() + ".html" + else -> null + } + } + + private fun DeclarationDescriptor.findPackage(): PackageFragmentDescriptor = + generateSequence(this) { it.containingDeclaration }.filterIsInstance().first() + + private fun ClassifierDescriptor.nameWithOuter(): String = + generateSequence(this) { it.containingDeclaration as? ClassifierDescriptor } + .toList().asReversed().joinToString(".") { it.name.asString() } + + private fun getPagePath(symbol: DeclarationDescriptor): String? { + return when (symbol) { + is PackageFragmentDescriptor -> getContainerPath(symbol) + "package-summary.html" + is ClassifierDescriptor -> getContainerPath(symbol) + "#" + is FunctionDescriptor, is PropertyDescriptor -> getContainerPath(symbol.containingDeclaration!!) + "#" + symbol.signatureForAnchorUrlEncoded() + else -> null + } + } + + private fun DeclarationDescriptor.signatureForAnchor(): String? { + + fun ReceiverParameterDescriptor.extractReceiverName(): String { + var receiverClass: DeclarationDescriptor = type.constructor.declarationDescriptor!! + if (receiverClass.isCompanionObject()) { + receiverClass = receiverClass.containingDeclaration!! + } else if (receiverClass is TypeParameterDescriptor) { + val upperBoundClass = receiverClass.upperBounds.singleOrNull()?.constructor?.declarationDescriptor + if (upperBoundClass != null) { + receiverClass = upperBoundClass + } + } + + return receiverClass.name.asString() + } + + fun KotlinType.qualifiedNameForSignature(): String { + val desc = constructor.declarationDescriptor + return desc?.fqNameUnsafe?.asString() ?: "" + } + + fun StringBuilder.appendReceiverAndCompanion(desc: CallableDescriptor) { + if (desc.containingDeclaration.isCompanionObject()) { + append("Companion.") + } + desc.extensionReceiverParameter?.let { + append("(") + append(it.extractReceiverName()) + append(").") + } + } + + return when(this) { + is FunctionDescriptor -> buildString { + appendReceiverAndCompanion(this@signatureForAnchor) + append(name.asString()) + valueParameters.joinTo(this, prefix = "(", postfix = ")") { + it.type.qualifiedNameForSignature() + } + } + is PropertyDescriptor -> buildString { + appendReceiverAndCompanion(this@signatureForAnchor) + append(name.asString()) + append(":") + append(returnType?.qualifiedNameForSignature()) + } + else -> null + } + } + + private fun DeclarationDescriptor.signatureForAnchorUrlEncoded(): String? = signatureForAnchor()?.urlEncoded() + + override fun getPath(symbol: DeclarationDescriptor) = getPagePath(symbol) } \ No newline at end of file diff --git a/core/src/main/resources/dokka/inbound-link-resolver/java-layout-html.properties b/core/src/main/resources/dokka/inbound-link-resolver/java-layout-html.properties new file mode 100644 index 00000000..3b61eabe --- /dev/null +++ b/core/src/main/resources/dokka/inbound-link-resolver/java-layout-html.properties @@ -0,0 +1,2 @@ +class=org.jetbrains.dokka.Formats.JavaLayoutHtmlInboundLinkResolutionService +description=Resolver for JavaLayoutHtml \ No newline at end of file -- cgit