kdoc: change highlighter2 into doclet
This commit is contained in:
@@ -30,15 +30,20 @@ import org.jetbrains.jet.lang.resolve.scopes.JetScope
|
|||||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.ExtensionReceiver
|
import org.jetbrains.jet.lang.resolve.scopes.receivers.ExtensionReceiver
|
||||||
import org.jetbrains.jet.util.slicedmap.WritableSlice
|
import org.jetbrains.jet.util.slicedmap.WritableSlice
|
||||||
import org.jetbrains.jet.lang.resolve.BindingContextUtils
|
import org.jetbrains.jet.lang.resolve.BindingContextUtils
|
||||||
|
import org.jetbrains.kotlin.doc.highlighter2.Html2CompilerPlugin
|
||||||
|
|
||||||
/** Generates the Kotlin Documentation for the model */
|
/** Generates the Kotlin Documentation for the model */
|
||||||
class KDoc(protected arguments: KDocArguments) : KModelCompilerPlugin(arguments) {
|
class KDoc(protected arguments: KDocArguments) : KModelCompilerPlugin(arguments) {
|
||||||
|
|
||||||
protected override fun processModel(model: KModel) {
|
protected override fun processModel(model: KModel) {
|
||||||
|
val outputDir = File(arguments.apply().docOutputDir)
|
||||||
|
|
||||||
// TODO allow this to be configured; maybe we use configuration on the KotlinModule
|
// TODO allow this to be configured; maybe we use configuration on the KotlinModule
|
||||||
// to define what doclets to use?
|
// to define what doclets to use?
|
||||||
val generator = JavadocStyleHtmlDoclet()
|
val generator = JavadocStyleHtmlDoclet()
|
||||||
val outputDir = File(arguments.apply().docOutputDir)
|
|
||||||
generator.generate(model, outputDir)
|
generator.generate(model, outputDir)
|
||||||
|
|
||||||
|
val srcGenerator = Html2CompilerPlugin(arguments)
|
||||||
|
srcGenerator.generate(model, outputDir)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,8 +29,6 @@ class KDocCompiler() : K2JVMCompiler() {
|
|||||||
if (coreEnvironment != null) {
|
if (coreEnvironment != null) {
|
||||||
val kdoc = KDoc(arguments as KDocArguments)
|
val kdoc = KDoc(arguments as KDocArguments)
|
||||||
val plugins = configuration.getCompilerPlugins()
|
val plugins = configuration.getCompilerPlugins()
|
||||||
val sourcePlugin = Html2CompilerPlugin(arguments as KDocArguments)
|
|
||||||
plugins.add(sourcePlugin)
|
|
||||||
plugins.add(kdoc);
|
plugins.add(kdoc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+7
-4
@@ -15,9 +15,12 @@ import org.jetbrains.jet.internal.com.intellij.psi.PsiElement
|
|||||||
import org.jetbrains.jet.internal.com.intellij.psi.impl.source.tree.LeafPsiElement
|
import org.jetbrains.jet.internal.com.intellij.psi.impl.source.tree.LeafPsiElement
|
||||||
import org.jetbrains.jet.JetNodeTypes
|
import org.jetbrains.jet.JetNodeTypes
|
||||||
import org.jetbrains.jet.lexer.JetTokens
|
import org.jetbrains.jet.lexer.JetTokens
|
||||||
|
import org.jetbrains.kotlin.doc.Doclet
|
||||||
|
import org.jetbrains.kotlin.doc.model.KModel
|
||||||
|
import org.jetbrains.jet.lang.psi.JetFile
|
||||||
|
|
||||||
|
|
||||||
class Html2CompilerPlugin(private val compilerArguments: KDocArguments) : CompilerPlugin {
|
class Html2CompilerPlugin(private val compilerArguments: KDocArguments) : Doclet {
|
||||||
|
|
||||||
private val docOutputRoot: File
|
private val docOutputRoot: File
|
||||||
{
|
{
|
||||||
@@ -51,7 +54,7 @@ class Html2CompilerPlugin(private val compilerArguments: KDocArguments) : Compil
|
|||||||
throw Exception("$file is not a child of any source roots $sourceDirPaths")
|
throw Exception("$file is not a child of any source roots $sourceDirPaths")
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun processFiles(context: CompilerPluginContext) {
|
override fun generate(model: KModel, outputDir: File) {
|
||||||
srcOutputRoot.mkdirs()
|
srcOutputRoot.mkdirs()
|
||||||
|
|
||||||
val css = javaClass<Html2CompilerPlugin>().getClassLoader()!!.getResourceAsStream(
|
val css = javaClass<Html2CompilerPlugin>().getClassLoader()!!.getResourceAsStream(
|
||||||
@@ -62,12 +65,12 @@ class Html2CompilerPlugin(private val compilerArguments: KDocArguments) : Compil
|
|||||||
#()
|
#()
|
||||||
}
|
}
|
||||||
|
|
||||||
for (file in context.getFiles().requireNoNulls()) {
|
for (file in model.sources) {
|
||||||
processFile(file)
|
processFile(file)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun processFile(psiFile: PsiFile) {
|
private fun processFile(psiFile: JetFile) {
|
||||||
val relativePath = fileToWrite(psiFile)
|
val relativePath = fileToWrite(psiFile)
|
||||||
val htmlFile = File(srcOutputRoot, relativePath.replaceFirst("\\.kt$", "") + ".html")
|
val htmlFile = File(srcOutputRoot, relativePath.replaceFirst("\\.kt$", "") + ".html")
|
||||||
|
|
||||||
|
|||||||
@@ -175,7 +175,7 @@ abstract class KClassOrPackage(model: KModel, declarationDescriptor: Declaration
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class KModel(val context: BindingContext, val config: KDocConfig, private val sources: List<JetFile>) {
|
class KModel(val context: BindingContext, val config: KDocConfig, val sources: List<JetFile>) {
|
||||||
// TODO generates java.lang.NoSuchMethodError: kotlin.util.namespace.hashMap(Ljet/TypeInfo;Ljet/TypeInfo;)Ljava/util/HashMap;
|
// TODO generates java.lang.NoSuchMethodError: kotlin.util.namespace.hashMap(Ljet/TypeInfo;Ljet/TypeInfo;)Ljava/util/HashMap;
|
||||||
//val packages = sortedMap<String,KPackage>()
|
//val packages = sortedMap<String,KPackage>()
|
||||||
public val packageMap: SortedMap<String, KPackage> = TreeMap<String, KPackage>()
|
public val packageMap: SortedMap<String, KPackage> = TreeMap<String, KPackage>()
|
||||||
|
|||||||
Reference in New Issue
Block a user