diff --git a/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/KDoc.kt b/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/KDoc.kt index fab359da67c..06d8729e09e 100644 --- a/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/KDoc.kt +++ b/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/KDoc.kt @@ -31,22 +31,6 @@ import org.jetbrains.jet.lang.resolve.scopes.receivers.ExtensionReceiver import org.jetbrains.jet.util.slicedmap.WritableSlice import org.jetbrains.jet.lang.resolve.BindingContextUtils - -/** Base class for any compiler plugin which needs to process a KModel */ -abstract class KModelCompilerPlugin : CompilerPlugin { - - override fun processFiles(context: BindingContext?, sources: List?) { - if (context != null && sources != null) { - val model = KModel(context) - model.load(sources) - - processModel(model) - } - } - - abstract fun processModel(model: KModel): Unit -} - /** Generates the Kotlin Documentation for the model */ class KDoc(val outputDir: File) : KModelCompilerPlugin() { @@ -55,47 +39,3 @@ class KDoc(val outputDir: File) : KModelCompilerPlugin() { generator.execute() } } - -class KDocGenerator(val model: KModel, val outputDir: File) { - - fun execute(): Unit { - println("Generating kdoc to $outputDir") - run("allclasses-frame.html", AllClassesFrameTemplate(model, " target=\"classFrame\"")) - run("allclasses-noframe.html", AllClassesFrameTemplate(model)) - // run("constant-values.html", ConstantValuesTemplate(model)) - // run("deprecated-list.html", DeprecatedListTemplate(model)) - run("help-doc.html", HelpDocTemplate(model)) - // run("index-all.html", IndexAllTemplate(model)) - run("index.html", IndexTemplate(model)) - run("overview-frame.html", OverviewFrameTemplate(model)) - run("overview-summary.html", OverviewSummaryTemplate(model)) - run("overview-tree.html", OverviewTreeTemplate(model)) - run("package-list", PackageListTemplate(model)) - // run("serialized-form.html", SerializedFormTemplate(model)) - /** - TODO - */ - for (p in model.packages) { - run("${p.nameAsPath}/package-frame.html", PackageFrameTemplate(model, p)) - run("${p.nameAsPath}/package-summary.html", PackageSummaryTemplate(model, p)) - //run("${p.nameAsPath}/package-tree.html", PackageTreeTemplate(model, p)) - //run("${p.nameAsPath}/package-use.html", PackageUseTemplate(model, p)) - for (c in p.classes) { - run("${c.nameAsPath}.html", ClassTemplate(model, p, c)) - } - } - } - - protected fun run(fileName: String, template: TextTemplate): Unit { - val file = File(outputDir, fileName) - file.getParentFile()?.mkdirs() - - log("Generating $fileName") - template.renderTo(file) - } - - protected fun log(text: String) { - println(text) - } - -} diff --git a/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/KDocGenerator.kt b/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/KDocGenerator.kt new file mode 100644 index 00000000000..1e76af44ce9 --- /dev/null +++ b/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/KDocGenerator.kt @@ -0,0 +1,85 @@ +package org.jetbrains.kotlin.doc + +import std.* +import std.util.* + +import org.jetbrains.kotlin.doc.templates.* +import org.jetbrains.kotlin.template.TextTemplate +import org.jetbrains.kotlin.model.* + +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 + +class KDocGenerator(val model: KModel, val outputDir: File) { + + fun execute(): Unit { + println("Generating kdoc to $outputDir") + run("allclasses-frame.html", AllClassesFrameTemplate(model, " target=\"classFrame\"")) + run("allclasses-noframe.html", AllClassesFrameTemplate(model)) + // run("constant-values.html", ConstantValuesTemplate(model)) + // run("deprecated-list.html", DeprecatedListTemplate(model)) + run("help-doc.html", HelpDocTemplate(model)) + // run("index-all.html", IndexAllTemplate(model)) + run("index.html", IndexTemplate(model)) + run("overview-frame.html", OverviewFrameTemplate(model)) + run("overview-summary.html", OverviewSummaryTemplate(model)) + run("overview-tree.html", OverviewTreeTemplate(model)) + run("package-list", PackageListTemplate(model)) + // run("serialized-form.html", SerializedFormTemplate(model)) + /** + TODO + */ + for (p in model.packages) { + run("${p.nameAsPath}/package-frame.html", PackageFrameTemplate(model, p)) + run("${p.nameAsPath}/package-summary.html", PackageSummaryTemplate(model, p)) + //run("${p.nameAsPath}/package-tree.html", PackageTreeTemplate(model, p)) + //run("${p.nameAsPath}/package-use.html", PackageUseTemplate(model, p)) + for (c in p.classes) { + run("${c.nameAsPath}.html", ClassTemplate(model, p, c)) + } + + val map = extensionFunctions(p.functions) + for (e in map.entrySet()) { + val c = e?.getKey() + val functions = e?.getValue() + if (c != null && functions != null) { + run("${p.nameAsPath}/${c.simpleName}-extensions.html", ClassExtensionsTemplate(model, p, c, functions)) + } + } + } + } + + protected fun run(fileName: String, template: TextTemplate): Unit { + val file = File(outputDir, fileName) + file.getParentFile()?.mkdirs() + + log("Generating $fileName") + template.renderTo(file) + } + + protected fun log(text: String) { + println(text) + } + +} diff --git a/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/templates/ClassExtensionsTemplate.kt b/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/templates/ClassExtensionsTemplate.kt new file mode 100644 index 00000000000..b4a8eaaba32 --- /dev/null +++ b/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/templates/ClassExtensionsTemplate.kt @@ -0,0 +1,45 @@ +package org.jetbrains.kotlin.doc.templates + +import std.* +import org.jetbrains.kotlin.template.* +import std.io.* +import std.util.* +import java.util.* +import org.jetbrains.kotlin.model.KModel +import org.jetbrains.kotlin.model.KPackage +import org.jetbrains.kotlin.model.KClass +import org.jetbrains.kotlin.model.KFunction +import org.jetbrains.kotlin.model.KAnnotation + +class ClassExtensionsTemplate(m: KModel, p: KPackage, k: KClass, var functions: List) : ClassTemplate(m, p, k) { + + override fun pageTitle(): String = "${klass.name} Extensions fom ${pkg.name} (${model.title})" + + override fun printBody(): Unit { + println("""
+ +

+""") + println("${pkg.name}") + println("
") + println("Extensions on ${klass.name}

") + println("
") + print("
") + print("extension functions on class ${klass.name}
") + + println("from package ") + println(link(pkg)) + println("
") + println(""" + +

""") + + printFunctionSummary(functions) + printFunctionDetail(functions) + + println(""" +


+""") + } + +} diff --git a/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/templates/ClassTemplate.kt b/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/templates/ClassTemplate.kt index eb55a3424d9..ae433e0442c 100644 --- a/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/templates/ClassTemplate.kt +++ b/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/templates/ClassTemplate.kt @@ -11,7 +11,10 @@ import org.jetbrains.kotlin.model.KClass import org.jetbrains.kotlin.model.KFunction import org.jetbrains.kotlin.model.KAnnotation -class ClassTemplate(val model: KModel, pkg: KPackage, val klass: KClass) : PackageTemplateSupport(pkg) { +open class ClassTemplate(open val model: KModel, pkg: KPackage, open val klass: KClass) : PackageTemplateSupport(pkg) { + + open fun pageTitle(): String = "${klass.name} (${model.title})" + override fun render() { // TODO could really do with templates in multi-line strings :) println(""" @@ -21,7 +24,7 @@ class ClassTemplate(val model: KModel, pkg: KPackage, val klass: KClass) : Packa println("") println(""" """) - println("${klass.name} (${model.title})") + println(pageTitle()) println(""" @@ -100,8 +103,74 @@ DETAIL: FIELD | CONSTR | METHO +""") -
+ printBody() + + println(""" + + + + + + + + + """) + printPrevNextClass() + println(""" + + + + + +
+ +
+ + + +
+ Copyright © 2010-2012. All Rights Reserved. + + """) + } + + open fun printBody(): Unit { + println("""

""") @@ -177,71 +246,10 @@ DETAIL: FIELD | CONSTR | METHO println("""
- - - -
- - - - - - - -""") - printPrevNextClass() - println(""" - - - - - -
- -
- - - -
-Copyright © 2010-2012. All Rights Reserved. - -""") +""") } - fun printPrevNextClass(): Unit { + open fun printPrevNextClass(): Unit { println("""""") val prev = pkg.previous(klass) if (prev != null) { diff --git a/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/templates/KDocTemplate.kt b/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/templates/KDocTemplate.kt index 4c202d355ad..79865287533 100644 --- a/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/templates/KDocTemplate.kt +++ b/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/templates/KDocTemplate.kt @@ -8,16 +8,24 @@ import org.jetbrains.kotlin.model.KFunction import java.util.Collection abstract class KDocTemplate() : TextTemplate() { - fun href(pkg: KPackage): String { + fun rootHref(pkg: KPackage): String { return if (pkg.external) { // TODO deal with external classes "" } else relativePrefix() } + fun href(p: KPackage): String + = "${rootHref(p)}${p.nameAsPath}/package-summary.html" + fun href(c: KClass): String { val postfix = if (c.pkg.external) "?is-external=true" else "" - return "${href(c.pkg)}${c.nameAsPath}.html$postfix" + return "${rootHref(c.pkg)}${c.nameAsPath}.html$postfix" + } + + fun extensionsHref(pkg: KPackage, c: KClass): String { + // is inside the pkg so no need to use it... + return "${c.nameAsPath}-extensions.html" } fun href(f: KFunction): String { @@ -30,7 +38,7 @@ abstract class KDocTemplate() : TextTemplate() { fun sourceHref(f: KFunction): String { return if (f.owner is KClass) { - "${href(f.owner.pkg)}src-html/${f.owner.simpleName}.html#line.${f.sourceLine}" + "${rootHref(f.owner.pkg)}src-html/${f.owner.simpleName}.html#line.${f.sourceLine}" } else { // TODO how to find the function in a package??? "" @@ -44,6 +52,10 @@ abstract class KDocTemplate() : TextTemplate() { return "$prefix$name" } + fun link(p: KPackage): String { + return "${p.name}" + } + fun link(a: KAnnotation): String { val c = a.klass return "@${c.simpleName}" diff --git a/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/templates/PackageFrameTemplate.kt b/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/templates/PackageFrameTemplate.kt index d21c2282751..484dd452192 100644 --- a/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/templates/PackageFrameTemplate.kt +++ b/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/templates/PackageFrameTemplate.kt @@ -93,7 +93,7 @@ class PackageFrameTemplate(val model: KModel, p: KPackage) : PackageTemplateSupp for (e in map.entrySet()) { val c = e?.getKey() if (c != null) { - println("${c.name}") + println("${c.name}") println("
") } } diff --git a/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/templates/PackageTemplateSupport.kt b/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/templates/PackageTemplateSupport.kt index 6fffec0e6d4..de60f6ba6ab 100644 --- a/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/templates/PackageTemplateSupport.kt +++ b/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/templates/PackageTemplateSupport.kt @@ -12,11 +12,7 @@ import org.jetbrains.kotlin.model.KFunction import org.jetbrains.kotlin.model.KAnnotation -abstract class PackageTemplateSupport(private val _pkg: KPackage) : KDocTemplate() { - - // TODO this verbosity is to work around this bug: http://youtrack.jetbrains.com/issue/KT-1398 - public val pkg: KPackage - get() = _pkg +abstract class PackageTemplateSupport(open val pkg: KPackage) : KDocTemplate() { protected override fun relativePrefix(): String = pkg.nameAsRelativePath diff --git a/kdoc/src/main/kotlin/org/jetbrains/kotlin/model/KModelCompilerPlugin.kt b/kdoc/src/main/kotlin/org/jetbrains/kotlin/model/KModelCompilerPlugin.kt new file mode 100644 index 00000000000..19a7719ca03 --- /dev/null +++ b/kdoc/src/main/kotlin/org/jetbrains/kotlin/model/KModelCompilerPlugin.kt @@ -0,0 +1,48 @@ +package org.jetbrains.kotlin.model + +import std.* +import std.util.* + +import org.jetbrains.kotlin.doc.templates.* +import org.jetbrains.kotlin.template.TextTemplate +import org.jetbrains.kotlin.model.* + +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 + + +/** Base class for any compiler plugin which needs to process a KModel */ +abstract class KModelCompilerPlugin : CompilerPlugin { + + override fun processFiles(context: BindingContext?, sources: List?) { + if (context != null && sources != null) { + val model = KModel(context) + model.load(sources) + + processModel(model) + } + } + + abstract fun processModel(model: KModel): Unit +} \ No newline at end of file diff --git a/kdoc/src/main/kotlin/org/jetbrains/kotlin/model/KModelHack.java b/kdoc/src/main/kotlin/org/jetbrains/kotlin/model/KModelHack.java deleted file mode 100644 index 832796c56d5..00000000000 --- a/kdoc/src/main/kotlin/org/jetbrains/kotlin/model/KModelHack.java +++ /dev/null @@ -1,24 +0,0 @@ -/** - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jetbrains.kotlin.model; - -/** - * Hack around the issue of - */ -public class KModelHack { -} diff --git a/kdoc/src/main/kotlin/org/jetbrains/kotlin/model/KModelVisitor.java b/kdoc/src/main/kotlin/org/jetbrains/kotlin/model/KModelVisitor.java deleted file mode 100644 index 1fedcaf85e4..00000000000 --- a/kdoc/src/main/kotlin/org/jetbrains/kotlin/model/KModelVisitor.java +++ /dev/null @@ -1,27 +0,0 @@ -/** - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jetbrains.kotlin.model; - -import org.jetbrains.jet.lang.psi.JetVisitor; - -/** - */ -public class KModelVisitor { // extends JetVisitor { - - -}