From 87edf7c5778a9e1ac3e17c9046110d69e8d197a6 Mon Sep 17 00:00:00 2001 From: Sergey Mashkov Date: Mon, 27 Jul 2015 16:11:36 +0300 Subject: Eliminate warnings caused by API changes --- src/Kotlin/ContentBuilder.kt | 2 +- src/Model/Content.kt | 2 +- src/Model/DocumentationNode.kt | 1 + src/Model/PackageDocs.kt | 4 ++-- 4 files changed, 5 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/Kotlin/ContentBuilder.kt b/src/Kotlin/ContentBuilder.kt index 273009ab..34018217 100644 --- a/src/Kotlin/ContentBuilder.kt +++ b/src/Kotlin/ContentBuilder.kt @@ -121,7 +121,7 @@ fun DocumentationBuilder.functionBody(descriptor: DeclarationDescriptor, functio return ContentBlockCode().let() { it.append(ContentText("Missing function name in @sample")); it } } val scope = getResolutionScope(resolutionFacade, descriptor) - val rootPackage = session.getModuleDescriptor().getPackage(FqName.ROOT)!! + val rootPackage = session.getModuleDescriptor().getPackage(FqName.ROOT) val rootScope = rootPackage.memberScope val symbol = resolveInScope(functionName, scope) ?: resolveInScope(functionName, rootScope) if (symbol == null) { diff --git a/src/Model/Content.kt b/src/Model/Content.kt index 810d6417..032de268 100644 --- a/src/Model/Content.kt +++ b/src/Model/Content.kt @@ -142,7 +142,7 @@ public open class MutableContent() : Content() { public override val summary: ContentNode get() = children.firstOrNull() ?: ContentEmpty - public override val description: ContentNode by Delegates.lazy { + public override val description: ContentNode by lazy { val descriptionNodes = children.drop(1) if (descriptionNodes.isEmpty()) { ContentEmpty diff --git a/src/Model/DocumentationNode.kt b/src/Model/DocumentationNode.kt index 2f0638bc..b4343347 100644 --- a/src/Model/DocumentationNode.kt +++ b/src/Model/DocumentationNode.kt @@ -134,6 +134,7 @@ fun DocumentationNode.findOrCreatePackageNode(packageName: String, packageConten fun DocumentationNode.append(child: DocumentationNode, kind: DocumentationReference.Kind) { addReferenceTo(child, kind) + @suppress("NON_EXHAUSTIVE_WHEN") when (kind) { DocumentationReference.Kind.Detail -> child.addReferenceTo(this, DocumentationReference.Kind.Owner) DocumentationReference.Kind.Member -> child.addReferenceTo(this, DocumentationReference.Kind.Owner) diff --git a/src/Model/PackageDocs.kt b/src/Model/PackageDocs.kt index 3b0be547..b5b34942 100644 --- a/src/Model/PackageDocs.kt +++ b/src/Model/PackageDocs.kt @@ -13,8 +13,8 @@ public class PackageDocs(val documentationBuilder: DocumentationBuilder, public val packageContent: Map get() = _packageContent - fun parse(file: String) { - val file = File(file) + fun parse(path: String) { + val file = File(path) if (file.exists()) { val text = file.readText() val tree = parseMarkdown(text) -- cgit From 12f91ee7d491b21359ff8e8822c594f35b904def Mon Sep 17 00:00:00 2001 From: Sergey Mashkov Date: Tue, 28 Jul 2015 14:15:55 +0300 Subject: Initial javadoc generation module --- src/Languages/JavaLanguageService.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/Languages/JavaLanguageService.kt b/src/Languages/JavaLanguageService.kt index e491d1bd..ad8307c1 100644 --- a/src/Languages/JavaLanguageService.kt +++ b/src/Languages/JavaLanguageService.kt @@ -46,7 +46,7 @@ public class JavaLanguageService : LanguageService { } } - private fun renderType(node: DocumentationNode): String { + public fun renderType(node: DocumentationNode): String { return when (node.name) { "Unit" -> "void" "Int" -> "int" -- cgit From e27fb69817b1417c1bc556a507b14f2700c7a736 Mon Sep 17 00:00:00 2001 From: Sergey Mashkov Date: Fri, 31 Jul 2015 15:35:34 +0300 Subject: Use Guice injector and ServiceLocator to load implementations on the fly --- src/Formats/FormatDescriptor.kt | 11 +++ src/Formats/HtmlFormatService.kt | 6 +- src/Formats/JekyllFormatService.kt | 4 +- src/Formats/KotlinWebsiteFormatService.kt | 5 +- src/Formats/MarkdownFormatService.kt | 4 +- src/Formats/StandardFormats.kt | 47 ++++++++++++ src/Formats/YamlOutlineService.kt | 3 +- src/Generation/FileGenerator.kt | 37 ++++++---- src/Generation/Generator.kt | 15 ++++ src/Locations/FoldersLocationService.kt | 5 +- src/Locations/LocationService.kt | 2 + src/Locations/SingleFolderLocationService.kt | 6 +- src/Utilities/GuiceModule.kt | 58 +++++++++++++++ src/Utilities/ServiceLocator.kt | 105 +++++++++++++++++++++++++++ src/main.kt | 37 +++------- 15 files changed, 295 insertions(+), 50 deletions(-) create mode 100644 src/Formats/FormatDescriptor.kt create mode 100644 src/Formats/StandardFormats.kt create mode 100644 src/Generation/Generator.kt create mode 100644 src/Utilities/GuiceModule.kt create mode 100644 src/Utilities/ServiceLocator.kt (limited to 'src') diff --git a/src/Formats/FormatDescriptor.kt b/src/Formats/FormatDescriptor.kt new file mode 100644 index 00000000..beff730f --- /dev/null +++ b/src/Formats/FormatDescriptor.kt @@ -0,0 +1,11 @@ +package org.jetbrains.dokka.Formats + +import org.jetbrains.dokka.FormatService +import org.jetbrains.dokka.Generator +import org.jetbrains.dokka.OutlineFormatService + +public interface FormatDescriptor { + val formatServiceClass: Class? + val outlineServiceClass: Class? + val generatorServiceClass: Class +} \ No newline at end of file diff --git a/src/Formats/HtmlFormatService.kt b/src/Formats/HtmlFormatService.kt index 78d3cff2..5dcd432b 100644 --- a/src/Formats/HtmlFormatService.kt +++ b/src/Formats/HtmlFormatService.kt @@ -1,10 +1,12 @@ package org.jetbrains.dokka +import com.google.inject.Inject +import com.google.inject.name.Named import java.io.File -public open class HtmlFormatService(locationService: LocationService, +public open class HtmlFormatService @Inject constructor(@Named("folders") locationService: LocationService, signatureGenerator: LanguageService, - val templateService: HtmlTemplateService = HtmlTemplateService.default()) + val templateService: HtmlTemplateService) : StructuredFormatService(locationService, signatureGenerator, "html"), OutlineFormatService { override public fun formatText(text: String): String { return text.htmlEscape() diff --git a/src/Formats/JekyllFormatService.kt b/src/Formats/JekyllFormatService.kt index e4c3ccd5..113f229f 100644 --- a/src/Formats/JekyllFormatService.kt +++ b/src/Formats/JekyllFormatService.kt @@ -1,6 +1,8 @@ package org.jetbrains.dokka -public open class JekyllFormatService(locationService: LocationService, +import com.google.inject.Inject + +public open class JekyllFormatService @Inject constructor(locationService: LocationService, signatureGenerator: LanguageService) : MarkdownFormatService(locationService, signatureGenerator) { diff --git a/src/Formats/KotlinWebsiteFormatService.kt b/src/Formats/KotlinWebsiteFormatService.kt index 21fc9dae..8fbebaae 100644 --- a/src/Formats/KotlinWebsiteFormatService.kt +++ b/src/Formats/KotlinWebsiteFormatService.kt @@ -1,8 +1,11 @@ package org.jetbrains.dokka -public class KotlinWebsiteFormatService(locationService: LocationService, +import com.google.inject.Inject + +public class KotlinWebsiteFormatService @Inject constructor(locationService: LocationService, signatureGenerator: LanguageService) : JekyllFormatService(locationService, signatureGenerator) { + override fun appendFrontMatter(nodes: Iterable, to: StringBuilder) { super.appendFrontMatter(nodes, to) to.appendln("layout: api") diff --git a/src/Formats/MarkdownFormatService.kt b/src/Formats/MarkdownFormatService.kt index ba7d8f7b..29a9f5c4 100644 --- a/src/Formats/MarkdownFormatService.kt +++ b/src/Formats/MarkdownFormatService.kt @@ -1,7 +1,9 @@ package org.jetbrains.dokka +import com.google.inject.Inject -public open class MarkdownFormatService(locationService: LocationService, + +public open class MarkdownFormatService @Inject constructor(locationService: LocationService, signatureGenerator: LanguageService) : StructuredFormatService(locationService, signatureGenerator, "md") { override public fun formatBreadcrumbs(items: Iterable): String { diff --git a/src/Formats/StandardFormats.kt b/src/Formats/StandardFormats.kt new file mode 100644 index 00000000..1d5ffe13 --- /dev/null +++ b/src/Formats/StandardFormats.kt @@ -0,0 +1,47 @@ +package org.jetbrains.dokka.Formats + +import org.jetbrains.dokka.* + +class HtmlFormatDescriptor : FormatDescriptor { + override val formatServiceClass: Class + get() = javaClass() + + override val outlineServiceClass: Class + get() = javaClass() + + override val generatorServiceClass: Class + get() = javaClass() +} + +class KotlinWebsiteFormatDescriptor : FormatDescriptor { + override val formatServiceClass: Class + get() = javaClass() + + override val outlineServiceClass: Class + get() = javaClass() + + override val generatorServiceClass: Class + get() = javaClass() +} + +class JekyllFormatDescriptor : FormatDescriptor { + override val formatServiceClass: Class + get() = javaClass() + + override val outlineServiceClass: Class? + get() = null + + override val generatorServiceClass: Class + get() = javaClass() +} + +class MarkdownFormatDescriptor : FormatDescriptor { + override val formatServiceClass: Class + get() = javaClass() + + override val outlineServiceClass: Class? + get() = null + + override val generatorServiceClass: Class + get() = javaClass() +} diff --git a/src/Formats/YamlOutlineService.kt b/src/Formats/YamlOutlineService.kt index cdab4eeb..7968824c 100644 --- a/src/Formats/YamlOutlineService.kt +++ b/src/Formats/YamlOutlineService.kt @@ -1,8 +1,9 @@ package org.jetbrains.dokka +import com.google.inject.Inject import java.io.File -class YamlOutlineService(val locationService: LocationService, +class YamlOutlineService @Inject constructor(val locationService: LocationService, val languageService: LanguageService) : OutlineFormatService { override fun getOutlineFileName(location: Location): File = File("${location.path}.yml") diff --git a/src/Generation/FileGenerator.kt b/src/Generation/FileGenerator.kt index abe4257f..08a885ab 100644 --- a/src/Generation/FileGenerator.kt +++ b/src/Generation/FileGenerator.kt @@ -1,36 +1,41 @@ package org.jetbrains.dokka +import com.google.inject.Inject +import java.io.File import java.io.FileOutputStream +import java.io.IOException import java.io.OutputStreamWriter -public class FileGenerator(val signatureGenerator: LanguageService, - val locationService: FileLocationService, +public class FileGenerator @Inject constructor(val locationService: FileLocationService, val formatService: FormatService, - val outlineService: OutlineFormatService?) { + @Inject(optional = true) val outlineService: OutlineFormatService?) : Generator { - public fun buildPage(node: DocumentationNode): Unit = buildPages(listOf(node)) - public fun buildOutline(node: DocumentationNode): Unit = buildOutlines(listOf(node)) + override fun buildPages(nodes: Iterable) { + val specificLocationService = locationService.withExtension(formatService.extension) - public fun buildPages(nodes: Iterable) { - for ((location, items) in nodes.groupBy { locationService.location(it) }) { + for ((location, items) in nodes.groupBy { specificLocationService.location(it) }) { val file = location.file - file.getParentFile()?.mkdirs() - FileOutputStream(file).use { - OutputStreamWriter(it, Charsets.UTF_8).use { - it.write(formatService.format(location, items)) + file.parentFile?.mkdirsOrFail() + try { + FileOutputStream(file).use { + OutputStreamWriter(it, Charsets.UTF_8).use { + it.write(formatService.format(location, items)) + } } + } catch (e: Throwable) { + println(e) } buildPages(items.flatMap { it.members }) } } - public fun buildOutlines(nodes: Iterable) { + override fun buildOutlines(nodes: Iterable) { if (outlineService == null) { return } for ((location, items) in nodes.groupBy { locationService.location(it) }) { val file = outlineService.getOutlineFileName(location) - file.getParentFile()?.mkdirs() + file.parentFile?.mkdirsOrFail() FileOutputStream(file).use { OutputStreamWriter(it, Charsets.UTF_8).use { it.write(outlineService.formatOutline(location, items)) @@ -38,4 +43,10 @@ public class FileGenerator(val signatureGenerator: LanguageService, } } } +} + +private fun File.mkdirsOrFail() { + if (!mkdirs() && !exists()) { + throw IOException("Failed to create directory $this") + } } \ No newline at end of file diff --git a/src/Generation/Generator.kt b/src/Generation/Generator.kt new file mode 100644 index 00000000..7dcabb0b --- /dev/null +++ b/src/Generation/Generator.kt @@ -0,0 +1,15 @@ +package org.jetbrains.dokka + +public interface Generator { + fun buildPages(nodes: Iterable) + fun buildOutlines(nodes: Iterable) + + final fun buildAll(nodes: Iterable) { + buildPages(nodes) + buildOutlines(nodes) + } + + final fun buildPage(node: DocumentationNode): Unit = buildPages(listOf(node)) + final fun buildOutline(node: DocumentationNode): Unit = buildOutlines(listOf(node)) + final fun buildAll(node: DocumentationNode): Unit = buildAll(listOf(node)) +} diff --git a/src/Locations/FoldersLocationService.kt b/src/Locations/FoldersLocationService.kt index e85c2c98..8a0cf6be 100644 --- a/src/Locations/FoldersLocationService.kt +++ b/src/Locations/FoldersLocationService.kt @@ -1,9 +1,12 @@ package org.jetbrains.dokka +import com.google.inject.Inject +import com.google.inject.name.Named import java.io.File public fun FoldersLocationService(root: String): FoldersLocationService = FoldersLocationService(File(root), "") -public class FoldersLocationService(val root: File, val extension: String) : FileLocationService { +public class FoldersLocationService @Inject constructor(@Named("outputDir") val root: File, val extension: String) : FileLocationService { + override fun withExtension(newExtension: String): FileLocationService { return if (extension.isEmpty()) FoldersLocationService(root, newExtension) else this } diff --git a/src/Locations/LocationService.kt b/src/Locations/LocationService.kt index 7d0b8b56..000b2c5e 100644 --- a/src/Locations/LocationService.kt +++ b/src/Locations/LocationService.kt @@ -55,6 +55,8 @@ public interface LocationService { public interface FileLocationService: LocationService { + override fun withExtension(newExtension: String): FileLocationService = this + override fun location(node: DocumentationNode): FileLocation = location(node.path.map { it.name }, node.members.any()) override fun location(qualifiedName: List, hasMembers: Boolean): FileLocation } diff --git a/src/Locations/SingleFolderLocationService.kt b/src/Locations/SingleFolderLocationService.kt index c26d2b34..049636c0 100644 --- a/src/Locations/SingleFolderLocationService.kt +++ b/src/Locations/SingleFolderLocationService.kt @@ -1,10 +1,12 @@ package org.jetbrains.dokka +import com.google.inject.Inject +import com.google.inject.name.Named import java.io.File public fun SingleFolderLocationService(root: String): SingleFolderLocationService = SingleFolderLocationService(File(root), "") -public class SingleFolderLocationService(val root: File, val extension: String) : FileLocationService { - override fun withExtension(newExtension: String): LocationService = +public class SingleFolderLocationService @Inject constructor(@Named("outputDir") val root: File, val extension: String) : FileLocationService { + override fun withExtension(newExtension: String): FileLocationService = SingleFolderLocationService(root, newExtension) override fun location(qualifiedName: List, hasMembers: Boolean): FileLocation { diff --git a/src/Utilities/GuiceModule.kt b/src/Utilities/GuiceModule.kt new file mode 100644 index 00000000..4ce4863d --- /dev/null +++ b/src/Utilities/GuiceModule.kt @@ -0,0 +1,58 @@ +package org.jetbrains.dokka.Utilities + +import com.google.inject.Binder +import com.google.inject.Module +import com.google.inject.Provider +import com.google.inject.name.Names +import org.jetbrains.dokka.* +import org.jetbrains.dokka.Formats.FormatDescriptor +import java.io.File + +class GuiceModule(val config: DokkaGenerator) : Module { + override fun configure(binder: Binder) { + binder.bind(javaClass()).toInstance(config) + binder.bind(javaClass()).annotatedWith(Names.named("outputDir")).toInstance(File(config.outputDir)) + + binder.bindNameAnnotated("singleFolder") + binder.bindNameAnnotated("singleFolder") + binder.bindNameAnnotated("folders") + binder.bindNameAnnotated("folders") + + // defaults + binder.bind(javaClass()).to(javaClass()) + binder.bind(javaClass()).to(javaClass()) + binder.bind(javaClass()).to(javaClass()) + + binder.bind(javaClass()).toProvider(object : Provider { + override fun get(): HtmlTemplateService = HtmlTemplateService.default("/dokka/styles/style.css") + }) + + binder.registerCategory("language") + binder.registerCategory("outline") + binder.registerCategory("format") + binder.registerCategory("generator") + + val descriptor = ServiceLocator.lookup("format", config.outputFormat, config) + + descriptor.outlineServiceClass?.let { clazz -> + binder.bind(javaClass()).to(clazz) + } + descriptor.formatServiceClass?.let { clazz -> + binder.bind(javaClass()).to(clazz) + } + binder.bind(javaClass()).to(descriptor.generatorServiceClass) + } + +} + +private inline fun Binder.registerCategory(category: String) { + ServiceLocator.allServices(category).forEach { + @suppress("UNCHECKED_CAST") + bind(javaClass()).annotatedWith(Names.named(it.name)).to(javaClass().classLoader.loadClass(it.className) as Class) + } +} + +private inline fun Binder.bindNameAnnotated(name: String) { + bind(javaClass()).annotatedWith(Names.named(name)).to(javaClass()) +} + diff --git a/src/Utilities/ServiceLocator.kt b/src/Utilities/ServiceLocator.kt new file mode 100644 index 00000000..e2ed0499 --- /dev/null +++ b/src/Utilities/ServiceLocator.kt @@ -0,0 +1,105 @@ +package org.jetbrains.dokka.Utilities + +import org.jetbrains.dokka.DokkaGenerator +import java.io.File +import java.util.Properties +import java.util.jar.JarFile +import java.util.zip.ZipEntry + +data class ServiceDescriptor(val name: String, val category: String, val description: String?, val className: String) + +class ServiceLookupException(message: String) : Exception(message) + +public object ServiceLocator { + public fun lookup(clazz: Class, category: String, implementationName: String, conf: DokkaGenerator): T { + val descriptor = lookupDescriptor(category, implementationName) + val loadedClass = javaClass.classLoader.loadClass(descriptor.className) + val constructor = loadedClass.constructors + .filter { it.parameterTypes.isEmpty() || (it.parameterTypes.size() == 1 && conf.javaClass.isInstance(it.parameterTypes[0])) } + .sortDescendingBy { it.parameterTypes.size() } + .firstOrNull() ?: throw ServiceLookupException("Class ${descriptor.className} has no corresponding 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}") + } + + @suppress("UNCHECKED_CAST") + return implementationRawType as T + } + + public fun lookupClass(clazz: Class, category: String, implementationName: String): Class = lookupDescriptor(category, implementationName).className.let { className -> + javaClass.classLoader.loadClass(className).let { loaded -> + if (!clazz.isAssignableFrom(loaded)) { + throw ServiceLookupException("Class $className is not a subtype of ${clazz.name}") + } + + @suppress("UNCHECKED_CAST") + val casted = loaded as Class + + casted + } + } + + private fun lookupDescriptor(category: String, implementationName: String): ServiceDescriptor { + val properties = javaClass.classLoader.getResourceAsStream("dokka/$category/$implementationName.properties")?.use { stream -> + Properties().let { properties -> + properties.load(stream) + properties + } + } ?: throw ServiceLookupException("No implementation with name $implementationName found in category $category") + + val className = properties["class"]?.toString() ?: throw ServiceLookupException("Implementation $implementationName has no class configured") + + return ServiceDescriptor(implementationName, category, properties["description"]?.toString(), className) + } + + fun allServices(category: String): List = javaClass.classLoader.getResourceAsStream("dokka/$category")?.use { stream -> + val entries = this.javaClass.classLoader.getResources("dokka/$category")?.toList() ?: emptyList() + + entries.flatMap { + when (it.protocol) { + "file" -> File(it.file).listFiles()?.filter { it.extension == "properties" }?.map { lookupDescriptor(category, it.nameWithoutExtension) } ?: emptyList() + "jar" -> { + val file = JarFile(it.file.removePrefix("file:").substringBefore("!")) + try { + val jarPath = it.file.substringAfterLast("!").removePrefix("/") + file.entries() + .asSequence() + .filter { entry -> !entry.isDirectory && entry.path == jarPath && entry.extension == "properties" } + .map { entry -> + lookupDescriptor(category, entry.fileName.substringBeforeLast(".")) + }.toList() + } finally { + file.close() + } + } + else -> emptyList() + } + } + } ?: emptyList() +} + +public inline fun ServiceLocator.lookup(category: String, implementationName: String, conf: DokkaGenerator): T = lookup(javaClass(), category, implementationName, conf) +public inline fun ServiceLocator.lookupClass(category: String, implementationName: String): Class = lookupClass(javaClass(), category, implementationName) +public inline fun ServiceLocator.lookupOrNull(category: String, implementationName: String, conf: DokkaGenerator): T? = try { + lookup(javaClass(), category, implementationName, conf) +} catch (any: Throwable) { + null +} + +fun main(args: Array) { + ServiceLocator.allServices("format").forEach { + println(it) + } +} + +private val ZipEntry.fileName: String + get() = name.substringAfterLast("/", name) + +private val ZipEntry.path: String + get() = name.substringBeforeLast("/", "").removePrefix("/") + +private val ZipEntry.extension: String? + get() = fileName.let { fn -> if ("." in fn) fn.substringAfterLast(".") else null } diff --git a/src/main.kt b/src/main.kt index 4a0c22f8..29a22672 100644 --- a/src/main.kt +++ b/src/main.kt @@ -1,5 +1,6 @@ package org.jetbrains.dokka +import com.google.inject.Guice import com.intellij.openapi.util.Disposer import com.intellij.openapi.vfs.VirtualFileManager import com.intellij.psi.PsiFile @@ -7,6 +8,7 @@ import com.intellij.psi.PsiJavaFile import com.intellij.psi.PsiManager import com.sampullara.cli.Args import com.sampullara.cli.Argument +import org.jetbrains.dokka.Utilities.GuiceModule import org.jetbrains.kotlin.cli.common.arguments.ValueDescription import org.jetbrains.kotlin.cli.common.messages.CompilerMessageLocation import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity @@ -17,6 +19,7 @@ import org.jetbrains.kotlin.cli.jvm.config.JavaSourceRoot import org.jetbrains.kotlin.config.CommonConfigurationKeys import org.jetbrains.kotlin.utils.PathUtil import java.io.File +import kotlin.util.measureTimeMillis class DokkaArguments { Argument(value = "src", description = "Source file or directory (allows many paths separated by the system path separator)") @@ -141,8 +144,8 @@ class DokkaGenerator(val logger: DokkaLogger, fun generate() { val environment = createAnalysisEnvironment() - logger.info("Module: ${moduleName}") - logger.info("Output: ${File(outputDir).getAbsolutePath()}") + logger.info("Module: $moduleName") + logger.info("Output: ${File(outputDir).absolutePath}") logger.info("Sources: ${environment.sources.join()}") logger.info("Classpath: ${environment.classpath.joinToString()}") @@ -155,34 +158,12 @@ class DokkaGenerator(val logger: DokkaLogger, val timeAnalyse = System.currentTimeMillis() - startAnalyse logger.info("done in ${timeAnalyse / 1000} secs") - val startBuild = System.currentTimeMillis() - val signatureGenerator = KotlinLanguageService() - val locationService = FoldersLocationService(outputDir) - val templateService = HtmlTemplateService.default("/dokka/styles/style.css") - - val (formatter, outlineFormatter) = when (outputFormat) { - "html" -> { - val htmlFormatService = HtmlFormatService(locationService, signatureGenerator, templateService) - htmlFormatService to htmlFormatService - } - "markdown" -> MarkdownFormatService(locationService, signatureGenerator) to null - "jekyll" -> JekyllFormatService(locationService.withExtension("html"), signatureGenerator) to null - "kotlin-website" -> KotlinWebsiteFormatService(locationService.withExtension("html"), signatureGenerator) to - YamlOutlineService(locationService, signatureGenerator) - else -> { - logger.error("Unrecognized output format ${outputFormat}") - null to null - } + val timeBuild = measureTimeMillis { + logger.info("Generating pages... ") + Guice.createInjector(GuiceModule(this)).getInstance(javaClass()).buildAll(documentation) } - if (formatter == null) return - - val generator = FileGenerator(signatureGenerator, locationService.withExtension(formatter.extension), - formatter, outlineFormatter) - logger.info("Generating pages... ") - generator.buildPage(documentation) - generator.buildOutline(documentation) - val timeBuild = System.currentTimeMillis() - startBuild logger.info("done in ${timeBuild / 1000} secs") + Disposer.dispose(environment) } -- cgit From e1f7ce7a16954d238345fe0e30257492c0886f37 Mon Sep 17 00:00:00 2001 From: Sergey Mashkov Date: Tue, 4 Aug 2015 18:47:25 +0300 Subject: ~ see also --- src/Java/JavaDocumentationBuilder.kt | 2 +- src/Kotlin/DocumentationBuilder.kt | 2 +- src/Model/Content.kt | 7 +++++-- 3 files changed, 7 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/Java/JavaDocumentationBuilder.kt b/src/Java/JavaDocumentationBuilder.kt index fdd385fb..aae82c18 100644 --- a/src/Java/JavaDocumentationBuilder.kt +++ b/src/Java/JavaDocumentationBuilder.kt @@ -112,7 +112,7 @@ public class JavaDocumentationBuilder(private val options: DocumentationOptions, if (linkElement == null) { return } - val seeSection = findSectionByTag("See Also") ?: addSection("See Also", null) + val seeSection = findSectionByTag(ContentTags.SeeAlso) ?: addSection(ContentTags.SeeAlso, null) val linkSignature = resolveLink(linkElement) val text = ContentText(linkElement.getText()) if (linkSignature != null) { diff --git a/src/Kotlin/DocumentationBuilder.kt b/src/Kotlin/DocumentationBuilder.kt index eda69841..8e36ae43 100644 --- a/src/Kotlin/DocumentationBuilder.kt +++ b/src/Kotlin/DocumentationBuilder.kt @@ -210,7 +210,7 @@ class DocumentationBuilder(val resolutionFacade: ResolutionFacade, private fun MutableContent.addTagToSeeAlso(descriptor: DeclarationDescriptor, seeTag: KDocTag) { val subjectName = seeTag.getSubjectName() if (subjectName != null) { - val seeSection = findSectionByTag("See Also") ?: addSection("See Also", null) + val seeSection = findSectionByTag(ContentTags.SeeAlso) ?: addSection(ContentTags.SeeAlso, null) val link = resolveContentLink(descriptor, subjectName) link.append(ContentText(subjectName)) val para = ContentParagraph() diff --git a/src/Model/Content.kt b/src/Model/Content.kt index 032de268..cd387b61 100644 --- a/src/Model/Content.kt +++ b/src/Model/Content.kt @@ -1,7 +1,5 @@ package org.jetbrains.dokka -import kotlin.properties.Delegates - public abstract class ContentNode public object ContentEmpty : ContentNode() @@ -87,6 +85,11 @@ public class ContentSection(public val tag: String, public val subjectName: Stri children.hashCode() * 31 * 31 + tag.hashCode() * 31 + (subjectName?.hashCode() ?: 0) } +public object ContentTags { + val Description = "Description" + val SeeAlso = "See Also" +} + fun content(body: ContentBlock.() -> Unit): ContentBlock { val block = ContentBlock() block.body() -- cgit From 4ed808d935125ab370d988f9cb32d96839959964 Mon Sep 17 00:00:00 2001 From: Sergey Mashkov Date: Thu, 6 Aug 2015 11:36:38 +0300 Subject: ~ description constant --- src/Formats/StructuredFormatService.kt | 2 +- src/Model/Content.kt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/Formats/StructuredFormatService.kt b/src/Formats/StructuredFormatService.kt index a90c60b1..1c2e5338 100644 --- a/src/Formats/StructuredFormatService.kt +++ b/src/Formats/StructuredFormatService.kt @@ -139,7 +139,7 @@ public abstract class StructuredFormatService(locationService: LocationService, fun appendDescription(location: Location, to: StringBuilder, node: DocumentationNode) { if (node.content.description != ContentEmpty) { - appendHeader(to, "Description", 3) + appendHeader(to, ContentTags.Description, 3) appendLine(to, formatText(location, node.content.description)) appendLine(to) } diff --git a/src/Model/Content.kt b/src/Model/Content.kt index cd387b61..0bb78454 100644 --- a/src/Model/Content.kt +++ b/src/Model/Content.kt @@ -150,7 +150,7 @@ public open class MutableContent() : Content() { if (descriptionNodes.isEmpty()) { ContentEmpty } else { - val result = ContentSection("Description", null) + val result = ContentSection(ContentTags.Description, null) result.children.addAll(descriptionNodes) result } -- cgit From 9b0c1b9b0d132aba484cafbb7e12d2e132522715 Mon Sep 17 00:00:00 2001 From: Sergey Mashkov Date: Thu, 6 Aug 2015 11:52:46 +0300 Subject: ~ move array type conversion to JavaLanguageService --- src/Languages/JavaLanguageService.kt | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src') diff --git a/src/Languages/JavaLanguageService.kt b/src/Languages/JavaLanguageService.kt index ad8307c1..488a2dc4 100644 --- a/src/Languages/JavaLanguageService.kt +++ b/src/Languages/JavaLanguageService.kt @@ -46,6 +46,18 @@ public class JavaLanguageService : LanguageService { } } + public fun getArrayElementType(node: DocumentationNode): DocumentationNode? = when (node.name) { + "Array" -> node.details(Kind.Type).singleOrNull()?.let { et -> getArrayElementType(et) ?: et } ?: DocumentationNode("Object", node.content, DocumentationNode.Kind.ExternalClass) + "IntArray", "LongArray", "ShortArray", "ByteArray", "CharArray", "DoubleArray", "FloatArray", "BooleanArray" -> DocumentationNode(node.name.removeSuffix("Array").toLowerCase(), node.content, DocumentationNode.Kind.Type) + else -> null + } + + public fun getArrayDimension(node: DocumentationNode): Int = when (node.name) { + "Array" -> 1 + (node.details(DocumentationNode.Kind.Type).singleOrNull()?.let { getArrayDimension(it) } ?: 0) + "IntArray", "LongArray", "ShortArray", "ByteArray", "CharArray", "DoubleArray", "FloatArray", "BooleanArray" -> 1 + else -> 0 + } + public fun renderType(node: DocumentationNode): String { return when (node.name) { "Unit" -> "void" -- cgit From b0b94df732fc6fa7a8c64da2398d729e57af74ca Mon Sep 17 00:00:00 2001 From: Sergey Mashkov Date: Thu, 6 Aug 2015 14:35:24 +0300 Subject: ~ remove unused function --- src/Kotlin/DocumentationBuilder.kt | 7 ------- 1 file changed, 7 deletions(-) (limited to 'src') diff --git a/src/Kotlin/DocumentationBuilder.kt b/src/Kotlin/DocumentationBuilder.kt index 8e36ae43..7f3063af 100644 --- a/src/Kotlin/DocumentationBuilder.kt +++ b/src/Kotlin/DocumentationBuilder.kt @@ -17,9 +17,7 @@ import org.jetbrains.kotlin.lexer.JetSingleValueToken import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.psi.JetParameter import org.jetbrains.kotlin.resolve.DescriptorUtils -import org.jetbrains.kotlin.resolve.constants.CompileTimeConstant import org.jetbrains.kotlin.resolve.constants.ConstantValue -import org.jetbrains.kotlin.resolve.constants.TypedCompileTimeConstant import org.jetbrains.kotlin.resolve.lazy.ResolveSession import org.jetbrains.kotlin.resolve.source.PsiSourceElement import org.jetbrains.kotlin.resolve.source.getPsi @@ -697,11 +695,6 @@ class DocumentationBuilder(val resolutionFacade: ResolutionFacade, return node } - fun CompileTimeConstant.build(): DocumentationNode? = when (this) { - is TypedCompileTimeConstant -> constantValue.toDocumentationNode() - else -> null - } - fun ConstantValue<*>.toDocumentationNode(): DocumentationNode? = value?.let { value -> when (value) { is String -> -- cgit From 97bea8c614bfea408c845f07ddc42c29db1e81ba Mon Sep 17 00:00:00 2001 From: Sergey Mashkov Date: Thu, 6 Aug 2015 14:43:37 +0300 Subject: ~ Use new property access syntax --- src/Kotlin/DocumentationBuilder.kt | 224 ++++++++++++++++++------------------- 1 file changed, 112 insertions(+), 112 deletions(-) (limited to 'src') diff --git a/src/Kotlin/DocumentationBuilder.kt b/src/Kotlin/DocumentationBuilder.kt index 7f3063af..6bfeb360 100644 --- a/src/Kotlin/DocumentationBuilder.kt +++ b/src/Kotlin/DocumentationBuilder.kt @@ -69,13 +69,13 @@ class DocumentationBuilder(val resolutionFacade: ResolutionFacade, if (kdoc is KDocSection) { val tags = kdoc.getTags() tags.forEach { - when (it.getName()) { + when (it.name) { "sample" -> content.append(functionBody(descriptor, it.getSubjectName())) "see" -> content.addTagToSeeAlso(descriptor, it) else -> { - val section = content.addSection(javadocSectionDisplayName(it.getName()), it.getSubjectName()) + val section = content.addSection(javadocSectionDisplayName(it.name), it.getSubjectName()) val sectionContent = it.getContent() val markdownNode = parseMarkdown(sectionContent) buildInlineContentTo(markdownNode, section, { href -> resolveContentLink(descriptor, href) }) @@ -94,16 +94,16 @@ class DocumentationBuilder(val resolutionFacade: ResolutionFacade, if (descriptor !is CallableMemberDescriptor) { return null } - val name = descriptor.getName().asString() + val name = descriptor.name.asString() if (name == "equals" || name == "hashCode" || name == "toString") { var deepestDescriptor: CallableMemberDescriptor = descriptor - while (!deepestDescriptor.getOverriddenDescriptors().isEmpty()) { - deepestDescriptor = deepestDescriptor.getOverriddenDescriptors().first() + while (!deepestDescriptor.overriddenDescriptors.isEmpty()) { + deepestDescriptor = deepestDescriptor.overriddenDescriptors.first() } - if (DescriptorUtils.getFqName(deepestDescriptor.getContainingDeclaration()).asString() == "kotlin.Any") { + if (DescriptorUtils.getFqName(deepestDescriptor.containingDeclaration).asString() == "kotlin.Any") { val anyClassDescriptors = session.getTopLevelClassDescriptors(FqName.fromSegments(listOf("kotlin", "Any"))) anyClassDescriptors.forEach { - val anyMethod = it.getMemberScope(listOf()).getFunctions(descriptor.getName()).single() + val anyMethod = it.getMemberScope(listOf()).getFunctions(descriptor.name).single() val kdoc = KDocFinder.findKDoc(anyMethod) if (kdoc != null) { return kdoc @@ -114,51 +114,51 @@ class DocumentationBuilder(val resolutionFacade: ResolutionFacade, return null } - fun DeclarationDescriptor.isDeprecated(): Boolean = getAnnotations().any { - DescriptorUtils.getFqName(it.getType().getConstructor().getDeclarationDescriptor()!!).asString() == "kotlin.deprecated" - } || (this is ConstructorDescriptor && getContainingDeclaration().isDeprecated()) + fun DeclarationDescriptor.isDeprecated(): Boolean = annotations.any { + DescriptorUtils.getFqName(it.type.constructor.declarationDescriptor!!).asString() == "kotlin.deprecated" + } || (this is ConstructorDescriptor && containingDeclaration.isDeprecated()) fun DeclarationDescriptor.signature(): String = when(this) { is ClassDescriptor, is PackageFragmentDescriptor -> DescriptorUtils.getFqName(this).asString() - is PropertyDescriptor -> getContainingDeclaration().signature() + "#" + getName() + receiverSignature() - is FunctionDescriptor -> getContainingDeclaration().signature() + "#" + getName() + parameterSignature() - is ValueParameterDescriptor -> getContainingDeclaration().signature() + ":" + getName() - is TypeParameterDescriptor -> getContainingDeclaration().signature() + "<" + getName() + is PropertyDescriptor -> containingDeclaration.signature() + "#" + name + receiverSignature() + is FunctionDescriptor -> containingDeclaration.signature() + "#" + name + parameterSignature() + is ValueParameterDescriptor -> containingDeclaration.signature() + ":" + name + is TypeParameterDescriptor -> containingDeclaration.signature() + "<" + name else -> throw UnsupportedOperationException("Don't know how to calculate signature for $this") } fun PropertyDescriptor.receiverSignature(): String { - val receiver = getExtensionReceiverParameter() + val receiver = extensionReceiverParameter if (receiver != null) { - return "#" + receiver.getType().signature() + return "#" + receiver.type.signature() } return "" } fun CallableMemberDescriptor.parameterSignature(): String { - val params = getValueParameters().map { it.getType() }.toArrayList() - val extensionReceiver = getExtensionReceiverParameter() + val params = valueParameters.map { it.type }.toArrayList() + val extensionReceiver = extensionReceiverParameter if (extensionReceiver != null) { - params.add(0, extensionReceiver.getType()) + params.add(0, extensionReceiver.type) } return "(" + params.map { it.signature() }.join() + ")" } fun JetType.signature(): String { - val declarationDescriptor = getConstructor().getDeclarationDescriptor() ?: return "" + val declarationDescriptor = constructor.declarationDescriptor ?: return "" val typeName = DescriptorUtils.getFqName(declarationDescriptor).asString() - if (typeName == "Array" && getArguments().size() == 1) { - return "Array<" + getArguments().first().getType().signature() + ">" + if (typeName == "Array" && arguments.size() == 1) { + return "Array<" + arguments.first().type.signature() + ">" } return typeName } fun DeclarationDescriptor.sourceLocation(): String? { if (this is DeclarationDescriptorWithSource) { - val psi = (this.getSource() as? PsiSourceElement)?.getPsi() + val psi = (this.source as? PsiSourceElement)?.getPsi() if (psi != null) { - val fileName = psi.getContainingFile().getName() + val fileName = psi.containingFile.name val lineNumber = psi.lineNumber() return if (lineNumber != null) "$fileName:$lineNumber" else fileName } @@ -197,8 +197,8 @@ class DocumentationBuilder(val resolutionFacade: ResolutionFacade, return null } val symbol = symbols.first() - if (symbol is CallableMemberDescriptor && symbol.getKind() == CallableMemberDescriptor.Kind.FAKE_OVERRIDE) { - return symbol.getOverriddenDescriptors().firstOrNull() + if (symbol is CallableMemberDescriptor && symbol.kind == CallableMemberDescriptor.Kind.FAKE_OVERRIDE) { + return symbol.overriddenDescriptors.firstOrNull() } return symbol } @@ -233,7 +233,7 @@ class DocumentationBuilder(val resolutionFacade: ResolutionFacade, fun DocumentationNode(descriptor: T, kind: Kind): DocumentationNode where T : DeclarationDescriptor, T : Named { val doc = parseDocumentation(descriptor) - val node = DocumentationNode(descriptor.getName().asString(), doc, kind).withModifiers(descriptor) + val node = DocumentationNode(descriptor.name.asString(), doc, kind).withModifiers(descriptor) return node } @@ -248,10 +248,10 @@ class DocumentationBuilder(val resolutionFacade: ResolutionFacade, } fun DocumentationNode.appendModality(descriptor: MemberDescriptor) { - var modality = descriptor.getModality() + var modality = descriptor.modality if (modality == Modality.OPEN) { - val containingClass = descriptor.getContainingDeclaration() as? ClassDescriptor - if (containingClass?.getModality() == Modality.FINAL) { + val containingClass = descriptor.containingDeclaration as? ClassDescriptor + if (containingClass?.modality == Modality.FINAL) { modality = Modality.FINAL } } @@ -260,22 +260,22 @@ class DocumentationBuilder(val resolutionFacade: ResolutionFacade, } fun DocumentationNode.appendVisibility(descriptor: DeclarationDescriptorWithVisibility) { - val modifier = descriptor.getVisibility().toString() + val modifier = descriptor.visibility.toString() appendTextNode(modifier, DocumentationNode.Kind.Modifier) } fun DocumentationNode.appendSupertypes(descriptor: ClassDescriptor) { - val superTypes = descriptor.getTypeConstructor().getSupertypes() + val superTypes = descriptor.typeConstructor.supertypes for (superType in superTypes) { if (!ignoreSupertype(superType)) { appendType(superType, DocumentationNode.Kind.Supertype) - link(superType?.getConstructor()?.getDeclarationDescriptor(), descriptor, DocumentationReference.Kind.Inheritor) + link(superType?.constructor?.declarationDescriptor, descriptor, DocumentationReference.Kind.Inheritor) } } } private fun ignoreSupertype(superType: JetType): Boolean { - val superClass = superType.getConstructor().getDeclarationDescriptor() as? ClassDescriptor + val superClass = superType.constructor.declarationDescriptor as? ClassDescriptor if (superClass != null) { val fqName = DescriptorUtils.getFqNameSafe(superClass).asString() return fqName == "kotlin.Annotation" || fqName == "kotlin.Enum" || fqName == "kotlin.Any" @@ -284,31 +284,31 @@ class DocumentationBuilder(val resolutionFacade: ResolutionFacade, } fun DocumentationNode.appendProjection(projection: TypeProjection, kind: DocumentationNode.Kind = DocumentationNode.Kind.Type) { - appendType(projection.getType(), kind, projection.getProjectionKind().label) + appendType(projection.type, kind, projection.projectionKind.label) } fun DocumentationNode.appendType(jetType: JetType?, kind: DocumentationNode.Kind = DocumentationNode.Kind.Type, prefix: String = "") { if (jetType == null) return - val classifierDescriptor = jetType.getConstructor().getDeclarationDescriptor() + val classifierDescriptor = jetType.constructor.declarationDescriptor val name = when (classifierDescriptor) { is ClassDescriptor -> { - if (classifierDescriptor.isCompanionObject()) { - classifierDescriptor.getContainingDeclaration().getName().asString() + - "." + classifierDescriptor.getName().asString() + if (classifierDescriptor.isCompanionObject) { + classifierDescriptor.containingDeclaration.name.asString() + + "." + classifierDescriptor.name.asString() } else { - classifierDescriptor.getName().asString() + classifierDescriptor.name.asString() } } - is Named -> classifierDescriptor.getName().asString() + is Named -> classifierDescriptor.name.asString() else -> "" } val node = DocumentationNode(name, Content.Empty, kind) if (prefix != "") { node.appendTextNode(prefix, Kind.Modifier) } - if (jetType.isMarkedNullable()) { + if (jetType.isMarkedNullable) { node.appendTextNode("?", Kind.NullabilityModifier) } if (classifierDescriptor != null && !classifierDescriptor.isBoringBuiltinClass()) { @@ -316,7 +316,7 @@ class DocumentationBuilder(val resolutionFacade: ResolutionFacade, } append(node, DocumentationReference.Kind.Detail) - for (typeArgument in jetType.getArguments()) + for (typeArgument in jetType.arguments) node.appendProjection(typeArgument) } @@ -324,7 +324,7 @@ class DocumentationBuilder(val resolutionFacade: ResolutionFacade, DescriptorUtils.getFqName(this).asString() in boringBuiltinClasses fun DocumentationNode.appendAnnotations(annotated: Annotated) { - annotated.getAnnotations().forEach { + annotated.annotations.forEach { val annotationNode = it.build() if (annotationNode != null) { append(annotationNode, @@ -339,7 +339,7 @@ class DocumentationBuilder(val resolutionFacade: ResolutionFacade, fun DocumentationNode.appendChild(descriptor: DeclarationDescriptor, kind: DocumentationReference.Kind): DocumentationNode? { // do not include generated code - if (descriptor is CallableMemberDescriptor && descriptor.getKind() != CallableMemberDescriptor.Kind.DECLARATION) + if (descriptor is CallableMemberDescriptor && descriptor.kind != CallableMemberDescriptor.Kind.DECLARATION) return null if (descriptor.isDocumented()) { @@ -353,7 +353,7 @@ class DocumentationBuilder(val resolutionFacade: ResolutionFacade, private fun DeclarationDescriptor.isDocumented(): Boolean { return (options.includeNonPublic || this !is MemberDescriptor - || this.getVisibility() in visibleToDocumentation) && + || this.visibility in visibleToDocumentation) && !isDocumentationSuppressed() && (!options.skipDeprecated || !isDeprecated()) } @@ -424,10 +424,10 @@ class DocumentationBuilder(val resolutionFacade: ResolutionFacade, else -> throw IllegalStateException("Descriptor $this is not known") } - fun ScriptDescriptor.build(): DocumentationNode = getClassDescriptor().build() + fun ScriptDescriptor.build(): DocumentationNode = classDescriptor.build() fun ClassDescriptor.build(): DocumentationNode { - val kind = when (getKind()) { + val kind = when (kind) { ClassKind.OBJECT -> Kind.Object ClassKind.INTERFACE -> Kind.Interface ClassKind.ENUM_CLASS -> Kind.Enum @@ -436,52 +436,52 @@ class DocumentationBuilder(val resolutionFacade: ResolutionFacade, else -> Kind.Class } val node = DocumentationNode(this, kind) - if (isInner()) { + if (isInner) { node.appendTextNode("inner", Kind.Modifier) } node.appendSupertypes(this) if (getKind() != ClassKind.OBJECT && getKind() != ClassKind.ENUM_ENTRY) { - node.appendInPageChildren(getTypeConstructor().getParameters(), DocumentationReference.Kind.Detail) + node.appendInPageChildren(typeConstructor.parameters, DocumentationReference.Kind.Detail) val constructorsToDocument = if (getKind() == ClassKind.ENUM_CLASS) - getConstructors().filter { it.getValueParameters().size() > 0 } + constructors.filter { it.valueParameters.size() > 0 } else - getConstructors() + constructors node.appendChildren(constructorsToDocument, DocumentationReference.Kind.Member) } - val members = getDefaultType().getMemberScope().getAllDescriptors().filter { it != getCompanionObjectDescriptor() } + val members = defaultType.memberScope.getAllDescriptors().filter { it != companionObjectDescriptor } node.appendChildren(members, DocumentationReference.Kind.Member) - val companionObjectDescriptor = getCompanionObjectDescriptor() + val companionObjectDescriptor = companionObjectDescriptor if (companionObjectDescriptor != null) { - node.appendChildren(companionObjectDescriptor.getDefaultType().getMemberScope().getAllDescriptors(), + node.appendChildren(companionObjectDescriptor.defaultType.memberScope.getAllDescriptors(), DocumentationReference.Kind.Member) } node.appendAnnotations(this) - node.appendSourceLink(getSource()) + node.appendSourceLink(source) register(this, node) return node } fun ConstructorDescriptor.build(): DocumentationNode { val node = DocumentationNode(this, Kind.Constructor) - node.appendInPageChildren(getValueParameters(), DocumentationReference.Kind.Detail) + node.appendInPageChildren(valueParameters, DocumentationReference.Kind.Detail) register(this, node) return node } private fun CallableMemberDescriptor.inCompanionObject(): Boolean { - val containingDeclaration = getContainingDeclaration() - if ((containingDeclaration as? ClassDescriptor)?.isCompanionObject() ?: false) { + val containingDeclaration = containingDeclaration + if ((containingDeclaration as? ClassDescriptor)?.isCompanionObject ?: false) { return true } - val receiver = getExtensionReceiverParameter() - return (receiver?.getType()?.getConstructor()?.getDeclarationDescriptor() as? ClassDescriptor)?.isCompanionObject() ?: false + val receiver = extensionReceiverParameter + return (receiver?.type?.constructor?.declarationDescriptor as? ClassDescriptor)?.isCompanionObject ?: false } fun CallableMemberDescriptor.getExtensionClassDescriptor(): ClassifierDescriptor? { - val extensionReceiver = getExtensionReceiverParameter() + val extensionReceiver = extensionReceiverParameter if (extensionReceiver != null) { - val type = extensionReceiver.getType() - return type.getConstructor().getDeclarationDescriptor() as? ClassDescriptor + val type = extensionReceiver.type + return type.constructor.declarationDescriptor as? ClassDescriptor } return null } @@ -493,15 +493,15 @@ class DocumentationBuilder(val resolutionFacade: ResolutionFacade, val node = DocumentationNode(this, if (inCompanionObject()) Kind.CompanionObjectFunction else Kind.Function) - node.appendInPageChildren(getTypeParameters(), DocumentationReference.Kind.Detail) - getExtensionReceiverParameter()?.let { node.appendChild(it, DocumentationReference.Kind.Detail) } - node.appendInPageChildren(getValueParameters(), DocumentationReference.Kind.Detail) - node.appendType(getReturnType()) + node.appendInPageChildren(typeParameters, DocumentationReference.Kind.Detail) + extensionReceiverParameter?.let { node.appendChild(it, DocumentationReference.Kind.Detail) } + node.appendInPageChildren(valueParameters, DocumentationReference.Kind.Detail) + node.appendType(returnType) node.appendAnnotations(this) - node.appendSourceLink(getSource()) + node.appendSourceLink(source) node.appendOperatorOverloadNote(this) - getOverriddenDescriptors().forEach { + overriddenDescriptors.forEach { addOverrideLink(it, this) } @@ -510,11 +510,11 @@ class DocumentationBuilder(val resolutionFacade: ResolutionFacade, } fun addOverrideLink(baseClassFunction: CallableMemberDescriptor, overridingFunction: CallableMemberDescriptor) { - val source = baseClassFunction.getOriginal().getSource().getPsi() + val source = baseClassFunction.original.source.getPsi() if (source != null) { link(overridingFunction, baseClassFunction, DocumentationReference.Kind.Override) } else { - baseClassFunction.getOverriddenDescriptors().forEach { + baseClassFunction.overriddenDescriptors.forEach { addOverrideLink(it, overridingFunction) } } @@ -537,36 +537,36 @@ class DocumentationBuilder(val resolutionFacade: ResolutionFacade, } fun FunctionDescriptor.getImplementedOperator(): String? { - var arity = getValueParameters().size() - if (getContainingDeclaration() is ClassDescriptor) { + var arity = valueParameters.size() + if (containingDeclaration is ClassDescriptor) { arity++ } - if (getExtensionReceiverParameter() != null) { + if (extensionReceiverParameter != null) { arity++ } val token = if (arity == 2) { - OperatorConventions.BINARY_OPERATION_NAMES.inverse()[getName()] ?: - OperatorConventions.ASSIGNMENT_OPERATIONS.inverse()[getName()] ?: - OperatorConventions.BOOLEAN_OPERATIONS.inverse()[getName()] + OperatorConventions.BINARY_OPERATION_NAMES.inverse()[name] ?: + OperatorConventions.ASSIGNMENT_OPERATIONS.inverse()[name] ?: + OperatorConventions.BOOLEAN_OPERATIONS.inverse()[name] } else if (arity == 1) { - OperatorConventions.UNARY_OPERATION_NAMES.inverse()[getName()] + OperatorConventions.UNARY_OPERATION_NAMES.inverse()[name] } else null if (token is JetSingleValueToken) { - return token.getValue() + return token.value } - val name = getName().asString() + val name = name.asString() if (arity == 2 && name == "contains") { return "in" } if (arity >= 2 && (name == "get" || name == "set")) { return "[]" } - if (arity == 2 && name == "equals" && getValueParameters().size() == 1 && - KotlinBuiltIns.isNullableAny(getValueParameters().first().getType())) { + if (arity == 2 && name == "equals" && valueParameters.size() == 1 && + KotlinBuiltIns.isNullableAny(valueParameters.first().type)) { return "==" } return null @@ -574,26 +574,26 @@ class DocumentationBuilder(val resolutionFacade: ResolutionFacade, fun PropertyDescriptor.build(): DocumentationNode { val node = DocumentationNode(this, if (inCompanionObject()) Kind.CompanionObjectProperty else Kind.Property) - node.appendInPageChildren(getTypeParameters(), DocumentationReference.Kind.Detail) - getExtensionReceiverParameter()?.let { node.appendChild(it, DocumentationReference.Kind.Detail) } - node.appendType(getReturnType()) + node.appendInPageChildren(typeParameters, DocumentationReference.Kind.Detail) + extensionReceiverParameter?.let { node.appendChild(it, DocumentationReference.Kind.Detail) } + node.appendType(returnType) node.appendAnnotations(this) - node.appendSourceLink(getSource()) - if (isVar()) { + node.appendSourceLink(source) + if (isVar) { node.appendTextNode("var", DocumentationNode.Kind.Modifier) } - getGetter()?.let { - if (!it.isDefault()) { + getter?.let { + if (!it.isDefault) { node.addAccessorDocumentation(parseDocumentation(it), "Getter") } } - getSetter()?.let { - if (!it.isDefault()) { + setter?.let { + if (!it.isDefault) { node.addAccessorDocumentation(parseDocumentation(it), "Setter") } } - getOverriddenDescriptors().forEach { + overriddenDescriptors.forEach { addOverrideLink(it, this) } @@ -617,17 +617,17 @@ class DocumentationBuilder(val resolutionFacade: ResolutionFacade, fun ValueParameterDescriptor.build(): DocumentationNode { val node = DocumentationNode(this, Kind.Parameter) - val varargType = getVarargElementType() + val varargType = varargElementType if (varargType != null) { node.appendTextNode("vararg", Kind.Annotation, DocumentationReference.Kind.Annotation) node.appendType(varargType) } else { - node.appendType(getType()) + node.appendType(type) } if (hasDefaultValue()) { - val psi = getSource().getPsi() as? JetParameter + val psi = source.getPsi() as? JetParameter if (psi != null) { - val defaultValueText = psi.getDefaultValue()?.getText() + val defaultValueText = psi.defaultValue?.text if (defaultValueText != null) { node.appendTextNode(defaultValueText, Kind.Value) } @@ -640,8 +640,8 @@ class DocumentationBuilder(val resolutionFacade: ResolutionFacade, fun TypeParameterDescriptor.build(): DocumentationNode { val doc = parseDocumentation(this) - val name = getName().asString() - val prefix = getVariance().label + val name = name.asString() + val prefix = variance.label val node = DocumentationNode(name, doc, DocumentationNode.Kind.TypeParameter) if (prefix != "") { @@ -649,13 +649,13 @@ class DocumentationBuilder(val resolutionFacade: ResolutionFacade, } val builtIns = KotlinBuiltIns.getInstance() - for (constraint in getUpperBounds()) { - if (constraint == builtIns.getDefaultBound()) + for (constraint in upperBounds) { + if (constraint == builtIns.defaultBound) continue node.appendType(constraint, Kind.UpperBound) } - for (constraint in getLowerBounds()) { + for (constraint in lowerBounds) { if (KotlinBuiltIns.isNothing(constraint)) continue node.appendType(constraint, Kind.LowerBound) @@ -664,30 +664,30 @@ class DocumentationBuilder(val resolutionFacade: ResolutionFacade, } fun ReceiverParameterDescriptor.build(): DocumentationNode { - var receiverClass: DeclarationDescriptor = getType().getConstructor().getDeclarationDescriptor()!! - if ((receiverClass as? ClassDescriptor)?.isCompanionObject() ?: false) { - receiverClass = receiverClass.getContainingDeclaration()!! + var receiverClass: DeclarationDescriptor = type.constructor.declarationDescriptor!! + if ((receiverClass as? ClassDescriptor)?.isCompanionObject ?: false) { + receiverClass = receiverClass.containingDeclaration!! } link(receiverClass, - getContainingDeclaration(), + containingDeclaration, DocumentationReference.Kind.Extension) - val node = DocumentationNode(getName().asString(), Content.Empty, Kind.Receiver) - node.appendType(getType()) + val node = DocumentationNode(name.asString(), Content.Empty, Kind.Receiver) + node.appendType(type) return node } fun AnnotationDescriptor.build(): DocumentationNode? { - val annotationClass = getType().getConstructor().getDeclarationDescriptor() + val annotationClass = type.constructor.declarationDescriptor if (annotationClass == null || ErrorUtils.isError(annotationClass)) { return null } - val node = DocumentationNode(annotationClass.getName().asString(), Content.Empty, DocumentationNode.Kind.Annotation) - val arguments = getAllValueArguments().toList().sortBy { it.first.getIndex() } + val node = DocumentationNode(annotationClass.name.asString(), Content.Empty, D