From 0ff0fc847d4ec84b727ab9f6dc83f14fe7b7d2d8 Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Tue, 21 Jul 2015 17:32:59 +0200 Subject: [PATCH] delete the rest of KDoc --- libraries/pom.xml | 1 - libraries/tools/kdoc/.gitignore | 1 - libraries/tools/kdoc/ApiDocsModule.kt | 12 - libraries/tools/kdoc/module.kt | 15 - libraries/tools/kdoc/pom.xml | 100 -- .../kotlin/org/jetbrains/kotlin/doc/Doclet.kt | 12 - .../kotlin/doc/JavadocStyleHtmlDoclet.kt | 67 - .../kotlin/org/jetbrains/kotlin/doc/KDoc.kt | 21 - .../org/jetbrains/kotlin/doc/KDocCompiler.kt | 52 - .../org/jetbrains/kotlin/doc/KDocConfig.kt | 123 -- .../kotlin/org/jetbrains/kotlin/doc/Names.kt | 10 - .../org/jetbrains/kotlin/doc/collections.kt | 15 - .../doc/highlighter/HtmlCompilerPlugin.kt | 15 - .../doc/highlighter/HtmlKotlinVisitor.kt | 57 - .../doc/highlighter/SyntaxHighlighter.kt | 131 -- .../doc/highlighter2/Html2CompilerPlugin.kt | 128 -- .../kotlin/doc/highlighter2/hightlight.css | 7 - .../kotlin/doc/highlighter2/ioUtils.kt | 7 - .../kotlin/doc/highlighter2/psiUtils.kt | 40 - .../kotlin/doc/model/KModelCompilerPlugin.kt | 24 - .../jetbrains/kotlin/doc/model/KotlinModel.kt | 1185 ----------------- .../doc/templates/AllClassesFrameTemplate.kt | 40 - .../doc/templates/ClassExtensionsTemplate.kt | 49 - .../kotlin/doc/templates/ClassTemplate.kt | 257 ---- .../kotlin/doc/templates/HelpDocTemplate.kt | 232 ---- .../kotlin/doc/templates/IndexTemplate.kt | 49 - .../kotlin/doc/templates/KDocTemplate.kt | 183 --- .../doc/templates/OverviewFrameTemplate.kt | 51 - .../doc/templates/OverviewSummaryTemplate.kt | 168 --- .../doc/templates/OverviewTreeTemplate.kt | 190 --- .../doc/templates/PackageFrameTemplate.kt | 118 -- .../doc/templates/PackageListTemplate.kt | 11 - .../doc/templates/PackageSummaryTemplate.kt | 304 ----- .../doc/templates/PackageTemplateSupport.kt | 279 ---- .../kotlin/doc/templates/SearchXmlTemplate.kt | 64 - .../jetbrains/kotlin/template/HtmlTemplate.kt | 84 -- .../jetbrains/kotlin/template/TemplateCore.kt | 111 -- .../jetbrains/kotlin/template/stringUtils.kt | 8 - .../test/kotlin/kdoc/HtmlVisitorTest.kt | 30 - .../kotlin/test/kotlin/kdoc/KDocSampleTest.kt | 50 - .../test/kotlin/test/kotlin/kdoc/KDocTest.kt | 33 - .../test/kotlin/test/kotlin/psiUtilsTest.kt | 58 - .../test/kotlin/template/PegdownTest.kt | 49 - .../test/kotlin/template/TemplateCoreTest.kt | 41 - libraries/tools/kdoc/src/test/sample/Hello.kt | 8 - 45 files changed, 4490 deletions(-) delete mode 100644 libraries/tools/kdoc/.gitignore delete mode 100644 libraries/tools/kdoc/ApiDocsModule.kt delete mode 100644 libraries/tools/kdoc/module.kt delete mode 100644 libraries/tools/kdoc/pom.xml delete mode 100644 libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/Doclet.kt delete mode 100644 libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/JavadocStyleHtmlDoclet.kt delete mode 100644 libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/KDoc.kt delete mode 100644 libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/KDocCompiler.kt delete mode 100644 libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/KDocConfig.kt delete mode 100644 libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/Names.kt delete mode 100644 libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/collections.kt delete mode 100644 libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/highlighter/HtmlCompilerPlugin.kt delete mode 100644 libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/highlighter/HtmlKotlinVisitor.kt delete mode 100644 libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/highlighter/SyntaxHighlighter.kt delete mode 100644 libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/highlighter2/Html2CompilerPlugin.kt delete mode 100644 libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/highlighter2/hightlight.css delete mode 100644 libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/highlighter2/ioUtils.kt delete mode 100644 libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/highlighter2/psiUtils.kt delete mode 100644 libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/model/KModelCompilerPlugin.kt delete mode 100644 libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/model/KotlinModel.kt delete mode 100644 libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/templates/AllClassesFrameTemplate.kt delete mode 100644 libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/templates/ClassExtensionsTemplate.kt delete mode 100644 libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/templates/ClassTemplate.kt delete mode 100644 libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/templates/HelpDocTemplate.kt delete mode 100644 libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/templates/IndexTemplate.kt delete mode 100644 libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/templates/KDocTemplate.kt delete mode 100644 libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/templates/OverviewFrameTemplate.kt delete mode 100644 libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/templates/OverviewSummaryTemplate.kt delete mode 100644 libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/templates/OverviewTreeTemplate.kt delete mode 100644 libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/templates/PackageFrameTemplate.kt delete mode 100644 libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/templates/PackageListTemplate.kt delete mode 100644 libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/templates/PackageSummaryTemplate.kt delete mode 100644 libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/templates/PackageTemplateSupport.kt delete mode 100644 libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/templates/SearchXmlTemplate.kt delete mode 100644 libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/template/HtmlTemplate.kt delete mode 100644 libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/template/TemplateCore.kt delete mode 100644 libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/template/stringUtils.kt delete mode 100644 libraries/tools/kdoc/src/test/kotlin/test/kotlin/kdoc/HtmlVisitorTest.kt delete mode 100644 libraries/tools/kdoc/src/test/kotlin/test/kotlin/kdoc/KDocSampleTest.kt delete mode 100644 libraries/tools/kdoc/src/test/kotlin/test/kotlin/kdoc/KDocTest.kt delete mode 100644 libraries/tools/kdoc/src/test/kotlin/test/kotlin/psiUtilsTest.kt delete mode 100644 libraries/tools/kdoc/src/test/kotlin/test/kotlin/template/PegdownTest.kt delete mode 100644 libraries/tools/kdoc/src/test/kotlin/test/kotlin/template/TemplateCoreTest.kt delete mode 100644 libraries/tools/kdoc/src/test/sample/Hello.kt diff --git a/libraries/pom.xml b/libraries/pom.xml index 120305026d5..c497fef5835 100644 --- a/libraries/pom.xml +++ b/libraries/pom.xml @@ -94,7 +94,6 @@ tools/kotlin-maven-plugin-test tools/kotlin-js-tests tools/kotlin-js-tests-junit - tools/kdoc kunit kotlin-jdbc diff --git a/libraries/tools/kdoc/.gitignore b/libraries/tools/kdoc/.gitignore deleted file mode 100644 index eb5a316cbd1..00000000000 --- a/libraries/tools/kdoc/.gitignore +++ /dev/null @@ -1 +0,0 @@ -target diff --git a/libraries/tools/kdoc/ApiDocsModule.kt b/libraries/tools/kdoc/ApiDocsModule.kt deleted file mode 100644 index 04c4dff936c..00000000000 --- a/libraries/tools/kdoc/ApiDocsModule.kt +++ /dev/null @@ -1,12 +0,0 @@ -import kotlin.modules.* - -fun project() { - module("apidocs") { - classpath += "../../lib/junit-4.11.jar" - - addSourceFiles("../../stdlib/src") - addSourceFiles("../../kunit/src/main/kotlin") - addSourceFiles("../../kotlin-jdbc/src/main/kotlin") - //addSourceFiles("../kotlin-swing/src/main/kotlin") - } -} \ No newline at end of file diff --git a/libraries/tools/kdoc/module.kt b/libraries/tools/kdoc/module.kt deleted file mode 100644 index e9249b20365..00000000000 --- a/libraries/tools/kdoc/module.kt +++ /dev/null @@ -1,15 +0,0 @@ -import kotlin.modules.* - -fun project() { - module("kdoc") { - classpath += "dist/kotlinc/lib/intellij-core.jar" - classpath += "dist/kotlinc/lib/kotlin-compiler.jar" - - // TODO its a bit sad we can't use patterns here... - addClasspathEntry("dist/kotlinc/lib/pegdown-1.1.0.jar") - addClasspathEntry("dist/kotlinc/lib/parboiled-core-1.0.2.jar") - addClasspathEntry("dist/kotlinc/lib/parboiled-java-1.0.2.jar") - - addSourceFiles("src/main/kotlin") - } -} \ No newline at end of file diff --git a/libraries/tools/kdoc/pom.xml b/libraries/tools/kdoc/pom.xml deleted file mode 100644 index 49dfb2368a0..00000000000 --- a/libraries/tools/kdoc/pom.xml +++ /dev/null @@ -1,100 +0,0 @@ - - - - 4.0.0 - - - org.jetbrains.kotlin - kotlin-project - 0.1-SNAPSHOT - ../../pom.xml - - - kdoc - - - - org.pegdown - pegdown - ${pegdown.version} - - - - org.jetbrains.kotlin - kotlin-compiler - ${project.version} - - - - org.jetbrains.kotlin - kotlin-stdlib - ${project.version} - - - - - src/main/kotlin - src/test/kotlin - - - - src/main/kotlin - - **/*.css - - - - - - - org.jetbrains.kotlin - kotlin-maven-plugin - ${project.version} - - - - compile - compile - - compile - - - - - test-compile - test-compile - - test-compile - - - - - - - - maven-surefire-plugin - ${surefire-version} - - once - -Xmx500m -XX:MaxPermSize=250m - false - false - false - - **/*Test.* - - - - **/KDocTest.* - - - ${project.version} - - - - - - - diff --git a/libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/Doclet.kt b/libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/Doclet.kt deleted file mode 100644 index 1b1efba610a..00000000000 --- a/libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/Doclet.kt +++ /dev/null @@ -1,12 +0,0 @@ -package org.jetbrains.kotlin.doc - -import java.io.File -import org.jetbrains.kotlin.doc.model.KModel - -/** -* A simple plugin to KDoc to generate information from the model into a directory -* which can be implemented using any kind of layout or format. -*/ -trait Doclet { - fun generate(model: KModel, outputDir: File): Unit -} diff --git a/libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/JavadocStyleHtmlDoclet.kt b/libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/JavadocStyleHtmlDoclet.kt deleted file mode 100644 index 05a04a4c965..00000000000 --- a/libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/JavadocStyleHtmlDoclet.kt +++ /dev/null @@ -1,67 +0,0 @@ -package org.jetbrains.kotlin.doc - -import java.io.File -import org.jetbrains.kotlin.doc.model.* -import org.jetbrains.kotlin.doc.templates.* -import org.jetbrains.kotlin.template.TextTemplate - -/** Creates JavaDoc style HTML output from the model */ -class JavadocStyleHtmlDoclet() : Doclet { - - override fun generate(model: KModel, outputDir: File): Unit { - fun run(fileName: String, template: TextTemplate): Unit { - val file = File(outputDir, fileName) - file.getParentFile()?.mkdirs() - - log("Generating $fileName") - template.renderTo(file) - } - - fun generateExtensionFunctions(p: KPackage): Unit { - val map = inheritedExtensionFunctions(p.functions) - val pmap = inheritedExtensionProperties(p.properties) - val classes = hashSetOf() - classes.addAll(map.keySet()) - classes.addAll(pmap.keySet()) - for (c in classes) { - val functions = map.get(c).orEmpty() - val properties = pmap.get(c).orEmpty() - run("${p.nameAsPath}/${c.nameAsPath}-extensions.html", - ClassExtensionsTemplate(model, p, c, functions, properties)) - } - } - - - println("Generating kdoc to $outputDir excluding packages ${model.config.ignorePackages}") - 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("search.xml", SearchXmlTemplate(model)) - // run("serialized-form.html", SerializedFormTemplate(model)) - 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)) - } - - generateExtensionFunctions(p) - } - } - - protected fun log(text: String) { - println(text) - } - - -} 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 deleted file mode 100644 index f8e60f41d70..00000000000 --- a/libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/KDoc.kt +++ /dev/null @@ -1,21 +0,0 @@ -package org.jetbrains.kotlin.doc - -import java.io.File -import org.jetbrains.kotlin.doc.highlighter2.Html2CompilerPlugin -import org.jetbrains.kotlin.doc.model.* - -/** Generates the Kotlin Documentation for the model */ -class KDoc(arguments: KDocArguments) : KModelCompilerPlugin(arguments) { - - 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 - // to define what doclets to use? - val generator = JavadocStyleHtmlDoclet() - generator.generate(model, outputDir) - - val srcGenerator = Html2CompilerPlugin(arguments) - srcGenerator.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 deleted file mode 100644 index 45705fcbe38..00000000000 --- a/libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/KDocCompiler.kt +++ /dev/null @@ -1,52 +0,0 @@ -package org.jetbrains.kotlin.doc - -import java.io.PrintStream -import org.jetbrains.kotlin.cli.common.CLICompiler -import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys -import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments; -import org.jetbrains.kotlin.cli.jvm.K2JVMCompiler -import org.jetbrains.kotlin.config.CompilerConfiguration -import org.jetbrains.kotlin.cli.common.messages.MessageCollector - -/** -* Main for running the KDocCompiler -*/ -fun main(args: Array): Unit { - CLICompiler.doMain(KDocCompiler(), args); -} - -/** - * A version of the [[K2JVMCompiler]] which includes the [[KDoc]] compiler plugin and allows - * command line validation or for the configuration to be provided via [[KDocArguments]] - */ -class KDocCompiler() : K2JVMCompiler() { - - protected override fun configureEnvironment(configuration : CompilerConfiguration, arguments : K2JVMCompilerArguments) { - super.configureEnvironment(configuration, arguments) - configuration.add(CLIConfigurationKeys.COMPILER_PLUGINS, KDoc(arguments as KDocArguments)) - - // Suppress all messages from the compiler, because KDoc is not a compiler - configuration.put(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY, MessageCollector.NONE) - } - - protected override fun createArguments() : K2JVMCompilerArguments { - return KDocArguments() - } - - protected override fun usage(target: PrintStream, extraHelp: Boolean) { - target.println("Usage: KDocCompiler -d [|] [-stdlib ] [|-module ] [-include-runtime]"); - } -} - -class KDocArguments() : K2JVMCompilerArguments() { - - public var docConfig: KDocConfig = KDocConfig() - - /** - * Applies the command line arguments to the given KDoc configuration - */ - fun apply(): KDocConfig { - // TODO... - return docConfig - } -} diff --git a/libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/KDocConfig.kt b/libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/KDocConfig.kt deleted file mode 100644 index 89f7a7ffd3d..00000000000 --- a/libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/KDocConfig.kt +++ /dev/null @@ -1,123 +0,0 @@ -package org.jetbrains.kotlin.doc - -import java.util.* -import org.jetbrains.kotlin.doc.model.KPackage - -/** -* The configuration used with KDoc -*/ -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 - */ - public var title: String = "Documentation" - - /** - * Returns the version name of the documentation set - */ - public var version: String = "SNAPSHOT" - - /** - * Returns a map of the package prefix to the HTML URL for the root of the apidoc using javadoc/kdoc style - * directory layouts so that this API doc report can link to external packages - */ - public val packagePrefixToUrls: MutableMap = TreeMap(LongestFirstStringComparator) - - /** - * Returns a Set of the package name prefixes to ignore from the KDoc report - */ - public val ignorePackages: MutableSet = HashSet() - - /** - * Returns true if a warning should be generated if there are no comments - * on documented function or property - */ - public var warnNoComments: Boolean = true - - /** - * Returns the HTTP URL of the root directory of source code that we should link to - */ - public var sourceRootHref: String? = null - - /** - * The root project directory used to deduce relative file names when linking to source code - */ - public var projectRootDir: String? = null - - /** - * A map of package name to html or markdown files used to describe the package. If none is - * specified we will look for a package.html or package.md file in the source tree - */ - public var packageDescriptionFiles: MutableMap = HashMap() - - /** - * A map of package name to summary text used in the package overviews - */ - public var packageSummaryText: MutableMap = HashMap() - - /** - * Returns true if protected functions and properties should be documented - */ - public var includeProtected: Boolean = true - - init { - // add some common defaults - addPackageLink("http://docs.oracle.com/javase/6/docs/api/", "java", "org.w3c.dom", "org.xml.sax", "org.omg", "org.ietf.jgss") - addPackageLink("http://kentbeck.github.com/junit/javadoc/latest/", "org.junit", "junit") - } - - /** - * Returns a set of all the package which have been warned that were missing an external URL - */ - private val mutableMissingPackageUrls: MutableSet = TreeSet() - public val missingPackageUrls: Set = mutableMissingPackageUrls - - /** - * Adds one or more package prefixes to the given javadoc URL - */ - fun addPackageLink(url: String, vararg packagePrefixes: String): Unit { - for (p in packagePrefixes) { - packagePrefixToUrls.put(p, url) - } - } - - /** - * Resolves a link to the given class name - */ - fun resolveLink(packageName: String, warn: Boolean = true): String { - for (e in packagePrefixToUrls) { - val p = e.key - val url = e.value - if (packageName.startsWith(p)) { - return url - } - } - if (warn && mutableMissingPackageUrls.add(packageName)) { - println("Warning: could not find external link to package: $packageName") - } - return "" - } - - /** - * Returns true if the package should be included in the report - */ - fun includePackage(pkg: KPackage): Boolean { - return !ignorePackages.any{ pkg.name.startsWith(it) } - } -} - -private object LongestFirstStringComparator : Comparator { - override fun compare(o1: String, o2: String): Int { - return compareValuesBy(o1, o2, { it.length() }, { it }) - } - - override fun equals(other: Any?): Boolean { - return other is LongestFirstStringComparator - } -} diff --git a/libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/Names.kt b/libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/Names.kt deleted file mode 100644 index f67256075ee..00000000000 --- a/libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/Names.kt +++ /dev/null @@ -1,10 +0,0 @@ -package org.jetbrains.kotlin.doc - - -object names { - - val htmlSourceDirName = "src-html" - - fun lineNumberLinkHref(lineNumber: Int) = "L$lineNumber" - -} diff --git a/libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/collections.kt b/libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/collections.kt deleted file mode 100644 index 6612f7c57c3..00000000000 --- a/libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/collections.kt +++ /dev/null @@ -1,15 +0,0 @@ -package org.jetbrains.kotlin.doc - -import java.util.HashMap - -fun List.toHashMap(f: (A) -> Pair): Map { - val r = HashMap() - for (item in this) { - val entry = f(item) - r.put(entry.first, entry.second) - } - return r -} - - -fun List.toHashMapMappingToKey(f: (V) -> K): Map = toHashMap { v -> Pair(f(v), v) } diff --git a/libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/highlighter/HtmlCompilerPlugin.kt b/libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/highlighter/HtmlCompilerPlugin.kt deleted file mode 100644 index e337f9676da..00000000000 --- a/libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/highlighter/HtmlCompilerPlugin.kt +++ /dev/null @@ -1,15 +0,0 @@ -package org.jetbrains.kotlin.doc.highlighter - -import org.jetbrains.kotlin.cli.common.CompilerPlugin -import org.jetbrains.kotlin.cli.common.CompilerPluginContext - -/** -*/ -class HtmlCompilerPlugin : CompilerPlugin { - public override fun processFiles(context: CompilerPluginContext) { - val files = context.getFiles() - for (file in files) { - file.accept(HtmlKotlinVisitor()) - } - } -} diff --git a/libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/highlighter/HtmlKotlinVisitor.kt b/libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/highlighter/HtmlKotlinVisitor.kt deleted file mode 100644 index 56c14afac9a..00000000000 --- a/libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/highlighter/HtmlKotlinVisitor.kt +++ /dev/null @@ -1,57 +0,0 @@ -package org.jetbrains.kotlin.doc.highlighter - -import com.intellij.psi.PsiComment -import com.intellij.psi.PsiElement -import com.intellij.psi.PsiFile -import com.intellij.psi.PsiWhiteSpace -import org.jetbrains.kotlin.psi.* - -class HtmlKotlinVisitor: JetTreeVisitor() { - - override fun visitFile(file: PsiFile?) { - if (file is JetFile) { - visitJetFile(file, StringBuilder()) - } - } - - override fun visitJetFile(file: JetFile, data: StringBuilder?): Void? { - println("============ Jet File ${file.getName()}") - acceptChildren(file, data) - return null - } - - override fun visitClass(klass: JetClass, data: StringBuilder?): Void? { - println("============ class $klass") - acceptChildren(klass, data) - return null - } - - override fun visitClassBody(classBody: JetClassBody, data: StringBuilder?): Void? { - println("============ class body $classBody data $data") - return super.visitClassBody(classBody, data) - } - - override fun visitFunctionType(type: JetFunctionType, data: StringBuilder?): Void? { - println("======================= function Type $type") - return super.visitFunctionType(type, data) - } - - protected fun accept(child: PsiElement?, data: StringBuilder?): Unit { - if (child is JetElement) { - child.accept(this, data) - } else { - if (child is PsiComment || child is PsiWhiteSpace) { - // ignore - } else { - println("------- Child $child of type ${child?.javaClass}") - } - child?.accept(this) - } - } - - protected fun acceptChildren(element: PsiElement, data: StringBuilder?): Unit { - for (child in element.getChildren()) { - accept(child, data) - } - } -} diff --git a/libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/highlighter/SyntaxHighlighter.kt b/libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/highlighter/SyntaxHighlighter.kt deleted file mode 100644 index 583ecc6d45f..00000000000 --- a/libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/highlighter/SyntaxHighlighter.kt +++ /dev/null @@ -1,131 +0,0 @@ -package org.jetbrains.kotlin.doc.highlighter - -import java.util.HashMap -import kotlin.template.HtmlFormatter -import com.intellij.psi.* -import com.intellij.psi.tree.IElementType -import com.intellij.psi.tree.TokenSet -import org.jetbrains.kotlin.lexer.* - -fun main(args: Array) { - val tool = SyntaxHighlighter() - val answer = tool.highlight(""" val x = listOf(1, 2, 3) - println("hello")""") - println(answer) -} - -/** - * Syntax highlights Kotlin code - */ -class SyntaxHighlighter() { - var formatter: HtmlFormatter = HtmlFormatter() - val styleMap = createStyleMap() - - /** Highlights the given kotlin code as HTML */ - fun highlight(code: String): String { - try { - val builder = StringBuilder() - builder.append( - "
" + - "
" + - "
" - ) - - // lets add the leading whitespace first - var idx = 0 - while (Character.isWhitespace(code[idx])) { - idx++ - } - if (idx > 0) { - val space = code.substring(0, idx) - builder.append("""$space""") - } - val lexer = JetLexer() - lexer.start(code) - while (true) { - lexer.advance() - val token = lexer.getTokenType() - if (token == null) break - val tokenText = lexer.getTokenSequence().toString().replace("\n", "\r\n") - var style: String? = null - if (token is JetKeywordToken) { - style = "keyword" - } else if (token == JetTokens.IDENTIFIER) { - for (softKeyword in JetTokens.SOFT_KEYWORDS.getTypes()) { - if (softKeyword is JetKeywordToken) { - if (softKeyword.getValue() == tokenText) { - style = "softkeyword" - break - } - } - } - style = if (style == null) "plain" else style - } else if (styleMap.containsKey(token)) { - style = styleMap.get(token) - if (style == null) { - println("Warning: No style for token $token") - } - } else { - style = "plain" - } - builder.append("""""") - formatter.format(builder, tokenText) - builder.append("") - } - - builder.append("
") - builder.append("
") - builder.append("
") - return builder.toString() - } catch (e: Exception) { - println("Warning: failed to parse code $e") - val builder = StringBuilder() - builder.append("""
Jet highlighter error ["${e.javaClass.getSimpleName()}"]: """) - formatter.format(builder, e.getMessage()) - builder.append("
") - builder.append("Original text:") - builder.append("
")
-            formatter.format(builder, code)
-            builder.append("
") - builder.append("
") - return builder.toString() - } - } - - - protected fun createStyleMap(): Map { - val styleMap = HashMap() - - fun putAll(tokenSet: TokenSet?, style: String): Unit { - if (tokenSet != null) { - for (token in tokenSet.getTypes()) { - styleMap.put(token, style) - } - } - } - - styleMap.put(JetTokens.BLOCK_COMMENT, "jet-comment") - styleMap.put(JetTokens.DOC_COMMENT, "jet-comment") - styleMap.put(JetTokens.EOL_COMMENT, "jet-comment") - styleMap.put(JetTokens.WHITE_SPACE, "whitespace") - styleMap.put(JetTokens.INTEGER_LITERAL, "number") - styleMap.put(JetTokens.FLOAT_LITERAL, "number") - styleMap.put(JetTokens.OPEN_QUOTE, "string") - styleMap.put(JetTokens.REGULAR_STRING_PART, "string") - styleMap.put(JetTokens.ESCAPE_SEQUENCE, "escape") - styleMap.put(JetTokens.LONG_TEMPLATE_ENTRY_START, "escape") - styleMap.put(JetTokens.LONG_TEMPLATE_ENTRY_END, "escape") - styleMap.put(JetTokens.SHORT_TEMPLATE_ENTRY_START, "escape") - styleMap.put(JetTokens.ESCAPE_SEQUENCE, "escape") - styleMap.put(JetTokens.CLOSING_QUOTE, "string") - styleMap.put(JetTokens.CHARACTER_LITERAL, "string") - styleMap.put(JetTokens.FIELD_IDENTIFIER, "field") - styleMap.put(TokenType.BAD_CHARACTER, "bad") - putAll(JetTokens.STRINGS, "string") - putAll(JetTokens.MODIFIER_KEYWORDS, "softkeyword") - putAll(JetTokens.SOFT_KEYWORDS, "softkeyword") - putAll(JetTokens.COMMENTS, "jet-comment") - putAll(JetTokens.OPERATIONS, "operation") - return styleMap - } -} diff --git a/libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/highlighter2/Html2CompilerPlugin.kt b/libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/highlighter2/Html2CompilerPlugin.kt deleted file mode 100644 index b4c5897db97..00000000000 --- a/libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/highlighter2/Html2CompilerPlugin.kt +++ /dev/null @@ -1,128 +0,0 @@ -package org.jetbrains.kotlin.doc.highlighter2 - -import java.io.File -import com.intellij.openapi.vfs.local.CoreLocalVirtualFile -import com.intellij.psi.PsiElement -import com.intellij.psi.PsiFile -import com.intellij.psi.impl.source.tree.LeafPsiElement -import org.jetbrains.kotlin.lexer.JetTokens -import org.jetbrains.kotlin.doc.* -import org.jetbrains.kotlin.doc.model.KModel -import org.jetbrains.kotlin.doc.model.SourceInfo -import org.jetbrains.kotlin.template.HtmlTemplate -import org.jetbrains.kotlin.template.escapeHtml - -class Html2CompilerPlugin(private val compilerArguments: KDocArguments) : Doclet { - - private val docOutputRoot: File - init { - val docOutputDir = compilerArguments.docConfig.docOutputDir - if (docOutputDir.isEmpty()) { - throw IllegalArgumentException("empty doc output dir") - } - docOutputRoot = File(docOutputDir) - } - - private val srcOutputRoot = File(docOutputRoot, names.htmlSourceDirName) - - private val sourceDirs: List = - compilerArguments.freeArgs.orEmpty().map { path -> File(path).getCanonicalFile() } - - private val sourceDirPaths: List = sourceDirs.map { d -> d.getPath() } - - private fun fileToWrite(psiFile: PsiFile): String { - val file = File((psiFile.getVirtualFile() as CoreLocalVirtualFile).getPath()!!).getCanonicalFile() - val filePath = file.getPath() - for (sourceDirPath in sourceDirPaths) { - if (filePath.startsWith(sourceDirPath) && filePath.length() > sourceDirPath.length()) { - val relativePath = filePath.substring(sourceDirPath.length() + 1) - return relativePath - } - } - throw Exception("$file is not a child of any source roots $sourceDirPaths") - } - - override fun generate(model: KModel, outputDir: File) { - srcOutputRoot.mkdirs() - - val css = javaClass().getClassLoader()!!.getResourceAsStream( - "org/jetbrains/kotlin/doc/highlighter2/hightlight.css")!! - - File(srcOutputRoot, "highlight.css").write { outputStream -> css.copyTo(outputStream) } - - for (sourceInfo in model.sourcesInfo) { - processFile(sourceInfo) - } - } - - private fun processFile(sourceInfo: SourceInfo) { - val psiFile = sourceInfo.psi - val htmlPath = sourceInfo.htmlPath - val htmlFile = File(srcOutputRoot, htmlPath) - - println("Generating $htmlFile") - htmlFile.getParentFile()!!.mkdirs() - - // see http://maven.apache.org/jxr/xref/index.html - - val template = object : HtmlTemplate() { - override fun render() { - html { - head { - title("${psiFile.getName()} xref") - linkCssStylesheet("highlight.css") - } - body { - table(style = "white-space: pre; font-size: 10pt; font-family: Monaco, monospace") { - tr { - td(style = "margin-right: 1.5em; text-align: right") { - val text = psiFile.getText()!! - val lineCount = - text.count { c -> c == '\n' } + (if (text.endsWith('\n')) 0 else 1) - - for (i in 1..lineCount) { - val label = "$i" - a(name = "$label", href = "#$label") { - print(i) - } - println() - } - } - - td { - fun classForPsi(psi: PsiElement): String? = when (psi) { - is LeafPsiElement -> { - val elementType = psi.getElementType() - if (elementType == JetTokens.WHITE_SPACE) - null - else if (elementType == JetTokens.DOC_COMMENT) - "hl-comment" - else if (JetTokens.KEYWORDS.contains(elementType)) - "hl-keyword" - else - // TODO - elementType.toString() - } - // TODO - else -> psi.javaClass.getName() - } - - for (t in splitPsi(psiFile)) { - val text = t.first - val psi = t.second - span(className = classForPsi(psi)) { - print(text.escapeHtml()) - } - } - } - } - } - } - } - } - } - - template.renderTo(htmlFile) - } - -} diff --git a/libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/highlighter2/hightlight.css b/libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/highlighter2/hightlight.css deleted file mode 100644 index 760f6b180d0..00000000000 --- a/libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/highlighter2/hightlight.css +++ /dev/null @@ -1,7 +0,0 @@ -.hl-comment { - color: #808080; -} - -.hl-keyword { - color: #000080; -} diff --git a/libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/highlighter2/ioUtils.kt b/libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/highlighter2/ioUtils.kt deleted file mode 100644 index 9d371d72b1d..00000000000 --- a/libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/highlighter2/ioUtils.kt +++ /dev/null @@ -1,7 +0,0 @@ -package org.jetbrains.kotlin.doc.highlighter2 - -import java.io.File -import java.io.FileOutputStream - -fun File.write(callback: (FileOutputStream) -> Unit) = - FileOutputStream(this).use(callback) diff --git a/libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/highlighter2/psiUtils.kt b/libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/highlighter2/psiUtils.kt deleted file mode 100644 index 3c383357d45..00000000000 --- a/libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/highlighter2/psiUtils.kt +++ /dev/null @@ -1,40 +0,0 @@ -package org.jetbrains.kotlin.doc.highlighter2 - -import com.intellij.psi.PsiElement - -private fun PsiElement.getTextChildRelativeOffset() = - getTextRange()!!.getStartOffset() - getParent()!!.getTextRange()!!.getStartOffset() - -private fun PsiElement.getAllChildren(): List { - val r = arrayListOf() - var child = getFirstChild() - while (child != null) { - r.add(child!!) - child = child!!.getNextSibling() - } - return r -} - -private fun splitPsiImpl(psi: PsiElement, listBuilder: MutableList>) { - var lastPos = 0 - for (child in psi.getAllChildren()) { - if (child.getTextChildRelativeOffset() > lastPos) { - val text = psi.getText()!!.substring(lastPos, child.getTextChildRelativeOffset()) - listBuilder.add(Pair(text, psi)) - } - splitPsiImpl(child, listBuilder) - lastPos = child.getTextChildRelativeOffset() + child.getTextRange()!!.getLength() - } - if (lastPos < psi.getTextRange()!!.getLength()) { - val text = psi.getText()!!.substring(lastPos) - listBuilder.add(Pair(text, psi)) - } -} - -fun splitPsi(psi: PsiElement): List> { - val listBuilder = arrayListOf>() - splitPsiImpl(psi, listBuilder) - return listBuilder -} - - 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 deleted file mode 100644 index 123b2e242e7..00000000000 --- a/libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/model/KModelCompilerPlugin.kt +++ /dev/null @@ -1,24 +0,0 @@ -package org.jetbrains.kotlin.doc.model - -import java.io.File -import org.jetbrains.kotlin.cli.common.CompilerPlugin -import org.jetbrains.kotlin.cli.common.CompilerPluginContext -import org.jetbrains.kotlin.doc.KDocArguments - -/** Base class for any compiler plugin which needs to process a KModel */ -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() - val sourceDirs: List = arguments.freeArgs.orEmpty().map { path -> File(path) } - val model = KModel(bindingContext, arguments.apply(), sourceDirs, sources.requireNoNulls()) - - processModel(model) - } - - protected abstract fun processModel(model: KModel): Unit -} 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 deleted file mode 100644 index b03fb24ee93..00000000000 --- a/libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/model/KotlinModel.kt +++ /dev/null @@ -1,1185 +0,0 @@ -package org.jetbrains.kotlin.doc.model - -import java.io.File -import java.util.* -import com.intellij.openapi.vfs.local.CoreLocalVirtualFile -import com.intellij.psi.PsiDirectory -import com.intellij.psi.PsiElement -import com.intellij.psi.PsiFile -import com.intellij.psi.PsiFileSystemItem -import org.jetbrains.kotlin.descriptors.CallableDescriptor -import org.jetbrains.kotlin.descriptors.ClassDescriptor -import org.jetbrains.kotlin.descriptors.ClassKind -import org.jetbrains.kotlin.descriptors.DeclarationDescriptor -import org.jetbrains.kotlin.descriptors.ModuleDescriptor -import org.jetbrains.kotlin.descriptors.PropertyDescriptor -import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor -import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor -import org.jetbrains.kotlin.descriptors.Visibilities -import org.jetbrains.kotlin.diagnostics.DiagnosticUtils -import org.jetbrains.kotlin.diagnostics.DiagnosticUtils.LineAndColumn -import org.jetbrains.kotlin.psi.JetFile -import org.jetbrains.kotlin.resolve.BindingContext -import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils -import org.jetbrains.kotlin.resolve.scopes.JetScope -import org.jetbrains.kotlin.types.JetType -import org.jetbrains.kotlin.lexer.JetTokens -import org.jetbrains.kotlin.doc.* -import org.jetbrains.kotlin.doc.highlighter.SyntaxHighlighter -import org.jetbrains.kotlin.doc.templates.KDocTemplate -import org.pegdown.Extensions -import org.pegdown.LinkRenderer -import org.pegdown.LinkRenderer.Rendering -import org.pegdown.PegDownProcessor -import org.pegdown.ast.WikiLinkNode -import org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor - -/** -* Returns the collection of functions with duplicate function names filtered out -* so only the first one is included -*/ -fun filterDuplicateNames(functions: Collection): Collection { - var lastName = "" - return functions.filter{ - val name = it.name - val answer = name != lastName - lastName = name - answer - } -} - -fun containerName(descriptor: DeclarationDescriptor): String = qualifiedName(descriptor.getContainingDeclaration()) - -fun qualifiedName(descriptor: DeclarationDescriptor?): String { - if (descriptor == null || descriptor is ModuleDescriptor) { - return "" - } - else if (descriptor is PackageFragmentDescriptor) { - return descriptor.fqName.asString() - } - else { - val parent = containerName(descriptor) - var name = descriptor.getName().asString() - if (name.startsWith("<")) { - name = "" - } - val answer = if (parent.length() > 0) parent + "." + name else name - return if (answer.startsWith(".")) answer.substring(1) else answer - } -} - -fun warning(message: String) { - println("Warning: $message") -} - -fun info(message: String) { - // println("info: $message") -} - -// TODO for some reason the SortedMap causes kotlin to freak out a little :) -fun inheritedExtensionFunctions(functions: Collection): Map> { - //fun inheritedExtensionFunctions(functions: Collection): SortedMap> { - val map = extensionFunctions(functions) - // for each class, lets walk its base classes and add any other extension functions from base classes - val answer = TreeMap>() - for (klass in map.keySet()) { - val allFunctions = map.get(klass).orEmpty().toSortedSet() - answer.put(klass, allFunctions) - for (descendant in klass.descendants()) { - for (f in map.get(descendant).orEmpty()) { - // add the methods from the base class if we don't have a matching method - if (!allFunctions.any { it.name == f.name && it.parameterTypeText == f.parameterTypeText }) { - allFunctions.add(f) - } - } - } - } - return answer -} - -// TODO for some reason the SortedMap causes kotlin to freak out a little :) -fun inheritedExtensionProperties(properties: Collection): Map> { - val map = extensionProperties(properties) - // for each class, lets walk its base classes and add any other extension properties from base classes - val answer = TreeMap>() - for (klass in map.keySet()) { - val allProperties = map.get(klass).orEmpty().toSortedSet() - answer.put(klass, allProperties) - for (descendant in klass.descendants()) { - for (f in map.get(descendant).orEmpty()) { - // add the properties from the base class if we don't have a matching property - if (!allProperties.any { it.name == f.name }) { - allProperties.add(f) - } - } - } - } - return answer -} - - -// TODO for some reason the SortedMap causes kotlin to freak out a little :) -fun extensionFunctions(functions: Collection): Map> { - val map = TreeMap>() - functions.filter{ it.extensionClass != null }.groupByTo(map){ it.extensionClass!! } - return map -} - -// TODO for some reason the SortedMap causes kotlin to freak out a little :) -fun extensionProperties(properties: Collection): Map> { - val map = TreeMap>() - properties.filter{ it.extensionClass != null }.groupByTo(map){ it.extensionClass!! } - return map -} - -abstract class KClassOrPackage(model: KModel, descriptor: DeclarationDescriptor): KAnnotated(model, descriptor) { - open val functions = sortedSetOf() - open val properties = sortedSetOf() - - fun findProperty(name: String): KProperty? { - // TODO we should use a Map? - return properties.find{ it.name == name } - } - - fun findFunction(expression: String): KFunction? { - val idx = expression.indexOf('(') - val name = if (idx > 0) expression.substring(0, idx) else expression - val postfix = if (idx > 0) expression.substring(idx).removeSuffix("()") else "" - return functions.find{ it.name == name && it.parameterTypeText == postfix } - } -} - -// htmlPath does not include "html-src" prefix -class SourceInfo(val psi: JetFile, val relativePath: String, val htmlPath: String) - -class KModel(val context: BindingContext, val config: KDocConfig, val sourceDirs: List, val sources: List) { - val packageMap = sortedMapOf() - - val allPackages: Collection - get() = packageMap.values() - - /** Returns the packages that should be included in the report */ - val packages: Collection - get() = allPackages.filter { config.includePackage(it) } - - val classes: Collection - get() = packages.flatMap { it.classes } - - var markdownProcessor = PegDownProcessor(Extensions.ALL) - var highlighter = SyntaxHighlighter() - - val title: String - get() = config.title - - val version: String - get() = config.version - - private var _projectRootDir: String? = null - - /** - * File names we look for in a package directory for the overall description of a package for KDoc - */ - val packageDescriptionFiles = listOf("readme.md", "ReadMe.md, readme.html, ReadMe.html") - - private val readMeDirsScanned = HashSet() - - - - val sourcesInfo: List - init { - - val normalizedSourceDirs: List = - sourceDirs.map { file -> file.getCanonicalPath() } - - fun relativePath(psiFile: PsiFile): String { - val file = File((psiFile.getVirtualFile() as CoreLocalVirtualFile).getPath()!!).getCanonicalFile() - val filePath = file.getPath() - for (sourceDirPath in normalizedSourceDirs) { - if (filePath.startsWith(sourceDirPath) && filePath.length() > sourceDirPath.length()) { - return filePath.substring(sourceDirPath.length() + 1) - } - } - throw Exception("$file is not a child of any source roots $normalizedSourceDirs") - } - - sourcesInfo = sources.map { source -> - val relativePath = relativePath(source) - val htmlPath = relativePath.replaceFirst("\\.kt$".toRegex(), "") + ".html" - SourceInfo(source, relativePath, htmlPath) - } - } - - private val sourceInfoByFile = sourcesInfo.toHashMapMappingToKey { sourceInfo -> sourceInfo.psi } - - fun sourceInfoByFile(file: JetFile) = sourceInfoByFile.get(file)!! - - - init { - /** Loads the model from the given set of source files */ - val allPackageFragments = HashSet() - for (source in sources) { - // We retrieve a descriptor by a PSI element from the context - val packageFragment = context.get(BindingContext.FILE_TO_PACKAGE_FRAGMENT, source) - if (packageFragment != null) { - allPackageFragments.add(packageFragment); - } else { - warning("No PackageFragmentDescriptor for source $source") - } - } - - for ((name, packageFragments) in allPackageFragments.groupBy { qualifiedName(it) }) { - createPackage(packageFragments, name) - - for (packageFragment in packageFragments) { - for (descriptor in packageFragment.getMemberScope().getAllDescriptors()) { - if (descriptor is ClassDescriptor) { - getClass(descriptor) - } - } - } - } - } - - - - - /** - * 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) - - /** Returns the package for the given descriptor, creating one if its not available */ - fun getOrCreatePackage(descriptor: PackageFragmentDescriptor): KPackage { - val name = qualifiedName(descriptor) - - val pkg = packageMap[name] - if (pkg != null) return pkg - - return createPackage(listOf(descriptor), name) - } - - private fun createPackage(descriptors: List, name: String): KPackage { - val pkg = KPackage(this, descriptors, name, config.resolveLink(name, false).isNotEmpty()) - - assert(!packageMap.containsKey(name)) { "packageMap entry created earlier for package $name: old=${packageMap[name]}, new=$pkg" } - - packageMap[name] = pkg - - for (descriptor in descriptors) { - addFunctions(pkg, descriptor.getMemberScope()) - } - - // lets try find a custom doc - var file = config.packageDescriptionFiles[name] - loadWikiDescription(pkg, file) - - return pkg - } - - protected fun loadWikiDescription(pkg: KPackage, file: String?): Unit { - if (file != null) { - try { - pkg.wikiDescription = File(file).readText() - } catch (e: Throwable) { - warning("Failed to load package ${pkg.name} documentation file $file. Reason $e") - } - } - } - - /** - * If a package has no detailed description lets try load it from the descriptors - * source directory if we've not checked that directory before - */ - fun tryLoadReadMe(pkg: KPackage, descriptor: DeclarationDescriptor): Unit { - if (pkg.wikiDescription.isEmpty()) { - // lets try find the package.html or package.md file - val srcPath = pkg.model.filePath(descriptor) - if (srcPath != null) { - val srcFile = File(srcPath) - val dir = if (srcFile.isDirectory()) srcFile else srcFile.getParentFile() - if (dir != null && readMeDirsScanned.add(dir.getPath())) { - val f = packageDescriptionFiles.map{ File(dir, it) }.find{ it.exists() } - if (f != null) { - val file = f.getCanonicalPath() - loadWikiDescription(pkg, file) - } - else { - info("package ${pkg.name} has no ReadMe.(html|md) in $dir") - } - } - } - } - } - - fun wikiConvert(text: String, linkRenderer: LinkRenderer, fileName: String?): String { - return markdownProcessor.markdownToHtml(text, linkRenderer)!! - } - - fun sourceLinkFor(filePath: String, sourceLine: Int, lineLinkText: String = "#L"): String? { - val root = config.sourceRootHref - if (root != null) { - // lets remove the root project directory - val rootDir = projectRootDir() - val canonicalFile = File(filePath).getCanonicalPath() - //println("=========== root dir for filePath: $canonicalFile is $rootDir") - val relativeFile = - if (canonicalFile.startsWith(rootDir)) - canonicalFile.substring(rootDir.length()) - else - canonicalFile - val cleanRoot = root.removeSuffix("/") - val cleanPath = relativeFile.removePrefix("/") - return "$cleanRoot/$cleanPath$lineLinkText$sourceLine" - } - return null - } - - fun addFunctions(owner: KClassOrPackage, scope: JetScope): Unit { - try { - val descriptors = scope.getAllDescriptors() - for (descriptor in descriptors) { - if (descriptor is PropertyDescriptor) { - val name = descriptor.getName().asString() - val returnType = getType(descriptor.getReturnType()) - if (returnType != null) { - val receiver = descriptor.getExtensionReceiverParameter() - val extensionClass = if (receiver != null) { - getType(receiver.getType()) - } else null - - val property = KProperty(owner, descriptor, name, returnType, extensionClass?.klass) - owner.properties.add(property) - } - } else if (descriptor is CallableDescriptor) { - val function = createFunction(owner, descriptor) - if (function != null) { - owner.functions.add(function) - } - } - } - } catch (e: Throwable) { - warning("Caught exception finding function declarations on $owner $e") - e.printStackTrace() - } - - } - - protected fun createFunction(owner: KClassOrPackage, descriptor: CallableDescriptor): KFunction? { - val returnType = getType(descriptor.getReturnType()) - if (returnType != null) { - val name = descriptor.getName().asString() - val parameters = ArrayList() - val params = descriptor.getValueParameters() - for (param in params) { - val p = createParameter(param) - if (p != null) { - parameters.add(p) - } - } - val function = KFunction(descriptor, owner, name, returnType, parameters) - addTypeParameters(function.typeParameters, descriptor.getTypeParameters()) - configureComments(function, descriptor) - val receiver = descriptor.getExtensionReceiverParameter() - if (receiver != null) { - val receiverType = getType(receiver.getType()) - function.receiverType = receiverType - function.extensionClass = receiverType?.klass - } - return function - } - return null - } - - fun addTypeParameters(answer: MutableList, descriptors: List): Unit { - for (typeParam in descriptors) { - if (typeParam != null) { - val p = createTypeParameter(typeParam) - if (p != null){ - answer.add(p) - } - } - } - } - - protected fun createTypeParameter(descriptor: TypeParameterDescriptor): KTypeParameter? { - val name = descriptor.getName().asString() - val answer = KTypeParameter(name, descriptor, this) - configureComments(answer, descriptor) - return answer - } - - protected fun createParameter(descriptor: ValueParameterDescriptor): KParameter? { - val returnType = getType(descriptor.getReturnType()) - if (returnType != null) { - val name = descriptor.getName().asString() - val answer = KParameter(descriptor, name, returnType) - configureComments(answer, descriptor) - return answer - } - return null - } - - fun locationFor(descriptor: DeclarationDescriptor): LineAndColumn? { - val psiElement = getPsiElement(descriptor) - if (psiElement != null) { - val document = psiElement.getContainingFile()?.getViewProvider()?.getDocument() - if (document != null) { - val offset = psiElement.getTextOffset() - return DiagnosticUtils.offsetToLineAndColumn(document, offset) - } - } - return null - } - - fun fileFor(descriptor: DeclarationDescriptor): String? { - val psiElement = getPsiElement(descriptor) - return psiElement?.getContainingFile()?.getName() - } - - fun filePath(descriptor: DeclarationDescriptor): String? { - val psiElement = getPsiElement(descriptor) - val file = psiElement?.getContainingFile() - return filePath(file) - } - - - fun getPsiElement(descriptor: DeclarationDescriptor): PsiElement? { - return try { - DescriptorToSourceUtils.descriptorToDeclaration(descriptor) - } catch (e: Throwable) { - // ignore exceptions on fake descriptors - null - } - } - - protected fun commentsFor(descriptor: DeclarationDescriptor): String { - val psiElement = getPsiElement(descriptor) - - // This method is a hack. Doc comments should be easily accessible, but they aren't for now. - if (psiElement != null) { - var node = psiElement.getNode()?.getTreePrev() - while (node != null && (node?.getElementType() == JetTokens.WHITE_SPACE || node?.getElementType() == JetTokens.BLOCK_COMMENT)) { - node = node?.getTreePrev() - } - if (node == null) return "" - if (node?.getElementType() != JetTokens.DOC_COMMENT) return "" - var nodeText = node?.getText() ?: "" - // lets remove the comment tokens - val lines = nodeText.trim().split('\n') - // lets remove the /** ... * ... */ tokens - val buffer = StringBuilder() - val last = lines.size() - 1 - for (i in 0.rangeTo(last)) { - var text = lines[i] - text = text.trim() - if (i == 0) { - text = text.removePrefix("/**").removePrefix("/*") - } else { - buffer.append("\n") - } - if (i >= last) { - text = text.removeSuffix("*/") - } else if (i > 0) { - text = text.removePrefix("* ") - if (text == "*") text = "" - } - text = processMacros(text, psiElement) - buffer.append(text) - } - return buffer.toString() - } - return "" - } - - protected fun processMacros(textWithWhitespace: String, psiElement: PsiElement): String { - val text = textWithWhitespace.trim() - // lets check for javadoc style @ tags and macros - if (text.startsWith("@")) { - val remaining = text.substring(1) - val macro = "includeFunctionBody" - if (remaining.startsWith(macro)) { - val next = remaining.substring(macro.length()).trim() - val words = next.split("\\s".toRegex()) - // TODO we could default the test function name to match that of the - // source code function if folks adopted a convention of naming the test method after the - // method its acting as a demo/test for - if (words.size() > 1) { - val includeFile = words[0] - val fnName = words[1] - val content = findFunctionInclude(psiElement, includeFile, fnName) - if (content != null) { - return content - } else { - warning("could not find function $fnName in file $includeFile from source file ${psiElement.getContainingFile()}") - } - } - } else { - warning("Unknown kdoc macro @$remaining") - } - } - return textWithWhitespace - } - - protected fun findFunctionInclude(psiElement: PsiElement, includeFile: String, functionName: String): String? { - var dir = psiElement.getContainingFile()?.getParent() - if (dir != null) { - val file = relativeFile(dir!!, includeFile) - if (file != null) { - val text = file.getText() - if (text != null) { - // lets find the function definition - val regex = """fun\s+$functionName\(.*\)""".toRegex() - val matcher = regex.matcher(text) - if (matcher.find()) { - val idx = matcher.end() - val remaining = text.substring(idx) - val content = extractBlock(remaining) - if (content != null) { - val highlight = highlighter.highlight(content) - val filePath = filePath(file) - val sourceLine = text.substring(0, idx).count{ it == '\n'} + 1 - val link = if (filePath != null) sourceLinkFor(filePath, sourceLine) else null - return if (link != null) - """
-$highlight""" - else highlight - } - } - } - } - } - return null - } - - protected fun filePath(file: PsiFileSystemItem?): String? { - if (file != null) { - var dir = file.getParent() - if (dir != null) { - val parentName = filePath(dir) ?: "" - return parentName + "/" + file.getName() - } - } - return null - } - - /** - * Extracts the block of code within { .. } tokens or returning null if it can't be found - */ - protected fun extractBlock(text: String): String? { - val idx = text.indexOf('{') - if (idx >= 0) { - var remaining = text.substring(idx + 1) - // lets remove any leading blank lines - while (true) { - val nidx = remaining.indexOf('\n') - if (nidx >= 0) { - val line = remaining.substring(0, nidx).trim() - if (line.isEmpty()) { - remaining = remaining.substring(nidx + 1) - continue - } - } - break - } - var count = 1 - for (i in 0.rangeTo(remaining.length() - 1)) { - val ch = remaining[i] - if (ch == '{') count ++ - else if (ch == '}') { - if (--count <= 0) { - return remaining.substring(0, i) - } - } - } - warning("missing } in code block for $remaining") - return remaining - } - return null - } - - protected fun relativeFile(directory: PsiDirectory, relativeName: String): PsiFile? { - // TODO would have thought there's some helper function already to resolve relative names! - - var dir: PsiDirectory? = directory - - // lets try resolve the include name relative to this file - val paths = relativeName.split('/') - val size = paths.size() - for (i in 0.rangeTo(size - 2)) { - val path = paths[i] - if (path == ".") continue - else if (path == "..") dir = dir?.getParent() - else dir = dir?.findSubdirectory(path) - } - val name = paths[size - 1] - if (dir != null) { - val file = dir?.findFile(name) - if (file != null) { - return file - } else { - warning("could not find file $relativeName in $dir with name $name") - } - } - return null - } - - fun configureComments(annotated: KAnnotated, descriptor: DeclarationDescriptor): Unit { - val detailedText = commentsFor(descriptor).trim() - annotated.wikiDescription = detailedText - } - - fun getType(aType: JetType?): KType? { - if (aType != null) { - val classifierDescriptor = aType.getConstructor().getDeclarationDescriptor() - val klass = if (classifierDescriptor is ClassDescriptor) { - getClass(classifierDescriptor) - } else null - return KType(aType, this, klass) - } - return null - } - - /** - * Returns the [[KClass]] for the fully qualified name or null if it could not be found - */ - fun getClass(qualifiedName: String): KClass? { - // TODO warning this only works for top level classes - // a better algorithm is to walk down each dot path dealing with nested packages/classes - val idx = qualifiedName.lastIndexOf('.') - val pkgName = if (idx >= 0) qualifiedName.substring(0, idx) else "" - val pkg = getPackage(pkgName) - if (pkg != null) { - val simpleName = if (idx >= 0) qualifiedName.substring(idx + 1) else qualifiedName - return pkg.classMap.get(simpleName) - } - return null - } - - fun getClass(classElement: ClassDescriptor): KClass? { - val name = classElement.getName().asString() - var dec: DeclarationDescriptor? = classElement.getContainingDeclaration() - while (dec != null) { - val container = dec - if (container is PackageFragmentDescriptor) { - val pkg = getOrCreatePackage(container) - return pkg.getClass(classElement) - } else { - dec = dec?.getContainingDeclaration() - } - } - warning("no package found for class $name") - return null - } - - fun previous(pkg: KPackage): KPackage? { - // TODO - return null - } - - fun next(pkg: KPackage): KPackage? { - // TODO - return null - } -} - -class TemplateLinkRenderer(val annotated: KAnnotated, val template: KDocTemplate): LinkRenderer() { - // TODO dirty hack - remove when this issue is fixed - // http://youtrack.jetbrains.com/issue/KT-1524 - val hackedLinks = mapOf( - Pair("IllegalArgumentException", Pair("java.lang", "java/lang/IllegalArgumentException.html")), - Pair("IllegalStateException", Pair("java.lang", "java/lang/IllegalStateException.html")), - Pair("Map.Entry", Pair("java.util", "java/util/Map.Entry.html")), - Pair("System.in", Pair("java.lang", "java/lang/System.html#in")), - Pair("System.out", Pair("java.lang", "java/lang/System.html#in")), - Pair("#equals()", Pair("java.lang", "java/lang/Object.html#equals(java.lang.Object)")), - Pair("#hashCode()", Pair("java.lang", "java/lang/Object.html#hashCode()")) - ) - - override fun render(node: WikiLinkNode?): Rendering? { - val answer = super.render(node) - if (answer != null) { - val text = answer.text - if (text != null) { - val qualified = resolveToQualifiedName(text) - var href = resolveClassNameLink(qualified) - if (href != null) { - answer.href = href - } else { - // TODO really dirty hack alert!!! - // until the resolver is working, lets try adding a few prefixes :) - for (prefix in listOf("java.lang", "java.util", "java.util.concurrent", "java.util.regex", "java.io", - "kotlin", "java.awt", "java.awt.event", "java.sql", "java.beans", - "javax.swing", "javax.swing.event", - "org.w3c.dom", - "kotlin.template")) { - href = resolveClassNameLink(prefix + "." + qualified) - if (href != null) { - break - } - } - } - if (href == null) { - // TODO even hacker than the above hack! - val link = hackedLinks.get(text) - if (link != null) { - href = annotated.model.config.resolveLink(link.first) + link.second - } - } - if (href != null) { - answer.href = href - } else { - answer.href = "#NotImplementedYet" - warning("could not resolve expression: $qualified into a wiki link") - } - } - } - return answer - } - - /** - * Try to resolve a fully qualified class name as a link - */ - protected fun resolveClassNameLink(qualifiedName: String): String? { - val model = annotated.model - val pkg = model.getPackage(qualifiedName) - if (pkg != null) { - return template.href(pkg) - } - val klass = model.getClass(qualifiedName) - if (klass != null) { - return template.href(klass) - } else { - // is it a method? - val idx = qualifiedName.lastIndexOf('.') - if (idx > 0) { - val className = qualifiedName.substring(0, idx) - val c = model.getClass(className) - if (c != null) { - // lets try find method... - val remaining = qualifiedName.substring(idx + 1) - // lets try find the function - val fn = c.findFunction(remaining) - if (fn != null) { - return template.href(fn) - } - val p = c.findProperty(remaining) - if (p != null) { - return template.href(p) - } - } - } - return null - } - } - /** - * Attempts to resolve the class, method or property expression using the - * current imports and declaration - */ - protected fun resolveToQualifiedName(text: String): String { - // TODO use the CompletionContributors maybe to figure out what local names are imported??? - return text - /* - val scope = findWritableScope(annotated.declarationDescriptor) - if (scope != null) { - val classifierDescriptor = scope.getClassifier(text) - if (classifierDescriptor == null) { - val o = scope.getObjectDescriptor(text) - println("Attempt to resolve HREF: $text Found objectDescriptor $o") - } else { - println("Attempt to resolve HREF: $text Found classifierDescriptor $classifierDescriptor") - } - } - } - - protected fun findWritableScope(declarationDescriptor: DeclarationDescriptor) : WritableScopeImpl? { - val container = declarationDescriptor.getContainingDeclaration() - if (container is PackageFragmentDescriptor) { - val scope = container.getMemberScope() - if (scope is WritableScopeImpl) { - return scope - } - } else if (container != null) { - return findWritableScope(container) - } - return null - - */ - } -} - -abstract class KAnnotated(val model: KModel, val declarationDescriptor: DeclarationDescriptor) { - open var wikiDescription: String = "" - open var deprecated: Boolean = false - - open fun description(template: KDocTemplate): String { - val detailedText = detailedDescription(template) - val idx = detailedText.indexOf("

") - return if (idx > 0) { - detailedText.substring(0, idx).removePrefix("

") - } else { - detailedText - } - } - - fun detailedDescription(template: KDocTemplate): String { - val wiki = wikiDescription - return wikiConvert(wiki, template) - } - - protected fun wikiConvert(wiki: String, template: KDocTemplate): String { - val file = model.fileFor(declarationDescriptor) - return model.wikiConvert(wiki, TemplateLinkRenderer(this, template), file) - } - - fun isLinkToSourceRepo(): Boolean { - return model.config.sourceRootHref != null - } - - fun sourceTargetAttribute(): String { - return if (isLinkToSourceRepo()) " target=\"_top\" class=\"repoSourceCode\"" else "" - } - - fun sourceLink(): String { - val file = filePath() - if (file != null) { - val link = model.sourceLinkFor(file, sourceLine) - if (link != null) return link - } - return "" - } - - fun filePath(): String? = model.filePath(declarationDescriptor) - - fun location(): LineAndColumn? = model.locationFor(declarationDescriptor) - - val sourceLine: Int - get() { - val loc = location() - return if (loc != null) loc.getLine() else 1 - } -} - -abstract class KNamed(val name: String, model: KModel, descriptor: DeclarationDescriptor): KAnnotated(model, descriptor), Comparable { - override fun compareTo(other: KNamed): Int = name.compareTo(other.name) - - open fun equals(other: KPackage) = name == other.name - - override fun toString() = name -} - - -class KPackage( - model: KModel, - descriptors: List, - val name: String, - val useExternalLink: Boolean = false -): KClassOrPackage(model, descriptors.first()), Comparable { - val classMap = sortedMapOf() - - val classes: Collection - get() = classMap.values().filter{ it.isApi() } - - val annotations = arrayListOf() - - override fun compareTo(other: KPackage): Int = name.compareTo(other.name) - - fun equals(other: KPackage) = name == other.name - - override fun toString() = "KPackage($name)" - - fun getClass(descriptor: ClassDescriptor): KClass { - val name = descriptor.getName().asString() - var created = false - val klass = classMap.getOrPut(name) { - created = true - val psiFile = model.getPsiElement(descriptor)?.getContainingFile() - val jetFile = psiFile as? JetFile - val sourceInfo = if (jetFile != null) model.sourceInfoByFile(jetFile) else null - KClass(this, descriptor, sourceInfo) - } - if (created) { - // sometimes we may have source files for a package in different source directories - // such as the kotlin package in generated directory; so lets always check if we can find - // the readme - model.tryLoadReadMe(this, descriptor) - model.configureComments(klass, descriptor) - val typeConstructor = descriptor.getTypeConstructor() - val superTypes = typeConstructor.getSupertypes() - for (st in superTypes) { - val sc = model.getType(st) - if (sc != null) { - klass.baseClasses.add(sc) - } - } - val scope = descriptor.getDefaultType().getMemberScope() - model.addFunctions(klass, scope) - model.addTypeParameters(klass.typeParameters, typeConstructor.getParameters()) - } - return klass - } - - /** Returns the name as a directory using '/' instead of '.' */ - val nameAsPath: String - get() = if (name.length() == 0) "." else name.replace('.', '/') - - /** Returns a list of all the paths in the package name */ - val namePaths: List - get() { - val answer = ArrayList() - for (n in name.split('.')) { - answer.add(n) - } - return answer; - } - - /** Returns a relative path like ../.. for each path in the name */ - val nameAsRelativePath: String - get() { - val answer = namePaths.map{ ".." }.joinToString("/") - return if (answer.length() == 0) "" else answer + "/" - } - - override fun description(template: KDocTemplate): String { - // lets see if we can find a custom summary - val text = model.config.packageSummaryText[name] - return if (text != null) - wikiConvert(text, template).removePrefix("

").removeSuffix("

") - else - super.description(template) - } - - fun qualifiedName(simpleName: String): String { - return if (name.length() > 0) { - "${name}.${simpleName}" - } else { - simpleName - } - } - - fun previous(pkg: KClass): KClass? { - // TODO - return null - } - - fun next(pkg: KClass): KClass? { - // TODO - return null - } - - fun groupClassMap(): Map> { - return classes.groupByTo(TreeMap>()){it.group} - } - - fun packageFunctions() = functions.filter{ it.extensionClass == null } - - fun packageProperties() = properties.filter{ it.extensionClass == null && it.isPublic() } -} - -class KType(val jetType: JetType, model: KModel, val klass: KClass?, val arguments: MutableList = ArrayList()) -: KNamed(klass?.name ?: jetType.toString()!!, model, jetType.getConstructor().getDeclarationDescriptor()!!) { - init { - if (klass != null) { - this.wikiDescription = klass.wikiDescription - } - for (arg in jetType.getArguments()) { - val t = model.getType(arg.getType()) - if (t != null) { - arguments.add(t) - } - } - } - - override fun toString() = if (nullable) "$name?" else name - - val nullable: Boolean - get() = jetType.isMarkedNullable() -} - -class KClass( - val pkg: KPackage, - val descriptor: ClassDescriptor, - val sourceInfo: SourceInfo?) - : KClassOrPackage(pkg.model, descriptor), Comparable -{ - val simpleName = descriptor.getName().asString() - var group: String = "Other" - var annotations: List = listOf() - var typeParameters: MutableList = arrayListOf() - var since: String = "" - var authors: List = listOf() - var baseClasses: MutableList = arrayListOf() - var nestedClasses: List = listOf() - - override fun compareTo(other: KClass): Int = name.compareTo(other.name) - - fun equals(other: KClass) = name == other.name - - override fun toString() = "$kind($name)" - - fun isApi() = descriptor.getVisibility().isPublicAPI() - - val kind: String - get() { - val k = descriptor.getKind() - return if (k == ClassKind.INTERFACE) "interface" - else if (k == ClassKind.OBJECT) "object" - else if (k == ClassKind.ENUM_CLASS || k == ClassKind.ENUM_ENTRY) "enum" - else if (k == ClassKind.ANNOTATION_CLASS) "annotation" - else "class" - } - - val kindCode: String - get() { - val k = descriptor.getKind() - return if (k == ClassKind.INTERFACE) "interface" - else if (k == ClassKind.OBJECT) "object" - else if (k == ClassKind.ENUM_CLASS || k == ClassKind.ENUM_ENTRY) "enum class" - else if (k == ClassKind.ANNOTATION_CLASS) "class" - else "class" - } - - val visibility: String - get() { - val v = descriptor.getVisibility() - return if (v == Visibilities.PUBLIC) "public" - else if (v == Visibilities.PROTECTED) "protected" - else if (v == Visibilities.PRIVATE) "private" - else "" - } - - /** Link to the type which is relative if its a local type but could be a type in a different library or null if no link */ - var url: String? = null - get() { - if ($url == null) $url = "${nameAsPath}.html" - return $url - } - - val name: String = pkg.qualifiedName(descriptor.getName().asString()) - - val packageName: String = pkg.name - - /** Returns the name as a directory using '/' instead of '.' */ - val nameAsPath: String - get() = name.replace('.', '/') - - - fun isAnnotation() = kind == "annotation" - fun isInterface() = kind == "interface" - - /** Returns all of the base classes and all of their descendants */ - fun descendants(answer: MutableSet = LinkedHashSet()): Set { - for (b in baseClasses) { - val c = b.klass - if (c != null) { - answer.add(c) - c.descendants(answer) - } - } - return answer - } -} - -class KFunction(val descriptor: CallableDescriptor, val owner: KClassOrPackage, val name: String, - var returnType: KType, - var parameters: List, - var receiverType: KType? = null, - var extensionClass: KClass? = null, - var modifiers: List = listOf(), - var typeParameters: MutableList = arrayListOf(), - var exceptions: List = listOf(), - var annotations: List = listOf()): KAnnotated(owner.model, descriptor), Comparable { - - val parameterTypeText: String = parameters.map{ it.aType.name }.joinToString(", ") - - override fun compareTo(other: KFunction): Int { - var answer = name.compareTo(other.name) - if (answer == 0) { - answer = parameterTypeText.compareTo(other.parameterTypeText) - if (answer == 0) { - val ec1 = extensionClass?.name ?: "" - val ec2 = other.extensionClass?.name ?: "" - answer = ec1.compareTo(ec2) - } - } - return answer - } - - fun equals(other: KFunction) = name == other.name && this.parameterTypeText == other.parameterTypeText && - this.extensionClass == other.extensionClass && this.owner == other.owner - - override fun toString() = "fun $name($parameterTypeText): $returnType" - - val link: String = "$name($parameterTypeText)" - - /** Returns a list of generic type parameter names kinds like "A, I" */ - val typeParametersText: String - get() = typeParameters.map{ it.name }.joinToString(", ") -} - -class KProperty(val owner: KClassOrPackage, val descriptor: PropertyDescriptor, val name: String, - val returnType: KType, val extensionClass: KClass?): KAnnotated(owner.model, descriptor), Comparable { - - override fun compareTo(other: KProperty): Int = name.compareTo(other.name) - - val link = "$name" - - fun equals(other: KFunction) = name == other.name - - fun isVar(): Boolean = descriptor.isVar() - - fun kind(): String = if (isVar()) "var" else "val" - - fun isPublic(): Boolean { - val visibility = descriptor.getVisibility() - return visibility.isPublicAPI() - } - - override fun toString() = "property $name" -} - -class KParameter(val descriptor: ValueParameterDescriptor, val name: String, - var aType: KType): KAnnotated(aType.model, aType.declarationDescriptor) { - - override fun toString() = "$name: ${aType.name}" - - fun isVarArg(): Boolean = descriptor.getVarargElementType() != null - - fun hasDefaultValue(): Boolean = descriptor.hasDefaultValue() - - fun varArgType(): KType? { - val varType = descriptor.getVarargElementType() - return if (varType != null) { - aType.model.getType(varType) - } else null - } -} - -class KTypeParameter(val name: String, - val descriptor: TypeParameterDescriptor, - model: KModel, - var extends: List = listOf()): KAnnotated(model, descriptor) { - - override fun toString() = "$name" -} - -class KAnnotation(var klass: KClass): KAnnotated(klass.model, klass.descriptor) { - - // TODO add some parameter values? - - override fun toString() = "@${klass.simpleName}" -} diff --git a/libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/templates/AllClassesFrameTemplate.kt b/libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/templates/AllClassesFrameTemplate.kt deleted file mode 100644 index 0a932709321..00000000000 --- a/libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/templates/AllClassesFrameTemplate.kt +++ /dev/null @@ -1,40 +0,0 @@ -package org.jetbrains.kotlin.doc.templates - -import org.jetbrains.kotlin.doc.model.KModel - -class AllClassesFrameTemplate(val model: KModel, val classAttributes: String = "") : KDocTemplate() { - override fun render() { - println(""" - - - -$generatedComment - - -All Classes (${model.title}) - - - - - - - -All Classes -
- - - - - -
""") - for (c in model.classes) { - println("""${c.simpleName} -
""") - } - println("""
- - -""") - } -} diff --git a/libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/templates/ClassExtensionsTemplate.kt b/libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/templates/ClassExtensionsTemplate.kt deleted file mode 100644 index cb2f837b8c1..00000000000 --- a/libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/templates/ClassExtensionsTemplate.kt +++ /dev/null @@ -1,49 +0,0 @@ -package org.jetbrains.kotlin.doc.templates - -import java.util.* -import org.jetbrains.kotlin.doc.model.KClass -import org.jetbrains.kotlin.doc.model.KFunction -import org.jetbrains.kotlin.doc.model.KModel -import org.jetbrains.kotlin.doc.model.KPackage -import org.jetbrains.kotlin.doc.model.KProperty - -class ClassExtensionsTemplate(m: KModel, p: KPackage, k: KClass, - val functions: Collection, val properties: Collection) : ClassTemplate(m, p, k) { - - protected override fun relativePrefix(): String = "${pkg.nameAsRelativePath}${klass.pkg.nameAsRelativePath}" - - override fun pageTitle(): String = "${klass.name} Extensions fom ${pkg.name} (${model.title})" - - override fun printBody(): Unit { - println("""
- -

- -${pkg.name} -
-Extensions on ${klass.name}

-
-
-extension functions on class ${klass.name}
-from package ${link(pkg)} -
- - -

""") - printPropertySummary(properties) - printFunctionSummary(functions) - printFunctionDetail(functions) - println(""" -


-""") - } - - override fun href(f: KFunction): String { - return if (f.extensionClass != null) "#${f.link}" else super.href(f) - } - - override fun href(f: KProperty): String { - return if (f.extensionClass != null) "#${f.link}" else super.href(f) - } - -} diff --git a/libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/templates/ClassTemplate.kt b/libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/templates/ClassTemplate.kt deleted file mode 100644 index 309bdd75035..00000000000 --- a/libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/templates/ClassTemplate.kt +++ /dev/null @@ -1,257 +0,0 @@ -package org.jetbrains.kotlin.doc.templates - -import org.jetbrains.kotlin.doc.model.KClass -import org.jetbrains.kotlin.doc.model.KModel -import org.jetbrains.kotlin.doc.model.KPackage - -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() { - println(""" - - - -$generatedComment - - -${pageTitle()} - - - - -${stylesheets()} - - - - - - - -
- - - - - - - - - - - - -""") - - printPrevNextClass() - println(""" - - - - - -
- -
- - -""") - - printBody() - - println(""" - - - - - - - - - """) - printPrevNextClass() - println(""" - - - - - -
- -
- - - -
- Copyright © 2010-2012. All Rights Reserved. - - """) - } - - open fun printBody(): Unit { - println("""
- -

- -${pkg.name} -
-Class ${klass.simpleName}

-
""")
-
-        for (bc in klass.baseClasses) {
-            println(link(bc, true))
-        }
-        println("""  extended by ${klass.name}
-
-
-
-
""")
-        printAnnotations(klass.annotations)
-        print("""${klass.visibility} ${klass.kindCode} ${klass.simpleName}
""") - if (!klass.baseClasses.isEmpty()) { - print("""extends """) - for (bc in klass.baseClasses) { - println(link(bc)) - } - } - println("""
- - -

""") - println(klass.detailedDescription(this)) - if (klass.since.length() > 0 || klass.authors.size() > 0) { - println("""

-

""") - if (klass.since.length() > 0) { - println("""
Since:
-
${klass.since}
""") - } - for (author in klass.authors) { - println("""
Author:
-
${author}
""") - } - println("""
""") - } - - println("""
- -

""") - val nestedClasses = klass.nestedClasses - if (!nestedClasses.isEmpty()) { - println(""" - - - - - -""") - for (nc in nestedClasses) { - println(""" - -""") - } - println(""" -
-Nested Class Summary
-static class${klass.simpleName}.${nc.simpleName} -
-          ${nc.description(this)} -
- """) - } - - printPropertySummary(klass.properties) - printFunctionSummary(klass.functions) - printFunctionDetail(klass.functions) - - println(""" -


-""") - } - - open fun printPrevNextClass(): Unit { - println("""""") - val prev = pkg.previous(klass) - if (prev != null) { - println(""" PREV CLASS """) - - } - val next = pkg.next(klass) - if (next != null) { - println(""" NEXT CLASS""") - } - println("""""") - } - -} diff --git a/libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/templates/HelpDocTemplate.kt b/libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/templates/HelpDocTemplate.kt deleted file mode 100644 index ffdb40fa3c9..00000000000 --- a/libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/templates/HelpDocTemplate.kt +++ /dev/null @@ -1,232 +0,0 @@ -package org.jetbrains.kotlin.doc.templates - -import org.jetbrains.kotlin.doc.model.KModel - -class HelpDocTemplate(val model: KModel) : KDocTemplate() { - override fun render() { - println(""" - - - -$generatedComment - - -API Help (${model.title}) - - - - - - - - - - - - -
- - - - - - - - - - - - - - - -
- -
- - - -
-
-

-How This API Document Is Organized

-
-This API (Application Programming Interface) document has pages corresponding to the items in the navigation bar, described as follows.

-Overview

-
- -

-The Overview page is the front page of this API document and provides a list of all packages with a summary for each. This page can also contain an overall description of the set of packages.

-

-Package

-
- -

-Each package has a page that contains a list of its classes and interfaces, with a summary for each. This page can contain four categories:

    -
  • Interfaces (italic)
  • Classes
  • Enums
  • Exceptions
  • Errors
  • Annotation Types
-
-

-Class/Interface

-
- -

-Each class, interface, nested class and nested interface has its own separate page. Each of these pages has three sections consisting of a class/interface description, summary tables, and detailed member descriptions:

    -
  • Class inheritance diagram
  • Direct Subclasses
  • All Known Subinterfaces
  • All Known Implementing Classes
  • Class/interface declaration
  • Class/interface description -

    -

  • Nested Class Summary
  • Field Summary
  • Constructor Summary
  • Method Summary -

    -

  • Field Detail
  • Constructor Detail
  • Method Detail
-Each summary entry contains the first sentence from the detailed description for that item. The summary entries are alphabetical, while the detailed descriptions are in the order they appear in the source code. This preserves the logical groupings established by the programmer.
- -

-Annotation Type

-
- -

-Each annotation type has its own separate page with the following sections:

    -
  • Annotation Type declaration
  • Annotation Type description
  • Required Element Summary
  • Optional Element Summary
  • Element Detail
-
- -

-Enum

-
- -

-Each enum has its own separate page with the following sections:

    -
  • Enum declaration
  • Enum description
  • Enum Constant Summary
  • Enum Constant Detail
-
-

-Use

-
-Each documented package, class and interface has its own Use page. This page describes what packages, classes, methods, constructors and fields use any part of the given class or package. Given a class or interface A, its Use page includes subclasses of A, fields declared as A, methods that return A, and methods and constructors with parameters of type A. You can access this page by first going to the package, class or interface, then clicking on the "Use" link in the navigation bar.
-

-Tree (Class Hierarchy)

-
-There is a Class Hierarchy page for all packages, plus a hierarchy for each package. Each hierarchy page contains a list of classes and a list of interfaces. The classes are organized by inheritance structure starting with java.lang.Object. The interfaces do not inherit from java.lang.Object.
    -
  • When viewing the Overview page, clicking on "Tree" displays the hierarchy for all packages.
  • When viewing a particular package, class or interface page, clicking "Tree" displays the hierarchy for only that package.
-
-

-Deprecated API

-
-The Deprecated API page lists all of the API that have been deprecated. A deprecated API is not recommended for use, generally due to improvements, and a replacement API is usually given. Deprecated APIs may be removed in future implementations.
-

-Index

-
-The Index contains an alphabetic list of all classes, interfaces, constructors, methods, and fields.
-

-Prev/Next

-These links take you to the next or previous class, interface, package, or related page.

-Frames/No Frames

-These links show and hide the HTML frames. All pages are available with or without frames. -

-

-Serialized Form

-Each serializable or externalizable class has a description of its serialization fields and methods. This information is of interest to re-implementors, not to developers using the API. While there is no link in the navigation bar, you can get to this information by going to any serialized class and clicking "Serialized Form" in the "See also" section of the class description. -

-

-Constant Field Values

-The Constant Field Values page lists the static final fields and their values. -

- - -This help file applies to API documentation generated using the standard doclet. - -
-


- - - - - - - - - - - - - - - -
- -
- - - -
-Copyright © 2012. All Rights Reserved. - -""") - } -} diff --git a/libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/templates/IndexTemplate.kt b/libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/templates/IndexTemplate.kt deleted file mode 100644 index 982d577c897..00000000000 --- a/libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/templates/IndexTemplate.kt +++ /dev/null @@ -1,49 +0,0 @@ -package org.jetbrains.kotlin.doc.templates - -import org.jetbrains.kotlin.doc.model.KModel - -class IndexTemplate(val model: KModel) : KDocTemplate() { - override fun render() { - print(""" - - - -$generatedComment - - -${model.title} - - - - - - - - - - - -<H2> -Frame Alert</H2> - -<P> -This document is designed to be viewed using the frames feature. If you see this message, you are using a non-frame-capable web client. -<BR> -Link to<A HREF="overview-summary.html">Non-frame version.</A> - - - -""") - } -} diff --git a/libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/templates/KDocTemplate.kt b/libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/templates/KDocTemplate.kt deleted file mode 100644 index c12985a152a..00000000000 --- a/libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/templates/KDocTemplate.kt +++ /dev/null @@ -1,183 +0,0 @@ -package org.jetbrains.kotlin.doc.templates - -import org.jetbrains.kotlin.doc.* -import org.jetbrains.kotlin.doc.model.KAnnotation -import org.jetbrains.kotlin.doc.model.KClass -import org.jetbrains.kotlin.doc.model.KFunction -import org.jetbrains.kotlin.doc.model.KPackage -import org.jetbrains.kotlin.doc.model.KProperty -import org.jetbrains.kotlin.doc.model.KType -import org.jetbrains.kotlin.template.TextTemplate - -abstract class KDocTemplate() : TextTemplate() { - // TODO: use same timestamp for all pages - protected val generatedComment: String = "" - - open fun rootHref(pkg: KPackage): String { - return if (!pkg.useExternalLink) - relativePrefix() - else - pkg.model.config.resolveLink(pkg.name) - } - - open fun href(p: KPackage): String - = "${rootHref(p)}${p.nameAsPath}/package-summary.html" - - open fun href(c: KClass): String { - val postfix = if (!c.pkg.useExternalLink) "" else "?is-external=true" - return "${rootHref(c.pkg)}${c.nameAsPath}.html$postfix" - } - - open fun href(f: KFunction): String { - return if (f.owner is KClass) { - "${href(f.owner)}#${f.link}" - } else { - "package-summary.html#${f.link}" - } - } - - /** - * Generates a link to a package level property - */ - open fun href(pkg: KPackage, p: KProperty): String { - return "${href(pkg)}#${p.link}" - } - - open fun href(f: KProperty): String { - return if (f.owner is KClass) { - "${href(f.owner)}#${f.link}" - } else { - "package-summary.html#${f.link}" - } - } - - open fun extensionsHref(pkg: KPackage, c: KClass): String { - // is inside the pkg so no need to use it... - return "${c.nameAsPath}-extensions.html" - } - - open fun extensionsHref(pkg: KPackage, c: KClass, f: KFunction): String { - return "${extensionsHref(pkg, c)}#${f.link}" - } - - open fun extensionsHref(pkg: KPackage, c: KClass, f: KProperty): String { - return "${extensionsHref(pkg, c)}#${f.link}" - } - - open fun sourceHref(klass: KClass): String { - if (klass.isLinkToSourceRepo()) { - return klass.sourceLink() - } else { - val pkg = klass.pkg - return if (klass.sourceInfo != null) { - "${pkg.nameAsRelativePath}${names.htmlSourceDirName}/${klass.sourceInfo.htmlPath}.html#${names.lineNumberLinkHref(klass.sourceLine)}" - } else { - href(klass) - } - } - } - open fun sourceHref(f: KFunction): String { - if (f.isLinkToSourceRepo()) { - return f.sourceLink() - } else { - val owner = f.owner - return if (owner is KClass) { - val pkg = owner.pkg - if (owner.sourceInfo != null) { - "${rootHref(pkg)}${names.htmlSourceDirName}/${owner.sourceInfo.htmlPath}.html#${names.lineNumberLinkHref(f.sourceLine)}" - } else { - href(f) - } - } else if (owner is KPackage) { - if (!owner.useExternalLink) { - // TODO how to find the function in a package??? - "${rootHref(owner)}${names.htmlSourceDirName}/package.html#${names.lineNumberLinkHref(f.sourceLine)}" - } else { - href(owner) - } - } else href(f) - } - } - - open fun sourceHref(f: KProperty): String { - if (f.isLinkToSourceRepo()) { - return f.sourceLink() - } else { - val owner = f.owner - return if (owner is KClass) { - val pkg = owner.pkg - if (owner.sourceInfo != null) { - "${rootHref(pkg)}${names.htmlSourceDirName}/${owner.sourceInfo.htmlPath}#${names.lineNumberLinkHref(f.sourceLine)}" - } else { - href(f) - } - } else if (owner is KPackage) { - if (!owner.useExternalLink) { - // TODO how to find the function in a package??? - "${rootHref(owner)}${names.htmlSourceDirName}/package.html#${names.lineNumberLinkHref(f.sourceLine)}" - } else { - href(owner) - } - } else href(f) - } - } - - open fun link(c: KClass, fullName: Boolean = false): String { - val prefix = if (c.isAnnotation()) "@" else "" - val name = if (fullName) c.name else c.simpleName - return "$prefix$name" - } - - open fun link(t: KType, fullName: Boolean = false): String { - val c = t.klass - val arguments = t.arguments - return if (c != null) { - val prefix = if (c.isAnnotation()) "@" else "" - val cname = c.name - if (cname.startsWith("kotlin.Function") && arguments.isNotEmpty()) { - val rt = arguments.last() - // TODO use drop() - val rest = arguments.dropLast(1) - "${typeArguments(rest, "(", ")", "()")} -> ${link(rt)}" - } else { - val name = if (fullName) cname else c.simpleName - "$prefix$name${typeArguments(arguments)}" - } - } else { - "${t.name}${typeArguments(arguments)}" - } - } - - open fun typeArguments(arguments: List, prefix: String = "<", postfix: String = ">", empty: String = ""): String { - val text = arguments.map() { link(it) }.joinToString(", ") - return if (text.length() == 0) empty else "$prefix$text$postfix" - } - - open fun link(p: KPackage): String { - return "${p.name}" - } - - open fun link(a: KAnnotation): String { - val c = a.klass - return "@${c.simpleName}" - } - - fun searchBox(): String = -""" - - - """ - - - fun stylesheets(): String { - return """ - - - - - -""" - } - - protected open fun relativePrefix(): String = "" -} diff --git a/libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/templates/OverviewFrameTemplate.kt b/libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/templates/OverviewFrameTemplate.kt deleted file mode 100644 index c86fc969f51..00000000000 --- a/libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/templates/OverviewFrameTemplate.kt +++ /dev/null @@ -1,51 +0,0 @@ -package org.jetbrains.kotlin.doc.templates - -import org.jetbrains.kotlin.doc.model.KModel - -class OverviewFrameTemplate(val model: KModel) : KDocTemplate() { - override fun render() { - println(""" - - - -$generatedComment - - -Overview List (${model.title}) - - - - - - - - - - - - -
-
- - - - - -
All Classes -

- -Packages -
""") - for (p in model.packages) { - println("""${p.name} -
""") - } - println("""

- -

-  - - -""") - } -} diff --git a/libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/templates/OverviewSummaryTemplate.kt b/libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/templates/OverviewSummaryTemplate.kt deleted file mode 100644 index 1b103df6cda..00000000000 --- a/libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/templates/OverviewSummaryTemplate.kt +++ /dev/null @@ -1,168 +0,0 @@ -package org.jetbrains.kotlin.doc.templates - -import org.jetbrains.kotlin.doc.model.KModel - -class OverviewSummaryTemplate(val model: KModel) : KDocTemplate() { - override fun render() { - println(""" - - - -$generatedComment - - -Overview (${model.title}) - - - - -${stylesheets()} - - - - - - - -


- - - - - - - - - - - - - - - -
- -
- - - -
-
-

-${model.title} -

-
- - - - -""") - for (p in model.packages) { - println(""" - - -""") - } -println("""
-Packages
${p.name}${p.description(this)}
- -


- - - - - - - - - - - - - - - -
- -
- - - -
-Copyright © 2010-2012. All Rights Reserved. - -""") - } -} diff --git a/libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/templates/OverviewTreeTemplate.kt b/libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/templates/OverviewTreeTemplate.kt deleted file mode 100644 index f14a8efc117..00000000000 --- a/libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/templates/OverviewTreeTemplate.kt +++ /dev/null @@ -1,190 +0,0 @@ -package org.jetbrains.kotlin.doc.templates - -import org.jetbrains.kotlin.doc.model.KModel - -class OverviewTreeTemplate(val model: KModel) : KDocTemplate() { - override fun render() { - println(""" - - - -$generatedComment - - -Class Hierarchy (${model.title}) - - - - -${stylesheets()} - - - - - - - -
- - - - - - - - - - - - - - - -
- -
- - - -
-
-

-Hierarchy For All Packages

-
-
-
Package Hierarchies:
""") - - var first = true - for (p in model.packages) { - if (first) { - first = false - } else { - print(""", -${p.nameAsPath}""") - } - } - println("""
-
-

-Class Hierarchy -

""") - - // TODO walk the hierarchy... - /* -
    -
  • java.util.AbstractQueue<E> (implements java.util.Queue<E>) -
      -*/ - - println("""

      -Interface Hierarchy -

      """) - - // TODO - println("""

      -Annotation Type Hierarchy -

      """) - - // TODO - println("""

      -Enum Hierarchy -

      -
      - - - - - - - - - - - - - - - -
      - -
      - - - -
      -Copyright © 2010-2012. All Rights Reserved. - -""") - } -} diff --git a/libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/templates/PackageFrameTemplate.kt b/libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/templates/PackageFrameTemplate.kt deleted file mode 100644 index 96187cb1de8..00000000000 --- a/libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/templates/PackageFrameTemplate.kt +++ /dev/null @@ -1,118 +0,0 @@ -package org.jetbrains.kotlin.doc.templates - -import org.jetbrains.kotlin.doc.model.KModel -import org.jetbrains.kotlin.doc.model.KPackage -import org.jetbrains.kotlin.doc.model.extensionFunctions -import org.jetbrains.kotlin.doc.model.filterDuplicateNames - -class PackageFrameTemplate(val model: KModel, p: KPackage) : PackageTemplateSupport(p) { - override fun render() { - println(""" - - - -$generatedComment - - -${pkg.name} (${model.title}) - - - -${stylesheets()} - - - - - -${pkg.name}""") - - printClasses("trait", "Traits") - printClasses("class", "Classes") - printClasses("enum", "Enums") - printClasses("annotation", "Annotations") - printClasses("exception", "Exceptions") - printPackageProperties() - printFunctions() - printExtensionFunctions() - - println(""" -""") - } - - protected fun printClasses(kind: String, description: String): Unit { - val classes = pkg.classes.filter{ it.kind == kind } - if (! classes.isEmpty()) { - println(""" - - -
      """) - print(description) - println("""  - -
      """) - for (c in classes) { - val formatted = if (kind == "interface") "${c.simpleName}" else c.simpleName - println("""$formatted -
      """) - } - println("""
      """) - } - } - - protected fun printFunctions(): Unit { - val functions = filterDuplicateNames(pkg.packageFunctions()) - if (! functions.isEmpty()) { - println(""" - - -
      Functions  - -
      """) - - var lastName = "" - for (c in functions) { - // only show the first function with a given name - if (c.name != lastName) { - println("""${c.name} -
      """) - } - lastName = c.name - } - println("""
      """) - } - } - - protected fun printExtensionFunctions(): Unit { - val map = extensionFunctions(pkg.functions) - if (!map.isEmpty()) { - println(""" - - -
      Extensions  - -
      """) - for (e in map) { - val c = e.key - println("""${c.name} -
      """) - } - println("""
      """) - } - } - protected fun printPackageProperties(): Unit { - val list = pkg.packageProperties() - if (list.isNotEmpty()) { - println(""" - - -
      Properties  - -
      """) - for (c in list) { - println("""${c.name} -
      """) - } - println("""
      """) - } - } -} diff --git a/libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/templates/PackageListTemplate.kt b/libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/templates/PackageListTemplate.kt deleted file mode 100644 index 79455db4527..00000000000 --- a/libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/templates/PackageListTemplate.kt +++ /dev/null @@ -1,11 +0,0 @@ -package org.jetbrains.kotlin.doc.templates - -import org.jetbrains.kotlin.doc.model.KModel - -class PackageListTemplate(val model: KModel) : KDocTemplate() { - override fun render() { - for (p in model.packages) { - println(p.name) - } - } -} diff --git a/libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/templates/PackageSummaryTemplate.kt b/libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/templates/PackageSummaryTemplate.kt deleted file mode 100644 index a371aa78ee8..00000000000 --- a/libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/templates/PackageSummaryTemplate.kt +++ /dev/null @@ -1,304 +0,0 @@ -package org.jetbrains.kotlin.doc.templates - -import org.jetbrains.kotlin.doc.model.KModel -import org.jetbrains.kotlin.doc.model.KPackage -import org.jetbrains.kotlin.doc.model.filterDuplicateNames -import org.jetbrains.kotlin.doc.model.inheritedExtensionFunctions - -class PackageSummaryTemplate(val model: KModel, pkg: KPackage) : PackageTemplateSupport(pkg) { - override fun render() { - println(""" - - - -$generatedComment - - -${pkg.name} (${model.title}) - - - - -${stylesheets()} - - - - - - - -
      - - - - - - - - - - - -""") - - printNextPrevPackages() - println(""" - -
      - -
      - - - -
      -""") - - for (a in pkg.annotations) { - val url = a.url - if (url != null) { - println("""@${a.simpleName}""") - } - } - println("""

      -Package ${pkg.name} -

      -${pkg.description(this)} -

      -See: -
      -          Description -

      -""") - - printClasses("trait", "Traits") - printClasses("class", "Classes") - printClasses("enum", "Enums") - printClasses("annotation", "Annotations") - printClasses("exception", "Exceptions") - - printPropertySummary(pkg.packageProperties()) - printFunctionSummary(pkg.packageFunctions()) - - printExtensionFunctions() - - println("""

      -Package ${pkg.name} Description -

      - -

      -${pkg.detailedDescription(this)} - -

      Contents

      - -""") - - for ((group, list) in pkg.groupClassMap()) { - println("""

      $group

      - -
        """) - for (c in list) { - println("""
      • ${c.simpleName}""") - } - println(""" -
      """) - } - println("""

      """) - - printFunctionDetail(pkg.packageFunctions()) - - println(""" - -

      -

      -
      -
      - - - - - - - - - - - -""") - - printNextPrevPackages() - - println(""" - -
      - -
      - - - -
      -Copyright © 2010-2012. All Rights Reserved. - -""") - } - - - protected fun printClasses(kind: String, description: String): Unit { - val classes = pkg.classes.filter{ it.kind == kind } - if (! classes.isEmpty()) { - print(""" - - -""") - - for (c in classes) { - println(""" - - -""") - } - println("""
      -$description Summary
      ${c.simpleName}${c.description(this)}
      -  - -

      -""") - } - } - - // TODO delete - protected fun printFunctions(): Unit { - val functions = pkg.functions.filter{ it.extensionClass == null } - if (! functions.isEmpty()) { - print(""" - - -""") - - for (f in functions) { - println(""" - - -""") - } - println("""
      -Functions Summary
      ${f.name}${f.description(this)}
      -  - -

      -""") - } - } - - protected fun printExtensionFunctions(): Unit { - val map = inheritedExtensionFunctions(pkg.functions) - if (! map.isEmpty()) { - print(""" - - -""") - - for ((c, list) in map) { - println(""" - - -""") - } - println("""
      -Extensions Summary
      ${c.name}""") - for (f in filterDuplicateNames(list)) { - println("""${f.name} """) - } - println("""
      -  - -

      -""") - } - } - - - protected fun printNextPrevPackages(): Unit { - println("""""") - val prev = model.previous(pkg) - if (prev != null) { - println(""" PREV PACKAGE """) - } else { - println(""" PREV PACKAGE """ ) - } - val next = model.next(pkg) - if (next != null) { - println(""" NEXT PACKAGE""") - } else { - println(""" NEXT PACKAGE""" ) - } - println("""""") - - } -} diff --git a/libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/templates/PackageTemplateSupport.kt b/libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/templates/PackageTemplateSupport.kt deleted file mode 100644 index a9431c4df74..00000000000 --- a/libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/templates/PackageTemplateSupport.kt +++ /dev/null @@ -1,279 +0,0 @@ -package org.jetbrains.kotlin.doc.templates - -import java.util.* -import org.jetbrains.kotlin.doc.model.KAnnotation -import org.jetbrains.kotlin.doc.model.KFunction -import org.jetbrains.kotlin.doc.model.KPackage -import org.jetbrains.kotlin.doc.model.KProperty - -abstract class PackageTemplateSupport(open val pkg: KPackage) : KDocTemplate() { - - protected override fun relativePrefix(): String = pkg.nameAsRelativePath - - val funKeyword = keyword("fun") - val valKeyword = keyword("val") - val varKeyword = keyword("var") - - protected fun keyword(name: String): String = "$name" - - fun printFunctionSummary(functions: Collection): Unit { - if (functions.isNotEmpty()) { - println(""" - - - - - -""") - - for (f in functions) { - printFunctionSummary(f) - } - println("""
      -Function Summary
      -  -

      -""") - } - } - - - fun printFunctionSummary(function: KFunction): Unit { - val deprecated = if (function.deprecated) "Deprecated." else "" - print(""" - -""") - if (!function.typeParameters.isEmpty()) { - println(""" - - - -
      - """) - print("$funKeyword ") - printTypeParameters(function) - printReceiverType(function, "
      ") - println("""
      """) - } else { - print(funKeyword) - printReceiverType(function) - } - // print receiver type - println("""
      """) - print("""${function.name}""") - printParameters(function) - print(": ") - print(link(function.returnType)) - println("""""") - println("") - if (true) { - println("""
      """) - println("""${function.description(this)}""") - } else { - println("""
      """) - println("""          ${deprecated} ${function.detailedDescription(this)}""") - } - println("""""") - println("""""") - } - - - fun printReceiverType(function: KFunction, prefix: String = " ", postfix: String = "", none: String = ""): Unit { - val receiverType = function.receiverType - if (receiverType != null) { - print(prefix) - print(link(receiverType)) - print(postfix) - } else { - print(none) - } - } - - fun printFunctionDetail(functions: Collection): Unit { - if (functions.isNotEmpty()) { - println(""" - - - - - - - - -
      - Function Detail
      - """) - - for (f in functions) { - printFunctionDetail(f) - } - } - } - - fun printFunctionDetail(function: KFunction): Unit { - println("""

      """) - println("""""") - - println("""

      """) - println("""${function.name}

      """) - println("""
      """)
      -        println("""""")
      -        printAnnotations(function.annotations)
      -        print("""${function.modifiers.joinToString(" ")} $funKeyword""")
      -
      -        printTypeParameters(function, " ")
      -        printReceiverType(function, " ", ".", " ")
      -        print("""${function.name}""")
      -        printParameters(function)
      -        print(": ")
      -        print(link(function.returnType))
      -
      -        val exlist = function.exceptions
      -        var first = true
      -        if (!exlist.isEmpty()) {
      -            println("""                                throws """);
      -            for (ex in exlist) {
      -                if (first) first = false else print(", ")
      -                print(link(ex))
      -            }
      -        }
      -        println("""
      """) - - println(function.detailedDescription(this)) - /* TODO - println("""
      -
      Deprecated. TODO text -

      -

      Deprecated. -

      -

      -
      -
      Throws: -
      ${link(ex}
      Since:
      -
      ${since}
      -
      -
      -
      -*/ - println("""
      """) - } - - fun printPropertySummary(properties: Collection): Unit { - if (properties.isNotEmpty()) { - println(""" - - - - - -""") - - for (f in properties) { - printPropertySummary(f) - } - println("""
      -Property Summary
      -  -

      -""") - } - } - - fun printPropertySummary(property: KProperty): Unit { - val deprecated = if (property.deprecated) "Deprecated." else "" - print(""" - -""") - print(if (property.isVar()) varKeyword else valKeyword) - /* - if (!property.typeParameters.isEmpty()) { - println(""" - - - -
      - """) - printTypeParameters(property) - println("""
      """) - print(link(property.returnType)) - println("""
      """) - } else { - print(link(property.returnType)) - } - */ - println("""
      """) - print(""" -

      - - ${property.name}: """) - print(link(property.returnType)) - //printParameters(property) - println("""""") - println("""""") - println("""
      """) - println("""          ${deprecated} ${property.detailedDescription(this)} -
      """) - println("""""") - } - - fun printTypeParameters(method: KFunction, separator: String = ""): Unit { - val typeParameters = method.typeParameters - if (!typeParameters.isEmpty()) { - print(separator) - print("<") - var separator = "" - for (t in typeParameters) { - print(separator) - separator = ", " - print(t.name) - val elist = t.extends - if (!elist.isEmpty()) { - print(" extends ") - var esep = "" - for (e in elist) { - print(esep) - esep = " & " - print(link(e)) - } - } - } - print(">") - } - } - - fun printParameters(method: KFunction): Unit { - print("(") - var first = true - var defaultValue = false - for (p in method.parameters) { - if (!p.hasDefaultValue() && defaultValue) { - print("]") - defaultValue = false - } - if (first) first = false else print(", ") - if (p.hasDefaultValue() && !defaultValue) { - print(" [") - defaultValue = true - } - val pType = if (p.isVarArg()) { - print("vararg ") - p.varArgType()!! - } else { - p.aType - } - print("${p.name}: ") - print(link(pType)) - } - if (defaultValue) { - print("]") - } - print(")") - } - - - fun printAnnotations(annotations: Collection): Unit { - for (a in annotations) { - println(link(a)) - } - } -} diff --git a/libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/templates/SearchXmlTemplate.kt b/libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/templates/SearchXmlTemplate.kt deleted file mode 100644 index c26407fb981..00000000000 --- a/libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/templates/SearchXmlTemplate.kt +++ /dev/null @@ -1,64 +0,0 @@ -package org.jetbrains.kotlin.doc.templates - -import java.util.* -import org.jetbrains.kotlin.doc.model.* - -class SearchXmlTemplate(val model: KModel): KDocTemplate() { - - class Search(val name: String, val href: String, val kind: String) { - override fun toString() = "Search($name, $href, $kind)" - } - - override fun render() { - val map = TreeMap() - - fun add(name: String, href: String, kind: String): Unit { - val search = Search(name, href, kind) - if (!map.containsKey(name)) { - map.put(name, search) - } - } - - fun add(owner: KClass, c: KFunction, href: String): Unit { - add("${c.name}() [${owner.name}]", href, "fun") - } - - fun add(owner: KClass, c: KProperty, href: String): Unit { - add("${c.name} [${owner.name}]", href, c.kind()) - } - - for (c in model.classes) { - add("${c.simpleName} [${c.pkg.name}]", "${c.nameAsPath}.html", c.kind) - - c.functions.forEach { add(c, it, href(it)) } - c.properties.forEach { add(c, it, href(it)) } - } - - for (p in model.packages) { - val fmap = inheritedExtensionFunctions(p.functions) - val pmap = inheritedExtensionProperties(p.properties) - val classes = hashSetOf() - classes.addAll(fmap.keySet()) - classes.addAll(pmap.keySet()) - for (c in classes) { - val functions = fmap.get(c).orEmpty() - val properties = pmap.get(c).orEmpty() - - functions.forEach { add(c, it, p.nameAsPath + "/" + extensionsHref(p, c, it)) } - properties.forEach { add(c, it, p.nameAsPath + "/" + extensionsHref(p, c, it)) } - } - } - - println(""" -""") - for (s in map.values()) { - println(""" - ${s.href} - ${s.name} - ${s.kind} -""") - } - println("""""") - } - -} diff --git a/libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/template/HtmlTemplate.kt b/libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/template/HtmlTemplate.kt deleted file mode 100644 index 5039be00863..00000000000 --- a/libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/template/HtmlTemplate.kt +++ /dev/null @@ -1,84 +0,0 @@ -package org.jetbrains.kotlin.template - -abstract class HtmlTemplate() : TextTemplate() { - - fun tag( - tagName: String, - style: String? = null, - className: String? = null, - attributes: List> = listOf(), - content: () -> Unit) { - val allAttributes = arrayListOf>() - if (style != null) - allAttributes.add(Pair("style", style)) - if (className != null) - allAttributes.add(Pair("class", className)) - - allAttributes.addAll(attributes) - - print( - if (allAttributes.isEmpty()) { - "<$tagName>" - } - else { - // TODO: escape values - "<$tagName ${allAttributes.map { t -> "${t.first}='${t.second.escapeHtml()}'" }.joinToString(" ")}>" - } - ) - content() - print("") - } - - fun text(text: String) { - print(text.escapeHtml()) - } - - fun tag(tagName: String, content: String) = - tag(tagName) { - text(content) - } - - fun html(content: () -> Unit) { - println("") - tag(tagName = "html", content = content) - } - - fun head(content: () -> Unit) = - tag(tagName = "head", content = content) - - fun linkCssStylesheet(href: String) = - tag( - tagName = "link", - attributes = listOf(Pair("rel", "stylesheet"), Pair("type", "text/css"), Pair("href", href))) {} - - fun body(style: String? = null, className: String? = null, content: () -> Unit) = - tag(tagName = "body", style = style, className = className, content = content) - - fun table(style: String? = null, className: String? = null, content: () -> Unit) = - tag(tagName = "table", style = style, className = className, content = content) - - fun tr(style: String? = null, className: String? = null, content: () -> Unit) = - tag(tagName = "tr", style = style, className = className, content = content) - - fun td(style: String? = null, className: String? = null, content: () -> Unit) = - tag(tagName = "td", style = style, className = className, content = content) - - fun title(title: String) = - tag("title", title) - - fun div(style: String? = null, className: String? = null, content: () -> Unit) = - tag(tagName = "div", style = style, className = className, content = content) - - fun span(style: String? = null, className: String? = null, content: () -> Unit) = - tag(tagName = "span", style = style, className = className, content = content) - - fun a(href: String? = null, name: String? = null, content: () -> Unit) { - val attributes = arrayListOf>() - if (href != null) - attributes.add(Pair("href", href)) - if (name != null) - attributes.add(Pair("name", name)) - tag(tagName = "a", attributes = attributes, content = content) - } -} - diff --git a/libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/template/TemplateCore.kt b/libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/template/TemplateCore.kt deleted file mode 100644 index 17932fa54df..00000000000 --- a/libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/template/TemplateCore.kt +++ /dev/null @@ -1,111 +0,0 @@ -package org.jetbrains.kotlin.template - -import java.io.File -import java.io.FileWriter -import java.io.OutputStream -import java.io.OutputStreamWriter -import java.io.StringWriter -import java.io.Writer - -/** -* Represents a generic API to templates which should be usable -* in JavaScript in a browser or on the server side stand alone or in a web app etc. -* -* To make things easier to implement in JS this package won't refer to any java.io or servlet -* stuff -*/ -trait Template { - - /** Renders the template to the output printer */ - fun render(): Unit -} - -/** - * Represents the output of a template which is a stream of objects - * usually strings which then write to some underlying output stream - * such as a java.io.Writer on the server side. - * - * We abstract away java.io.* APIs here to make the JS implementation simpler - */ -trait Printer { - fun print(value: Any?): Unit - //fun print(text: String): Unit - -} - - -class NullPrinter() : Printer { - override fun print(value: Any?) { - throw UnsupportedOperationException("No Printer defined on the Template") - } -} - -/** - * Base class for template implementations to hold any helpful behaviour - */ -abstract class TemplateSupport : Template { -} - -val newline: String = System.getProperty("line.separator") ?: "\n" - -/** - * Base class for templates generating text output - * by printing values to some underlying Printer which - * will typically output to a String, File, stream etc. - */ -abstract class TextTemplate() : TemplateSupport(), Printer { - public var printer: Printer = NullPrinter() - - fun String.plus(): Unit { - printer.print(this) - } - - override fun print(value: Any?) = printer.print(value) - - fun println(value: Any?) { - print(value) - print(newline) - } - - fun println() = println("") - - fun renderToText(): String { - val buffer = StringWriter() - renderTo(buffer) - return buffer.toString() - } - - fun renderTo(writer: Writer): Unit { - this.printer = WriterPrinter(writer) - this.render() - } - - fun renderTo(os: OutputStream): Unit { - // TODO compiler error - //OutputStreamWriter(os).forEach{ renderTo(it) } - val s = OutputStreamWriter(os) - renderTo(s) - s.close() - } - - fun renderTo(file: File): Unit { - // TODO compiler error - //FileWriter(file).forEach{ s -> renderTo(s) } - val s = FileWriter(file) - renderTo(s) - s.close() - } -} - - - -/** - * A Printer implementation which uses a Writer - */ -class WriterPrinter(val writer: Writer) : Printer { - - override fun print(value: Any?) { - // TODO should be using a formatter to do the conversion - writer.write(value.toString()) - } -} diff --git a/libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/template/stringUtils.kt b/libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/template/stringUtils.kt deleted file mode 100644 index cb573f68dd7..00000000000 --- a/libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/template/stringUtils.kt +++ /dev/null @@ -1,8 +0,0 @@ -package org.jetbrains.kotlin.template - -fun String.escapeHtml() = - this - .replace("&", "&") - .replace("\"", """) - .replace("<", "<") - .replace(">", ">") diff --git a/libraries/tools/kdoc/src/test/kotlin/test/kotlin/kdoc/HtmlVisitorTest.kt b/libraries/tools/kdoc/src/test/kotlin/test/kotlin/kdoc/HtmlVisitorTest.kt deleted file mode 100644 index 9b471185321..00000000000 --- a/libraries/tools/kdoc/src/test/kotlin/test/kotlin/kdoc/HtmlVisitorTest.kt +++ /dev/null @@ -1,30 +0,0 @@ -package test.kotlin.kdoc - -import java.io.File -import kotlin.test.assertTrue -import org.jetbrains.kotlin.cli.jvm.K2JVMCompiler -import org.jetbrains.kotlin.doc.highlighter.HtmlCompilerPlugin -import org.junit.Test - -class HtmlVisitorTest { - Test fun generateHtmlFromSource() { - val src = "src/test/sample" - var dir = File(".") - if (!File(dir, src).exists()) { - dir = File("kdoc") - assertTrue(File(dir, src).exists(), "Cannot find file $src") - } - val srcDir = File(dir, src) - val outDir = File(dir, "target/htmldocs") - println("Generating source HTML to $outDir") - - val compiler = K2JVMCompiler() - compiler.getCompilerPlugins().add(HtmlCompilerPlugin()) - compiler.exec( - System.out, - "-kotlin-home", "../../../dist/kotlinc", - "-d", File(dir, "target/classes-htmldocs").toString(), - srcDir.toString() - ) - } -} diff --git a/libraries/tools/kdoc/src/test/kotlin/test/kotlin/kdoc/KDocSampleTest.kt b/libraries/tools/kdoc/src/test/kotlin/test/kotlin/kdoc/KDocSampleTest.kt deleted file mode 100644 index a3b8c8e7813..00000000000 --- a/libraries/tools/kdoc/src/test/kotlin/test/kotlin/kdoc/KDocSampleTest.kt +++ /dev/null @@ -1,50 +0,0 @@ -package test.kotlin.kdoc - -import java.io.File -import java.io.IOException -import org.jetbrains.kotlin.cli.common.ExitCode -import org.jetbrains.kotlin.doc.KDocCompiler -import org.junit.Assert -import org.junit.Test - -fun File.rmrf() { - val children = listFiles() - if (children != null) { - for (child in children) { - child.rmrf() - } - } - delete() - if (exists()) { - throw IOException("failed to delete $this") - } -} - -fun File.mkdirsProperly() { - mkdirs() - if (!exists()) - throw IOException("failed to crete directory $this") - if (!isDirectory()) { - throw IOException("cannot create directory $this because it exists and it is not a directory") - } -} - - -class KDocSampleTest { - @Test - fun generateKDocForSample() { - val compiler = KDocCompiler() - - val classesOutputDir = File("target/classes-sample") - classesOutputDir.rmrf() - classesOutputDir.mkdirsProperly() - - val exitCode = compiler.exec( - System.err, - "-kotlin-home", "../../../dist/kotlinc", - "-d", classesOutputDir.getPath(), - "src/test/sample" - ) - Assert.assertEquals(ExitCode.OK, exitCode) - } -} diff --git a/libraries/tools/kdoc/src/test/kotlin/test/kotlin/kdoc/KDocTest.kt b/libraries/tools/kdoc/src/test/kotlin/test/kotlin/kdoc/KDocTest.kt deleted file mode 100644 index cad5242fb84..00000000000 --- a/libraries/tools/kdoc/src/test/kotlin/test/kotlin/kdoc/KDocTest.kt +++ /dev/null @@ -1,33 +0,0 @@ -package test.kotlin.kdoc - -import java.io.File -import kotlin.test.assertTrue -import org.jetbrains.kotlin.cli.common.ExitCode -import org.jetbrains.kotlin.doc.KDocCompiler -import org.junit.Assert -import org.junit.Test - -class KDocTest { - Test fun generateKDocForStandardLibrary() { - var moduleName = "ApiDocsModule.kt" - var dir = "." - if (!File(moduleName).exists()) { - dir = "kdoc" - moduleName = dir + "/" + moduleName - assertTrue(File(moduleName).exists(), "Cannot find file $moduleName") - } - val outDir = File(dir, "target/apidocs") - println("Generating library KDocs to $outDir") - - val compiler = KDocCompiler() - val r = compiler.exec( - System.out, - "-kotlin-home", "../../../dist/kotlinc", - "-d", "target/classes-stdlib", - "-no-stdlib", - "-classpath", "../runtime/target/kotlin-runtime-0.1-SNAPSHOT.jar${File.pathSeparator}../../lib/junit-4.11.jar", - "../../stdlib/src", "../../kunit/src/main/kotlin", "../../kotlin-jdbc/src/main/kotlin" - ) - Assert.assertEquals(ExitCode.OK, r) - } -} diff --git a/libraries/tools/kdoc/src/test/kotlin/test/kotlin/psiUtilsTest.kt b/libraries/tools/kdoc/src/test/kotlin/test/kotlin/psiUtilsTest.kt deleted file mode 100644 index 8fe98f14ca2..00000000000 --- a/libraries/tools/kdoc/src/test/kotlin/test/kotlin/psiUtilsTest.kt +++ /dev/null @@ -1,58 +0,0 @@ -package test.kotlin - -import org.jetbrains.kotlin.cli.jvm.config.* -import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment -import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles -import org.jetbrains.kotlin.config.CompilerConfiguration -import com.intellij.openapi.Disposable -import com.intellij.openapi.util.Disposer -import com.intellij.openapi.vfs.CharsetToolkit -import com.intellij.psi.PsiFileFactory -import com.intellij.psi.impl.PsiFileFactoryImpl -import com.intellij.testFramework.LightVirtualFile -import org.jetbrains.kotlin.psi.JetFile -import org.jetbrains.kotlin.idea.JetLanguage -import org.jetbrains.kotlin.utils.PathUtil -import org.jetbrains.kotlin.doc.highlighter2.splitPsi -import org.junit.After -import org.junit.Assert -import org.junit.Before -import org.junit.Test - -class PsiUtilsTest { - - val rootDisposable = object : Disposable { - override fun dispose() { - } - } - - private var environment: KotlinCoreEnvironment? = null - - @Before - fun before() { - System.setProperty("java.awt.headless", "true") - - val configuration = CompilerConfiguration() - configuration.addJvmClasspathRoots(PathUtil.getJdkClassesRoots()) - environment = KotlinCoreEnvironment.createForTests(rootDisposable, configuration, EnvironmentConfigFiles.JVM_CONFIG_FILES) - } - - @After - fun after() { - Disposer.dispose(rootDisposable) - } - - private fun createFile(content: String): JetFile { - val virtualFile = LightVirtualFile("file.kt", JetLanguage.INSTANCE, content); - virtualFile.setCharset(CharsetToolkit.UTF8_CHARSET); - return (PsiFileFactory.getInstance(environment!!.project) as PsiFileFactoryImpl) - .trySetupPsiForFile(virtualFile, JetLanguage.INSTANCE, true, false) as JetFile - } - - @Test - fun splitPsi() { - val file = createFile("class Foo") - val items: List = splitPsi(file).map { t -> t.first } - Assert.assertEquals(listOf("class", " ", "Foo"), items) - } -} diff --git a/libraries/tools/kdoc/src/test/kotlin/test/kotlin/template/PegdownTest.kt b/libraries/tools/kdoc/src/test/kotlin/test/kotlin/template/PegdownTest.kt deleted file mode 100644 index f00af67f971..00000000000 --- a/libraries/tools/kdoc/src/test/kotlin/test/kotlin/template/PegdownTest.kt +++ /dev/null @@ -1,49 +0,0 @@ -package test.pegdown - -import junit.framework.TestCase -import org.pegdown.* -import org.pegdown.LinkRenderer.Rendering -import org.pegdown.ast.* - -class PegdownTest() : TestCase() { - var markdownProcessor = PegDownProcessor(Extensions.ALL) - var linkRenderer = CustomLinkRenderer() - - fun testPegDown() { - val markups = listOf( - "hello **there **", - "a [[WikiLink]] blah", - "a [[WikiLink someText]] blah", - "a [[SomeClass.property]] blah", - "a [[SomeClass.method()]] blah", - "a [Link](somewhere) blah") - - for (text in markups) { - val answer = markdownProcessor.markdownToHtml(text, linkRenderer)!! - println("$text = $answer") - } - } -} - - -class CustomLinkRenderer : LinkRenderer() { - override fun render(node: WikiLinkNode?): Rendering? { - println("LinkRenderer.render(WikiLinkNode): $node") - return super.render(node) - } - - override fun render(node: RefLinkNode?, url: String?, title: String?, text: String?): Rendering? { - println("LinkRenderer.render(RefLinkNode): $node url: $url title: $title text: $text") - return super.render(node, url, title, text) - } - - override fun render(node: AutoLinkNode?): Rendering? { - println("LinkRenderer.render(AutoLinkNode): $node") - return super.render(node) - } - - override fun render(node: ExpLinkNode?, text: String?): Rendering? { - println("LinkRenderer.render(ExpLinkNode): $node text: $text") - return super.render(node, text) - } -} diff --git a/libraries/tools/kdoc/src/test/kotlin/test/kotlin/template/TemplateCoreTest.kt b/libraries/tools/kdoc/src/test/kotlin/test/kotlin/template/TemplateCoreTest.kt deleted file mode 100644 index 2f519155ce1..00000000000 --- a/libraries/tools/kdoc/src/test/kotlin/test/kotlin/template/TemplateCoreTest.kt +++ /dev/null @@ -1,41 +0,0 @@ -package test.kotlin.template - -import java.util.* -import junit.framework.Assert.* -import junit.framework.TestCase -import org.jetbrains.kotlin.template.* - -class EmailTemplate(var name: String = "James", var time: Date = Date()) : TextTemplate() { - override fun render() { - print("Hello there $name and how are you? Today is $time. Kotlin rocks") - } -} - -class MoreDryTemplate(var name: String = "James", var time: Date = Date()) : TextTemplate() { - override fun render() { - +"Hey there $name and how are you? Today is $time. Kotlin rocks" - } -} - -class TemplateCoreTest() : TestCase() { - fun testDefaultValues() { - val text = EmailTemplate().renderToText() - assertTrue( - text.startsWith("Hello there James") - ) - } - - fun testDifferentValues() { - val text = EmailTemplate("Andrey").renderToText() - assertTrue( - text.startsWith("Hello there Andrey") - ) - } - - fun testMoreDryTemplate() { - val text = MoreDryTemplate("Alex").renderToText() - assertTrue( - text.startsWith("Hey there Alex") - ) - } -} \ No newline at end of file diff --git a/libraries/tools/kdoc/src/test/sample/Hello.kt b/libraries/tools/kdoc/src/test/sample/Hello.kt deleted file mode 100644 index 49f4a969152..00000000000 --- a/libraries/tools/kdoc/src/test/sample/Hello.kt +++ /dev/null @@ -1,8 +0,0 @@ -package sample - -/** A Comment */ -public class Person(val name: String, val city: String) { - override fun toString(): String = "Person($name, $city)" - - public fun hello(): String = "Hello $name" -}