refactored out the KDocLoader stuff from the KotlinCompiler; also introduced CompilerPluginContext to wrap up the Project, BindingContext and List<JetFiles> in case a plugin were to need any of those things (or we added extra stuff later like the environment)

This commit is contained in:
James Strachan
2012-03-29 16:35:58 +01:00
parent ed04839901
commit beedd36456
14 changed files with 108 additions and 199 deletions
@@ -32,12 +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(val outputDir: File) : KModelCompilerPlugin() {
class KDoc() : KModelCompilerPlugin() {
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)
generator.generate(model, outputDir)
}
}
@@ -14,7 +14,6 @@ fun main(args: Array<String?>): Unit {
KotlinCompiler.doMain(KDocCompiler(), args);
}
/**
* A version of the [[KotlinCompiler]] which includes the [[KDoc]] compiler plugin and allows
* command line validation or for the configuration to be provided via [[KDocArguments]]
@@ -22,20 +21,10 @@ fun main(args: Array<String?>): Unit {
class KDocCompiler() : KotlinCompiler() {
override fun configureEnvironment(environment : CompileEnvironment?, arguments : CompilerArguments?, errStream : PrintStream?) {
// TODO lets clear the docOutput as a temporary hack while
// KotlinCompiler has a KDoc hook...
val docOutputDir = if (arguments != null) {
val answer = arguments.docOutputDir
arguments.docOutputDir = null
answer
} else null
super.configureEnvironment(environment, arguments, errStream)
val coreEnvironment = environment?.getMyEnvironment()
if (coreEnvironment != null) {
// now lets add the KDoc plugin
val outDir = File(docOutputDir ?: "target/apidocs")
val kdoc = KDoc(outDir)
val kdoc = KDoc()
if (arguments is KDocArguments) {
kdoc.config = arguments.apply()
@@ -69,13 +58,4 @@ class KDocArguments() : CompilerArguments() {
// TODO...
return docConfig
}
/**
* Add more configurations here when value attributes supported
* see: KT-1522
@Argument(value = "docOutput", description = "KDoc output directory")
public String docOutputDir;
*/
}
@@ -10,6 +10,11 @@ import org.jetbrains.kotlin.doc.model.KPackage
*/
class KDocConfig() {
/**
* Returns the directory to use to output the API docs
*/
public var docOutputDir: String = "target/site/apidocs"
/**
* Returns the name of the documentation set
*/
@@ -1,23 +1,26 @@
package org.jetbrains.kotlin.doc.highlighter
import org.jetbrains.jet.compiler.CompilerPlugin
import org.jetbrains.jet.lang.resolve.BindingContext
import java.util.List
import org.jetbrains.jet.lang.psi.JetFile
import org.jetbrains.jet.compiler.CompilerPluginContext
/**
*/
class HtmlCompilerPlugin : CompilerPlugin {
*/
class HtmlCompilerPlugin: CompilerPlugin {
override fun processFiles(bindingContext: BindingContext?, files: List<JetFile?>?) {
if (files != null && bindingContext != null) {
for (file in files) {
if (file != null) {
val visitor = HtmlKotlinVisitor()
file.accept(visitor)
override fun processFiles(context: CompilerPluginContext?) {
if (context != null) {
val bindingContext = context.getContext()
val files = context.getFiles()
if (bindingContext != null && files != null) {
if (files != null && bindingContext != null) {
for (file in files) {
if (file != null) {
val visitor = HtmlKotlinVisitor()
file.accept(visitor)
}
}
}
}
}
}
}
@@ -1,48 +1,25 @@
package org.jetbrains.kotlin.doc.model
import kotlin.*
import kotlin.util.*
import org.jetbrains.kotlin.doc.KDocConfig
import org.jetbrains.kotlin.doc.templates.*
import org.jetbrains.kotlin.template.TextTemplate
import java.io.File
import java.util.List
import java.util.HashSet
import java.util.Collection
import com.intellij.psi.PsiElement
import org.jetbrains.jet.lang.resolve.BindingContext
import org.jetbrains.jet.lang.resolve.BindingContext.*
import org.jetbrains.jet.compiler.CompilerPlugin
import org.jetbrains.jet.lang.psi.JetFile
import org.jetbrains.jet.lang.descriptors.NamespaceDescriptor
import org.jetbrains.jet.lexer.JetTokens
import org.jetbrains.jet.lang.descriptors.ClassDescriptor
import org.jetbrains.jet.lang.descriptors.CallableDescriptor
import org.jetbrains.jet.lang.types.JetType
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor
import org.jetbrains.jet.lang.descriptors.ModuleDescriptor
import org.jetbrains.jet.lang.resolve.java.JavaNamespaceDescriptor
import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor
import org.jetbrains.jet.lang.resolve.scopes.JetScope
import org.jetbrains.jet.lang.resolve.scopes.receivers.ExtensionReceiver
import org.jetbrains.jet.util.slicedmap.WritableSlice
import org.jetbrains.jet.lang.resolve.BindingContextUtils
import org.jetbrains.jet.compiler.CompilerPluginContext
import org.jetbrains.kotlin.doc.KDocConfig
/** Base class for any compiler plugin which needs to process a KModel */
abstract class KModelCompilerPlugin : CompilerPlugin {
abstract class KModelCompilerPlugin: CompilerPlugin {
public open var config: KDocConfig = KDocConfig()
override fun processFiles(context: BindingContext?, sources: List<JetFile?>?) {
if (context != null && sources != null) {
val model = KModel(context, config)
model.load(sources)
processModel(model)
override fun processFiles(context: CompilerPluginContext?) {
if (context != null) {
val bindingContext = context.getContext()
val sources = context.getFiles()
if (bindingContext != null && sources != null) {
val model = KModel(bindingContext, config)
model.load(sources)
processModel(model)
}
}
}
@@ -24,10 +24,10 @@ class KDocTest {
val args = KDocArguments()
args.setModule(moduleName)
args.setDocOutputDir(outDir.toString())
args.setOutputDir("target/classes-stdlib")
val config = args.docConfig
config.docOutputDir = outDir.toString()!!
config.title = "Kotlin API"
config.ignorePackages.add("org.jetbrains.kotlin")
config.ignorePackages.add("java")