kdoc: cleanup

This commit is contained in:
Stepan Koltsov
2012-06-25 23:55:28 +04:00
parent 72ef07acef
commit 8372ad7ec2
4 changed files with 52 additions and 54 deletions
@@ -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)
}
}
@@ -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);
@@ -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
}
}
@@ -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<JetFile>) {
// TODO generates java.lang.NoSuchMethodError: kotlin.util.namespace.hashMap(Ljet/TypeInfo;Ljet/TypeInfo;)Ljava/util/HashMap;
//val packages = sortedMap<String,KPackage>()
public val packageMap: SortedMap<String, KPackage> = TreeMap<String, KPackage>()
@@ -208,35 +208,16 @@ class KModel(var context: BindingContext, val config: KDocConfig) {
private val readMeDirsScanned = HashSet<String>()
/**
* 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<JetFile?>): Unit {
;{
/** Loads the model from the given set of source files */
val allNamespaces = HashSet<NamespaceDescriptor>()
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<KClass>()
@@ -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<KAnnotation> = arrayList<KAnnotation>(),
var typeParameters: List<KTypeParameter> = arrayList<KTypeParameter>(),
var since: String = "",
var authors: List<String> = arrayList<String>(),
var baseClasses: List<KType> = arrayList<KType>(),
var nestedClasses: List<KClass> = arrayList<KClass>()): KClassOrPackage(pkg.model, descriptor), Comparable<KClass> {
class KClass(
val pkg: KPackage,
val descriptor: ClassDescriptor,
val simpleName: String)
: KClassOrPackage(pkg.model, descriptor), Comparable<KClass>
{
var group: String = "Other"
var annotations: List<KAnnotation> = arrayList<KAnnotation>()
var typeParameters: List<KTypeParameter> = arrayList<KTypeParameter>()
var since: String = ""
var authors: List<String> = arrayList<String>()
var baseClasses: List<KType> = arrayList<KType>()
var nestedClasses: List<KClass> = arrayList<KClass>()
public override fun compareTo(other: KClass): Int = name.compareTo(other.name)