aboutsummaryrefslogtreecommitdiff
path: root/src/Kotlin
diff options
context:
space:
mode:
Diffstat (limited to 'src/Kotlin')
-rw-r--r--src/Kotlin/DocumentationBuildingVisitor.kt3
-rw-r--r--src/Kotlin/DocumentationNodeBuilder.kt52
2 files changed, 35 insertions, 20 deletions
diff --git a/src/Kotlin/DocumentationBuildingVisitor.kt b/src/Kotlin/DocumentationBuildingVisitor.kt
index 754ef8ef..364c4f6c 100644
--- a/src/Kotlin/DocumentationBuildingVisitor.kt
+++ b/src/Kotlin/DocumentationBuildingVisitor.kt
@@ -90,7 +90,8 @@ class DocumentationBuildingVisitor(val context: BindingContext,
}
public override fun visitConstructorDescriptor(descriptor: ConstructorDescriptor?, data: DocumentationNode?): DocumentationNode? {
- val node = visitFunctionDescriptor(descriptor!!, data)
+ val node = createDocumentation(descriptor!!, data!!)
+ visitChildren(descriptor.getValueParameters(), node)
return node
}
diff --git a/src/Kotlin/DocumentationNodeBuilder.kt b/src/Kotlin/DocumentationNodeBuilder.kt
index f29a17d5..8f77a3d6 100644
--- a/src/Kotlin/DocumentationNodeBuilder.kt
+++ b/src/Kotlin/DocumentationNodeBuilder.kt
@@ -16,6 +16,8 @@ import org.jetbrains.jet.lang.descriptors.PackageViewDescriptor
import org.jetbrains.jet.lang.descriptors.PackageFragmentDescriptor
import org.jetbrains.jet.lang.descriptors.ClassKind
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns
+import org.jetbrains.jet.lang.types.TypeProjection
+import org.jetbrains.jet.lang.types.Variance
class DocumentationNodeBuilder(val context: DocumentationContext) : DeclarationDescriptorVisitorEmptyBodies<DocumentationNode, DocumentationNode>() {
@@ -43,30 +45,35 @@ class DocumentationNodeBuilder(val context: DocumentationContext) : DeclarationD
fun addSupertypes(descriptor: ClassDescriptor, data: DocumentationNode) {
val superTypes = descriptor.getTypeConstructor().getSupertypes()
for (superType in superTypes) {
- val superDescriptor = superType.getConstructor().getDeclarationDescriptor()
- if (superDescriptor != null && superType.toString() != "Any") {
- val node = DocumentationNode(superType.toString(), Content.Empty, DocumentationNode.Kind.Supertype)
- context.attach(node, superDescriptor)
- reference(data, node, DocumentationReference.Kind.Detail)
- }
+ if (superType.toString() != "Any")
+ addType(superType, data, DocumentationNode.Kind.Supertype)
}
}
- fun addType(descriptor: DeclarationDescriptor, t: JetType?, data: DocumentationNode) {
- if (t == null)
+ fun addProjection(projection: TypeProjection, data: DocumentationNode, kind: DocumentationNode.Kind = DocumentationNode.Kind.Type) {
+ val prefix = when (projection.getProjectionKind()) {
+ Variance.IN_VARIANCE -> "in "
+ Variance.OUT_VARIANCE -> "out "
+ else -> ""
+ }
+ addType(projection.getType(), data, kind, prefix)
+ }
+
+ fun addType(jetType: JetType?, data: DocumentationNode, kind: DocumentationNode.Kind = DocumentationNode.Kind.Type, prefix : String = "") {
+ if (jetType == null)
return
- val classifierDescriptor = t.getConstructor().getDeclarationDescriptor()
+ val classifierDescriptor = jetType.getConstructor().getDeclarationDescriptor()
val name = when (classifierDescriptor) {
- is Named -> classifierDescriptor.getName().asString()
+ is Named -> prefix + classifierDescriptor.getName().asString() + if (jetType.isNullable()) "?" else ""
else -> "<anonymous>"
}
- val node = DocumentationNode(name, Content.Empty, DocumentationNode.Kind.Type)
+ val node = DocumentationNode(name, Content.Empty, kind)
if (classifierDescriptor != null)
context.attach(node, classifierDescriptor)
reference(data, node, DocumentationReference.Kind.Detail)
- for (param in t.getArguments())
- addType(descriptor, param.getType(), node)
+ for (typeArgument in jetType.getArguments())
+ addProjection(typeArgument, node)
}
override fun visitDeclarationDescriptor(descriptor: DeclarationDescriptor?, data: DocumentationNode?): DocumentationNode? {
@@ -83,7 +90,7 @@ class DocumentationNodeBuilder(val context: DocumentationContext) : DeclarationD
val node = DocumentationNode(descriptor.getName().asString(), Content.Empty, DocumentationNode.Kind.Receiver)
reference(data!!, node, DocumentationReference.Kind.Detail)
- addType(descriptor, descriptor.getType(), node)
+ addType(descriptor.getType(), node)
return node
}
@@ -94,7 +101,7 @@ class DocumentationNodeBuilder(val context: DocumentationContext) : DeclarationD
val node = DocumentationNode(descriptor.getName().asString(), doc, DocumentationNode.Kind.Parameter)
reference(data!!, node, DocumentationReference.Kind.Detail)
- addType(descriptor, descriptor.getType(), node)
+ addType(descriptor.getType(), node)
return node
}
@@ -124,7 +131,7 @@ class DocumentationNodeBuilder(val context: DocumentationContext) : DeclarationD
val node = DocumentationNode(descriptor.getName().asString(), doc, DocumentationNode.Kind.Function)
reference(data!!, node, DocumentationReference.Kind.Member)
- addType(descriptor, descriptor.getReturnType(), node)
+ addType(descriptor.getReturnType(), node)
addModality(descriptor, node)
addVisibility(descriptor, node)
context.register(descriptor, node)
@@ -134,7 +141,14 @@ class DocumentationNodeBuilder(val context: DocumentationContext) : DeclarationD
override fun visitTypeParameterDescriptor(descriptor: TypeParameterDescriptor?, data: DocumentationNode?): DocumentationNode? {
descriptor!!
val doc = context.parseDocumentation(descriptor)
- val node = DocumentationNode(descriptor.getName().asString(), doc, DocumentationNode.Kind.TypeParameter)
+ val name = descriptor.getName().asString()
+ val prefix = when (descriptor.getVariance()) {
+ Variance.IN_VARIANCE -> "in "
+ Variance.OUT_VARIANCE -> "out "
+ else -> ""
+ }
+
+ val node = DocumentationNode(prefix + name, doc, DocumentationNode.Kind.TypeParameter)
reference(data!!, node, DocumentationReference.Kind.Detail)
val builtIns = KotlinBuiltIns.getInstance()
for (constraint in descriptor.getUpperBounds()) {
@@ -158,7 +172,7 @@ class DocumentationNodeBuilder(val context: DocumentationContext) : DeclarationD
val node = DocumentationNode(descriptor.getName().asString(), doc, DocumentationNode.Kind.Property)
reference(data!!, node, DocumentationReference.Kind.Member)
- addType(descriptor, descriptor.getType(), node)
+ addType(descriptor.getType(), node)
addModality(descriptor, node)
addVisibility(descriptor, node)
context.register(descriptor, node)
@@ -168,7 +182,7 @@ class DocumentationNodeBuilder(val context: DocumentationContext) : DeclarationD
override fun visitConstructorDescriptor(descriptor: ConstructorDescriptor?, data: DocumentationNode?): DocumentationNode? {
descriptor!!
val doc = context.parseDocumentation(descriptor)
- val node = DocumentationNode(descriptor.getName().asString(), doc, DocumentationNode.Kind.Constructor)
+ val node = DocumentationNode("<constructor>", doc, DocumentationNode.Kind.Constructor)
reference(data!!, node, DocumentationReference.Kind.Member)
addVisibility(descriptor, node)