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">
|
<fileset dir="${basedir}/kdoc/target">
|
||||||
<include name="**/*.jar"/>
|
<include name="**/*.jar"/>
|
||||||
</fileset>
|
</fileset>
|
||||||
|
|
||||||
|
<!-- TODO Dirty Hack until kdoc jar has stdlib inside it -->
|
||||||
|
<pathelement location="${output}/classes/stdlib"/>
|
||||||
</classpath>
|
</classpath>
|
||||||
<arg value="-src"/>
|
<arg value="-src"/>
|
||||||
<arg value="${basedir}/stdlib/ktSrc"/>
|
<arg value="${basedir}/stdlib/ktSrc"/>
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import org.jetbrains.jet.lang.descriptors.NamespaceDescriptor
|
|||||||
import java.util.HashSet
|
import java.util.HashSet
|
||||||
import com.intellij.psi.PsiElement
|
import com.intellij.psi.PsiElement
|
||||||
import org.jetbrains.jet.lexer.JetTokens
|
import org.jetbrains.jet.lexer.JetTokens
|
||||||
|
import org.jetbrains.jet.lang.descriptors.ClassDescriptor
|
||||||
|
|
||||||
class KDoc(val outputDir: File) : KDocSupport() {
|
class KDoc(val outputDir: File) : KDocSupport() {
|
||||||
val model = KModel()
|
val model = KModel()
|
||||||
@@ -36,17 +37,26 @@ class KDoc(val outputDir: File) : KDocSupport() {
|
|||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
override fun generate() {
|
override fun addClass(namespace: NamespaceDescriptor?, classElement: ClassDescriptor?) {
|
||||||
for (classElement in allClasses) {
|
if (namespace != null && classElement != null) {
|
||||||
if (classElement != null) {
|
//val docComment = getDocCommentFor(classElement.sure()) ?: "";
|
||||||
//val docComment = getDocCommentFor(classElement.sure()) ?: "";
|
val name = classElement.getName()
|
||||||
val name = classElement?.getName()
|
val namespaceName = namespace.getName() ?: ""
|
||||||
if (name != null) {
|
val pkg = model.getPackage(namespaceName)
|
||||||
println("Found class: ${name}")
|
if (name != null) {
|
||||||
//model.getClass(name)
|
println("Found namespace ${namespaceName} class: ${name}")
|
||||||
}
|
pkg.getClass(name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun generate() {
|
||||||
|
/*
|
||||||
|
for (classElement in allClasses) {
|
||||||
|
if (classElement != null) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
if (!model.packages.isEmpty()) {
|
if (!model.packages.isEmpty()) {
|
||||||
val generator = KDocGenerator(model, outputDir)
|
val generator = KDocGenerator(model, outputDir)
|
||||||
generator.execute()
|
generator.execute()
|
||||||
@@ -63,6 +73,7 @@ class KDoc(val outputDir: File) : KDocSupport() {
|
|||||||
if (node?.getElementType() != JetTokens.DOC_COMMENT) return null;
|
if (node?.getElementType() != JetTokens.DOC_COMMENT) return null;
|
||||||
return node?.getText();
|
return node?.getText();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class KDocGenerator(val model: KModel, val outputDir: File) {
|
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...
|
* TODO This class is written in Java for now to work around a few gremlins in Kotlin...
|
||||||
*/
|
*/
|
||||||
public abstract class KDocSupport implements CompilerPlugin {
|
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) {
|
public void processFiles(BindingContext context, List<JetFile> sources) {
|
||||||
|
Set<NamespaceDescriptor> allNamespaces = new HashSet<NamespaceDescriptor>();
|
||||||
for (JetFile source : sources) {
|
for (JetFile source : sources) {
|
||||||
// We retrieve a descriptor by a PSI element from the context
|
// We retrieve a descriptor by a PSI element from the context
|
||||||
NamespaceDescriptor namespaceDescriptor = context.get(BindingContext.NAMESPACE, source);
|
NamespaceDescriptor namespaceDescriptor = context.get(BindingContext.NAMESPACE, source);
|
||||||
@@ -45,29 +43,19 @@ public abstract class KDocSupport implements CompilerPlugin {
|
|||||||
allNamespaces.add(namespaceDescriptor);
|
allNamespaces.add(namespaceDescriptor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (NamespaceDescriptor namespace : allNamespaces) {
|
for (NamespaceDescriptor namespace : allNamespaces) {
|
||||||
// Let's take all the declarations in the namespace...
|
// Let's take all the declarations in the namespace...
|
||||||
processDescriptors(namespace.getMemberScope().getAllDescriptors(), context);
|
processDescriptors(namespace, namespace.getMemberScope().getAllDescriptors(), context);
|
||||||
}
|
}
|
||||||
|
|
||||||
generate();
|
generate();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract void 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) {
|
for (DeclarationDescriptor descriptor : allDescriptors) {
|
||||||
PsiElement classElement = context.get(BindingContext.DESCRIPTOR_TO_DECLARATION, descriptor);
|
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)
|
// Print the class header (verbose)
|
||||||
System.out.println(DescriptorRenderer.TEXT.render(descriptor));
|
System.out.println(DescriptorRenderer.TEXT.render(descriptor));
|
||||||
*/
|
*/
|
||||||
@@ -75,10 +63,12 @@ public abstract class KDocSupport implements CompilerPlugin {
|
|||||||
if (descriptor instanceof ClassDescriptor) {
|
if (descriptor instanceof ClassDescriptor) {
|
||||||
ClassDescriptor classDescriptor = (ClassDescriptor) descriptor;
|
ClassDescriptor classDescriptor = (ClassDescriptor) descriptor;
|
||||||
if (classElement != null) {
|
if (classElement != null) {
|
||||||
allClasses.add(classDescriptor);
|
addClass(namespace, classDescriptor);
|
||||||
}
|
}
|
||||||
//processDescriptors(classDescriptor.getDefaultType().getMemberScope().getAllDescriptors(), context);
|
//processDescriptors(classDescriptor.getDefaultType().getMemberScope().getAllDescriptors(), context);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected abstract void addClass(NamespaceDescriptor namespace, ClassDescriptor classDescriptor);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user