diff options
author | sebastian.sellmair <sebastian.sellmair@jetbrains.com> | 2020-07-18 12:18:59 +0200 |
---|---|---|
committer | Sebastian Sellmair <34319766+sellmair@users.noreply.github.com> | 2020-08-14 17:51:11 +0200 |
commit | eae1ce49d18c2978b49166ea502bf2c109a85504 (patch) | |
tree | 477f39e33f14c71042f06eecc938d6efaa95e66c /plugins/base/src/main/kotlin/translators | |
parent | 6c635551ed3ea0cfe5f04b54a98cb28225061d26 (diff) | |
download | dokka-eae1ce49d18c2978b49166ea502bf2c109a85504.tar.gz dokka-eae1ce49d18c2978b49166ea502bf2c109a85504.tar.bz2 dokka-eae1ce49d18c2978b49166ea502bf2c109a85504.zip |
Simplify Dokka Gradle Plugin
Diffstat (limited to 'plugins/base/src/main/kotlin/translators')
2 files changed, 45 insertions, 21 deletions
diff --git a/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt b/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt index c4c6483f..1ac4edf7 100644 --- a/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt +++ b/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt @@ -95,7 +95,7 @@ private class DokkaDescriptorVisitor( private fun Collection<DeclarationDescriptor>.filterDescriptorsInSourceSet() = filter { it.toSourceElement.containingFile.toString().let { path -> path.isNotBlank() && sourceSet.sourceRoots.any { root -> - Paths.get(path).startsWith(Paths.get(root.path)) + Paths.get(path).startsWith(root.directory.toPath()) } } } @@ -356,7 +356,8 @@ private class DokkaDescriptorVisitor( sources = actual, visibility = descriptor.visibility.toDokkaVisibility().toSourceSetDependent(), generics = descriptor.typeParameters.map { it.toTypeParameter() }, - documentation = descriptor.takeIf { it.kind != CallableMemberDescriptor.Kind.SYNTHESIZED }?.resolveDescriptorData() ?: emptyMap(), + documentation = descriptor.takeIf { it.kind != CallableMemberDescriptor.Kind.SYNTHESIZED } + ?.resolveDescriptorData() ?: emptyMap(), modifier = descriptor.modifier().toSourceSetDependent(), type = descriptor.returnType!!.toBound(), sourceSets = setOf(sourceSet), @@ -746,11 +747,19 @@ private class DokkaDescriptorVisitor( private data class InheritanceLevel(val level: Int, val superclass: DRI?, val interfaces: List<DRI>) - private data class ClassInfo(val inheritance: List<InheritanceLevel>, val docs: SourceSetDependent<DocumentationNode>){ + private data class ClassInfo( + val inheritance: List<InheritanceLevel>, + val docs: SourceSetDependent<DocumentationNode> + ) { val supertypes: List<DriWithKind> get() = inheritance.firstOrNull { it.level == 0 }?.let { - listOfNotNull(it.superclass?.let { DriWithKind(it, KotlinClassKindTypes.CLASS) }) + it.interfaces.map { DriWithKind(it, KotlinClassKindTypes.INTERFACE) } - }.orEmpty() + listOfNotNull(it.superclass?.let { + DriWithKind( + it, + KotlinClassKindTypes.CLASS + ) + }) + it.interfaces.map { DriWithKind(it, KotlinClassKindTypes.INTERFACE) } + }.orEmpty() val allImplementedInterfaces: List<DRI> get() = inheritance.flatMap { it.interfaces }.distinct() diff --git a/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt b/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt index 9ed37c30..cd43e635 100644 --- a/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt +++ b/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt @@ -43,8 +43,8 @@ class DefaultPsiToDocumentableTranslator( override fun invoke(sourceSet: DokkaSourceSet, context: DokkaContext): DModule { - fun isFileInSourceRoots(file: File) : Boolean { - return sourceSet.sourceRoots.any { root -> file.path.startsWith(File(root.path).absolutePath) } + fun isFileInSourceRoots(file: File): Boolean { + return sourceSet.sourceRoots.any { root -> file.startsWith(root.directory) } } val (environment, _) = kotlinAnalysis[sourceSet] @@ -133,7 +133,7 @@ class DefaultPsiToDocumentableTranslator( val superMethods = mutableListOf<Pair<PsiMethod, DRI>>() methods.forEach { superMethodsKeys.add(it.hash) } fun parseSupertypes(superTypes: Array<PsiClassType>, level: Int = 0) { - if(superTypes.isEmpty()) return + if (superTypes.isEmpty()) return val parsedClasses = superTypes.filter { !it.shouldBeIgnored }.mapNotNull { it.resolve()?.let { when { @@ -178,7 +178,8 @@ class DefaultPsiToDocumentableTranslator( }) + it.interfaces.map { DriWithKind(dri = it, kind = JavaClassKindTypes.INTERFACE) } }.toSourceSetDependent() val modifiers = getModifier().toSourceSetDependent() - val implementedInterfacesExtra = ImplementedInterfaces(inheritanceTree.flatMap { it.interfaces }.distinct().toSourceSetDependent()) + val implementedInterfacesExtra = + ImplementedInterfaces(inheritanceTree.flatMap { it.interfaces }.distinct().toSourceSetDependent()) return when { isAnnotationType -> DAnnotation( @@ -195,8 +196,11 @@ class DefaultPsiToDocumentableTranslator( constructors.map { parseFunction(it, true) }, mapTypeParameters(dri), setOf(sourceSetData), - PropertyContainer.withAll(implementedInterfacesExtra, annotations.toList().toListOfAnnotations().toSourceSetDependent() - .toAnnotations()) + PropertyContainer.withAll( + implementedInterfacesExtra, + annotations.toList().toListOfAnnotations().toSourceSetDependent() + .toAnnotations() + ) ) isEnum -> DEnum( dri, @@ -211,8 +215,11 @@ class DefaultPsiToDocumentableTranslator( emptyList(), emptyList(), setOf(sourceSetData), - PropertyContainer.withAll(implementedInterfacesExtra, annotations.toList().toListOfAnnotations().toSourceSetDependent() - .toAnnotations()) + PropertyContainer.withAll( + implementedInterfacesExtra, + annotations.toList().toListOfAnnotations().toSourceSetDependent() + .toAnnotations() + ) ) }, documentation, @@ -226,8 +233,10 @@ class DefaultPsiToDocumentableTranslator( constructors.map { parseFunction(it, true) }, ancestors, setOf(sourceSetData), - PropertyContainer.withAll(implementedInterfacesExtra, annotations.toList().toListOfAnnotations().toSourceSetDependent() - .toAnnotations()) + PropertyContainer.withAll( + implementedInterfacesExtra, annotations.toList().toListOfAnnotations().toSourceSetDependent() + .toAnnotations() + ) ) isInterface -> DInterface( dri, @@ -243,8 +252,10 @@ class DefaultPsiToDocumentableTranslator( mapTypeParameters(dri), ancestors, setOf(sourceSetData), - PropertyContainer.withAll(implementedInterfacesExtra, annotations.toList().toListOfAnnotations().toSourceSetDependent() - .toAnnotations()) + PropertyContainer.withAll( + implementedInterfacesExtra, annotations.toList().toListOfAnnotations().toSourceSetDependent() + .toAnnotations() + ) ) else -> DClass( dri, @@ -262,8 +273,10 @@ class DefaultPsiToDocumentableTranslator( null, modifiers, setOf(sourceSetData), - PropertyContainer.withAll(implementedInterfacesExtra, annotations.toList().toListOfAnnotations().toSourceSetDependent() - .toAnnotations()) + PropertyContainer.withAll( + implementedInterfacesExtra, annotations.toList().toListOfAnnotations().toSourceSetDependent() + .toAnnotations() + ) ) } } @@ -305,7 +318,8 @@ class DefaultPsiToDocumentableTranslator( PropertyContainer.withAll( InheritedFunction(inheritedFrom.toSourceSetDependent()), it.toSourceSetDependent().toAdditionalModifiers(), - (psi.annotations.toList().toListOfAnnotations() + it.toListOfAnnotations()).toSourceSetDependent() + (psi.annotations.toList() + .toListOfAnnotations() + it.toListOfAnnotations()).toSourceSetDependent() .toAnnotations() ) } @@ -434,7 +448,8 @@ class DefaultPsiToDocumentableTranslator( psi.additionalExtras().let { PropertyContainer.withAll<DProperty>( it.toSourceSetDependent().toAdditionalModifiers(), - (psi.annotations.toList().toListOfAnnotations() + it.toListOfAnnotations()).toSourceSetDependent() + (psi.annotations.toList() + .toListOfAnnotations() + it.toListOfAnnotations()).toSourceSetDependent() .toAnnotations() ) } |