really simple implementation of kdoc that lets us navigate the packages and classes at least (though the package name is not correct :)
This commit is contained in:
@@ -71,6 +71,9 @@
|
||||
<fileset dir="${basedir}/kdoc/target">
|
||||
<include name="**/*.jar"/>
|
||||
</fileset>
|
||||
|
||||
<!-- TODO Dirty Hack until kdoc jar has stdlib inside it -->
|
||||
<pathelement location="${output}/classes/stdlib"/>
|
||||
</classpath>
|
||||
<arg value="-src"/>
|
||||
<arg value="${basedir}/stdlib/ktSrc"/>
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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<NamespaceDescriptor> allNamespaces = new HashSet<NamespaceDescriptor>();
|
||||
protected Set<ClassDescriptor> allClasses = new HashSet<ClassDescriptor>();
|
||||
|
||||
public void processFiles(BindingContext context, List<JetFile> sources) {
|
||||
Set<NamespaceDescriptor> allNamespaces = new HashSet<NamespaceDescriptor>();
|
||||
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<DeclarationDescriptor> allDescriptors, BindingContext context) {
|
||||
private void processDescriptors(NamespaceDescriptor namespace, Collection<DeclarationDescriptor> 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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user