From 8372ad7ec20ee3abfbfdc3082366b3e5a4f1e759 Mon Sep 17 00:00:00 2001 From: Stepan Koltsov Date: Mon, 25 Jun 2012 23:55:28 +0400 Subject: [PATCH] kdoc: cleanup --- .../kotlin/org/jetbrains/kotlin/doc/KDoc.kt | 4 +- .../org/jetbrains/kotlin/doc/KDocCompiler.kt | 8 +- .../kotlin/doc/model/KModelCompilerPlugin.kt | 18 ++--- .../jetbrains/kotlin/doc/model/KotlinModel.kt | 76 ++++++++++--------- 4 files changed, 52 insertions(+), 54 deletions(-) diff --git a/libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/KDoc.kt b/libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/KDoc.kt index 2bd2ecf4c53..2850fdf7181 100644 --- a/libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/KDoc.kt +++ b/libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/KDoc.kt @@ -32,13 +32,13 @@ import org.jetbrains.jet.util.slicedmap.WritableSlice import org.jetbrains.jet.lang.resolve.BindingContextUtils /** Generates the Kotlin Documentation for the model */ -class KDoc() : KModelCompilerPlugin() { +class KDoc(protected arguments: KDocArguments) : KModelCompilerPlugin(arguments) { protected override fun processModel(model: KModel) { // TODO allow this to be configured; maybe we use configuration on the KotlinModule // to define what doclets to use? val generator = JavadocStyleHtmlDoclet() - val outputDir = File(config.docOutputDir) + val outputDir = File(arguments.apply().docOutputDir) generator.generate(model, outputDir) } } diff --git a/libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/KDocCompiler.kt b/libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/KDocCompiler.kt index c73deb2b733..5db711e9fee 100644 --- a/libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/KDocCompiler.kt +++ b/libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/KDocCompiler.kt @@ -27,12 +27,8 @@ class KDocCompiler() : K2JVMCompiler() { super.configureEnvironment(configuration, arguments) val coreEnvironment = configuration.getEnvironment() if (coreEnvironment != null) { - val kdoc = KDoc() - - if (arguments is KDocArguments) { - kdoc.config = arguments.apply() - } - val plugins = configuration.getCompilerPlugins().orEmpty() + val kdoc = KDoc(arguments as KDocArguments) + val plugins = configuration.getCompilerPlugins() val sourcePlugin = Html2CompilerPlugin(arguments as KDocArguments) plugins.add(sourcePlugin) plugins.add(kdoc); diff --git a/libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/model/KModelCompilerPlugin.kt b/libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/model/KModelCompilerPlugin.kt index cb784cd5662..dd2fbfee013 100644 --- a/libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/model/KModelCompilerPlugin.kt +++ b/libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/model/KModelCompilerPlugin.kt @@ -3,23 +3,23 @@ package org.jetbrains.kotlin.doc.model import org.jetbrains.jet.cli.common.CompilerPlugin import org.jetbrains.jet.cli.common.CompilerPluginContext import org.jetbrains.kotlin.doc.KDocConfig +import org.jetbrains.kotlin.doc.KDocArguments /** Base class for any compiler plugin which needs to process a KModel */ -abstract class KModelCompilerPlugin: CompilerPlugin { - - public open var config: KDocConfig = KDocConfig() +abstract class KModelCompilerPlugin( + // TODO: fix compiler and make protected + val arguments: KDocArguments) + : CompilerPlugin +{ public override fun processFiles(context: CompilerPluginContext) { val bindingContext = context.getContext() val sources = context.getFiles() - if (bindingContext != null && sources != null) { - val model = KModel(bindingContext, config) - model.load(sources) + val model = KModel(bindingContext, arguments.apply(), sources.requireNoNulls()) - processModel(model) - } + processModel(model) } protected abstract fun processModel(model: KModel): Unit -} \ No newline at end of file +} diff --git a/libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/model/KotlinModel.kt b/libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/model/KotlinModel.kt index 5fac9286525..caed823d377 100644 --- a/libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/model/KotlinModel.kt +++ b/libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/model/KotlinModel.kt @@ -175,7 +175,7 @@ abstract class KClassOrPackage(model: KModel, declarationDescriptor: Declaration } } -class KModel(var context: BindingContext, val config: KDocConfig) { +class KModel(val context: BindingContext, val config: KDocConfig, private val sources: List) { // TODO generates java.lang.NoSuchMethodError: kotlin.util.namespace.hashMap(Ljet/TypeInfo;Ljet/TypeInfo;)Ljava/util/HashMap; //val packages = sortedMap() public val packageMap: SortedMap = TreeMap() @@ -208,35 +208,16 @@ class KModel(var context: BindingContext, val config: KDocConfig) { private val readMeDirsScanned = HashSet() - /** - * Returns the root project directory for calculating relative source links - */ - fun projectRootDir(): String { - if (_projectRootDir == null) { - val rootDir = config.projectRootDir - _projectRootDir = if (rootDir == null) { - warning("KDocConfig does not have a projectRootDir defined so we cannot generate relative source Hrefs") - "" - } else { - File(rootDir).getCanonicalPath() ?: "" - } - } - return _projectRootDir ?: "" - } - - - /** Loads the model from the given set of source files */ - fun load(sources: List): Unit { + ;{ + /** Loads the model from the given set of source files */ val allNamespaces = HashSet() for (source in sources) { - if (source != null) { - // We retrieve a descriptor by a PSI element from the context - val namespaceDescriptor = BindingContextUtils.namespaceDescriptor(context, source) - if (namespaceDescriptor != null) { - allNamespaces.add(namespaceDescriptor); - } else { - warning("No NamespaceDescriptor for source $source") - } + // We retrieve a descriptor by a PSI element from the context + val namespaceDescriptor = BindingContextUtils.namespaceDescriptor(context, source) + if (namespaceDescriptor != null) { + allNamespaces.add(namespaceDescriptor); + } else { + warning("No NamespaceDescriptor for source $source") } } val allClasses = HashSet() @@ -255,6 +236,23 @@ class KModel(var context: BindingContext, val config: KDocConfig) { } } + /** + * Returns the root project directory for calculating relative source links + */ + fun projectRootDir(): String { + if (_projectRootDir == null) { + val rootDir = config.projectRootDir + _projectRootDir = if (rootDir == null) { + warning("KDocConfig does not have a projectRootDir defined so we cannot generate relative source Hrefs") + "" + } else { + File(rootDir).getCanonicalPath() ?: "" + } + } + return _projectRootDir ?: "" + } + + /* Returns the package for the given name or null if it does not exist */ fun getPackage(name: String): KPackage? = packageMap.get(name) @@ -1037,15 +1035,19 @@ class KType(val jetType: JetType, model: KModel, val klass: KClass?, val argumen get() = jetType.isNullable() } -class KClass(val pkg: KPackage, val descriptor: ClassDescriptor, - val simpleName: String, - var group: String = "Other", - var annotations: List = arrayList(), - var typeParameters: List = arrayList(), - var since: String = "", - var authors: List = arrayList(), - var baseClasses: List = arrayList(), - var nestedClasses: List = arrayList()): KClassOrPackage(pkg.model, descriptor), Comparable { +class KClass( + val pkg: KPackage, + val descriptor: ClassDescriptor, + val simpleName: String) + : KClassOrPackage(pkg.model, descriptor), Comparable +{ + var group: String = "Other" + var annotations: List = arrayList() + var typeParameters: List = arrayList() + var since: String = "" + var authors: List = arrayList() + var baseClasses: List = arrayList() + var nestedClasses: List = arrayList() public override fun compareTo(other: KClass): Int = name.compareTo(other.name)