From e93440bd4a520ab81203e8b0105ac43323f67e6b Mon Sep 17 00:00:00 2001 From: Ilya Ryzhenkov Date: Fri, 3 Oct 2014 21:29:56 +0400 Subject: Constructors, variance, links and styles. --- src/Kotlin/DocumentationBuildingVisitor.kt | 3 +- src/Kotlin/DocumentationNodeBuilder.kt | 52 +++++++++++++++++++----------- src/Languages/KotlinLanguageService.kt | 30 ++++++++--------- src/Locations/LocationService.kt | 12 +++---- styles/style.css | 5 +++ 5 files changed, 60 insertions(+), 42 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() { @@ -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 -> "" } - 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("", doc, DocumentationNode.Kind.Constructor) reference(data!!, node, DocumentationReference.Kind.Member) addVisibility(descriptor, node) diff --git a/src/Languages/KotlinLanguageService.kt b/src/Languages/KotlinLanguageService.kt index 65ec6a57..46b58574 100644 --- a/src/Languages/KotlinLanguageService.kt +++ b/src/Languages/KotlinLanguageService.kt @@ -65,35 +65,35 @@ class KotlinLanguageService : LanguageService { // lambda symbol("(") renderList(typeArguments.take(typeArguments.size - 1)) { - renderLinked(it) { renderType(it) } + renderType(it) } symbol(")") text(" ") symbol("->") text(" ") - renderLinked(typeArguments.last()) { renderType(it) } + renderType(typeArguments.last()) return } if (node.name == "ExtensionFunction${typeArguments.count() - 2}") { // extension lambda - renderLinked(typeArguments.first()) { renderType(it) } + renderType(typeArguments.first()) symbol(".") symbol("(") renderList(typeArguments.drop(1).take(typeArguments.size - 2)) { - renderLinked(it) { renderType(it) } + renderType(it) } symbol(")") text(" ") symbol("->") text(" ") - renderLinked(typeArguments.last()) { renderType(it) } + renderType(typeArguments.last()) return } - identifier(node.name) + renderLinked(node) { identifier(it.name) } if (typeArguments.any()) { symbol("<") renderList(typeArguments) { - renderLinked(it) { renderType(it) } + renderType(it) } symbol(">") } @@ -113,7 +113,7 @@ class KotlinLanguageService : LanguageService { if (constraints.any()) { symbol(" : ") renderList(constraints) { - renderLinked(it) { renderType(it) } + renderType(it) } } } @@ -122,7 +122,7 @@ class KotlinLanguageService : LanguageService { identifier(node.name) symbol(": ") val parameterType = node.detail(Kind.Type) - renderLinked(parameterType) { renderType(it) } + renderType(parameterType) } fun ContentNode.renderTypeParametersForNode(node: DocumentationNode) { @@ -130,7 +130,7 @@ class KotlinLanguageService : LanguageService { if (typeParameters.any()) { symbol("<") renderList(typeParameters) { - renderLinked(it) { renderType(it) } + renderType(it) } symbol("> ") } @@ -141,7 +141,7 @@ class KotlinLanguageService : LanguageService { if (supertypes.any()) { symbol(" : ") renderList(supertypes) { - renderLinked(it) { renderType(it) } + renderType(it) } } } @@ -182,7 +182,7 @@ class KotlinLanguageService : LanguageService { renderTypeParametersForNode(node) val receiver = node.details(Kind.Receiver).singleOrNull() if (receiver != null) { - renderLinked(receiver.detail(Kind.Type)) { renderType(it) } + renderType(receiver.detail(Kind.Type)) symbol(".") } @@ -196,7 +196,7 @@ class KotlinLanguageService : LanguageService { symbol(")") if (node.kind != Kind.Constructor) { symbol(": ") - renderLinked(node.detail(Kind.Type)) { renderType(it) } + renderType(node.detail(Kind.Type)) } } @@ -209,12 +209,12 @@ class KotlinLanguageService : LanguageService { renderTypeParametersForNode(node) val receiver = node.details(Kind.Receiver).singleOrNull() if (receiver != null) { - renderLinked(receiver.detail(Kind.Type)) { renderType(it) } + renderType(receiver.detail(Kind.Type)) symbol(".") } identifier(node.name) symbol(": ") - renderLinked(node.detail(Kind.Type)) { renderType(it) } + renderType(node.detail(Kind.Type)) } } \ No newline at end of file diff --git a/src/Locations/LocationService.kt b/src/Locations/LocationService.kt index 277169fd..f89fedd0 100644 --- a/src/Locations/LocationService.kt +++ b/src/Locations/LocationService.kt @@ -14,14 +14,12 @@ public trait LocationService { public fun escapeUri(path: String): String = path.replace('<', '_').replace('>', '_') -fun LocationService.relativeLocation(node: DocumentationNode, link: DocumentationNode, extension: String): Location { - val ownerFolder = location(node).file.getParentFile()!! - val memberPath = location(link).file.appendExtension(extension) - return Location(ownerFolder.getRelativePath(memberPath)) +fun LocationService.relativeLocation(owner: DocumentationNode, node: DocumentationNode, extension: String): Location { + return relativeLocation(location(owner), node, extension) } -fun LocationService.relativeLocation(location: Location, link: DocumentationNode, extension: String): Location { - val ownerFolder = location.file.getParentFile()!! - val memberPath = location(link).file.appendExtension(extension) +fun LocationService.relativeLocation(owner: Location, node: DocumentationNode, extension: String): Location { + val ownerFolder = owner.file.getParentFile()!! + val memberPath = location(node).file.appendExtension(extension) return Location(ownerFolder.getRelativePath(memberPath)) } diff --git a/styles/style.css b/styles/style.css index 82798bf8..ce546546 100644 --- a/styles/style.css +++ b/styles/style.css @@ -49,6 +49,11 @@ a { text-decoration:none; } +a:hover { + color: inherit; + text-decoration:underline; +} + a small { font-size:11px; color:#555; -- cgit