diff options
author | Ilya Ryzhenkov <orangy@jetbrains.com> | 2014-07-11 20:07:35 +0400 |
---|---|---|
committer | Ilya Ryzhenkov <orangy@jetbrains.com> | 2014-07-11 20:07:35 +0400 |
commit | cc008898485627a805c8275dede9883529712cb9 (patch) | |
tree | f4759bbb7f751336b22755689971a27468eeca40 | |
parent | e4a6e2d908b285a3a92a65d99322f810fb5ff37d (diff) | |
download | dokka-cc008898485627a805c8275dede9883529712cb9.tar.gz dokka-cc008898485627a805c8275dede9883529712cb9.tar.bz2 dokka-cc008898485627a805c8275dede9883529712cb9.zip |
Process properties in classes without accessors
-rw-r--r-- | src/CompilerAPI.kt | 9 | ||||
-rw-r--r-- | src/DocumentationBuilder.kt | 13 | ||||
-rw-r--r-- | src/DocumentationBuildingVisitor.kt | 20 | ||||
-rw-r--r-- | src/DocumentationModel.kt | 1 | ||||
-rw-r--r-- | test/data/classes/classWithProperty.kt | 3 | ||||
-rw-r--r-- | test/src/ClassTest.kt | 41 |
6 files changed, 76 insertions, 11 deletions
diff --git a/src/CompilerAPI.kt b/src/CompilerAPI.kt index 756cd915..3429aeae 100644 --- a/src/CompilerAPI.kt +++ b/src/CompilerAPI.kt @@ -12,6 +12,7 @@ import com.intellij.psi.* import org.jetbrains.jet.lang.resolve.* import org.jetbrains.jet.lang.psi.* import org.jetbrains.jet.analyzer.* +import org.jetbrains.jet.lang.descriptors.* private fun getAnnotationsPath(paths: KotlinPaths, arguments: K2JVMCompilerArguments): MutableList<File> { val annotationsPath = arrayListOf<File>() @@ -51,3 +52,11 @@ private fun JetCoreEnvironment.analyze(messageCollector: MessageCollector): Bind fun AnalyzerWithCompilerReport.analyzeAndReport(files: List<JetFile>, analyser: () -> AnalyzeExhaust) = analyzeAndReport(analyser, files) fun BindingContext.getPackageFragment(file: JetFile) = get(BindingContext.FILE_TO_PACKAGE_FRAGMENT, file) + +fun DeclarationDescriptor.isUserCode() = + when (this) { + is PackageFragmentDescriptor -> false + is PropertyAccessorDescriptor -> !isDefault() + is CallableMemberDescriptor -> getKind() == CallableMemberDescriptor.Kind.DECLARATION + else -> true + } diff --git a/src/DocumentationBuilder.kt b/src/DocumentationBuilder.kt index 8b33e2b9..b82049a5 100644 --- a/src/DocumentationBuilder.kt +++ b/src/DocumentationBuilder.kt @@ -46,6 +46,19 @@ class DocumentationBuilderVisitor(val context : BindingContext) : DeclarationDes return node } + override fun visitPropertyDescriptor(descriptor: PropertyDescriptor?, data: DocumentationNode?): DocumentationNode? { + val doc = context.getDocumentation(descriptor!!).extractText() + val node = DocumentationNode(descriptor.getName().asString(), doc, DocumentationNodeKind.Property) + data?.addReferenceTo(node, DocumentationReferenceKind.Member) + return node + } + + override fun visitConstructorDescriptor(descriptor: ConstructorDescriptor?, data: DocumentationNode?): DocumentationNode? { + val doc = context.getDocumentation(descriptor!!).extractText() + val node = DocumentationNode(descriptor.getName().asString(), doc, DocumentationNodeKind.Constructor) + data?.addReferenceTo(node, DocumentationReferenceKind.Member) + return node + } override fun visitPackageFragmentDescriptor(descriptor: PackageFragmentDescriptor?, data: DocumentationNode?): DocumentationNode? { val node = DocumentationNode(descriptor!!.fqName.asString(), "", DocumentationNodeKind.Package) diff --git a/src/DocumentationBuildingVisitor.kt b/src/DocumentationBuildingVisitor.kt index f6a3156a..4f76ed0e 100644 --- a/src/DocumentationBuildingVisitor.kt +++ b/src/DocumentationBuildingVisitor.kt @@ -8,12 +8,14 @@ class DocumentationBuildingVisitor(private val worker: DeclarationDescriptorVisi private fun visitChildren(descriptors: Collection<DeclarationDescriptor>, data: DocumentationNode) { for (descriptor in descriptors) { - descriptor.accept(this, data) + if (descriptor.isUserCode()) + descriptor.accept(this, data) } } - private fun visitChildren(descriptor: DeclarationDescriptor?, data: DocumentationNode) { - descriptor?.accept(this, data) + private fun visitChild(descriptor: DeclarationDescriptor?, data: DocumentationNode) { + if (descriptor != null && descriptor.isUserCode()) + descriptor.accept(this, data) } private fun createDocumentation(descriptor: DeclarationDescriptor, data: DocumentationNode): DocumentationNode { @@ -23,7 +25,7 @@ class DocumentationBuildingVisitor(private val worker: DeclarationDescriptorVisi private fun processCallable(descriptor: CallableDescriptor, data: DocumentationNode): DocumentationNode { val node = createDocumentation(descriptor, data) visitChildren(descriptor.getTypeParameters(), node) - visitChildren(descriptor.getReceiverParameter(), node) + visitChild(descriptor.getReceiverParameter(), node) visitChildren(descriptor.getValueParameters(), node) return node } @@ -47,8 +49,8 @@ class DocumentationBuildingVisitor(private val worker: DeclarationDescriptorVisi public override fun visitPropertyDescriptor(descriptor: PropertyDescriptor?, data: DocumentationNode?): DocumentationNode? { val node = processCallable(descriptor!!, data!!) - visitChildren(descriptor.getGetter(), node) - visitChildren(descriptor.getSetter(), node) + visitChild(descriptor.getGetter(), node) + visitChild(descriptor.getSetter(), node) return node } @@ -66,9 +68,9 @@ class DocumentationBuildingVisitor(private val worker: DeclarationDescriptorVisi val node = createDocumentation(descriptor!!, data!!) visitChildren(descriptor.getConstructors(), node) visitChildren(descriptor.getTypeConstructor().getParameters(), node) - visitChildren(descriptor.getClassObjectDescriptor(), node) + visitChild(descriptor.getClassObjectDescriptor(), node) val members = descriptor.getDefaultType().getMemberScope().getAllDescriptors().filter { - it !is CallableMemberDescriptor || it.getKind().isReal() + it !is CallableMemberDescriptor || it.isUserCode() } visitChildren(members, node) return node @@ -76,7 +78,7 @@ class DocumentationBuildingVisitor(private val worker: DeclarationDescriptorVisi public override fun visitModuleDeclaration(descriptor: ModuleDescriptor?, data: DocumentationNode?): DocumentationNode? { val node = createDocumentation(descriptor!!, data!!) - visitChildren(descriptor.getPackage(FqName.ROOT), node) + visitChild(descriptor.getPackage(FqName.ROOT), node) return node } diff --git a/src/DocumentationModel.kt b/src/DocumentationModel.kt index feddccde..048f3e4e 100644 --- a/src/DocumentationModel.kt +++ b/src/DocumentationModel.kt @@ -8,6 +8,7 @@ public enum class DocumentationNodeKind { Package Class + Constructor Function Property Parameter diff --git a/test/data/classes/classWithProperty.kt b/test/data/classes/classWithProperty.kt new file mode 100644 index 00000000..2a849572 --- /dev/null +++ b/test/data/classes/classWithProperty.kt @@ -0,0 +1,3 @@ +class Klass { + val name: String = "" +}
\ No newline at end of file diff --git a/test/src/ClassTest.kt b/test/src/ClassTest.kt index 348e74d4..328cc358 100644 --- a/test/src/ClassTest.kt +++ b/test/src/ClassTest.kt @@ -31,13 +31,18 @@ public class ClassTest { with(members.elementAt(0)) { assertEquals("<init>", name) assertEquals("", doc) + assertEquals(DocumentationNodeKind.Constructor, kind) assertEquals(1, details.count()) with(details.elementAt(0)) { assertEquals("name", name) + assertEquals(DocumentationNodeKind.Parameter, kind) assertEquals("", doc) + assertTrue(details.none()) + assertTrue(links.none()) + assertTrue(members.none()) } - assertTrue(members.none()) assertTrue(links.none()) + assertTrue(members.none()) } } } @@ -56,13 +61,45 @@ public class ClassTest { with(members.elementAt(0)) { assertEquals("<init>", name) assertEquals("", doc) + assertEquals(DocumentationNodeKind.Constructor, kind) assertTrue(details.none()) - assertTrue(members.none()) assertTrue(links.none()) + assertTrue(members.none()) } with(members.elementAt(1)) { assertEquals("fn", name) assertEquals("", doc) + assertEquals(DocumentationNodeKind.Function, kind) + assertTrue(details.none()) + assertTrue(links.none()) + assertTrue(members.none()) + } + } + } + } + + Test fun classWithProperty() { + verifyModel("test/data/classes/classWithProperty.kt") { model -> + with(model.nodes.single().members.single()) { + assertEquals(DocumentationNodeKind.Class, kind) + assertEquals("Klass", name) + assertEquals("", doc) + assertTrue(details.none()) + assertTrue(links.none()) + + assertEquals(2, members.count()) + with(members.elementAt(0)) { + assertEquals("<init>", name) + assertEquals("", doc) + assertEquals(DocumentationNodeKind.Constructor, kind) + assertTrue(details.none()) + assertTrue(members.none()) + assertTrue(links.none()) + } + with(members.elementAt(1)) { + assertEquals("name", name) + assertEquals("", doc) + assertEquals(DocumentationNodeKind.Property, kind) assertTrue(details.none()) assertTrue(members.none()) assertTrue(links.none()) |