Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -273,16 +273,13 @@ class KSClassDeclarationImpl private constructor(internal val ktClassOrObjectSym
return if ((origin == Origin.JAVA || origin == Origin.JAVA_LIB) && classKind != ClassKind.ANNOTATION_CLASS) {
decls.flatMap { decl ->
if (decl is KSPropertyDeclarationImpl && decl.ktPropertySymbol is KaSyntheticJavaPropertySymbol) {
sequenceOf(decl.getter, decl.setter).mapNotNull { accessor ->
KSFunctionDeclarationImpl.getCached(
(accessor as? KSPropertyAccessorImpl)?.ktPropertyAccessorSymbol
?: return@mapNotNull null
)
}
sequenceOf(decl.ktPropertySymbol.javaGetterSymbol, decl.ktPropertySymbol.javaSetterSymbol)
.filterNotNull()
.map { KSFunctionDeclarationImpl.getCached(it) }
} else {
sequenceOf(decl)
}
}
}.distinct()
} else decls
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ import org.jetbrains.kotlin.analysis.api.symbols.KaSymbolLocation
import org.jetbrains.kotlin.analysis.api.symbols.KaSymbolModality
import org.jetbrains.kotlin.analysis.api.symbols.KaSymbolOrigin
import org.jetbrains.kotlin.analysis.api.symbols.KaSymbolVisibility
import org.jetbrains.kotlin.analysis.api.symbols.KaSyntheticJavaPropertySymbol
import org.jetbrains.kotlin.analysis.api.symbols.contextParameters
import org.jetbrains.kotlin.analysis.api.symbols.name
import org.jetbrains.kotlin.analysis.api.symbols.receiverType
Expand Down Expand Up @@ -467,7 +468,7 @@ fun KaSession.findKaFunctionSymbol(psiMethod: PsiMethod, parentClass: KSClassDec
private fun KaSession.findKaPropertyAccessorSymbols(
psiMethod: PsiMethod,
parentClass: KSClassDeclarationImpl
): Sequence<KaPropertyAccessorSymbol> {
): Sequence<KaFunctionSymbol> {
val methodName = psiMethod.name
val namesToSearch = when {
// A standard Java getter like `getFoo()` overrides a Kotlin property named `foo` or `Foo`.
Expand Down Expand Up @@ -496,7 +497,13 @@ private fun KaSession.findKaPropertyAccessorSymbols(
return namesToSearch
.flatMap { parentClass.ktClassOrObjectSymbol.memberScope.callables(Name.identifier(it)) }
.filterIsInstance<KaPropertySymbol>()
.flatMap { sequenceOf(it.getter, it.setter) }
.flatMap {
if (it is KaSyntheticJavaPropertySymbol) {
sequenceOf(it.javaGetterSymbol, it.javaSetterSymbol)
} else {
sequenceOf(it.getter, it.setter)
}
}
.filterNotNull()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,6 @@ abstract class AAConfiguredUnitTestSuiteBase(
override fun testGroupedAnnotationsWithUseSiteTargets() {
runKSPTest("getSymbolsWithAnnotation/groupedAnnotationsWithUseSiteTargets.kt")
}

@TestMetadata("functionKindsJavaInheritsKotlin.kt")
@Test
override fun testFunctionKindsJavaInheritsKotlin() {
runThrowingKSPTest("functionKindsJavaInheritsKotlin.kt")
}

@TestMetadata("javaSubtypeOfKotlinInterface.kt")
@Test
override fun testJavaSubtypeOfKotlinInterface() {
runKSPTest("javaSubtypeOfKotlinInterface.kt")
}
}

class AAConfiguredDefaultFeaturesUnitTestSuite : AAConfiguredUnitTestSuiteBase(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -504,9 +504,12 @@ abstract class KSPUnitTestSuite(
runKSPTest("functionKinds.kt")
}

@Bug("https://github.com/google/ksp/issues/2496", BugState.OPEN)
@Bug("https://github.com/google/ksp/issues/2496", BugState.FIXED)
@TestMetadata("functionKindsJavaInheritsKotlin.kt")
abstract fun testFunctionKindsJavaInheritsKotlin()
@Test
fun testFunctionKindsJavaInheritsKotlin() {
runKSPTest("functionKindsJavaInheritsKotlin.kt")
}

@TestMetadata("getAnnotationByTypeWithInnerDefault.kt")
@Test
Expand Down Expand Up @@ -638,9 +641,12 @@ abstract class KSPUnitTestSuite(
runKSPTest("javaSubtype.kt")
}

@Bug("https://github.com/google/ksp/issues/2925", BugState.OPEN)
@Bug("https://github.com/google/ksp/issues/2925", BugState.FIXED)
@TestMetadata("javaSubtypeOfKotlinInterface.kt")
abstract fun testJavaSubtypeOfKotlinInterface()
@Test
fun testJavaSubtypeOfKotlinInterface() {
runKSPTest("javaSubtypeOfKotlinInterface.kt")
}

@TestMetadata("javaToKotlinMapper.kt")
@Test
Expand Down Expand Up @@ -840,11 +846,11 @@ abstract class KSPUnitTestSuite(
runKSPTest("parameterTypes.kt")
}

@Bug("https://github.com/google/ksp/issues/2498", BugState.OPEN)
@Bug("https://github.com/google/ksp/issues/2498", BugState.FIXED)
@TestMetadata("parentOfJavaMethodOverridingKotlinProperty.kt")
@Test
fun testParentOfJavaMethodOverridingKotlinProperty() {
runFailingKSPTest("parentOfJavaMethodOverridingKotlinProperty.kt")
runKSPTest("parentOfJavaMethodOverridingKotlinProperty.kt")
}

@TestMetadata("parent.kt")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,6 @@ abstract class PsiConfiguredUnitTestSuiteBase(
runKSPTest("getSymbolsWithAnnotation/negative/allUseSiteTargetAppliedToAnnotationList.kt")
}

@TestMetadata("functionKindsJavaInheritsKotlin.kt")
@Test
override fun testFunctionKindsJavaInheritsKotlin() {
runFailingKSPTest("functionKindsJavaInheritsKotlin.kt")
}

@TestMetadata("javaSubtypeOfKotlinInterface.kt")
@Test
override fun testJavaSubtypeOfKotlinInterface() {
runFailingKSPTest("javaSubtypeOfKotlinInterface.kt")
}

@TestMetadata("getSymbolsWithAnnotation/groupedAnnotationsWithUseSiteTargets.kt")
@Test
override fun testGroupedAnnotationsWithUseSiteTargets() {
Expand Down
15 changes: 9 additions & 6 deletions kotlin-analysis-api/testData/declarationsInClass.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
// CLASS: lib.CustomMap (JAVA_LIB)
// CLASS: lib.InterfaceWithNonObjectMethodOverrides (JAVA_LIB)
// CLASS: lib.InterfaceWithObjectMethodOverrides (JAVA_LIB)
// CLASS: lib.OverridesBaseWithCapitalizedProperties (JAVA_LIB)
// CLASS: lib.OverridesBaseWithIsProperties (JAVA_LIB)
// CLASS: lib.OverridesBaseWithProperties (JAVA_LIB)
// CLASS: lib.StaticVsMemberDeclarations (JAVA_LIB)
Expand All @@ -37,6 +38,7 @@
// CONSTRUCTOR: CustomMap.<init> (JAVA_LIB)
// CONSTRUCTOR: InnerC.<init> (JAVA_LIB)
// CONSTRUCTOR: NestedC.<init> (JAVA_LIB)
// CONSTRUCTOR: OverridesBaseWithCapitalizedProperties.<init> (JAVA_LIB)
// CONSTRUCTOR: OverridesBaseWithIsProperties.<init> (JAVA_LIB)
// CONSTRUCTOR: OverridesBaseWithProperties.<init> (JAVA_LIB)
// CONSTRUCTOR: StaticVsMemberDeclarations.<init> (JAVA_LIB)
Expand All @@ -48,14 +50,15 @@
// FUNCTION: ConcreteClassWithObjectMethodOverrides.toString (JAVA_LIB)
// FUNCTION: CustomList.get (JAVA_LIB)
// FUNCTION: CustomList.removeAt (JAVA_LIB)
// FUNCTION: CustomList.size (SYNTHETIC)
// FUNCTION: CustomMap.entrySet (SYNTHETIC)
// FUNCTION: CustomList.size (JAVA_LIB)
// FUNCTION: CustomMap.entrySet (JAVA_LIB)
// FUNCTION: InterfaceWithNonObjectMethodOverrides.equals (JAVA_LIB)
// FUNCTION: InterfaceWithNonObjectMethodOverrides.someMethod (JAVA_LIB)
// FUNCTION: OverridesBaseWithIsProperties.getFoo (SYNTHETIC)
// FUNCTION: OverridesBaseWithIsProperties.isBar (SYNTHETIC)
// FUNCTION: OverridesBaseWithProperties.getFoo (SYNTHETIC)
// FUNCTION: OverridesBaseWithProperties.getGetBar (SYNTHETIC)
// FUNCTION: OverridesBaseWithCapitalizedProperties.getFoo (JAVA_LIB)
// FUNCTION: OverridesBaseWithIsProperties.getFoo (JAVA_LIB)
// FUNCTION: OverridesBaseWithIsProperties.isBar (JAVA_LIB)
// FUNCTION: OverridesBaseWithProperties.getFoo (JAVA_LIB)
// FUNCTION: OverridesBaseWithProperties.getGetBar (JAVA_LIB)
// FUNCTION: OverridesBaseWithProperties.getNonProperty (JAVA_LIB)
// GETTER: BaseWithCapitalizedProperties.Foo (KOTLIN_LIB)
// GETTER: BaseWithIsProperties.foo (KOTLIN_LIB)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
// Declaration qualifiedName: MyInterface.Foo (Origin: KOTLIN)
// Declaration simpleName: getFoo
// Declaration qualifiedName: MyClass.getFoo (Origin: JAVA)
// Declaration simpleName: getFoo
// Declaration qualifiedName: MyClass.getFoo (Origin: SYNTHETIC)
// Declaration simpleName: <init>
// END

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,7 @@ class DeclarationsInClassProcessor(override val apiFeatures: ApiFeatures): Abstr
processDeclaration(resolver.getClassDeclarationByName("lib.BaseWithIsProperties")!!)
processDeclaration(resolver.getClassDeclarationByName("lib.OverridesBaseWithIsProperties")!!)
processDeclaration(resolver.getClassDeclarationByName("lib.BaseWithCapitalizedProperties")!!)
// TODO(https://github.com/google/ksp/issues/2925): Enable this once we've sorted out the differences between
// the AA and PSI implementations. Currently, the main issue is that for the case where a property is
// capitalized and a Java method overrides the getter, the AA implementation includes both the original Java
// method and the synthetic accessor method; whereas the PSI implementation only includes the original method.
// processDeclaration(resolver.getClassDeclarationByName("lib.OverridesBaseWithCapitalizedProperties")!!)
processDeclaration(resolver.getClassDeclarationByName("lib.OverridesBaseWithCapitalizedProperties")!!)
processDeclaration(resolver.getClassDeclarationByName("lib.StaticVsMemberDeclarations")!!)
return emptyList()
}
Expand Down
Loading