Skip to content

Commit

Permalink
Store checked exceptions into ExtraProperties (#2222)
Browse files Browse the repository at this point in the history
  • Loading branch information
vmishenev authored Nov 12, 2021
1 parent 4a1b8a9 commit 0303fa8
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 2 deletions.
20 changes: 20 additions & 0 deletions core/api/core.api
Original file line number Diff line number Diff line change
Expand Up @@ -732,6 +732,26 @@ public abstract interface class org/jetbrains/dokka/model/Callable : org/jetbrai
public abstract fun getReceiver ()Lorg/jetbrains/dokka/model/DParameter;
}

public final class org/jetbrains/dokka/model/CheckedExceptions : org/jetbrains/dokka/model/properties/ExtraProperty, org/jetbrains/dokka/model/properties/ExtraProperty$Key {
public static final field Companion Lorg/jetbrains/dokka/model/CheckedExceptions$Companion;
public fun <init> (Ljava/util/Map;)V
public final fun component1 ()Ljava/util/Map;
public final fun copy (Ljava/util/Map;)Lorg/jetbrains/dokka/model/CheckedExceptions;
public static synthetic fun copy$default (Lorg/jetbrains/dokka/model/CheckedExceptions;Ljava/util/Map;ILjava/lang/Object;)Lorg/jetbrains/dokka/model/CheckedExceptions;
public fun equals (Ljava/lang/Object;)Z
public final fun getExceptions ()Ljava/util/Map;
public fun getKey ()Lorg/jetbrains/dokka/model/properties/ExtraProperty$Key;
public fun hashCode ()I
public synthetic fun mergeStrategyFor (Ljava/lang/Object;Ljava/lang/Object;)Lorg/jetbrains/dokka/model/properties/MergeStrategy;
public fun mergeStrategyFor (Lorg/jetbrains/dokka/model/ObviousMember;Lorg/jetbrains/dokka/model/ObviousMember;)Lorg/jetbrains/dokka/model/properties/MergeStrategy;
public fun toString ()Ljava/lang/String;
}

public final class org/jetbrains/dokka/model/CheckedExceptions$Companion : org/jetbrains/dokka/model/properties/ExtraProperty$Key {
public synthetic fun mergeStrategyFor (Ljava/lang/Object;Ljava/lang/Object;)Lorg/jetbrains/dokka/model/properties/MergeStrategy;
public fun mergeStrategyFor (Lorg/jetbrains/dokka/model/CheckedExceptions;Lorg/jetbrains/dokka/model/CheckedExceptions;)Lorg/jetbrains/dokka/model/properties/MergeStrategy$Replace;
}

public abstract interface class org/jetbrains/dokka/model/ClassKind {
}

Expand Down
10 changes: 9 additions & 1 deletion core/src/main/kotlin/model/documentableProperties.kt
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,12 @@ data class ExceptionInSupertypes(val exceptions: SourceSetDependent<List<TypeCon

object ObviousMember : ExtraProperty<Documentable>, ExtraProperty.Key<Documentable, ObviousMember> {
override val key: ExtraProperty.Key<Documentable, *> = this
}
}

data class CheckedExceptions(val exceptions: SourceSetDependent<List<DRI>>) : ExtraProperty<Documentable>, ExtraProperty.Key<Documentable, ObviousMember> {
companion object : ExtraProperty.Key<Documentable, CheckedExceptions> {
override fun mergeStrategyFor(left: CheckedExceptions, right: CheckedExceptions) =
MergeStrategy.Replace(CheckedExceptions(left.exceptions + right.exceptions))
}
override val key: ExtraProperty.Key<Documentable, *> = CheckedExceptions
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ import org.jetbrains.kotlin.psi.psiUtil.getChildOfType
import org.jetbrains.kotlin.resolve.DescriptorUtils
import org.jetbrains.kotlin.utils.KotlinExceptionWithAttachments
import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstance
import org.jetbrains.kotlin.utils.addToStdlib.ifNotEmpty
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
import java.io.File

Expand Down Expand Up @@ -403,12 +404,16 @@ class DefaultPsiToDocumentableTranslator(
(psi.annotations.toList()
.toListOfAnnotations() + it.toListOfAnnotations()).toSourceSetDependent()
.toAnnotations(),
ObviousMember.takeIf { inheritedFrom != null && inheritedFrom.isObvious }
ObviousMember.takeIf { inheritedFrom != null && inheritedFrom.isObvious },
psi.throwsList.toDriList().takeIf { it.isNotEmpty() }
?.let { CheckedExceptions(it.toSourceSetDependent()) }
)
}
)
}

private fun PsiReferenceList.toDriList() = referenceElements.mapNotNull { it?.resolve()?.let { DRI.from(it) } }

private fun PsiModifierListOwner.additionalExtras() = listOfNotNull(
ExtraModifiers.JavaOnlyModifiers.Static.takeIf { hasModifier(JvmModifier.STATIC) },
ExtraModifiers.JavaOnlyModifiers.Native.takeIf { hasModifier(JvmModifier.NATIVE) },
Expand Down
21 changes: 21 additions & 0 deletions plugins/base/src/test/kotlin/model/JavaTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,27 @@ class JavaTest : AbstractModelTest("/src/main/kotlin/java/Test.java", "java") {
}
}

@Test
fun throwsList() {
inlineModelTest(
"""
|class C {
| public void foo() throws java.io.IOException, ArithmeticException {}
|}
""", configuration = configuration
) {
with((this / "java" / "C" / "foo").cast<DFunction>()) {
with(extra[CheckedExceptions]?.exceptions?.entries?.single()?.value.assertNotNull("CheckedExceptions")) {
this counts 2
first().packageName equals "java.io"
first().classNames equals "IOException"
get(1).packageName equals "java.lang"
get(1).classNames equals "ArithmeticException"
}
}
}
}

@Test
fun annotatedAnnotation() {
inlineModelTest(
Expand Down

0 comments on commit 0303fa8

Please sign in to comment.