Skip to content

Commit

Permalink
fix java type resolution for checked exception
Browse files Browse the repository at this point in the history
  • Loading branch information
neetopia committed Jan 17, 2024
1 parent 5083a96 commit e5e9e5d
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -898,7 +898,8 @@ class ResolverImpl(
return when (function.origin) {
Origin.JAVA -> {
val psi = (function as KSFunctionDeclarationJavaImpl).psi
psi.throwsList.referencedTypes.asSequence().map { getKSTypeCached(resolveJavaType(it)) }
psi.throwsList.referencedTypes.asSequence()
.map { KSTypeReferenceJavaImpl.getCached(it, function).resolve() }
}
Origin.KOTLIN -> {
extractThrowsAnnotation(function)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ class ResolverAAImpl(
val psi = (function as KSFunctionDeclarationImpl).ktFunctionSymbol.psi as PsiMethod
psi.throwsList.referencedTypes.asSequence().mapNotNull {
analyze {
it.resolve()?.qualifiedName?.let { getClassDeclarationByName(it)?.asStarProjectedType() }
it.asKtType(psi)?.let { KSTypeImpl.getCached(it) }
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ class ThrowListProcessor : AbstractTestProcessor() {
)
).toResult()
)
result.add(
resolver.getJvmCheckedException(
(
jlass.declarations.single {
it.simpleName.asString() == "method"
} as KSFunctionDeclaration
)
).toResult()
)
val propertyA = klass.declarations.single { it.simpleName.asString() == "a" } as KSPropertyDeclaration
result.add(resolver.getJvmCheckedException(propertyA.getter!!).toResult())
result.add(resolver.getJvmCheckedException(propertyA.setter!!).toResult())
Expand Down
3 changes: 3 additions & 0 deletions test-utils/testData/api/throwList.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
// EXPECTED:
// java.io.IOException,java.util.NoSuchElementException
// java.io.IOException,java.lang.IndexOutOfBoundsException
// ThrowsException.method.T
// java.io.IOException,java.util.NoSuchElementException
// java.lang.IndexOutOfBoundsException
// java.io.IOException
Expand Down Expand Up @@ -89,6 +90,8 @@ public class ThrowsException {
public int foo() throws IOException, IndexOutOfBoundsException{
return 1;
}

<T extends Throwable> void method() throws T {}
}
// FILE: a.kt
class ThrowsKt {
Expand Down

0 comments on commit e5e9e5d

Please # to comment.