From 19a67c8edf643302d12437f7fbe89e5a97ccb293 Mon Sep 17 00:00:00 2001 From: James Strachan Date: Wed, 22 Feb 2012 14:02:28 +0000 Subject: [PATCH] really simple implementation of kdoc that lets us navigate the packages and classes at least (though the package name is not correct :) --- build.xml | 3 ++ .../kotlin/org/jetbrains/kotlin/doc/KDoc.kt | 29 +++++++++++++------ .../org/jetbrains/kotlin/doc/KDocSupport.java | 22 ++++---------- 3 files changed, 29 insertions(+), 25 deletions(-) diff --git a/build.xml b/build.xml index 6a2a51b6aaf..84c4c0bdae4 100644 --- a/build.xml +++ b/build.xml @@ -71,6 +71,9 @@ + + + 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 af5429a2d71..ffb19457bca 100644 --- a/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/KDoc.kt +++ b/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/KDoc.kt @@ -13,6 +13,7 @@ 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 class KDoc(val outputDir: File) : KDocSupport() { val model = KModel() @@ -36,17 +37,26 @@ class KDoc(val outputDir: File) : KDocSupport() { } */ - override fun generate() { - for (classElement in allClasses) { - if (classElement != null) { - //val docComment = getDocCommentFor(classElement.sure()) ?: ""; - val name = classElement?.getName() - if (name != null) { - println("Found class: ${name}") - //model.getClass(name) - } + override fun addClass(namespace: NamespaceDescriptor?, classElement: ClassDescriptor?) { + if (namespace != null && classElement != null) { + //val docComment = getDocCommentFor(classElement.sure()) ?: ""; + val name = classElement.getName() + val namespaceName = namespace.getName() ?: "" + val pkg = model.getPackage(namespaceName) + if (name != null) { + println("Found namespace ${namespaceName} class: ${name}") + pkg.getClass(name) } } + } + + override fun generate() { + /* + for (classElement in allClasses) { + if (classElement != null) { + } + } + */ if (!model.packages.isEmpty()) { val generator = KDocGenerator(model, outputDir) generator.execute() @@ -63,6 +73,7 @@ class KDoc(val outputDir: File) : KDocSupport() { if (node?.getElementType() != JetTokens.DOC_COMMENT) return null; return node?.getText(); } + } class KDocGenerator(val model: KModel, val outputDir: File) { diff --git a/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/KDocSupport.java b/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/KDocSupport.java index 8944f5877a2..728fbeb706c 100644 --- a/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/KDocSupport.java +++ b/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/KDocSupport.java @@ -34,10 +34,8 @@ import java.util.Set; * TODO This class is written in Java for now to work around a few gremlins in Kotlin... */ public abstract class KDocSupport implements CompilerPlugin { - protected Set allNamespaces = new HashSet(); - protected Set allClasses = new HashSet(); - public void processFiles(BindingContext context, List sources) { + Set allNamespaces = new HashSet(); for (JetFile source : sources) { // We retrieve a descriptor by a PSI element from the context NamespaceDescriptor namespaceDescriptor = context.get(BindingContext.NAMESPACE, source); @@ -45,29 +43,19 @@ public abstract class KDocSupport implements CompilerPlugin { allNamespaces.add(namespaceDescriptor); } } - for (NamespaceDescriptor namespace : allNamespaces) { // Let's take all the declarations in the namespace... - processDescriptors(namespace.getMemberScope().getAllDescriptors(), context); + processDescriptors(namespace, namespace.getMemberScope().getAllDescriptors(), context); } - generate(); } protected abstract void generate(); - private void processDescriptors(Collection allDescriptors, BindingContext context) { + private void processDescriptors(NamespaceDescriptor namespace, Collection allDescriptors, BindingContext context) { for (DeclarationDescriptor descriptor : allDescriptors) { PsiElement classElement = context.get(BindingContext.DESCRIPTOR_TO_DECLARATION, descriptor); /* - // Print the doc comment text - String docComment = getDocCommentFor(classElement); - if (docComment != null) { - System.out.println("Docs for " + descriptor.getName() + ": " + docComment); - } - else { - System.out.println("No docs for " + descriptor.getName()); - } // Print the class header (verbose) System.out.println(DescriptorRenderer.TEXT.render(descriptor)); */ @@ -75,10 +63,12 @@ public abstract class KDocSupport implements CompilerPlugin { if (descriptor instanceof ClassDescriptor) { ClassDescriptor classDescriptor = (ClassDescriptor) descriptor; if (classElement != null) { - allClasses.add(classDescriptor); + addClass(namespace, classDescriptor); } //processDescriptors(classDescriptor.getDefaultType().getMemberScope().getAllDescriptors(), context); } } } + + protected abstract void addClass(NamespaceDescriptor namespace, ClassDescriptor classDescriptor); }