diff options
Diffstat (limited to 'src/Kotlin')
-rw-r--r-- | src/Kotlin/ContentBuilder.kt | 41 | ||||
-rw-r--r-- | src/Kotlin/DocumentationBuilder.kt | 7 |
2 files changed, 31 insertions, 17 deletions
diff --git a/src/Kotlin/ContentBuilder.kt b/src/Kotlin/ContentBuilder.kt index 58e41bec..635fc74f 100644 --- a/src/Kotlin/ContentBuilder.kt +++ b/src/Kotlin/ContentBuilder.kt @@ -5,6 +5,8 @@ import java.util.ArrayDeque import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor import org.jetbrains.jet.lang.resolve.name.Name import org.jetbrains.jet.lang.resolve.DescriptorToSourceUtils +import org.jetbrains.jet.lang.resolve.scopes.JetScope +import org.jetbrains.jet.lang.resolve.name.FqName public fun DocumentationBuilder.buildContent(tree: MarkdownTree, descriptor: DeclarationDescriptor): Content { val nodeStack = ArrayDeque<ContentNode>() @@ -100,29 +102,40 @@ public fun DocumentationBuilder.buildContent(tree: MarkdownTree, descriptor: Dec fun DocumentationBuilder.functionBody(descriptor: DeclarationDescriptor, functionName: String): ContentNode { - var scope = context.getResolutionScope(descriptor) + val scope = getResolutionScope(descriptor) + val rootPackage = session.getModuleDescriptor().getPackage(FqName.ROOT)!! + val rootScope = rootPackage.getMemberScope() + val symbol = resolveInScope(functionName, scope) ?: resolveInScope(functionName, rootScope) + if (symbol == null) + return ContentBlockCode().let() { it.append(ContentText("Unresolved: $functionName")); it } + val psiElement = DescriptorToSourceUtils.descriptorToDeclaration(symbol) + if (psiElement == null) + return ContentBlockCode().let() { it.append(ContentText("Source not found: $functionName")); it } + + return ContentBlockCode().let() { it.append(ContentText(psiElement.getText())); it } +} + +private fun DocumentationBuilder.resolveInScope(functionName: String, scope: JetScope): DeclarationDescriptor? { + var currentScope = scope val parts = functionName.split('.') var symbol: DeclarationDescriptor? = null for (part in parts) { // short name val symbolName = Name.guess(part) - val partSymbol = scope.getLocalVariable(symbolName) ?: - scope.getProperties(symbolName).firstOrNull() ?: - scope.getFunctions(symbolName).firstOrNull() ?: - scope.getClassifier(symbolName) ?: - scope.getPackage(symbolName) + val partSymbol = currentScope.getLocalVariable(symbolName) ?: + currentScope.getProperties(symbolName).firstOrNull() ?: + currentScope.getFunctions(symbolName).firstOrNull() ?: + currentScope.getClassifier(symbolName) ?: + currentScope.getPackage(symbolName) - if (partSymbol == null) + if (partSymbol == null) { + symbol = null break - scope = context.getResolutionScope(partSymbol) + } + currentScope = getResolutionScope(partSymbol) symbol = partSymbol } - if (symbol != null) { - val psi = DescriptorToSourceUtils.descriptorToDeclaration(descriptor) - - - } - return ContentCode().let() { it.append(ContentText("inline")); it } + return symbol }
\ No newline at end of file diff --git a/src/Kotlin/DocumentationBuilder.kt b/src/Kotlin/DocumentationBuilder.kt index b18902e4..cee374d9 100644 --- a/src/Kotlin/DocumentationBuilder.kt +++ b/src/Kotlin/DocumentationBuilder.kt @@ -11,10 +11,11 @@ import org.jetbrains.jet.lang.resolve.name.Name import org.jetbrains.jet.lang.resolve.scopes.JetScope import org.jetbrains.jet.lang.psi.JetFile import org.jetbrains.jet.lang.resolve.name.FqName +import org.jetbrains.jet.lang.resolve.lazy.ResolveSession public data class DocumentationOptions(val includeNonPublic: Boolean = false) -class DocumentationBuilder(val context: BindingContext, val options: DocumentationOptions) { +class DocumentationBuilder(val session: ResolveSession, val options: DocumentationOptions) { val visibleToDocumentation = setOf(Visibilities.INTERNAL, Visibilities.PROTECTED, Visibilities.PUBLIC) val descriptorToNode = hashMapOf<DeclarationDescriptor, DocumentationNode>() val nodeToDescriptor = hashMapOf<DocumentationNode, DeclarationDescriptor>() @@ -22,7 +23,7 @@ class DocumentationBuilder(val context: BindingContext, val options: Documentati val packages = hashMapOf<FqName, DocumentationNode>() fun parseDocumentation(descriptor: DeclarationDescriptor): Content { - val docText = context.getDocumentationElements(descriptor).map { it.extractText() }.join("\n") + val docText = descriptor.getDocumentationElements().map { it.extractText() }.join("\n") val tree = MarkdownProcessor.parse(docText) //println(tree.toTestString()) val content = buildContent(tree, descriptor) @@ -295,7 +296,7 @@ class DocumentationBuilder(val context: BindingContext, val options: Documentati fun getResolutionScope(node: DocumentationNode): JetScope { val descriptor = nodeToDescriptor[node] ?: throw IllegalArgumentException("Node is not known to this context") - return context.getResolutionScope(descriptor) + return getResolutionScope(descriptor) } fun resolveContentLinks(node: DocumentationNode, content: ContentNode) { |