diff options
author | Jiaxiang Chen <jiaxiang@google.com> | 2023-01-06 16:10:43 -0800 |
---|---|---|
committer | Jiaxiang Chen <roaringacw@gmail.com> | 2023-01-06 23:44:30 -0800 |
commit | b51373ac31c307afb68aca3d0d80acaa2f46d17a (patch) | |
tree | 74ef3af93c4b8fed72673e8bb67b75c71c10fd03 /test-utils | |
parent | 0aaa7a5ab6ec21179a0c682e962ecd9b75f393a2 (diff) | |
download | ksp-b51373ac31c307afb68aca3d0d80acaa2f46d17a.tar.gz |
Use correct psi implementation for finding type parameter declaration.
Fixes #1210.
Diffstat (limited to 'test-utils')
3 files changed, 54 insertions, 1 deletions
diff --git a/test-utils/src/main/kotlin/com/google/devtools/ksp/processor/TypeParameterEqualsProcessor.kt b/test-utils/src/main/kotlin/com/google/devtools/ksp/processor/TypeParameterEqualsProcessor.kt new file mode 100644 index 00000000..b7fa16cb --- /dev/null +++ b/test-utils/src/main/kotlin/com/google/devtools/ksp/processor/TypeParameterEqualsProcessor.kt @@ -0,0 +1,22 @@ +package com.google.devtools.ksp.processor + +import com.google.devtools.ksp.getClassDeclarationByName +import com.google.devtools.ksp.getDeclaredProperties +import com.google.devtools.ksp.processing.Resolver +import com.google.devtools.ksp.symbol.KSAnnotated + +class TypeParameterEqualsProcessor : AbstractTestProcessor() { + val result = mutableListOf<Boolean>() + + override fun toResult(): List<String> { + return result.map { it.toString() } + } + + override fun process(resolver: Resolver): List<KSAnnotated> { + val foo = resolver.getClassDeclarationByName("Foo")!! + val i = resolver.getClassDeclarationByName("I")!! + result.add(foo.typeParameters.first() == foo.getDeclaredProperties().first().type.resolve().declaration) + result.add(i.typeParameters[0] == i.typeParameters[1].bounds.single().resolve().declaration) + return emptyList() + } +} diff --git a/test-utils/testData/api/libOrigins.kt b/test-utils/testData/api/libOrigins.kt index 983c63fe..91141a30 100644 --- a/test-utils/testData/api/libOrigins.kt +++ b/test-utils/testData/api/libOrigins.kt @@ -110,7 +110,6 @@ // classifier ref: T4: JAVA // classifier ref: T4: JAVA // declaration: <init>: KOTLIN -// declaration: T3: KOTLIN // declaration: foo.bar.Anno1.<init>: KOTLIN_LIB // declaration: foo.bar.Anno1: KOTLIN_LIB // declaration: foo.bar.Anno2.<init>: KOTLIN_LIB @@ -143,6 +142,7 @@ // declaration: foo.bar.KotlinLibClass.p2: KOTLIN_LIB // declaration: foo.bar.KotlinLibClass.p3: KOTLIN_LIB // declaration: foo.bar.KotlinLibClass: KOTLIN_LIB +// declaration: foo.bar.KotlinSrcClass.T3: KOTLIN // declaration: foo.bar.KotlinSrcClass.g1: KOTLIN // declaration: foo.bar.KotlinSrcClass.g2: KOTLIN // declaration: foo.bar.KotlinSrcClass.g3: KOTLIN diff --git a/test-utils/testData/api/typeParameterEquals.kt b/test-utils/testData/api/typeParameterEquals.kt new file mode 100644 index 00000000..93060cb7 --- /dev/null +++ b/test-utils/testData/api/typeParameterEquals.kt @@ -0,0 +1,31 @@ +/* + * Copyright 2022 Google LLC + * Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// TEST PROCESSOR: TypeParameterEqualsProcessor +// EXPECTED: +// true +// true +// END + + +// FILE: a.kt + +interface Foo<T> { + val t: T +} + +interface I<T, K: T> |