aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIlya Ryzhenkov <orangy@jetbrains.com>2014-10-13 18:22:02 +0400
committerIlya Ryzhenkov <orangy@jetbrains.com>2014-10-13 18:22:02 +0400
commitad14ea91a52563c83a3aba0c7d279cd5535b77e4 (patch)
treed78275d4d0ff3e51f604f059aee1b485028156f4
parent498448826d8762add15a524097e91e96b545a631 (diff)
downloaddokka-ad14ea91a52563c83a3aba0c7d279cd5535b77e4.tar.gz
dokka-ad14ea91a52563c83a3aba0c7d279cd5535b77e4.tar.bz2
dokka-ad14ea91a52563c83a3aba0c7d279cd5535b77e4.zip
Fixing formats and started work on inline function body.
-rw-r--r--.idea/runConfigurations/Stdlib.xml2
-rw-r--r--gen/org/jetbrains/markdown/MarkdownParser.java19
-rw-r--r--src/Formats/StructuredFormatService.kt8
-rw-r--r--src/Kotlin/ContentBuilder.kt51
-rw-r--r--src/Kotlin/DocumentationBuilder.kt2
-rw-r--r--src/Kotlin/KotlinLanguageService.kt7
-rw-r--r--src/Markdown/markdown.bnf2
-rw-r--r--src/Model/Content.kt3
-rw-r--r--src/main.kt26
-rw-r--r--styles/style.css2
10 files changed, 99 insertions, 23 deletions
diff --git a/.idea/runConfigurations/Stdlib.xml b/.idea/runConfigurations/Stdlib.xml
index 222fb78c..2a040cac 100644
--- a/.idea/runConfigurations/Stdlib.xml
+++ b/.idea/runConfigurations/Stdlib.xml
@@ -3,7 +3,7 @@
<extension name="coverage" enabled="false" merge="false" sample_coverage="true" runner="idea" />
<option name="MAIN_CLASS_NAME" value="org.jetbrains.dokka.DokkaPackage" />
<option name="VM_PARAMETERS" value="-Xmx2048m -Xms256m" />
- <option name="PROGRAM_PARAMETERS" value="../kotlin/libraries/stdlib/src ../kotlin/core/builtins -output doc -module stdlib" />
+ <option name="PROGRAM_PARAMETERS" value="../kotlin/libraries/stdlib/src ../kotlin/core/builtins -samples ../kotlin/libraries/stdlib/test -output doc -module stdlib" />
<option name="WORKING_DIRECTORY" value="file://$PROJECT_DIR$" />
<option name="ALTERNATIVE_JRE_PATH_ENABLED" value="false" />
<option name="ALTERNATIVE_JRE_PATH" />
diff --git a/gen/org/jetbrains/markdown/MarkdownParser.java b/gen/org/jetbrains/markdown/MarkdownParser.java
index ab84cd5e..05a1ada8 100644
--- a/gen/org/jetbrains/markdown/MarkdownParser.java
+++ b/gen/org/jetbrains/markdown/MarkdownParser.java
@@ -336,19 +336,36 @@ public class MarkdownParser implements PsiParser {
}
/* ********************************************************** */
- // '{' DirectiveName DirectiveParams '}'
+ // '{' DirectiveName Space+ DirectiveParams '}'
public static boolean Directive(PsiBuilder b, int l) {
if (!recursion_guard_(b, l, "Directive")) return false;
boolean r;
Marker m = enter_section_(b, l, _NONE_, "<directive>");
r = consumeToken(b, "{");
r = r && DirectiveName(b, l + 1);
+ r = r && Directive_2(b, l + 1);
r = r && DirectiveParams(b, l + 1);
r = r && consumeToken(b, "}");
exit_section_(b, l, m, DIRECTIVE, r, false, null);
return r;
}
+ // Space+
+ private static boolean Directive_2(PsiBuilder b, int l) {
+ if (!recursion_guard_(b, l, "Directive_2")) return false;
+ boolean r;
+ Marker m = enter_section_(b);
+ r = consumeToken(b, SPACE);
+ int c = current_position_(b);
+ while (r) {
+ if (!consumeToken(b, SPACE)) break;
+ if (!empty_element_parsed_guard_(b, "Directive_2", c)) break;
+ c = current_position_(b);
+ }
+ exit_section_(b, m, null, r);
+ return r;
+ }
+
/* ********************************************************** */
// Word
public static boolean DirectiveName(PsiBuilder b, int l) {
diff --git a/src/Formats/StructuredFormatService.kt b/src/Formats/StructuredFormatService.kt
index 75b51ab8..4285f8c9 100644
--- a/src/Formats/StructuredFormatService.kt
+++ b/src/Formats/StructuredFormatService.kt
@@ -55,6 +55,9 @@ public abstract class StructuredFormatService(val locationService: LocationServi
val linkText = formatText(location, content.children)
append(formatLink(linkText, content.href))
}
+ is ContentParagraph -> {
+ appendText(this, formatText(location, content.children))
+ }
else -> append(formatText(location, content.children))
}
}.toString()
@@ -82,7 +85,6 @@ public abstract class StructuredFormatService(val locationService: LocationServi
continue
appendLine(to, formatStrong(formatText(label)))
appendLine(to, formatText(location, section))
- appendLine(to)
}
}
}
@@ -126,14 +128,14 @@ public abstract class StructuredFormatService(val locationService: LocationServi
appendText(to, formatLink(memberLocation))
}
appendTableCell(to) {
- val breakdownBySummary = members.groupBy { it.doc.summary }
+ val breakdownBySummary = members.groupBy { formatText(location, it.doc.summary) }
for ((summary, items) in breakdownBySummary) {
for (signature in items) {
appendBlockCode(to, formatText(location, languageService.render(signature)))
}
if (!summary.isEmpty()) {
- appendText(to, formatText(location, summary))
+ appendText(to, summary)
}
}
}
diff --git a/src/Kotlin/ContentBuilder.kt b/src/Kotlin/ContentBuilder.kt
index 9de3001a..58e41bec 100644
--- a/src/Kotlin/ContentBuilder.kt
+++ b/src/Kotlin/ContentBuilder.kt
@@ -2,15 +2,18 @@ package org.jetbrains.dokka
import org.jetbrains.markdown.MarkdownElementTypes
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
-public fun MarkdownTree.toContent(): Content {
+public fun DocumentationBuilder.buildContent(tree: MarkdownTree, descriptor: DeclarationDescriptor): Content {
val nodeStack = ArrayDeque<ContentNode>()
nodeStack.push(Content())
- visit {(node, text, processChildren) ->
+ tree.visit {(node, text, processChildren) ->
val parent = nodeStack.peek()!!
val nodeType = node.getTokenType()
- val nodeText = getNodeText(node)
+ val nodeText = tree.getNodeText(node)
when (nodeType) {
MarkdownElementTypes.BULLET_LIST -> {
nodeStack.push(ContentList())
@@ -49,15 +52,22 @@ public fun MarkdownTree.toContent(): Content {
processChildren()
parent.append(nodeStack.pop())
}
+ MarkdownElementTypes.DIRECTIVE -> {
+ val name = tree.findChildByType(node, MarkdownElementTypes.DIRECTIVE_NAME)?.let { tree.getNodeText(it) } ?: ""
+ val params = tree.findChildByType(node, MarkdownElementTypes.DIRECTIVE_PARAMS)?.let { tree.getNodeText(it) } ?: ""
+ when (name) {
+ "code" -> parent.append(functionBody(descriptor, params))
+ }
+ }
MarkdownElementTypes.NAMED_SECTION -> {
- val label = findChildByType(node, MarkdownElementTypes.SECTION_NAME)?.let { getNodeText(it) } ?: ""
+ val label = tree.findChildByType(node, MarkdownElementTypes.SECTION_NAME)?.let { tree.getNodeText(it) } ?: ""
nodeStack.push(ContentSection(label))
processChildren()
parent.append(nodeStack.pop())
}
MarkdownElementTypes.LINK -> {
- val target = findChildByType(node, MarkdownElementTypes.TARGET)?.let { getNodeText(it) } ?: ""
- val href = findChildByType(node, MarkdownElementTypes.HREF)?.let { getNodeText(it) }
+ val target = tree.findChildByType(node, MarkdownElementTypes.TARGET)?.let { tree.getNodeText(it) } ?: ""
+ val href = tree.findChildByType(node, MarkdownElementTypes.HREF)?.let { tree.getNodeText(it) }
val link = if (href != null) ContentExternalLink(href) else ContentExternalLink(target)
link.append(ContentText(target))
parent.append(link)
@@ -76,7 +86,7 @@ public fun MarkdownTree.toContent(): Content {
processChildren()
}
MarkdownElementTypes.PARA -> {
- nodeStack.push(ContentBlock())
+ nodeStack.push(ContentParagraph())
processChildren()
parent.append(nodeStack.pop())
}
@@ -89,3 +99,30 @@ public fun MarkdownTree.toContent(): Content {
}
+fun DocumentationBuilder.functionBody(descriptor: DeclarationDescriptor, functionName: String): ContentNode {
+ var scope = context.getResolutionScope(descriptor)
+ 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)
+
+ if (partSymbol == null)
+ break
+ scope = context.getResolutionScope(partSymbol)
+ symbol = partSymbol
+ }
+
+ if (symbol != null) {
+ val psi = DescriptorToSourceUtils.descriptorToDeclaration(descriptor)
+
+
+ }
+ return ContentCode().let() { it.append(ContentText("inline")); it }
+} \ No newline at end of file
diff --git a/src/Kotlin/DocumentationBuilder.kt b/src/Kotlin/DocumentationBuilder.kt
index 7f8a423e..b18902e4 100644
--- a/src/Kotlin/DocumentationBuilder.kt
+++ b/src/Kotlin/DocumentationBuilder.kt
@@ -25,7 +25,7 @@ class DocumentationBuilder(val context: BindingContext, val options: Documentati
val docText = context.getDocumentationElements(descriptor).map { it.extractText() }.join("\n")
val tree = MarkdownProcessor.parse(docText)
//println(tree.toTestString())
- val content = tree.toContent()
+ val content = buildContent(tree, descriptor)
return content
}
diff --git a/src/Kotlin/KotlinLanguageService.kt b/src/Kotlin/KotlinLanguageService.kt
index 80467914..c7fabda9 100644
--- a/src/Kotlin/KotlinLanguageService.kt
+++ b/src/Kotlin/KotlinLanguageService.kt
@@ -110,9 +110,11 @@ class KotlinLanguageService : LanguageService {
private fun ContentNode.renderModifier(node: DocumentationNode) {
when (node.name) {
- "final", "internal" -> {
+ "final", "internal" -> {}
+ else -> {
+ keyword(node.name)
+ text(" ")
}
- else -> keyword(node.name)
}
}
@@ -161,7 +163,6 @@ class KotlinLanguageService : LanguageService {
if (node.kind == org.jetbrains.dokka.DocumentationNode.Kind.Interface && it.name == "abstract")
continue
renderModifier(it)
- text(" ")
}
}
diff --git a/src/Markdown/markdown.bnf b/src/Markdown/markdown.bnf
index f3c484d5..2e4979ec 100644
--- a/src/Markdown/markdown.bnf
+++ b/src/Markdown/markdown.bnf
@@ -59,7 +59,7 @@ HorizontalRule ::= NonindentSpace
| '_' OptionalSpace '_' OptionalSpace '_' (OptionalSpace '_')*)
OptionalSpace EOL BlankLine+
-Directive ::= '{' DirectiveName DirectiveParams '}'
+Directive ::= '{' DirectiveName Space+ DirectiveParams '}'
DirectiveName ::= Word
DirectiveParams ::= PlainText
diff --git a/src/Model/Content.kt b/src/Model/Content.kt
index a3691fd0..9f716209 100644
--- a/src/Model/Content.kt
+++ b/src/Model/Content.kt
@@ -24,6 +24,7 @@ public class ContentKeyword(val text: String) : ContentNode()
public class ContentIdentifier(val text: String) : ContentNode()
public class ContentSymbol(val text: String) : ContentNode()
+public class ContentParagraph() : ContentBlock()
public class ContentEmphasis() : ContentBlock()
public class ContentStrong() : ContentBlock()
public class ContentCode() : ContentBlock()
@@ -51,7 +52,7 @@ fun ContentNode.link(to: DocumentationNode, body: ContentNode.() -> Unit) {
public class Content() : ContentNode() {
public val sections: Map<String, ContentSection> by Delegates.lazy {
- val map = hashMapOf<String, ContentSection>()
+ val map = linkedMapOf<String, ContentSection>()
for (child in children) {
if (child is ContentSection)
map.put(child.label, child)
diff --git a/src/main.kt b/src/main.kt
index 44d78187..e234a110 100644
--- a/src/main.kt
+++ b/src/main.kt
@@ -11,7 +11,11 @@ import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor
class DokkaArguments {
Argument(value = "src", description = "Source file or directory (allows many paths separated by the system path separator)")
ValueDescription("<path>")
- public var src: String? = null
+ public var src: String = ""
+
+ Argument(value = "samples", description = "Source root for samples")
+ ValueDescription("<path>")
+ public var samples: String = ""
Argument(value = "output", description = "Output directory path for .md files")
ValueDescription("<path>")
@@ -24,21 +28,25 @@ class DokkaArguments {
Argument(value = "classpath", description = "Classpath for symbol resolution")
ValueDescription("<path>")
public var classpath: String = ""
+
}
public fun main(args: Array<String>) {
val arguments = DokkaArguments()
- val sourceFiles = Args.parse(arguments, args)
- val sources: List<String> = sourceFiles ?: listOf()
+ val freeArgs: List<String> = Args.parse(arguments, args) ?: listOf()
+ val sources = if (arguments.src.isNotEmpty()) arguments.src.split(File.pathSeparatorChar).toList() + freeArgs else freeArgs
+ val samples = if (arguments.samples.isNotEmpty()) arguments.samples.split(File.pathSeparatorChar).toList() else listOf()
val environment = AnalysisEnvironment(MessageCollectorPlainTextToStream.PLAIN_TEXT_TO_SYSTEM_ERR) {
addClasspath(PathUtil.getJdkClassesRoots())
+ // addClasspath(PathUtil.getKotlinPathsForCompiler().getRuntimePath())
for (element in arguments.classpath.split(File.pathSeparatorChar)) {
addClasspath(File(element))
}
- // addClasspath(PathUtil.getKotlinPathsForCompiler().getRuntimePath())
+
addSources(sources)
+ addSources(samples)
}
println("Module: ${arguments.moduleName}")
@@ -52,7 +60,15 @@ public fun main(args: Array<String>) {
val startAnalyse = System.currentTimeMillis()
val documentation = environment.withContext { environment, module, context ->
- val fragments = environment.getSourceFiles().map { context.getPackageFragment(it) }.filterNotNull().distinct()
+ val fragmentFiles = environment.getSourceFiles().filter {
+ val sourceFile = File(it.getVirtualFile()!!.getPath())
+ samples.none { sample ->
+ val canonicalSample = File(sample).canonicalPath
+ val canonicalSource = sourceFile.canonicalPath
+ canonicalSource.startsWith(canonicalSample)
+ }
+ }
+ val fragments = fragmentFiles.map { context.getPackageFragment(it) }.filterNotNull().distinct()
val documentationModule = DocumentationModule(arguments.moduleName)
val options = DocumentationOptions()
val documentationBuilder = DocumentationBuilder(context, options)
diff --git a/styles/style.css b/styles/style.css
index 5bfb25bc..09586237 100644
--- a/styles/style.css
+++ b/styles/style.css
@@ -87,10 +87,12 @@ code, pre {
pre {
display: block;
+/*
padding:8px 8px;
background: #f8f8f8;
border-radius:5px;
border:1px solid #e5e5e5;
+*/
overflow-x: auto;
}