diff --git a/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/KDoc.kt b/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/KDoc.kt index bd244dbd6a0..382faec2c26 100644 --- a/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/KDoc.kt +++ b/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/KDoc.kt @@ -2,50 +2,32 @@ package org.jetbrains.kotlin.doc import org.jetbrains.kotlin.doc.templates.* import org.jetbrains.kotlin.template.TextTemplate -import org.jetbrains.kotlin.model.KModel +import org.jetbrains.kotlin.model.* import java.io.File +import java.util.List +import java.util.HashSet +import java.util.Collection + +import com.intellij.psi.PsiElement import org.jetbrains.jet.lang.resolve.BindingContext import org.jetbrains.jet.compiler.CompilerPlugin -import java.util.List import org.jetbrains.jet.lang.psi.JetFile import org.jetbrains.jet.lang.descriptors.NamespaceDescriptor -import java.util.HashSet -import com.intellij.psi.PsiElement import org.jetbrains.jet.lexer.JetTokens import org.jetbrains.jet.lang.descriptors.ClassDescriptor -import org.jetbrains.kotlin.model.KMethod import org.jetbrains.jet.lang.descriptors.CallableDescriptor import org.jetbrains.jet.lang.types.JetType -import org.jetbrains.kotlin.model.KClass import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor import org.jetbrains.jet.lang.descriptors.ModuleDescriptor import org.jetbrains.jet.lang.resolve.java.JavaNamespaceDescriptor import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor -import org.jetbrains.kotlin.model.KParameter +import org.jetbrains.jet.lang.resolve.scopes.JetScope +import org.jetbrains.jet.lang.resolve.scopes.receivers.ExtensionReceiver class KDoc(val outputDir: File) : KDocSupport() { val model = KModel() - /** TODO compile errors so lets use Java for this bit for now... - override fun processFiles(context: BindingContext, files: List?) { - println("==== KDoc running! Generating to $outputDir") - if (context != null) { - val namespaces = HashSet() - if (files != null) { - for (source in files) { - if (source != null) { - val namespaceDescriptor = context.get(BindingContext.NAMESPACE, source) - if (namespaceDescriptor != null) { - namespaces.add(namespaceDescriptor) - } - } - } - } - } - } - */ - override fun addClass(namespace: NamespaceDescriptor?, classElement: ClassDescriptor?) { if (namespace != null && classElement != null) { val klass = getOrCreateClass(classElement) @@ -72,41 +54,64 @@ class KDoc(val outputDir: File) : KDocSupport() { val container = classElement.containingDeclaration val namespaceName = containerName(classElement) val pkg = model.getPackage(namespaceName) + pkg.initialise{ + if (container is NamespaceDescriptor) { + addFunctions(pkg, pkg.functions, container.getMemberScope()) + } + } val name = classElement.getName() if (name != null) { val klass = pkg.getClass(name) klass.initialise { + if (klass.pkg.description.length() == 0) { + klass.pkg.description = commentsFor(container) + } klass.description = commentsFor(classElement) - val descriptors = classElement.getDefaultType().getMemberScope().getAllDescriptors() - for (descriptor in descriptors) { - if (descriptor is CallableDescriptor) { - val method = createMethod(descriptor) - if (method != null) { - klass.methods.add(method) - } + val superTypes = classElement.getTypeConstructor().getSupertypes() + for (st in superTypes) { + val sc = getType(st) + if (sc != null) { + klass.baseClasses.add(sc) } } + addFunctions(klass, klass.functions, classElement.getDefaultType().getMemberScope()) } return klass } return null } - protected fun createMethod(descriptor: CallableDescriptor): KMethod? { + protected fun addFunctions(owner: KClassOrPackage, list: Collection, scope: JetScope): Unit { + val descriptors = scope.getAllDescriptors() + for (descriptor in descriptors) { + if (descriptor is CallableDescriptor) { + val function = createFunction(owner, descriptor) + if (function != null) { + list.add(function) + } + } + } + } + + protected fun createFunction(owner: KClassOrPackage, descriptor: CallableDescriptor): KFunction? { val returnType = getType(descriptor.getReturnType()) if (returnType != null) { - val method = KMethod(descriptor.getName() ?: "null", returnType) - method.description = commentsFor(descriptor) + val function = KFunction(owner, descriptor.getName() ?: "null", returnType) + function.description = commentsFor(descriptor) val params = descriptor.getValueParameters() for (param in params) { if (param != null) { val p = createParameter(param) if (p != null) { - method.parameters.add(p) + function.parameters.add(p) } } } - return method + val receiver = descriptor.getReceiverParameter() + if (receiver is ExtensionReceiver) { + function.extensionClass = getType(receiver.getType()) + } + return function } return null } diff --git a/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/templates/ClassTemplate.kt b/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/templates/ClassTemplate.kt index e157ad5cf09..9ad42bea492 100644 --- a/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/templates/ClassTemplate.kt +++ b/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/templates/ClassTemplate.kt @@ -8,7 +8,7 @@ import java.util.* import org.jetbrains.kotlin.model.KModel import org.jetbrains.kotlin.model.KPackage import org.jetbrains.kotlin.model.KClass -import org.jetbrains.kotlin.model.KMethod +import org.jetbrains.kotlin.model.KFunction import org.jetbrains.kotlin.model.KAnnotation class ClassTemplate(val model: KModel, pkg: KPackage, val klass: KClass) : PackageTemplateSupport(pkg) { @@ -110,9 +110,7 @@ DETAIL: FIELD | CONSTR | METHO println("Class ${klass.simpleName}") println("
")
 
-        // TODO base class...
-        val bc = klass.baseClass
-        if (bc != null) {
+        for (bc in klass.baseClasses) {
             println(link(bc, true))
         }
         println("  \"extended${klass.name}")
@@ -122,9 +120,11 @@ DETAIL: FIELD | CONSTR | METHO
         print("
")
         printAnnotations(klass.annotations)
         print("public class ${klass.simpleName}
") - if (bc != null) { + if (!klass.baseClasses.isEmpty()) { print("extends ") - println(link(bc)) + for (bc in klass.baseClasses) { + println(link(bc)) + } } println("") println("""
@@ -181,9 +181,7 @@ DETAIL: FIELD | CONSTR | METHO Method Summary """) - for (method in klass.methods) { - printMethodSummary(method) - } + printFunctionSummary(klass.functions) println("""   @@ -199,9 +197,7 @@ DETAIL: FIELD | CONSTR | METHO """) - for (method in klass.methods) { - printMethodDetail(method) - } + printFunctionDetail(klass.functions) println("""
@@ -283,115 +279,4 @@ Copyright © 2010-2012. All Rights Reserved. println("""""") } - fun printMethodSummary(method: KMethod): Unit { - val deprecated = if (method.deprecated) "Deprecated." else "" - print(""" - -""") - if (!method.typeParameters.isEmpty()) { - println(""" - - - -
- """) - printTypeParameters(method) - println("
") - print(link(method.returnType)) - println("""
""") - } else { - print(link(method.returnType)) - } - println("
") - print("
${method.name}") - printParameters(method) - println("") - println("") - println("
") - println("          ${deprecated} ${method.detailedDescription}") - println("") - } - - - fun printMethodDetail(method: KMethod): Unit { - println("

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

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

-

Deprecated. -

-

-
-
Throws: -
${link(ex}
Since:
-
${since}
-
-
-
-*/ - println("
") - } - - fun printTypeParameters(method: KMethod): Unit { - val typeParameters = method.typeParameters - if (!typeParameters.isEmpty()) { - 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: KMethod): Unit { - print("(") - var first = true - for (p in method.parameters) { - if (first) first = false else print(", ") - print("${p.name}: ") - print(link(p.klass)) - } - print(")") - } - - fun printAnnotations(annotations: Collection): Unit { - for (a in annotations) { - println(link(a)) - } - } } diff --git a/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/templates/HelperMethods.kt b/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/templates/KDocTemplate.kt similarity index 67% rename from kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/templates/HelperMethods.kt rename to kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/templates/KDocTemplate.kt index e607137f5ac..f5a875e97d4 100644 --- a/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/templates/HelperMethods.kt +++ b/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/templates/KDocTemplate.kt @@ -4,6 +4,8 @@ import org.jetbrains.kotlin.model.KClass import org.jetbrains.kotlin.model.KAnnotation import org.jetbrains.kotlin.model.KPackage import org.jetbrains.kotlin.template.TextTemplate +import org.jetbrains.kotlin.model.KFunction +import java.util.Collection abstract class KDocTemplate() : TextTemplate() { fun href(pkg: KPackage): String { @@ -18,6 +20,24 @@ abstract class KDocTemplate() : TextTemplate() { return "${href(c.pkg)}${c.nameAsPath}.html$postfix" } + fun href(f: KFunction): String { + return if (f.owner is KClass) { + "${href(f.owner)}#${f.link}" + } else { + // TODO how to find the function in a package??? + "" + } + } + + fun sourceHref(f: KFunction): String { + return if (f.owner is KClass) { + "${href(f.owner.pkg)}src-html/${f.owner.simpleName}.html#line.${f.sourceLine}" + } else { + // TODO how to find the function in a package??? + "" + } + } + fun link(c: KClass, fullName: Boolean = false): String { // TODO if a class is a generic type parameter, just return the name... val prefix = if (c.isAnnotation()) "@" else "" @@ -32,13 +52,3 @@ abstract class KDocTemplate() : TextTemplate() { protected open fun relativePrefix(): String = "" } - -abstract class PackageTemplateSupport(private val _pkg: KPackage) : KDocTemplate() { - - // TODO this verbosity is to work around this bug: http://youtrack.jetbrains.com/issue/KT-1398 - public val pkg: KPackage - get() = _pkg - - protected override fun relativePrefix(): String = pkg.nameAsRelativePath - -} \ No newline at end of file diff --git a/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/templates/PackageFrameTemplate.kt b/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/templates/PackageFrameTemplate.kt index 84450b5504d..1e930cc2031 100644 --- a/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/templates/PackageFrameTemplate.kt +++ b/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/templates/PackageFrameTemplate.kt @@ -7,6 +7,9 @@ import std.util.* import java.util.* import org.jetbrains.kotlin.model.KModel import org.jetbrains.kotlin.model.KPackage +import org.jetbrains.kotlin.model.KClass +import org.jetbrains.kotlin.model.KFunction +import org.jetbrains.kotlin.model.extensionFunctions class PackageFrameTemplate(val model: KModel, p: KPackage) : PackageTemplateSupport(p) { override fun render() { @@ -22,8 +25,8 @@ class PackageFrameTemplate(val model: KModel, p: KPackage) : PackageTemplateSupp println(""" """) -println("") -println(""" + println("") + println(""" @@ -35,6 +38,8 @@ println(""" printClasses("enum", "Enums") printClasses("annotation", "Annotations") printClasses("exception", "Exceptions") + printFunctions() + printExtensionFunctions() println(""" """) @@ -58,6 +63,42 @@ println(""" println(""" """) } + } + protected fun printFunctions(): Unit { + val functions = pkg.functions.filter{ it.extensionClass == null } + if (! functions.isEmpty()) { + println(""" + + +
Functions  + +
""") + for (c in functions) { + println("${c.name}") + println("
") + } + println("""
""") + } + } + + protected fun printExtensionFunctions(): Unit { + val map = extensionFunctions(pkg.functions) + if (! map.isEmpty()) { + println(""" + + +
Extensions  + +
""") + for (e in map.entrySet()) { + val c = e?.getKey() + if (c != null) { + println("${c.name}") + println("
") + } + } + println("""
""") + } } } diff --git a/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/templates/PackageSummaryTemplate.kt b/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/templates/PackageSummaryTemplate.kt index 91e537c8b3f..e400eb07a61 100644 --- a/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/templates/PackageSummaryTemplate.kt +++ b/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/templates/PackageSummaryTemplate.kt @@ -8,6 +8,7 @@ import java.util.* import org.jetbrains.kotlin.model.KModel import org.jetbrains.kotlin.model.KPackage import org.jetbrains.kotlin.model.KClass +import org.jetbrains.kotlin.model.extensionFunctions class PackageSummaryTemplate(val model: KModel, pkg: KPackage) : PackageTemplateSupport(pkg) { override fun render() { @@ -120,6 +121,9 @@ function windowTitle() printClasses("annotation", "Annotations") printClasses("exception", "Exceptions") + printFunctions() + printExtensionFunctions() + println("""

""") println("Package ${pkg.name} Description") println("""

@@ -237,9 +241,58 @@ Copyright © 2010-2012. All Rights Reserved.

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

+""") + } + } + + protected fun printExtensionFunctions(): Unit { + val map = extensionFunctions(pkg.functions) + if (! map.isEmpty()) { + print(""" + + +""") + + for (e in map.entrySet()) { + val c = e?.getKey() + if (c != null) { + println("""""") + println("") + println("") + println("") + } + } + println("""
+Extensions Summary
${c.name}${c.description}
+  + +

+""") + } + } + + protected fun printNextPrevPackages(): Unit { println("""""") val prev = model.previous(pkg) diff --git a/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/templates/PackageTemplateSupport.kt b/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/templates/PackageTemplateSupport.kt new file mode 100644 index 00000000000..3a85abdddbe --- /dev/null +++ b/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/templates/PackageTemplateSupport.kt @@ -0,0 +1,146 @@ +package org.jetbrains.kotlin.doc.templates + +import std.* +import org.jetbrains.kotlin.template.* +import std.io.* +import std.util.* +import java.util.* +import org.jetbrains.kotlin.model.KModel +import org.jetbrains.kotlin.model.KPackage +import org.jetbrains.kotlin.model.KClass +import org.jetbrains.kotlin.model.KFunction +import org.jetbrains.kotlin.model.KAnnotation + + +abstract class PackageTemplateSupport(private val _pkg: KPackage) : KDocTemplate() { + + // TODO this verbosity is to work around this bug: http://youtrack.jetbrains.com/issue/KT-1398 + public val pkg: KPackage + get() = _pkg + + protected override fun relativePrefix(): String = pkg.nameAsRelativePath + + + fun printFunctionSummary(functions: Collection): Unit { + for (f in functions) { + printFunctionSummary(f) + } + } + + fun printFunctionDetail(functions: Collection): Unit { + for (f in functions) { + printFunctionDetail(f) + } + } + + fun printFunctionSummary(method: KFunction): Unit { + val deprecated = if (method.deprecated) "Deprecated." else "" + print(""" + +""") + if (!method.typeParameters.isEmpty()) { + println(""" + + + +
+ """) + printTypeParameters(method) + println("
") + print(link(method.returnType)) + println("""
""") + } else { + print(link(method.returnType)) + } + println("
") + print("${method.name}") + printParameters(method) + println("") + println("") + println("
") + println("          ${deprecated} ${method.detailedDescription}") + println("") + } + + fun printFunctionDetail(method: KFunction): Unit { + println("

") + println("${method.name}

") + println("
")
+        println("")
+        printAnnotations(method.annotations)
+        print("${method.modifiers.join(" ")} ")
+
+        printTypeParameters(method)
+        print(link(method.returnType))
+        print(" ${method.name}")
+        printParameters(method)
+        val exlist = method.exceptions
+        var first = true
+        if (!exlist.isEmpty()) {
+            println("                                throws ");
+            for (ex in exlist) {
+                if (first) first = false else print(", ")
+                print(link(ex))
+            }
+        }
+        println("
") + + /* TODO + println("""
+
Deprecated. TODO text +

+

Deprecated. +

+

+
+
Throws: +
${link(ex}
Since:
+
${since}
+
+
+
+*/ + println("
") + } + + fun printTypeParameters(method: KFunction): Unit { + val typeParameters = method.typeParameters + if (!typeParameters.isEmpty()) { + 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 + for (p in method.parameters) { + if (first) first = false else print(", ") + print("${p.name}: ") + print(link(p.klass)) + } + print(")") + } + + fun printAnnotations(annotations: Collection): Unit { + for (a in annotations) { + println(link(a)) + } + } +} \ No newline at end of file diff --git a/kdoc/src/main/kotlin/org/jetbrains/kotlin/model/KotlinModel.kt b/kdoc/src/main/kotlin/org/jetbrains/kotlin/model/KotlinModel.kt index e8cf66d5020..f90fb40da42 100644 --- a/kdoc/src/main/kotlin/org/jetbrains/kotlin/model/KotlinModel.kt +++ b/kdoc/src/main/kotlin/org/jetbrains/kotlin/model/KotlinModel.kt @@ -6,20 +6,30 @@ import std.util.* import java.util.* +fun extensionFunctions(functions: Collection): SortedMap> { + val map = TreeMap>() + functions.filter{ it.extensionClass != null }.groupBy(map){ it.extensionClass.sure() } + return map +} + +trait KClassOrPackage { + +} + class KModel(var title: String = "Documentation", var version: String = "TODO") { // TODO generates java.lang.NoSuchMethodError: std.util.namespace.hashMap(Ljet/TypeInfo;Ljet/TypeInfo;)Ljava/util/HashMap; //val packages = sortedMap() - public val packageMap: SortedMap = TreeMap() + public val packageMap: SortedMap = TreeMap() public val allPackages: Collection - get() = packageMap.values().sure() + get() = packageMap.values().sure() /** Returns the local packages */ public val packages: Collection - get() = allPackages.filter{ it.local } + get() = allPackages.filter{ it.local } public val classes: Collection - get() = packages.flatMap{ it.classes } + get() = packages.flatMap{ it.classes } /* Returns the package for the given name, creating one if its not already been create yet */ fun getPackage(name: String): KPackage { @@ -49,39 +59,51 @@ class KModel(var title: String = "Documentation", var version: String = "TODO") class KPackage(val model: KModel, val name: String, var external: Boolean = false, var description: String = "", var detailedDescription: String = "", - var local: Boolean = false) : Comparable { + var functions: SortedSet = TreeSet(), + var local: Boolean = false) : Comparable, KClassOrPackage { override fun compareTo(other: KPackage): Int = name.compareTo(other.name) + fun equals(other: KPackage) = name == other.name fun toString() = "KPackage($name)" + private var _initialised = false + + /** Runs the initialisation block if this class has not yet been initialised */ + fun initialise(fn: () -> Unit): Unit { + if (!_initialised) { + _initialised = true + fn() + } + } + /** Returns the name as a directory using '/' instead of '.' */ public val nameAsPath: String - get() = name.replace('.', '/') + get() = name.replace('.', '/') /** Returns a list of all the paths in the package name */ public val namePaths: List - get() { - val answer = ArrayList() - for (n in name.split("\\.")) { - if (n != null) { - answer.add(n) - } + get() { + val answer = ArrayList() + for (n in name.split("\\.")) { + if (n != null) { + answer.add(n) } - return answer; } + return answer; + } /** Returns a relative path like ../.. for each path in the name */ public val nameAsRelativePath: String - get() { - val answer = namePaths.map{ ".." }.join("/") - return if (answer.length == 0) "" else answer + "/" - } + get() { + val answer = namePaths.map{ ".." }.join("/") + return if (answer.length == 0) "" else answer + "/" + } // TODO generates java.lang.NoSuchMethodError: std.util.namespace.hashMap(Ljet/TypeInfo;Ljet/TypeInfo;)Ljava/util/HashMap; //val classes = sortedMap() - public val classMap: SortedMap = TreeMap() + public val classMap: SortedMap = TreeMap() public val classes: Collection = classMap.values().sure() @@ -91,8 +113,7 @@ class KPackage(val model: KModel, val name: String, var external: Boolean = fals /* Returns the class for the given name, creating one if its not already been create yet */ fun getClass(simpleName: String): KClass { return classMap.getOrPut(simpleName) { - val base = if (simpleName == "Object" && name == "java.lang") null else model.getClass("java.lang.Object") - KClass(this, simpleName, base) } + KClass(this, simpleName) } } fun qualifiedName(simpleName: String): String { @@ -114,21 +135,21 @@ class KPackage(val model: KModel, val name: String, var external: Boolean = fals return null } - fun groupClassMap(): Map> { - return classes.groupBy(TreeMap>()){it.group} + fun groupClassMap(): Map> { + return classes.groupBy(TreeMap>()){it.group} } } class KClass(val pkg: KPackage, val simpleName: String, - var baseClass: KClass? = null, var kind: String = "class", var group: String = "Other", var description: String = "", var detailedDescription: String = "", var annotations: List = arrayList(), var since: String = "", var authors: List = arrayList(), - var methods: List = arrayList(), + var functions: SortedSet = TreeSet(), + var baseClasses: List = arrayList(), var nestedClasses: List = arrayList(), - var sourceLine: Int = 2) : Comparable { + var sourceLine: Int = 2) : Comparable, KClassOrPackage { private var _initialised = false @@ -148,46 +169,63 @@ class KClass(val pkg: KPackage, val simpleName: String, /** 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 */ public var url: String? = null - get() { - if ($url == null) $url = "${nameAsPath}.html" - return $url - } + get() { + if ($url == null) $url = "${nameAsPath}.html" + return $url + } public val name: String = pkg.qualifiedName(simpleName) public val packageName: String = pkg.name /** Returns the name as a directory using '/' instead of '.' */ public val nameAsPath: String - get() = name.replace('.', '/') + get() = name.replace('.', '/') fun isAnnotation() = kind == "annotation" fun isInterface() = kind == "interface" } -class KMethod(val name: String, +class KFunction(val owner: KClassOrPackage, val name: String, var returnType: KClass, var description: String = "", var detailedDescription: String = "", var deprecated: Boolean = false, + var extensionClass: KClass? = null, var modifiers: List = arrayList(), var typeParameters: List = arrayList(), var parameters: List = arrayList(), var exceptions: List = arrayList(), - var annotations: List = arrayList()) : Comparable { - // TODO compare other things than just name :) + var annotations: List = arrayList(), + var sourceLine: Int = 2) : Comparable { - override fun compareTo(other: KMethod): Int = name.compareTo(other.name) + override fun compareTo(other: KFunction): Int { + var answer = name.compareTo(other.name) + if (answer == 0) { + answer = parameterTypeText.compareTo(other.parameterTypeText) + } + return answer + } - fun equals(other: KMethod) = name == other.name + fun equals(other: KFunction) = name == other.name fun toString() = "fun ($name)" /** TODO generate a link with the argument type names */ - public val link: String = name + public val link: String = "$name($parameterTypeText)" /** Returns a list of generic type parameter names kinds like "A, I" */ public val typeParametersText: String - get() = typeParameters.map{ it.name }.join(", ") + get() = typeParameters.map{ it.name }.join(", ") + + /** Returns a list of parameter value types */ + private var _parameterTypeText: String? = null + public val parameterTypeText: String + get() { + if (_parameterTypeText == null) { + _parameterTypeText = typeParameters.map{ it.klass.name }.join(", ") + } + return _parameterTypeText.sure() + } } class KParameter(val name: String, diff --git a/kdoc/src/test/kotlin/test/kotlin/doc/KDocTestAll.java b/kdoc/src/test/kotlin/test/kotlin/doc/KDocTestAll.java deleted file mode 100644 index e7a02770889..00000000000 --- a/kdoc/src/test/kotlin/test/kotlin/doc/KDocTestAll.java +++ /dev/null @@ -1,28 +0,0 @@ -/** - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package test.kotlin.doc; - -import junit.framework.TestSuite; - -/** - */ -public class KDocTestAll { - public static TestSuite suite() { - return new TestSuite("test.kotlin.doc.ModelTest"); - } -} diff --git a/kdoc/src/test/kotlin/test/kotlin/doc/ModelTest.kt b/kdoc/src/test/kotlin/test/kotlin/doc/ModelTest.kt deleted file mode 100644 index 0755772bd26..00000000000 --- a/kdoc/src/test/kotlin/test/kotlin/doc/ModelTest.kt +++ /dev/null @@ -1,62 +0,0 @@ -package test.kotlin.doc - -import std.* -import std.util.* - -import org.jetbrains.kotlin.model.* - -import junit.framework.TestCase - -// TODO should use the ktest library really for nicer asserts -import junit.framework.Assert.assertEquals -import org.jetbrains.kotlin.doc.KDocGenerator -import java.io.File - -class ModelTest : TestCase() { - val model = KModel() - - fun testGetClassViaPackage() { - val p = model.getPackage("foo.bar") - val c = p.getClass("Cheese") - - println("Got class: $c") - - assertEquals("foo.bar.Cheese", c.name) - assertEquals("foo.bar", c.packageName) - assertEquals("Cheese", c.simpleName) - } - - fun testGetClassViaQualifiedName() { - val c = model.getClass("something.else.Foo") - - println("Got class: $c") - - assertEquals("something.else.Foo", c.name) - assertEquals("something.else", c.packageName) - assertEquals("Foo", c.simpleName) - } - - fun testModelWalk() { - val a = model.getClass("something.else.Aaa") - val z = model.getClass("something.else.Zzz") - val c = model.getClass("another.Cheese") - - c.methods.add(KMethod("addFoo", a, "add some foos")) - val m1 = KMethod("addZzzz", z, "add some zzz") - m1.parameters.add(KParameter("myz", z)) - c.methods.add(m1) - - // now lets iterate through the model - println("Walking the model...") - for (p in model.packages) { - println("Package ${p.name}") - for (c in p.classes) { - println(" ${c.simpleName}") - } - println() - } - - val processor = KDocGenerator(model, File("target/test-data/ModelTest")) - processor.execute() - } -}