diff options
author | Kamil Doległo <kamilok1965@interia.pl> | 2019-10-31 12:10:10 +0100 |
---|---|---|
committer | Kamil Doległo <kamilok1965@interia.pl> | 2019-10-31 12:10:10 +0100 |
commit | 7c30624e3d0868346823b15b5cea5e29a56357f2 (patch) | |
tree | 5cc8175510c907d23f7bdcb5d5617ef03b587965 /core/src/main/kotlin/Kotlin | |
parent | 57830827b9bc13aad7af6ab899f25b278b248ef7 (diff) | |
download | dokka-7c30624e3d0868346823b15b5cea5e29a56357f2.tar.gz dokka-7c30624e3d0868346823b15b5cea5e29a56357f2.tar.bz2 dokka-7c30624e3d0868346823b15b5cea5e29a56357f2.zip |
Remove all unnecessary files
Diffstat (limited to 'core/src/main/kotlin/Kotlin')
5 files changed, 0 insertions, 662 deletions
diff --git a/core/src/main/kotlin/Kotlin/ContentBuilder.kt b/core/src/main/kotlin/Kotlin/ContentBuilder.kt deleted file mode 100644 index 0e60ff26..00000000 --- a/core/src/main/kotlin/Kotlin/ContentBuilder.kt +++ /dev/null @@ -1,192 +0,0 @@ -package org.jetbrains.dokka - -import org.intellij.markdown.MarkdownElementTypes -import org.intellij.markdown.MarkdownTokenTypes -import org.intellij.markdown.html.entities.EntityConverter -import org.intellij.markdown.parser.LinkMap -import java.util.* - -class LinkResolver(private val linkMap: LinkMap, private val contentFactory: (String) -> ContentBlock) { - fun getLinkInfo(refLabel: String) = linkMap.getLinkInfo(refLabel) - fun resolve(href: String): ContentBlock = contentFactory(href) -} - -fun buildContent(tree: MarkdownNode, linkResolver: LinkResolver, inline: Boolean = false): MutableContent { - val result = MutableContent() - if (inline) { - buildInlineContentTo(tree, result, linkResolver) - } else { - buildContentTo(tree, result, linkResolver) - } - return result -} - -fun buildContentTo(tree: MarkdownNode, target: ContentBlock, linkResolver: LinkResolver) { -// println(tree.toTestString()) - val nodeStack = ArrayDeque<ContentBlock>() - nodeStack.push(target) - - tree.visit { node, processChildren -> - val parent = nodeStack.peek() - - fun appendNodeWithChildren(content: ContentBlock) { - nodeStack.push(content) - processChildren() - parent.append(nodeStack.pop()) - } - - when (node.type) { - MarkdownElementTypes.ATX_1 -> appendNodeWithChildren(ContentHeading(1)) - MarkdownElementTypes.ATX_2 -> appendNodeWithChildren(ContentHeading(2)) - MarkdownElementTypes.ATX_3 -> appendNodeWithChildren(ContentHeading(3)) - MarkdownElementTypes.ATX_4 -> appendNodeWithChildren(ContentHeading(4)) - MarkdownElementTypes.ATX_5 -> appendNodeWithChildren(ContentHeading(5)) - MarkdownElementTypes.ATX_6 -> appendNodeWithChildren(ContentHeading(6)) - MarkdownElementTypes.UNORDERED_LIST -> appendNodeWithChildren(ContentUnorderedList()) - MarkdownElementTypes.ORDERED_LIST -> appendNodeWithChildren(ContentOrderedList()) - MarkdownElementTypes.LIST_ITEM -> appendNodeWithChildren(ContentListItem()) - MarkdownElementTypes.EMPH -> appendNodeWithChildren(ContentEmphasis()) - MarkdownElementTypes.STRONG -> appendNodeWithChildren(ContentStrong()) - MarkdownElementTypes.CODE_SPAN -> { - val startDelimiter = node.child(MarkdownTokenTypes.BACKTICK)?.text - if (startDelimiter != null) { - val text = node.text.substring(startDelimiter.length).removeSuffix(startDelimiter) - val codeSpan = ContentCode().apply { append(ContentText(text)) } - parent.append(codeSpan) - } - } - MarkdownElementTypes.CODE_BLOCK, - MarkdownElementTypes.CODE_FENCE -> { - val language = node.child(MarkdownTokenTypes.FENCE_LANG)?.text?.trim() ?: "" - appendNodeWithChildren(ContentBlockCode(language)) - } - MarkdownElementTypes.PARAGRAPH -> appendNodeWithChildren(ContentParagraph()) - - MarkdownElementTypes.INLINE_LINK -> { - val linkTextNode = node.child(MarkdownElementTypes.LINK_TEXT) - val destination = node.child(MarkdownElementTypes.LINK_DESTINATION) - if (linkTextNode != null) { - if (destination != null) { - val link = ContentExternalLink(destination.text) - renderLinkTextTo(linkTextNode, link, linkResolver) - parent.append(link) - } else { - val link = ContentExternalLink(linkTextNode.getLabelText()) - renderLinkTextTo(linkTextNode, link, linkResolver) - parent.append(link) - } - } - } - MarkdownElementTypes.SHORT_REFERENCE_LINK, - MarkdownElementTypes.FULL_REFERENCE_LINK -> { - val labelElement = node.child(MarkdownElementTypes.LINK_LABEL) - if (labelElement != null) { - val linkInfo = linkResolver.getLinkInfo(labelElement.text) - val labelText = labelElement.getLabelText() - val link = linkInfo?.let { linkResolver.resolve(it.destination.toString()) } ?: linkResolver.resolve(labelText) - val linkText = node.child(MarkdownElementTypes.LINK_TEXT) - if (linkText != null) { - renderLinkTextTo(linkText, link, linkResolver) - } else { - link.append(ContentText(labelText)) - } - parent.append(link) - } - } - MarkdownTokenTypes.WHITE_SPACE -> { - // Don't append first space if start of header (it is added during formatting later) - // v - // #### Some Heading - if (nodeStack.peek() !is ContentHeading || node.parent?.children?.first() != node) { - parent.append(ContentText(node.text)) - } - } - MarkdownTokenTypes.EOL -> { - if ((keepEol(nodeStack.peek()) && node.parent?.children?.last() != node) || - // Keep extra blank lines when processing lists (affects Markdown formatting) - (processingList(nodeStack.peek()) && node.previous?.type == MarkdownTokenTypes.EOL)) { - parent.append(ContentText(node.text)) - } - } - - MarkdownTokenTypes.CODE_LINE -> { - val content = ContentText(node.text) - if (parent is ContentBlockCode) { - parent.append(content) - } else { - parent.append(ContentBlockCode().apply { append(content) }) - } - } - - MarkdownTokenTypes.TEXT -> { - fun createEntityOrText(text: String): ContentNode { - if (text == "&" || text == """ || text == "<" || text == ">") { - return ContentEntity(text) - } - if (text == "&") { - return ContentEntity("&") - } - val decodedText = EntityConverter.replaceEntities(text, true, true) - if (decodedText != text) { - return ContentEntity(text) - } - return ContentText(text) - } - - parent.append(createEntityOrText(node.text)) - } - - MarkdownTokenTypes.EMPH -> { - val parentNodeType = node.parent?.type - if (parentNodeType != MarkdownElementTypes.EMPH && parentNodeType != MarkdownElementTypes.STRONG) { - parent.append(ContentText(node.text)) - } - } - - MarkdownTokenTypes.COLON, - MarkdownTokenTypes.SINGLE_QUOTE, - MarkdownTokenTypes.DOUBLE_QUOTE, - MarkdownTokenTypes.LT, - MarkdownTokenTypes.GT, - MarkdownTokenTypes.LPAREN, - MarkdownTokenTypes.RPAREN, - MarkdownTokenTypes.LBRACKET, - MarkdownTokenTypes.RBRACKET, - MarkdownTokenTypes.EXCLAMATION_MARK, - MarkdownTokenTypes.BACKTICK, - MarkdownTokenTypes.CODE_FENCE_CONTENT -> { - parent.append(ContentText(node.text)) - } - - MarkdownElementTypes.LINK_DEFINITION -> { - } - - MarkdownTokenTypes.EMAIL_AUTOLINK -> { - parent.append(ContentText(node.text)) // TODO: create new ContentType for email to create mailto: links - } - - else -> { - processChildren() - } - } - } -} - -private fun MarkdownNode.getLabelText() = children.filter { it.type == MarkdownTokenTypes.TEXT || it.type == MarkdownTokenTypes.EMPH || it.type == MarkdownTokenTypes.COLON }.joinToString("") { it.text } - -private fun keepEol(node: ContentNode) = node is ContentParagraph || node is ContentSection || node is ContentBlockCode -private fun processingList(node: ContentNode) = node is ContentOrderedList || node is ContentUnorderedList - -fun buildInlineContentTo(tree: MarkdownNode, target: ContentBlock, linkResolver: LinkResolver) { - val inlineContent = tree.children.singleOrNull { it.type == MarkdownElementTypes.PARAGRAPH }?.children ?: listOf(tree) - inlineContent.forEach { - buildContentTo(it, target, linkResolver) - } -} - -fun renderLinkTextTo(tree: MarkdownNode, target: ContentBlock, linkResolver: LinkResolver) { - val linkTextNodes = tree.children.drop(1).dropLast(1) - linkTextNodes.forEach { - buildContentTo(it, target, linkResolver) - } -} diff --git a/core/src/main/kotlin/Kotlin/DeclarationLinkResolver.kt b/core/src/main/kotlin/Kotlin/DeclarationLinkResolver.kt deleted file mode 100644 index 88494581..00000000 --- a/core/src/main/kotlin/Kotlin/DeclarationLinkResolver.kt +++ /dev/null @@ -1,73 +0,0 @@ -package org.jetbrains.dokka - -import com.google.inject.Inject -import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor -import org.jetbrains.kotlin.descriptors.DeclarationDescriptor -import org.jetbrains.kotlin.descriptors.TypeAliasDescriptor -import org.jetbrains.kotlin.idea.kdoc.resolveKDocLink - -class DeclarationLinkResolver - @Inject constructor(val resolutionFacade: DokkaResolutionFacade, - val refGraph: NodeReferenceGraph, - val logger: DokkaLogger, - val passConfiguration: DokkaConfiguration.PassConfiguration, - val externalDocumentationLinkResolver: ExternalDocumentationLinkResolver, - val elementSignatureProvider: ElementSignatureProvider) { - - - fun tryResolveContentLink(fromDescriptor: DeclarationDescriptor, href: String): ContentBlock? { - val symbol = try { - val symbols = resolveKDocLink(resolutionFacade.resolveSession.bindingContext, - resolutionFacade, fromDescriptor, null, href.split('.').toList()) - findTargetSymbol(symbols) - } catch(e: Exception) { - null - } - - // don't include unresolved links in generated doc - // assume that if an href doesn't contain '/', it's not an attempt to reference an external file - if (symbol != null) { - val externalHref = externalDocumentationLinkResolver.buildExternalDocumentationLink(symbol) - if (externalHref != null) { - return ContentExternalLink(externalHref) - } - val signature = elementSignatureProvider.signature(symbol) - val referencedAt = fromDescriptor.signatureWithSourceLocation() - - return ContentNodeLazyLink(href) { - val target = refGraph.lookup(signature) - - if (target == null) { - logger.warn("Can't find node by signature `$signature`, referenced at $referencedAt. " + - "This is probably caused by invalid configuration of cross-module dependencies") - } - target - } - } - if ("/" in href) { - return ContentExternalLink(href) - } - return null - } - - fun resolveContentLink(fromDescriptor: DeclarationDescriptor, href: String) = - tryResolveContentLink(fromDescriptor, href) ?: run { - logger.warn("Unresolved link to $href in doc comment of ${fromDescriptor.signatureWithSourceLocation()}") - ContentExternalLink("#") - } - - fun findTargetSymbol(symbols: Collection<DeclarationDescriptor>): DeclarationDescriptor? { - if (symbols.isEmpty()) { - return null - } - val symbol = symbols.first() - if (symbol is CallableMemberDescriptor && symbol.kind == CallableMemberDescriptor.Kind.FAKE_OVERRIDE) { - return symbol.overriddenDescriptors.firstOrNull() - } - if (symbol is TypeAliasDescriptor && !symbol.isDocumented(passConfiguration)) { - return symbol.classDescriptor - } - return symbol - } - -} diff --git a/core/src/main/kotlin/Kotlin/ExternalDocumentationLinkResolver.kt b/core/src/main/kotlin/Kotlin/ExternalDocumentationLinkResolver.kt deleted file mode 100644 index 793f9589..00000000 --- a/core/src/main/kotlin/Kotlin/ExternalDocumentationLinkResolver.kt +++ /dev/null @@ -1,305 +0,0 @@ -package org.jetbrains.dokka - -import com.google.inject.Inject -import com.google.inject.Singleton -import com.intellij.psi.PsiElement -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.* -import org.jetbrains.kotlin.name.FqName -import org.jetbrains.kotlin.resolve.DescriptorUtils -import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe -import org.jetbrains.kotlin.resolve.descriptorUtil.parents -import java.io.ByteArrayOutputStream -import java.io.PrintWriter -import java.net.HttpURLConnection -import java.net.URL -import java.net.URLConnection -import java.nio.file.Path -import java.nio.file.Paths -import java.security.MessageDigest -import javax.inject.Named -import kotlin.reflect.full.findAnnotation - -fun ByteArray.toHexString() = this.joinToString(separator = "") { "%02x".format(it) } - -typealias PackageFqNameToLocation = MutableMap<FqName, PackageListProvider.ExternalDocumentationRoot> - -@Singleton -class PackageListProvider @Inject constructor( - val configuration: DokkaConfiguration, - val logger: DokkaLogger -) { - val storage = mutableMapOf<DokkaConfiguration.ExternalDocumentationLink, PackageFqNameToLocation>() - - val cacheDir: Path? = when { - configuration.cacheRoot == "default" -> Paths.get(System.getProperty("user.home"), ".cache", "dokka") - configuration.cacheRoot != null -> Paths.get(configuration.cacheRoot) - else -> null - }?.resolve("packageListCache")?.apply { createDirectories() } - - val cachedProtocols = setOf("http", "https", "ftp") - - init { - for (conf in configuration.passesConfigurations) { - for (link in conf.externalDocumentationLinks) { - if (link in storage) { - continue - } - - try { - loadPackageList(link) - } catch (e: Exception) { - throw RuntimeException("Exception while loading package-list from $link", e) - } - } - - } - } - - - - fun URL.doOpenConnectionToReadContent(timeout: Int = 10000, redirectsAllowed: Int = 16): URLConnection { - val connection = this.openConnection() - connection.connectTimeout = timeout - connection.readTimeout = timeout - - when (connection) { - is HttpURLConnection -> { - return when (connection.responseCode) { - in 200..299 -> { - connection - } - HttpURLConnection.HTTP_MOVED_PERM, - HttpURLConnection.HTTP_MOVED_TEMP, - HttpURLConnection.HTTP_SEE_OTHER -> { - if (redirectsAllowed > 0) { - val newUrl = connection.getHeaderField("Location") - URL(newUrl).doOpenConnectionToReadContent(timeout, redirectsAllowed - 1) - } else { - throw RuntimeException("Too many redirects") - } - } - else -> { - throw RuntimeException("Unhandled http code: ${connection.responseCode}") - } - } - } - else -> return connection - } - } - - fun loadPackageList(link: DokkaConfiguration.ExternalDocumentationLink) { - - val packageListUrl = link.packageListUrl - val needsCache = packageListUrl.protocol in cachedProtocols - - val packageListStream = if (cacheDir != null && needsCache) { - val packageListLink = packageListUrl.toExternalForm() - - val digest = MessageDigest.getInstance("SHA-256") - val hash = digest.digest(packageListLink.toByteArray(Charsets.UTF_8)).toHexString() - val cacheEntry = cacheDir.resolve(hash) - - if (cacheEntry.exists()) { - try { - val connection = packageListUrl.doOpenConnectionToReadContent() - val originModifiedDate = connection.date - val cacheDate = cacheEntry.lastModified().toMillis() - if (originModifiedDate > cacheDate || originModifiedDate == 0L) { - if (originModifiedDate == 0L) - logger.warn("No date header for $packageListUrl, downloading anyway") - else - logger.info("Renewing package-list from $packageListUrl") - connection.getInputStream().copyTo(cacheEntry.outputStream()) - } - } catch (e: Exception) { - logger.error("Failed to update package-list cache for $link") - val baos = ByteArrayOutputStream() - PrintWriter(baos).use { - e.printStackTrace(it) - } - baos.flush() - logger.error(baos.toString()) - } - } else { - logger.info("Downloading package-list from $packageListUrl") - packageListUrl.openStream().copyTo(cacheEntry.outputStream()) - } - cacheEntry.inputStream() - } else { - packageListUrl.doOpenConnectionToReadContent().getInputStream() - } - - val (params, packages) = - packageListStream - .bufferedReader() - .useLines { lines -> lines.partition { it.startsWith(ExternalDocumentationLinkResolver.DOKKA_PARAM_PREFIX) } } - - val paramsMap = params.asSequence() - .map { it.removePrefix(ExternalDocumentationLinkResolver.DOKKA_PARAM_PREFIX).split(":", limit = 2) } - .groupBy({ (key, _) -> key }, { (_, value) -> value }) - - val format = paramsMap["format"]?.singleOrNull() ?: "javadoc" - - val locations = paramsMap["location"].orEmpty() - .map { it.split("\u001f", limit = 2) } - .map { (key, value) -> key to value } - .toMap() - - - val defaultResolverDesc = ExternalDocumentationLinkResolver.services.getValue("dokka-default") - val resolverDesc = ExternalDocumentationLinkResolver.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<Inject>() != null } - val resolver = constructor.call(paramsMap) as InboundExternalLinkResolutionService - - val rootInfo = ExternalDocumentationRoot(link.url, resolver, locations) - - val packageFqNameToLocation = mutableMapOf<FqName, ExternalDocumentationRoot>() - storage[link] = packageFqNameToLocation - - val fqNames = packages.map { FqName(it) } - for(name in fqNames) { - packageFqNameToLocation[name] = rootInfo - } - } - - - - class ExternalDocumentationRoot(val rootUrl: URL, val resolver: InboundExternalLinkResolutionService, val locations: Map<String, String>) { - override fun toString(): String = rootUrl.toString() - } - - companion object { - private val formatsWithDefaultResolver = - ServiceLocator - .allServices("format") - .filter { - val desc = ServiceLocator.lookup<FormatDescriptor>(it) as? FileGeneratorBasedFormatDescriptor - desc?.generatorServiceClass == FileGenerator::class - }.map { it.name } - .toSet() - - } - -} - -class ExternalDocumentationLinkResolver @Inject constructor( - val configuration: DokkaConfiguration, - val passConfiguration: DokkaConfiguration.PassConfiguration, - @Named("libraryResolutionFacade") val libraryResolutionFacade: DokkaResolutionFacade, - val logger: DokkaLogger, - val packageListProvider: PackageListProvider -) { - - val formats = mutableMapOf<String, InboundExternalLinkResolutionService>() - val packageFqNameToLocation = mutableMapOf<FqName, PackageListProvider.ExternalDocumentationRoot>() - - init { - val fqNameToLocationMaps = passConfiguration.externalDocumentationLinks - .mapNotNull { packageListProvider.storage[it] } - - for(map in fqNameToLocationMaps) { - packageFqNameToLocation.putAll(map) - } - } - - fun buildExternalDocumentationLink(element: PsiElement): String? { - return element.extractDescriptor(libraryResolutionFacade)?.let { - buildExternalDocumentationLink(it) - } - } - - fun buildExternalDocumentationLink(symbol: DeclarationDescriptor): String? { - val packageFqName: FqName = - when (symbol) { - is PackageFragmentDescriptor -> symbol.fqName - is DeclarationDescriptorNonRoot -> symbol.parents.firstOrNull { it is PackageFragmentDescriptor }?.fqNameSafe ?: return null - else -> return null - } - - val externalLocation = packageFqNameToLocation[packageFqName] ?: return null - - val path = externalLocation.locations[symbol.signature()] ?: - externalLocation.resolver.getPath(symbol) ?: return null - - return URL(externalLocation.rootUrl, path).toExternalForm() - } - - companion object { - const val DOKKA_PARAM_PREFIX = "\$dokka." - val services = ServiceLocator.allServices("inbound-link-resolver").associateBy { it.name } - } -} - - -interface InboundExternalLinkResolutionService { - fun getPath(symbol: DeclarationDescriptor): String? - - class Javadoc(paramsMap: Map<String, List<String>>) : InboundExternalLinkResolutionService { - override fun getPath(symbol: DeclarationDescriptor): String? { - if (symbol is EnumEntrySyntheticClassDescriptor) { - return getPath(symbol.containingDeclaration)?.let { it + "#" + symbol.name.asString() } - } else if (symbol is JavaClassDescriptor) { - return DescriptorUtils.getFqName(symbol).asString().replace(".", "/") + ".html" - } else if (symbol is JavaCallableMemberDescriptor) { - val containingClass = symbol.containingDeclaration as? JavaClassDescriptor ?: return null - val containingClassLink = getPath(containingClass) - if (containingClassLink != null) { - if (symbol is JavaMethodDescriptor || symbol is JavaClassConstructorDescriptor) { - val psi = symbol.sourcePsi() as? PsiMethod - if (psi != null) { - val params = psi.parameterList.parameters.joinToString { it.type.canonicalText } - return containingClassLink + "#" + symbol.name + "(" + params + ")" - } - } else if (symbol is JavaPropertyDescriptor) { - return "$containingClassLink#${symbol.name}" - } - } - } - // TODO Kotlin javadoc - return null - } - } - - class Dokka(val paramsMap: Map<String, List<String>>) : 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 - else -> false - } - val path = getPathWithoutExtension(symbol) - if (leafElement) return "$path.$extension" - else return "$path/index.$extension" - } - - private fun getPathWithoutExtension(symbol: DeclarationDescriptor): String { - return when { - symbol.containingDeclaration == null -> identifierToFilename(symbol.name.asString()) - symbol is PackageFragmentDescriptor -> identifierToFilename(symbol.fqName.asString()) - else -> getPathWithoutExtension(symbol.containingDeclaration!!) + '/' + identifierToFilename(symbol.name.asString()) - } - } - - } -} - diff --git a/core/src/main/kotlin/Kotlin/KotlinAsJavaDocumentationBuilder.kt b/core/src/main/kotlin/Kotlin/KotlinAsJavaDocumentationBuilder.kt deleted file mode 100644 index 70c04da6..00000000 --- a/core/src/main/kotlin/Kotlin/KotlinAsJavaDocumentationBuilder.kt +++ /dev/null @@ -1,67 +0,0 @@ -package org.jetbrains.dokka - -import com.google.inject.Inject -import com.intellij.psi.JavaPsiFacade -import com.intellij.psi.PsiClass -import com.intellij.psi.PsiNamedElement -import org.jetbrains.dokka.Kotlin.DescriptorDocumentationParser -import org.jetbrains.kotlin.asJava.elements.KtLightElement -import org.jetbrains.kotlin.asJava.elements.KtLightMethod -import org.jetbrains.kotlin.descriptors.DeclarationDescriptor -import org.jetbrains.kotlin.lexer.KtTokens -import org.jetbrains.kotlin.name.FqName -import org.jetbrains.kotlin.psi.KtClass -import org.jetbrains.kotlin.psi.KtDeclaration -import org.jetbrains.kotlin.psi.KtParameter -import org.jetbrains.kotlin.psi.KtPropertyAccessor - -class KotlinAsJavaDocumentationBuilder - @Inject constructor(val kotlinAsJavaDocumentationParser: KotlinAsJavaDocumentationParser) : PackageDocumentationBuilder -{ - override fun buildPackageDocumentation(documentationBuilder: DocumentationBuilder, - packageName: FqName, - packageNode: DocumentationNode, - declarations: List<DeclarationDescriptor>, - allFqNames: Collection<FqName>) { - val project = documentationBuilder.resolutionFacade.project - val psiPackage = JavaPsiFacade.getInstance(project).findPackage(packageName.asString()) - if (psiPackage == null) { - documentationBuilder.logger.error("Cannot find Java package by qualified name: ${packageName.asString()}") - return - } - - val javaDocumentationBuilder = JavaPsiDocumentationBuilder(documentationBuilder, - kotlinAsJavaDocumentationParser) - - psiPackage.classes.filter { it is KtLightElement<*, *> }.filter { it.isVisibleInDocumentation() }.forEach { - javaDocumentationBuilder.appendClasses(packageNode, arrayOf(it)) - } - } - - fun PsiClass.isVisibleInDocumentation(): Boolean { - val origin: KtDeclaration = (this as KtLightElement<*, *>).kotlinOrigin as? KtDeclaration ?: return true - - return !origin.hasModifier(KtTokens.INTERNAL_KEYWORD) && !origin.hasModifier(KtTokens.PRIVATE_KEYWORD) - } -} - -class KotlinAsJavaDocumentationParser - @Inject constructor(val resolutionFacade: DokkaResolutionFacade, - val descriptorDocumentationParser: DescriptorDocumentationParser) : JavaDocumentationParser -{ - override fun parseDocumentation(element: PsiNamedElement): JavadocParseResult { - val kotlinLightElement = element as? KtLightElement<*, *> ?: return JavadocParseResult.Empty - val origin = kotlinLightElement.kotlinOrigin as? KtDeclaration ?: return JavadocParseResult.Empty - if (origin is KtParameter) { - // LazyDeclarationResolver does not support setter parameters - val grandFather = origin.parent?.parent - if (grandFather is KtPropertyAccessor) { - return JavadocParseResult.Empty - } - } - val isDefaultNoArgConstructor = kotlinLightElement is KtLightMethod && origin is KtClass - val descriptor = resolutionFacade.resolveToDescriptor(origin) - val content = descriptorDocumentationParser.parseDocumentation(descriptor, origin is KtParameter, isDefaultNoArgConstructor) - return JavadocParseResult(content, null) - } -} diff --git a/core/src/main/kotlin/Kotlin/KotlinAsJavaElementSignatureProvider.kt b/core/src/main/kotlin/Kotlin/KotlinAsJavaElementSignatureProvider.kt deleted file mode 100644 index 20ea179e..00000000 --- a/core/src/main/kotlin/Kotlin/KotlinAsJavaElementSignatureProvider.kt +++ /dev/null @@ -1,25 +0,0 @@ -package org.jetbrains.dokka - -import com.intellij.psi.PsiElement -import org.jetbrains.kotlin.asJava.toLightElements -import org.jetbrains.kotlin.descriptors.DeclarationDescriptor -import org.jetbrains.kotlin.psi.KtElement - -class KotlinAsJavaElementSignatureProvider : ElementSignatureProvider { - - private fun PsiElement.javaLikePsi() = when { - this is KtElement -> toLightElements().firstOrNull() - else -> this - } - - override fun signature(forPsi: PsiElement): String { - return getSignature(forPsi.javaLikePsi()) ?: - "not implemented for $forPsi" - } - - override fun signature(forDesc: DeclarationDescriptor): String { - val sourcePsi = forDesc.sourcePsi() - return getSignature(sourcePsi?.javaLikePsi()) ?: - "not implemented for $forDesc with psi: $sourcePsi" - } -}
\ No newline at end of file |