diff --git a/common-util/build.gradle.kts b/common-util/build.gradle.kts index 97663404a9..85f22c714d 100644 --- a/common-util/build.gradle.kts +++ b/common-util/build.gradle.kts @@ -4,7 +4,6 @@ evaluationDependsOn(":api") description = "Kotlin Symbol Processing Util" -val kotlinBaseVersion: String by project val intellijVersion: String by project val junitVersion: String by project @@ -34,10 +33,6 @@ dependencies { implementation("$it:$intellijVersion") { isTransitive = false } } - implementation(kotlin("stdlib", kotlinBaseVersion)) - - compileOnly("org.jetbrains.kotlin:kotlin-compiler:$kotlinBaseVersion") - implementation(project(":api")) testImplementation("junit:junit:$junitVersion") } diff --git a/common-util/src/main/kotlin/com/google/devtools/ksp/KSPUtils.kt b/common-util/src/main/kotlin/com/google/devtools/ksp/KSPUtils.kt index 72d1192360..73163e3415 100644 --- a/common-util/src/main/kotlin/com/google/devtools/ksp/KSPUtils.kt +++ b/common-util/src/main/kotlin/com/google/devtools/ksp/KSPUtils.kt @@ -1,9 +1,7 @@ package com.google.devtools.ksp -import com.google.devtools.ksp.processing.impl.KSNameImpl import com.google.devtools.ksp.symbol.KSAnnotated import com.google.devtools.ksp.symbol.KSType -import org.jetbrains.kotlin.name.ClassId class IdKey(private val k: T) { override fun equals(other: Any?): Boolean = if (other is IdKey<*>) k === other.k else false @@ -22,8 +20,6 @@ class IdKeyTriple(private val k1: T, private val k2: P, private val k3: override fun hashCode(): Int = k1.hashCode() * 31 * 31 + k2.hashCode() * 31 + k3.hashCode() } -fun ClassId.toKSName() = KSNameImpl.getCached(asSingleFqName().toString()) - @SuppressWarnings("UNCHECKED_CAST") fun extractThrowsAnnotation(annotated: KSAnnotated): Sequence { return annotated.annotations diff --git a/common-util/src/main/kotlin/com/google/devtools/ksp/PsiUtils.kt b/common-util/src/main/kotlin/com/google/devtools/ksp/PsiUtils.kt index 9003a7feda..286947c680 100644 --- a/common-util/src/main/kotlin/com/google/devtools/ksp/PsiUtils.kt +++ b/common-util/src/main/kotlin/com/google/devtools/ksp/PsiUtils.kt @@ -20,19 +20,10 @@ package com.google.devtools.ksp import com.google.devtools.ksp.symbol.* import com.intellij.lang.jvm.JvmModifier import com.intellij.openapi.project.Project -import com.intellij.psi.PsiComment import com.intellij.psi.PsiDocumentManager import com.intellij.psi.PsiElement import com.intellij.psi.PsiFile import com.intellij.psi.PsiModifierListOwner -import org.jetbrains.kotlin.lexer.KtTokens -import org.jetbrains.kotlin.psi.KtClass -import org.jetbrains.kotlin.psi.KtClassOrObject -import org.jetbrains.kotlin.psi.KtEnumEntry -import org.jetbrains.kotlin.psi.KtModifierList -import org.jetbrains.kotlin.psi.KtModifierListOwner -import org.jetbrains.kotlin.psi.KtObjectDeclaration -import org.jetbrains.kotlin.psi.psiUtil.siblings val jvmModifierMap = mapOf( JvmModifier.PUBLIC to Modifier.PUBLIC, @@ -63,57 +54,6 @@ val javaModifiers = setOf( Modifier.PUBLIC, ) -val modifierMap = mapOf( - KtTokens.PUBLIC_KEYWORD to Modifier.PUBLIC, - KtTokens.PRIVATE_KEYWORD to Modifier.PRIVATE, - KtTokens.INTERNAL_KEYWORD to Modifier.INTERNAL, - KtTokens.PROTECTED_KEYWORD to Modifier.PROTECTED, - KtTokens.IN_KEYWORD to Modifier.IN, - KtTokens.OUT_KEYWORD to Modifier.OUT, - KtTokens.OVERRIDE_KEYWORD to Modifier.OVERRIDE, - KtTokens.LATEINIT_KEYWORD to Modifier.LATEINIT, - KtTokens.ENUM_KEYWORD to Modifier.ENUM, - KtTokens.SEALED_KEYWORD to Modifier.SEALED, - KtTokens.ANNOTATION_KEYWORD to Modifier.ANNOTATION, - KtTokens.DATA_KEYWORD to Modifier.DATA, - KtTokens.INNER_KEYWORD to Modifier.INNER, - KtTokens.FUN_KEYWORD to Modifier.FUN, - KtTokens.VALUE_KEYWORD to Modifier.VALUE, - KtTokens.SUSPEND_KEYWORD to Modifier.SUSPEND, - KtTokens.TAILREC_KEYWORD to Modifier.TAILREC, - KtTokens.OPERATOR_KEYWORD to Modifier.OPERATOR, - KtTokens.INFIX_KEYWORD to Modifier.INFIX, - KtTokens.INLINE_KEYWORD to Modifier.INLINE, - KtTokens.EXTERNAL_KEYWORD to Modifier.EXTERNAL, - KtTokens.ABSTRACT_KEYWORD to Modifier.ABSTRACT, - KtTokens.FINAL_KEYWORD to Modifier.FINAL, - KtTokens.OPEN_KEYWORD to Modifier.OPEN, - KtTokens.VARARG_KEYWORD to Modifier.VARARG, - KtTokens.NOINLINE_KEYWORD to Modifier.NOINLINE, - KtTokens.CROSSINLINE_KEYWORD to Modifier.CROSSINLINE, - KtTokens.REIFIED_KEYWORD to Modifier.REIFIED, - KtTokens.EXPECT_KEYWORD to Modifier.EXPECT, - KtTokens.ACTUAL_KEYWORD to Modifier.ACTUAL, - KtTokens.CONST_KEYWORD to Modifier.CONST -) - -fun KtModifierList?.toKSModifiers(): Set { - if (this == null) - return emptySet() - val modifiers = mutableSetOf() - modifiers.addAll( - modifierMap.entries - .filter { hasModifier(it.key) } - .map { it.value } - ) - return modifiers -} - -fun KtModifierListOwner.toKSModifiers(): Set { - val modifierList = this.modifierList - return modifierList.toKSModifiers() -} - fun PsiModifierListOwner.toKSModifiers(): Set { val modifiers = mutableSetOf() modifiers.addAll( @@ -145,25 +85,6 @@ private fun parseDocString(raw: String): String? { } } -fun PsiElement.getDocString(): String? = - this.firstChild.siblings().firstOrNull { it is PsiComment }?.let { - parseDocString(it.text) - } - -fun KtClassOrObject.getClassType(): ClassKind { - return when (this) { - is KtObjectDeclaration -> ClassKind.OBJECT - is KtEnumEntry -> ClassKind.ENUM_ENTRY - is KtClass -> when { - this.isEnum() -> ClassKind.ENUM_CLASS - this.isInterface() -> ClassKind.INTERFACE - this.isAnnotation() -> ClassKind.ANNOTATION_CLASS - else -> ClassKind.CLASS - } - else -> throw IllegalStateException("Unexpected psi type ${this.javaClass}, $ExceptionMessage") - } -} - inline fun PsiElement.findParentOfType(): T? { var parent = this.parent while (parent != null && parent !is T) { diff --git a/compiler-plugin/build.gradle.kts b/compiler-plugin/build.gradle.kts index bb7299b20c..b94e74932d 100644 --- a/compiler-plugin/build.gradle.kts +++ b/compiler-plugin/build.gradle.kts @@ -1,4 +1,3 @@ -import com.google.devtools.ksp.RelativizingPathProvider import org.jetbrains.kotlin.gradle.tasks.KotlinCompile evaluationDependsOn(":common-util") @@ -7,12 +6,6 @@ description = "Kotlin Symbol Processing" val intellijVersion: String by project val kotlinBaseVersion: String by project -val junitVersion: String by project -val junit5Version: String by project -val junitPlatformVersion: String by project - -val libsForTesting by configurations.creating -val libsForTestingCommon by configurations.creating tasks.withType { compilerOptions.freeCompilerArgs.add("-Xjvm-default=all-compatibility") @@ -55,73 +48,6 @@ dependencies { implementation(project(":api")) implementation(project(":common-util")) - - testImplementation(kotlin("stdlib", kotlinBaseVersion)) - testImplementation("org.jetbrains.kotlin:kotlin-compiler:$kotlinBaseVersion") - testImplementation("org.jetbrains.kotlin:kotlin-compiler-internal-test-framework:$kotlinBaseVersion") - testImplementation("org.jetbrains.kotlin:kotlin-scripting-compiler:$kotlinBaseVersion") - - testImplementation("junit:junit:$junitVersion") - testImplementation("org.junit.jupiter:junit-jupiter-api:$junit5Version") - testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:$junit5Version") - testRuntimeOnly("org.junit.jupiter:junit-jupiter-params:$junit5Version") - testRuntimeOnly("org.junit.platform:junit-platform-suite:$junitPlatformVersion") - - testImplementation(project(":test-utils")) - - libsForTesting(kotlin("stdlib", kotlinBaseVersion)) - libsForTesting(kotlin("test", kotlinBaseVersion)) - libsForTesting(kotlin("script-runtime", kotlinBaseVersion)) - libsForTestingCommon(kotlin("stdlib-common", kotlinBaseVersion)) -} - -tasks.register("CopyLibsForTesting") { - from(configurations.get("libsForTesting")) - into("dist/kotlinc/lib") - val escaped = Regex.escape(kotlinBaseVersion) - rename("(.+)-$escaped\\.jar", "$1.jar") -} - -tasks.register("CopyLibsForTestingCommon") { - from(configurations.get("libsForTestingCommon")) - into("dist/common") - val escaped = Regex.escape(kotlinBaseVersion) - rename("(.+)-$escaped\\.jar", "$1.jar") -} - -fun Project.javaPluginConvention(): JavaPluginConvention = the() -val JavaPluginConvention.testSourceSet: SourceSet - get() = sourceSets.getByName("test") -val Project.testSourceSet: SourceSet - get() = javaPluginConvention().testSourceSet - -tasks.test { - dependsOn("CopyLibsForTesting") - dependsOn("CopyLibsForTestingCommon") - maxHeapSize = "2g" - - useJUnitPlatform() - - systemProperty("idea.is.unit.test", "true") - systemProperty("java.awt.headless", "true") - environment("NO_FS_ROOTS_ACCESS_CHECK", "true") - - testLogging { - events("passed", "skipped", "failed") - } - - lateinit var tempTestDir: File - doFirst { - val ideaHomeDir = buildDir.resolve("tmp/ideaHome").takeIf { it.exists() || it.mkdirs() }!! - jvmArgumentProviders.add(RelativizingPathProvider("idea.home.path", ideaHomeDir)) - - tempTestDir = createTempDir() - jvmArgumentProviders.add(RelativizingPathProvider("java.io.tmpdir", tempTestDir)) - } - - doLast { - delete(tempTestDir) - } } val dokkaJavadocJar by tasks.register("dokkaJavadocJar") { diff --git a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/KotlinSymbolProcessingPlugin.kt b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/KotlinSymbolProcessingPlugin.kt index 0d128779aa..91035836a7 100644 --- a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/KotlinSymbolProcessingPlugin.kt +++ b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/KotlinSymbolProcessingPlugin.kt @@ -34,7 +34,6 @@ import org.jetbrains.kotlin.config.CompilerConfiguration import org.jetbrains.kotlin.config.CompilerConfigurationKey import org.jetbrains.kotlin.config.KotlinCompilerVersion import org.jetbrains.kotlin.config.languageVersionSettings -import org.jetbrains.kotlin.config.toKotlinVersion import org.jetbrains.kotlin.resolve.extensions.AnalysisHandlerExtension private val KSP_OPTIONS = CompilerConfigurationKey.create("Ksp options") diff --git a/common-util/src/main/kotlin/com/google/devtools/ksp/KspOptions.kt b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/KspOptions.kt similarity index 100% rename from common-util/src/main/kotlin/com/google/devtools/ksp/KspOptions.kt rename to compiler-plugin/src/main/kotlin/com/google/devtools/ksp/KspOptions.kt diff --git a/common-util/src/main/kotlin/com/google/devtools/ksp/DescriptorUtils.kt b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/DescriptorUtils.kt similarity index 95% rename from common-util/src/main/kotlin/com/google/devtools/ksp/DescriptorUtils.kt rename to compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/DescriptorUtils.kt index 8feb0615c2..77165f8061 100644 --- a/common-util/src/main/kotlin/com/google/devtools/ksp/DescriptorUtils.kt +++ b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/DescriptorUtils.kt @@ -15,13 +15,14 @@ * limitations under the License. */ -package com.google.devtools.ksp +package com.google.devtools.ksp.symbol.impl +import com.google.devtools.ksp.KSObjectCache +import com.google.devtools.ksp.getClassDeclarationByName import com.google.devtools.ksp.processing.Resolver import com.google.devtools.ksp.symbol.KSAnnotated import com.google.devtools.ksp.symbol.KSType import com.google.devtools.ksp.symbol.Modifier -import com.google.devtools.ksp.symbol.Variance import org.jetbrains.kotlin.descriptors.ClassDescriptor import org.jetbrains.kotlin.descriptors.DescriptorVisibilities import org.jetbrains.kotlin.descriptors.FunctionDescriptor @@ -123,15 +124,6 @@ fun FunctionDescriptor.toFunctionKSModifiers(): Set { return modifiers } -fun org.jetbrains.kotlin.types.Variance.toKSVariance(): Variance { - return when (this) { - org.jetbrains.kotlin.types.Variance.IN_VARIANCE -> Variance.CONTRAVARIANT - org.jetbrains.kotlin.types.Variance.OUT_VARIANCE -> Variance.COVARIANT - org.jetbrains.kotlin.types.Variance.INVARIANT -> Variance.INVARIANT - else -> throw IllegalStateException("Unexpected variance value $this, $ExceptionMessage") - } -} - /** * Custom check for backing fields of descriptors that support properties coming from .class files. * The compiler API always returns true for them even when they don't have backing fields. diff --git a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/PsiUtils.kt b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/PsiUtils.kt new file mode 100644 index 0000000000..61ddb13e0a --- /dev/null +++ b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/PsiUtils.kt @@ -0,0 +1,111 @@ +/* + * Copyright 2023 Google LLC + * Copyright 2010-2023 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. + */ +package com.google.devtools.ksp.symbol.impl + +import com.google.devtools.ksp.ExceptionMessage +import com.google.devtools.ksp.symbol.ClassKind +import com.google.devtools.ksp.symbol.Modifier +import com.intellij.psi.PsiComment +import com.intellij.psi.PsiElement +import org.jetbrains.kotlin.lexer.KtTokens +import org.jetbrains.kotlin.psi.KtClass +import org.jetbrains.kotlin.psi.KtClassOrObject +import org.jetbrains.kotlin.psi.KtEnumEntry +import org.jetbrains.kotlin.psi.KtModifierList +import org.jetbrains.kotlin.psi.KtModifierListOwner +import org.jetbrains.kotlin.psi.KtObjectDeclaration +import org.jetbrains.kotlin.psi.psiUtil.siblings + +private fun parseDocString(raw: String): String? { + val t1 = raw.trim() + if (!t1.startsWith("/**") || !t1.endsWith("*/")) + return null + val lineSep = t1.findAnyOf(listOf("\r\n", "\n", "\r"))?.second ?: "" + return t1.trim('/').trim('*').lines().joinToString(lineSep) { + it.trimStart().trimStart('*') + } +} + +fun PsiElement.getDocString(): String? = + this.firstChild.siblings().firstOrNull { it is PsiComment }?.let { + parseDocString(it.text) + } + +fun KtModifierListOwner.toKSModifiers(): Set { + val modifierList = this.modifierList + return modifierList.toKSModifiers() +} + +fun KtModifierList?.toKSModifiers(): Set { + if (this == null) + return emptySet() + val modifiers = mutableSetOf() + modifiers.addAll( + modifierMap.entries + .filter { hasModifier(it.key) } + .map { it.value } + ) + return modifiers +} + +val modifierMap = mapOf( + KtTokens.PUBLIC_KEYWORD to Modifier.PUBLIC, + KtTokens.PRIVATE_KEYWORD to Modifier.PRIVATE, + KtTokens.INTERNAL_KEYWORD to Modifier.INTERNAL, + KtTokens.PROTECTED_KEYWORD to Modifier.PROTECTED, + KtTokens.IN_KEYWORD to Modifier.IN, + KtTokens.OUT_KEYWORD to Modifier.OUT, + KtTokens.OVERRIDE_KEYWORD to Modifier.OVERRIDE, + KtTokens.LATEINIT_KEYWORD to Modifier.LATEINIT, + KtTokens.ENUM_KEYWORD to Modifier.ENUM, + KtTokens.SEALED_KEYWORD to Modifier.SEALED, + KtTokens.ANNOTATION_KEYWORD to Modifier.ANNOTATION, + KtTokens.DATA_KEYWORD to Modifier.DATA, + KtTokens.INNER_KEYWORD to Modifier.INNER, + KtTokens.FUN_KEYWORD to Modifier.FUN, + KtTokens.VALUE_KEYWORD to Modifier.VALUE, + KtTokens.SUSPEND_KEYWORD to Modifier.SUSPEND, + KtTokens.TAILREC_KEYWORD to Modifier.TAILREC, + KtTokens.OPERATOR_KEYWORD to Modifier.OPERATOR, + KtTokens.INFIX_KEYWORD to Modifier.INFIX, + KtTokens.INLINE_KEYWORD to Modifier.INLINE, + KtTokens.EXTERNAL_KEYWORD to Modifier.EXTERNAL, + KtTokens.ABSTRACT_KEYWORD to Modifier.ABSTRACT, + KtTokens.FINAL_KEYWORD to Modifier.FINAL, + KtTokens.OPEN_KEYWORD to Modifier.OPEN, + KtTokens.VARARG_KEYWORD to Modifier.VARARG, + KtTokens.NOINLINE_KEYWORD to Modifier.NOINLINE, + KtTokens.CROSSINLINE_KEYWORD to Modifier.CROSSINLINE, + KtTokens.REIFIED_KEYWORD to Modifier.REIFIED, + KtTokens.EXPECT_KEYWORD to Modifier.EXPECT, + KtTokens.ACTUAL_KEYWORD to Modifier.ACTUAL, + KtTokens.CONST_KEYWORD to Modifier.CONST +) + +fun KtClassOrObject.getClassType(): ClassKind { + return when (this) { + is KtObjectDeclaration -> ClassKind.OBJECT + is KtEnumEntry -> ClassKind.ENUM_ENTRY + is KtClass -> when { + this.isEnum() -> ClassKind.ENUM_CLASS + this.isInterface() -> ClassKind.INTERFACE + this.isAnnotation() -> ClassKind.ANNOTATION_CLASS + else -> ClassKind.CLASS + } + else -> throw IllegalStateException("Unexpected psi type ${this.javaClass}, $ExceptionMessage") + } +} diff --git a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/binary/KSFunctionDeclarationDescriptorImpl.kt b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/binary/KSFunctionDeclarationDescriptorImpl.kt index 0749a095b6..e9fe9c764e 100644 --- a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/binary/KSFunctionDeclarationDescriptorImpl.kt +++ b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/binary/KSFunctionDeclarationDescriptorImpl.kt @@ -22,8 +22,6 @@ import com.google.devtools.ksp.KSObjectCache import com.google.devtools.ksp.processing.impl.ResolverImpl import com.google.devtools.ksp.symbol.* import com.google.devtools.ksp.symbol.impl.* -import com.google.devtools.ksp.toFunctionKSModifiers -import com.google.devtools.ksp.toKSModifiers import org.jetbrains.kotlin.descriptors.FunctionDescriptor import org.jetbrains.kotlin.descriptors.impl.AnonymousFunctionDescriptor import org.jetbrains.kotlin.load.java.isFromJava diff --git a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/binary/KSPropertyAccessorDescriptorImpl.kt b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/binary/KSPropertyAccessorDescriptorImpl.kt index 505bb56902..99ad99dc06 100644 --- a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/binary/KSPropertyAccessorDescriptorImpl.kt +++ b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/binary/KSPropertyAccessorDescriptorImpl.kt @@ -19,8 +19,9 @@ package com.google.devtools.ksp.symbol.impl.binary import com.google.devtools.ksp.memoized import com.google.devtools.ksp.symbol.* +import com.google.devtools.ksp.symbol.impl.toFunctionKSModifiers +import com.google.devtools.ksp.symbol.impl.toKSModifiers import com.google.devtools.ksp.symbol.impl.toKSPropertyDeclaration -import com.google.devtools.ksp.toFunctionKSModifiers import com.google.devtools.ksp.toKSModifiers import org.jetbrains.kotlin.descriptors.PropertyAccessorDescriptor diff --git a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/binary/KSPropertyDeclarationDescriptorImpl.kt b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/binary/KSPropertyDeclarationDescriptorImpl.kt index ad9e52f316..6107fc90cd 100644 --- a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/binary/KSPropertyDeclarationDescriptorImpl.kt +++ b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/binary/KSPropertyDeclarationDescriptorImpl.kt @@ -18,7 +18,6 @@ package com.google.devtools.ksp.symbol.impl.binary import com.google.devtools.ksp.KSObjectCache -import com.google.devtools.ksp.hasBackingFieldWithBinaryClassSupport import com.google.devtools.ksp.memoized import com.google.devtools.ksp.processing.impl.ResolverImpl import com.google.devtools.ksp.symbol.* diff --git a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/binary/KSTypeAliasDescriptorImpl.kt b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/binary/KSTypeAliasDescriptorImpl.kt index 29dc06130e..fe1ab3493d 100644 --- a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/binary/KSTypeAliasDescriptorImpl.kt +++ b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/binary/KSTypeAliasDescriptorImpl.kt @@ -3,7 +3,7 @@ package com.google.devtools.ksp.symbol.impl.binary import com.google.devtools.ksp.KSObjectCache import com.google.devtools.ksp.processing.impl.KSNameImpl import com.google.devtools.ksp.symbol.* -import com.google.devtools.ksp.toKSModifiers +import com.google.devtools.ksp.symbol.impl.toKSModifiers import org.jetbrains.kotlin.descriptors.TypeAliasDescriptor class KSTypeAliasDescriptorImpl(descriptor: TypeAliasDescriptor) : diff --git a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/binary/KSTypeParameterDescriptorImpl.kt b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/binary/KSTypeParameterDescriptorImpl.kt index 98de3b988f..7dc8241b54 100644 --- a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/binary/KSTypeParameterDescriptorImpl.kt +++ b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/binary/KSTypeParameterDescriptorImpl.kt @@ -22,7 +22,7 @@ import com.google.devtools.ksp.KSObjectCache import com.google.devtools.ksp.processing.impl.KSNameImpl import com.google.devtools.ksp.symbol.* import com.google.devtools.ksp.symbol.impl.kotlin.KSExpectActualNoImpl -import com.google.devtools.ksp.toKSVariance +import com.google.devtools.ksp.symbol.impl.toKSVariance import org.jetbrains.kotlin.descriptors.ClassDescriptor import org.jetbrains.kotlin.descriptors.FunctionDescriptor import org.jetbrains.kotlin.descriptors.PropertyDescriptor diff --git a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/java/KSDeclarationJavaImpl.kt b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/java/KSDeclarationJavaImpl.kt index 3609a5a3f6..ebdffaccd7 100644 --- a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/java/KSDeclarationJavaImpl.kt +++ b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/java/KSDeclarationJavaImpl.kt @@ -17,12 +17,12 @@ package com.google.devtools.ksp.symbol.impl.java -import com.google.devtools.ksp.getDocString import com.google.devtools.ksp.symbol.KSDeclaration import com.google.devtools.ksp.symbol.KSName import com.google.devtools.ksp.symbol.KSNode import com.google.devtools.ksp.symbol.impl.findParentAnnotated import com.google.devtools.ksp.symbol.impl.findParentDeclaration +import com.google.devtools.ksp.symbol.impl.getDocString import com.intellij.psi.PsiElement abstract class KSDeclarationJavaImpl(private val psi: PsiElement) : KSDeclaration { diff --git a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/kotlin/KSClassDeclarationImpl.kt b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/kotlin/KSClassDeclarationImpl.kt index d4c1fb02ab..16f669334a 100644 --- a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/kotlin/KSClassDeclarationImpl.kt +++ b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/kotlin/KSClassDeclarationImpl.kt @@ -18,7 +18,6 @@ package com.google.devtools.ksp.symbol.impl.kotlin import com.google.devtools.ksp.KSObjectCache -import com.google.devtools.ksp.getClassType import com.google.devtools.ksp.isConstructor import com.google.devtools.ksp.memoized import com.google.devtools.ksp.processing.impl.KSTypeReferenceSyntheticImpl diff --git a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/kotlin/KSDeclarationImpl.kt b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/kotlin/KSDeclarationImpl.kt index 3e596664d7..b1f2a8499f 100644 --- a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/kotlin/KSDeclarationImpl.kt +++ b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/kotlin/KSDeclarationImpl.kt @@ -17,15 +17,11 @@ package com.google.devtools.ksp.symbol.impl.kotlin -import com.google.devtools.ksp.getDocString import com.google.devtools.ksp.isConstructor import com.google.devtools.ksp.memoized import com.google.devtools.ksp.processing.impl.KSNameImpl import com.google.devtools.ksp.symbol.* -import com.google.devtools.ksp.symbol.impl.findParentAnnotated -import com.google.devtools.ksp.symbol.impl.findParentDeclaration -import com.google.devtools.ksp.symbol.impl.toLocation -import com.google.devtools.ksp.toKSModifiers +import com.google.devtools.ksp.symbol.impl.* import org.jetbrains.kotlin.psi.* abstract class KSDeclarationImpl(val ktDeclaration: KtDeclaration) : KSDeclaration { diff --git a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/kotlin/KSPropertyAccessorImpl.kt b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/kotlin/KSPropertyAccessorImpl.kt index adde6d3487..9d57b25d27 100644 --- a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/kotlin/KSPropertyAccessorImpl.kt +++ b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/kotlin/KSPropertyAccessorImpl.kt @@ -21,8 +21,8 @@ import com.google.devtools.ksp.memoized import com.google.devtools.ksp.processing.impl.findAnnotationFromUseSiteTarget import com.google.devtools.ksp.symbol.* import com.google.devtools.ksp.symbol.impl.getKSDeclarations +import com.google.devtools.ksp.symbol.impl.toKSModifiers import com.google.devtools.ksp.symbol.impl.toLocation -import com.google.devtools.ksp.toKSModifiers import org.jetbrains.kotlin.psi.KtProperty import org.jetbrains.kotlin.psi.KtPropertyAccessor diff --git a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/kotlin/KSTypeReferenceImpl.kt b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/kotlin/KSTypeReferenceImpl.kt index 9f7517009d..43ecd5274f 100644 --- a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/kotlin/KSTypeReferenceImpl.kt +++ b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/kotlin/KSTypeReferenceImpl.kt @@ -30,8 +30,8 @@ import com.google.devtools.ksp.symbol.KSVisitor import com.google.devtools.ksp.symbol.Location import com.google.devtools.ksp.symbol.Modifier import com.google.devtools.ksp.symbol.Origin +import com.google.devtools.ksp.symbol.impl.toKSModifiers import com.google.devtools.ksp.symbol.impl.toLocation -import com.google.devtools.ksp.toKSModifiers import org.jetbrains.kotlin.psi.* class KSTypeReferenceImpl private constructor(val ktTypeReference: KtTypeReference) : KSTypeReference { diff --git a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/utils.kt b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/utils.kt index ff003e4fa8..66de2f9d6a 100644 --- a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/utils.kt +++ b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/utils.kt @@ -16,9 +16,9 @@ */ package com.google.devtools.ksp.symbol.impl -import com.google.devtools.ksp.BinaryClassInfoCache import com.google.devtools.ksp.ExceptionMessage import com.google.devtools.ksp.KspExperimental +import com.google.devtools.ksp.processing.impl.KSNameImpl import com.google.devtools.ksp.processing.impl.ResolverImpl import com.google.devtools.ksp.symbol.* import com.google.devtools.ksp.symbol.Variance @@ -48,6 +48,7 @@ import org.jetbrains.kotlin.load.java.structure.impl.classFiles.BinaryJavaMethod import org.jetbrains.kotlin.load.kotlin.KotlinJvmBinaryClass import org.jetbrains.kotlin.load.kotlin.KotlinJvmBinarySourceElement import org.jetbrains.kotlin.load.kotlin.getContainingKotlinJvmBinaryClass +import org.jetbrains.kotlin.name.ClassId import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.psi.psiUtil.parentsWithSelf @@ -560,3 +561,5 @@ fun DeclarationDescriptor.findPsi(): PsiElement? { internal fun KSFile.getPackageAnnotations() = (this as? KSFileJavaImpl)?.psi?.packageStatement ?.annotationList?.annotations?.map { KSAnnotationJavaImpl.getCached(it) } ?: emptyList() + +fun ClassId.toKSName() = KSNameImpl.getCached(asSingleFqName().toString()) diff --git a/kotlin-analysis-api/build.gradle.kts b/kotlin-analysis-api/build.gradle.kts index e8e5a5578d..738947da24 100644 --- a/kotlin-analysis-api/build.gradle.kts +++ b/kotlin-analysis-api/build.gradle.kts @@ -1,13 +1,7 @@ import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar -import com.google.devtools.ksp.RelativizingPathProvider description = "Kotlin Symbol Processing implementation using Kotlin Analysis API" -val junitVersion: String by project -val junit5Version: String by project -val junitPlatformVersion: String by project -val libsForTesting by configurations.creating -val libsForTestingCommon by configurations.creating val signingKey: String? by project val signingPassword: String? by project @@ -71,40 +65,6 @@ dependencies { implementation(project(":api")) implementation(project(":common-util")) - - testImplementation("junit:junit:$junitVersion") - testImplementation("org.junit.jupiter:junit-jupiter-api:$junit5Version") - testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:$junit5Version") - testRuntimeOnly("org.junit.jupiter:junit-jupiter-params:$junit5Version") - testRuntimeOnly("org.junit.platform:junit-platform-suite:$junitPlatformVersion") - - testImplementation(project(":test-utils")) - testImplementation(project(":api")) - testImplementation(project(":common-util")) - - testImplementation(kotlin("stdlib", aaKotlinBaseVersion)) - testImplementation("org.jetbrains.kotlin:kotlin-compiler:$aaKotlinBaseVersion") - testImplementation("org.jetbrains.kotlin:kotlin-compiler-internal-test-framework:$aaKotlinBaseVersion") - testImplementation("org.jetbrains.kotlin:kotlin-scripting-compiler:$aaKotlinBaseVersion") - - libsForTesting(kotlin("stdlib", aaKotlinBaseVersion)) - libsForTesting(kotlin("test", aaKotlinBaseVersion)) - libsForTesting(kotlin("script-runtime", aaKotlinBaseVersion)) - libsForTestingCommon(kotlin("stdlib-common", aaKotlinBaseVersion)) -} - -tasks.register("CopyLibsForTesting") { - from(configurations.get("libsForTesting")) - into("dist/kotlinc/lib") - val escaped = Regex.escape(aaKotlinBaseVersion) - rename("(.+)-$escaped\\.jar", "$1.jar") -} - -tasks.register("CopyLibsForTestingCommon") { - from(configurations.get("libsForTestingCommon")) - into("dist/common") - val escaped = Regex.escape(aaKotlinBaseVersion) - rename("(.+)-$escaped\\.jar", "$1.jar") } sourceSets.main { @@ -117,35 +77,6 @@ val JavaPluginConvention.testSourceSet: SourceSet val Project.testSourceSet: SourceSet get() = javaPluginConvention().testSourceSet -tasks.test { - dependsOn("CopyLibsForTesting") - dependsOn("CopyLibsForTestingCommon") - maxHeapSize = "2g" - - useJUnitPlatform() - - systemProperty("idea.is.unit.test", "true") - systemProperty("java.awt.headless", "true") - environment("NO_FS_ROOTS_ACCESS_CHECK", "true") - - testLogging { - events("passed", "skipped", "failed") - } - - lateinit var tempTestDir: File - doFirst { - val ideaHomeDir = buildDir.resolve("tmp/ideaHome").takeIf { it.exists() || it.mkdirs() }!! - jvmArgumentProviders.add(RelativizingPathProvider("idea.home.path", ideaHomeDir)) - - tempTestDir = createTempDir() - jvmArgumentProviders.add(RelativizingPathProvider("java.io.tmpdir", tempTestDir)) - } - - doLast { - delete(tempTestDir) - } -} - repositories { flatDir { dirs("${project.rootDir}/third_party/prebuilt/repo/") diff --git a/kotlin-analysis-api/src/main/kotlin/com/google/devtools/ksp/impl/KSPCommandLineProcessor.kt b/kotlin-analysis-api/src/main/kotlin/com/google/devtools/ksp/impl/KSPCommandLineProcessor.kt deleted file mode 100644 index 96b8307457..0000000000 --- a/kotlin-analysis-api/src/main/kotlin/com/google/devtools/ksp/impl/KSPCommandLineProcessor.kt +++ /dev/null @@ -1,56 +0,0 @@ -/* - * 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. - */ - -package com.google.devtools.ksp.impl - -import com.google.devtools.ksp.KspOptions -import com.google.devtools.ksp.processing.SymbolProcessorProvider -import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys -import org.jetbrains.kotlin.cli.common.config.addKotlinSourceRoots -import org.jetbrains.kotlin.cli.common.messages.MessageCollector -import org.jetbrains.kotlin.cli.jvm.config.addJavaSourceRoots -import org.jetbrains.kotlin.config.CompilerConfiguration -import org.jetbrains.kotlin.config.languageVersionSettings -import org.jetbrains.kotlin.util.ServiceLoaderLite -import java.io.File -import java.net.URLClassLoader - -class KSPCommandLineProcessor(val compilerConfiguration: CompilerConfiguration) { - private val kspOptionsBuilder = KspOptions.Builder().apply { - languageVersionSettings = compilerConfiguration.languageVersionSettings - } - - val kspOptions: KspOptions - get() = kspOptionsBuilder.build() - - lateinit var providers: List - - fun processArgs(args: Array) { - // TODO: support KSP options - val sources = args.toList() - compilerConfiguration.addKotlinSourceRoots(sources) - compilerConfiguration.addJavaSourceRoots(sources.map { File(it) }) - compilerConfiguration.put(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY, MessageCollector.NONE) - val processingClasspath = kspOptionsBuilder.processingClasspath - val classLoader = URLClassLoader( - processingClasspath.map { it.toURI().toURL() }.toTypedArray(), - javaClass.classLoader - ) - - providers = ServiceLoaderLite.loadImplementations(SymbolProcessorProvider::class.java, classLoader) - } -} diff --git a/kotlin-analysis-api/src/main/kotlin/com/google/devtools/ksp/impl/KotlinSymbolProcessing.kt b/kotlin-analysis-api/src/main/kotlin/com/google/devtools/ksp/impl/KotlinSymbolProcessing.kt index c18b0bcd5b..19d4cd0388 100644 --- a/kotlin-analysis-api/src/main/kotlin/com/google/devtools/ksp/impl/KotlinSymbolProcessing.kt +++ b/kotlin-analysis-api/src/main/kotlin/com/google/devtools/ksp/impl/KotlinSymbolProcessing.kt @@ -33,7 +33,6 @@ import com.google.devtools.ksp.processing.impl.JvmPlatformInfoImpl import com.google.devtools.ksp.symbol.KSFile import com.google.devtools.ksp.symbol.KSNode import com.google.devtools.ksp.symbol.Origin -import com.google.devtools.ksp.toKotlinVersion import com.intellij.core.CoreApplicationEnvironment import com.intellij.core.CorePackageIndex import com.intellij.ide.highlighter.JavaFileType @@ -623,3 +622,17 @@ private fun getDefaultJdkModuleRoots( result } } + +fun String?.toKotlinVersion(): KotlinVersion { + if (this == null) + return KotlinVersion.CURRENT + + return split('-').first().split('.').map { it.toInt() }.let { + when (it.size) { + 1 -> KotlinVersion(it[0], 0, 0) + 2 -> KotlinVersion(it[0], it[1], 0) + 3 -> KotlinVersion(it[0], it[1], it[2]) + else -> KotlinVersion.CURRENT + } + } +} diff --git a/kotlin-analysis-api/src/main/kotlin/com/google/devtools/ksp/impl/ResolverAAImpl.kt b/kotlin-analysis-api/src/main/kotlin/com/google/devtools/ksp/impl/ResolverAAImpl.kt index 7e48213bf5..d32aa91d98 100644 --- a/kotlin-analysis-api/src/main/kotlin/com/google/devtools/ksp/impl/ResolverAAImpl.kt +++ b/kotlin-analysis-api/src/main/kotlin/com/google/devtools/ksp/impl/ResolverAAImpl.kt @@ -20,6 +20,9 @@ package com.google.devtools.ksp.impl import com.google.devtools.ksp.* import com.google.devtools.ksp.impl.symbol.kotlin.* +import com.google.devtools.ksp.impl.symbol.util.BinaryClassInfoCache +import com.google.devtools.ksp.impl.symbol.util.extractThrowsFromClassFile +import com.google.devtools.ksp.impl.symbol.util.hasAnnotation import com.google.devtools.ksp.processing.KSBuiltIns import com.google.devtools.ksp.processing.Resolver import com.google.devtools.ksp.processing.SymbolProcessor diff --git a/kotlin-analysis-api/src/main/kotlin/com/google/devtools/ksp/impl/symbol/kotlin/AbstractKSDeclarationImpl.kt b/kotlin-analysis-api/src/main/kotlin/com/google/devtools/ksp/impl/symbol/kotlin/AbstractKSDeclarationImpl.kt index dc05b00bcd..f96dae191b 100644 --- a/kotlin-analysis-api/src/main/kotlin/com/google/devtools/ksp/impl/symbol/kotlin/AbstractKSDeclarationImpl.kt +++ b/kotlin-analysis-api/src/main/kotlin/com/google/devtools/ksp/impl/symbol/kotlin/AbstractKSDeclarationImpl.kt @@ -17,6 +17,7 @@ package com.google.devtools.ksp.impl.symbol.kotlin import com.google.devtools.ksp.impl.symbol.java.KSAnnotationJavaImpl +import com.google.devtools.ksp.impl.symbol.util.toKSModifiers import com.google.devtools.ksp.processing.impl.KSNameImpl import com.google.devtools.ksp.symbol.KSAnnotation import com.google.devtools.ksp.symbol.KSDeclaration diff --git a/kotlin-analysis-api/src/main/kotlin/com/google/devtools/ksp/impl/symbol/kotlin/KSPropertyAccessorImpl.kt b/kotlin-analysis-api/src/main/kotlin/com/google/devtools/ksp/impl/symbol/kotlin/KSPropertyAccessorImpl.kt index 724d413571..fb5863c85b 100644 --- a/kotlin-analysis-api/src/main/kotlin/com/google/devtools/ksp/impl/symbol/kotlin/KSPropertyAccessorImpl.kt +++ b/kotlin-analysis-api/src/main/kotlin/com/google/devtools/ksp/impl/symbol/kotlin/KSPropertyAccessorImpl.kt @@ -18,8 +18,8 @@ package com.google.devtools.ksp.impl.symbol.kotlin import com.google.devtools.ksp.KSObjectCache +import com.google.devtools.ksp.impl.symbol.util.toKSModifiers import com.google.devtools.ksp.symbol.* -import com.google.devtools.ksp.toKSModifiers import org.jetbrains.kotlin.analysis.api.annotations.annotations import org.jetbrains.kotlin.analysis.api.symbols.KtPropertyAccessorSymbol import org.jetbrains.kotlin.analysis.api.symbols.KtPropertyGetterSymbol diff --git a/kotlin-analysis-api/src/main/kotlin/com/google/devtools/ksp/impl/symbol/kotlin/KSPropertyDeclarationImpl.kt b/kotlin-analysis-api/src/main/kotlin/com/google/devtools/ksp/impl/symbol/kotlin/KSPropertyDeclarationImpl.kt index ad049328cc..99327c7971 100644 --- a/kotlin-analysis-api/src/main/kotlin/com/google/devtools/ksp/impl/symbol/kotlin/KSPropertyDeclarationImpl.kt +++ b/kotlin-analysis-api/src/main/kotlin/com/google/devtools/ksp/impl/symbol/kotlin/KSPropertyDeclarationImpl.kt @@ -17,9 +17,9 @@ package com.google.devtools.ksp.impl.symbol.kotlin -import com.google.devtools.ksp.BinaryClassInfoCache import com.google.devtools.ksp.KSObjectCache import com.google.devtools.ksp.impl.ResolverAAImpl +import com.google.devtools.ksp.impl.symbol.util.BinaryClassInfoCache import com.google.devtools.ksp.processing.impl.KSNameImpl import com.google.devtools.ksp.symbol.* import com.intellij.psi.PsiClass diff --git a/kotlin-analysis-api/src/main/kotlin/com/google/devtools/ksp/impl/symbol/kotlin/util.kt b/kotlin-analysis-api/src/main/kotlin/com/google/devtools/ksp/impl/symbol/kotlin/util.kt index eb296b9350..cad4f87cf7 100644 --- a/kotlin-analysis-api/src/main/kotlin/com/google/devtools/ksp/impl/symbol/kotlin/util.kt +++ b/kotlin-analysis-api/src/main/kotlin/com/google/devtools/ksp/impl/symbol/kotlin/util.kt @@ -19,10 +19,11 @@ package com.google.devtools.ksp.impl.symbol.kotlin import com.google.devtools.ksp.ExceptionMessage -import com.google.devtools.ksp.getDocString import com.google.devtools.ksp.impl.KSPCoreEnvironment import com.google.devtools.ksp.impl.ResolverAAImpl +import com.google.devtools.ksp.impl.symbol.util.getDocString import com.google.devtools.ksp.memoized +import com.google.devtools.ksp.processing.impl.KSNameImpl import com.google.devtools.ksp.symbol.* import com.intellij.psi.PsiElement import com.intellij.psi.PsiJavaFile @@ -489,3 +490,5 @@ fun T.defer(restore: (T) -> KSAnnotated?): Restorable? { } } } + +fun ClassId.toKSName() = KSNameImpl.getCached(asSingleFqName().toString()) diff --git a/kotlin-analysis-api/src/main/kotlin/com/google/devtools/ksp/impl/symbol/util/BinaryUtils.kt b/kotlin-analysis-api/src/main/kotlin/com/google/devtools/ksp/impl/symbol/util/BinaryUtils.kt new file mode 100644 index 0000000000..17a67d2e92 --- /dev/null +++ b/kotlin-analysis-api/src/main/kotlin/com/google/devtools/ksp/impl/symbol/util/BinaryUtils.kt @@ -0,0 +1,141 @@ +/* + * 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. + */ + +package com.google.devtools.ksp.impl.symbol.util + +import com.google.devtools.ksp.KSObjectCache +import com.google.devtools.ksp.getClassDeclarationByName +import com.google.devtools.ksp.processing.Resolver +import com.google.devtools.ksp.symbol.KSAnnotated +import com.google.devtools.ksp.symbol.KSType +import org.jetbrains.kotlin.load.kotlin.KotlinJvmBinaryClass +import org.jetbrains.kotlin.load.kotlin.KotlinJvmBinarySourceElement +import org.jetbrains.kotlin.load.kotlin.VirtualFileKotlinClass +import org.jetbrains.kotlin.load.kotlin.getContainingKotlinJvmBinaryClass +import org.jetbrains.kotlin.name.ClassId +import org.jetbrains.kotlin.resolve.descriptorUtil.isCompanionObject +import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedClassDescriptor +import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedPropertyDescriptor +import org.jetbrains.org.objectweb.asm.ClassReader +import org.jetbrains.org.objectweb.asm.ClassVisitor +import org.jetbrains.org.objectweb.asm.FieldVisitor +import org.jetbrains.org.objectweb.asm.MethodVisitor +import org.jetbrains.org.objectweb.asm.Opcodes + +data class BinaryClassInfo( + val fieldAccFlags: Map, + val methodAccFlags: Map +) + +/** + * Lookup cache for field names names for deserialized classes. + * To check if a field has backing field, we need to look for binary field names, hence they are cached here. + */ +object BinaryClassInfoCache : KSObjectCache() { + fun getCached( + kotlinJvmBinaryClass: KotlinJvmBinaryClass, + ) = getCached( + kotlinJvmBinaryClass.classId, (kotlinJvmBinaryClass as? VirtualFileKotlinClass)?.file?.contentsToByteArray() + ) + + fun getCached(classId: ClassId, virtualFileContent: ByteArray?) = cache.getOrPut(classId) { + val fieldAccFlags = mutableMapOf() + val methodAccFlags = mutableMapOf() + ClassReader(virtualFileContent).accept( + object : ClassVisitor(Opcodes.API_VERSION) { + override fun visitField( + access: Int, + name: String?, + descriptor: String?, + signature: String?, + value: Any? + ): FieldVisitor? { + if (name != null) { + fieldAccFlags.put(name, access) + } + return null + } + + override fun visitMethod( + access: Int, + name: String?, + descriptor: String?, + signature: String?, + exceptions: Array? + ): MethodVisitor? { + if (name != null) { + methodAccFlags.put(name + descriptor, access) + } + return null + } + }, + ClassReader.SKIP_CODE or ClassReader.SKIP_DEBUG or ClassReader.SKIP_FRAMES + ) + BinaryClassInfo(fieldAccFlags, methodAccFlags) + } +} + +/** + * Workaround for backingField in deserialized descriptors. + * They always return non-null for backing field even when they don't have a backing field. + */ +private fun DeserializedPropertyDescriptor.hasBackingFieldInBinaryClass(): Boolean { + val kotlinJvmBinaryClass = if (containingDeclaration.isCompanionObject()) { + // Companion objects have backing fields in containing classes. + // https://kotlinlang.org/docs/java-to-kotlin-interop.html#static-fields + val container = containingDeclaration.containingDeclaration as? DeserializedClassDescriptor + (container?.source as? KotlinJvmBinarySourceElement)?.binaryClass + } else { + this.getContainingKotlinJvmBinaryClass() + } ?: return false + return BinaryClassInfoCache.getCached(kotlinJvmBinaryClass).fieldAccFlags.containsKey(name.asString()) +} + +fun KSAnnotated.hasAnnotation(fqn: String): Boolean = + annotations.any { + fqn.endsWith(it.shortName.asString()) && + it.annotationType.resolve().declaration.qualifiedName?.asString() == fqn + } + +fun Resolver.extractThrowsFromClassFile( + virtualFileContent: ByteArray, + jvmDesc: String?, + simpleName: String? +): Sequence { + val exceptionNames = mutableListOf() + ClassReader(virtualFileContent).accept( + object : ClassVisitor(Opcodes.API_VERSION) { + override fun visitMethod( + access: Int, + name: String?, + descriptor: String?, + signature: String?, + exceptions: Array?, + ): MethodVisitor { + if (name == simpleName && jvmDesc == descriptor) { + exceptions?.toList()?.let { exceptionNames.addAll(it) } + } + return object : MethodVisitor(Opcodes.API_VERSION) { + } + } + }, + ClassReader.SKIP_CODE or ClassReader.SKIP_DEBUG or ClassReader.SKIP_FRAMES + ) + return exceptionNames.mapNotNull { + this.getClassDeclarationByName(it.replace("/", "."))?.asStarProjectedType() + }.asSequence() +} diff --git a/kotlin-analysis-api/src/main/kotlin/com/google/devtools/ksp/impl/symbol/util/PsiUtils.kt b/kotlin-analysis-api/src/main/kotlin/com/google/devtools/ksp/impl/symbol/util/PsiUtils.kt new file mode 100644 index 0000000000..2e2820746f --- /dev/null +++ b/kotlin-analysis-api/src/main/kotlin/com/google/devtools/ksp/impl/symbol/util/PsiUtils.kt @@ -0,0 +1,112 @@ +/* + * Copyright 2023 Google LLC + * Copyright 2010-2023 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. + */ + +package com.google.devtools.ksp.impl.symbol.util + +import com.google.devtools.ksp.ExceptionMessage +import com.google.devtools.ksp.symbol.ClassKind +import com.google.devtools.ksp.symbol.Modifier +import com.intellij.psi.PsiComment +import com.intellij.psi.PsiElement +import org.jetbrains.kotlin.lexer.KtTokens +import org.jetbrains.kotlin.psi.KtClass +import org.jetbrains.kotlin.psi.KtClassOrObject +import org.jetbrains.kotlin.psi.KtEnumEntry +import org.jetbrains.kotlin.psi.KtModifierList +import org.jetbrains.kotlin.psi.KtModifierListOwner +import org.jetbrains.kotlin.psi.KtObjectDeclaration +import org.jetbrains.kotlin.psi.psiUtil.siblings + +private fun parseDocString(raw: String): String? { + val t1 = raw.trim() + if (!t1.startsWith("/**") || !t1.endsWith("*/")) + return null + val lineSep = t1.findAnyOf(listOf("\r\n", "\n", "\r"))?.second ?: "" + return t1.trim('/').trim('*').lines().joinToString(lineSep) { + it.trimStart().trimStart('*') + } +} + +fun PsiElement.getDocString(): String? = + this.firstChild.siblings().firstOrNull { it is PsiComment }?.let { + parseDocString(it.text) + } + +fun KtModifierListOwner.toKSModifiers(): Set { + val modifierList = this.modifierList + return modifierList.toKSModifiers() +} + +fun KtModifierList?.toKSModifiers(): Set { + if (this == null) + return emptySet() + val modifiers = mutableSetOf() + modifiers.addAll( + modifierMap.entries + .filter { hasModifier(it.key) } + .map { it.value } + ) + return modifiers +} + +val modifierMap = mapOf( + KtTokens.PUBLIC_KEYWORD to Modifier.PUBLIC, + KtTokens.PRIVATE_KEYWORD to Modifier.PRIVATE, + KtTokens.INTERNAL_KEYWORD to Modifier.INTERNAL, + KtTokens.PROTECTED_KEYWORD to Modifier.PROTECTED, + KtTokens.IN_KEYWORD to Modifier.IN, + KtTokens.OUT_KEYWORD to Modifier.OUT, + KtTokens.OVERRIDE_KEYWORD to Modifier.OVERRIDE, + KtTokens.LATEINIT_KEYWORD to Modifier.LATEINIT, + KtTokens.ENUM_KEYWORD to Modifier.ENUM, + KtTokens.SEALED_KEYWORD to Modifier.SEALED, + KtTokens.ANNOTATION_KEYWORD to Modifier.ANNOTATION, + KtTokens.DATA_KEYWORD to Modifier.DATA, + KtTokens.INNER_KEYWORD to Modifier.INNER, + KtTokens.FUN_KEYWORD to Modifier.FUN, + KtTokens.VALUE_KEYWORD to Modifier.VALUE, + KtTokens.SUSPEND_KEYWORD to Modifier.SUSPEND, + KtTokens.TAILREC_KEYWORD to Modifier.TAILREC, + KtTokens.OPERATOR_KEYWORD to Modifier.OPERATOR, + KtTokens.INFIX_KEYWORD to Modifier.INFIX, + KtTokens.INLINE_KEYWORD to Modifier.INLINE, + KtTokens.EXTERNAL_KEYWORD to Modifier.EXTERNAL, + KtTokens.ABSTRACT_KEYWORD to Modifier.ABSTRACT, + KtTokens.FINAL_KEYWORD to Modifier.FINAL, + KtTokens.OPEN_KEYWORD to Modifier.OPEN, + KtTokens.VARARG_KEYWORD to Modifier.VARARG, + KtTokens.NOINLINE_KEYWORD to Modifier.NOINLINE, + KtTokens.CROSSINLINE_KEYWORD to Modifier.CROSSINLINE, + KtTokens.REIFIED_KEYWORD to Modifier.REIFIED, + KtTokens.EXPECT_KEYWORD to Modifier.EXPECT, + KtTokens.ACTUAL_KEYWORD to Modifier.ACTUAL, + KtTokens.CONST_KEYWORD to Modifier.CONST +) + +fun KtClassOrObject.getClassType(): ClassKind { + return when (this) { + is KtObjectDeclaration -> ClassKind.OBJECT + is KtEnumEntry -> ClassKind.ENUM_ENTRY + is KtClass -> when { + this.isEnum() -> ClassKind.ENUM_CLASS + this.isInterface() -> ClassKind.INTERFACE + this.isAnnotation() -> ClassKind.ANNOTATION_CLASS + else -> ClassKind.CLASS + } + else -> throw IllegalStateException("Unexpected psi type ${this.javaClass}, $ExceptionMessage") + } +} diff --git a/test-utils/build.gradle.kts b/test-utils/build.gradle.kts index 2c936db41f..6c3e951239 100644 --- a/test-utils/build.gradle.kts +++ b/test-utils/build.gradle.kts @@ -1,8 +1,13 @@ +import com.google.devtools.ksp.RelativizingPathProvider import org.jetbrains.kotlin.gradle.tasks.KotlinCompile -val kotlinBaseVersion: String by project val intellijVersion: String by project +val junitVersion: String by project val junit5Version: String by project +val junitPlatformVersion: String by project +val kotlinBaseVersion: String by project +val libsForTesting by configurations.creating +val libsForTestingCommon by configurations.creating tasks.withType { compilerOptions.freeCompilerArgs.add("-Xjvm-default=all-compatibility") @@ -14,17 +19,93 @@ plugins { version = "2.0.255-SNAPSHOT" repositories { - mavenCentral() + maven("https://maven.pkg.jetbrains.space/kotlin/p/kotlin/kotlin-ide-plugin-dependencies") + maven("https://packages.jetbrains.team/maven/p/ij/intellij-dependencies") } dependencies { - implementation(kotlin("stdlib")) + listOf( + "com.jetbrains.intellij.platform:util-rt", + "com.jetbrains.intellij.platform:util-class-loader", + "com.jetbrains.intellij.platform:util-text-matching", + "com.jetbrains.intellij.platform:util", + "com.jetbrains.intellij.platform:util-base", + "com.jetbrains.intellij.platform:util-xml-dom", + "com.jetbrains.intellij.platform:core", + "com.jetbrains.intellij.platform:core-impl", + "com.jetbrains.intellij.platform:extensions", + "com.jetbrains.intellij.java:java-psi", + "com.jetbrains.intellij.java:java-psi-impl", + ).forEach { + implementation("$it:$intellijVersion") { isTransitive = false } + } + implementation(project(":api")) + implementation(project(":compiler-plugin")) + implementation(project(":kotlin-analysis-api")) + + implementation("org.jetbrains.kotlinx:kotlinx-collections-immutable-jvm:0.3.4") + implementation("junit:junit:$junitVersion") + implementation("org.junit.jupiter:junit-jupiter-api:$junit5Version") + runtimeOnly("org.junit.jupiter:junit-jupiter-engine:$junit5Version") + runtimeOnly("org.junit.jupiter:junit-jupiter-params:$junit5Version") + runtimeOnly("org.junit.platform:junit-platform-suite:$junitPlatformVersion") + implementation(kotlin("stdlib", kotlinBaseVersion)) implementation("org.jetbrains.kotlin:kotlin-compiler:$kotlinBaseVersion") implementation("org.jetbrains.kotlin:kotlin-compiler-internal-test-framework:$kotlinBaseVersion") + implementation("org.jetbrains.kotlin:kotlin-scripting-compiler:$kotlinBaseVersion") - implementation("org.junit.jupiter:junit-jupiter-api:$junit5Version") + libsForTesting(kotlin("stdlib", kotlinBaseVersion)) + libsForTesting(kotlin("test", kotlinBaseVersion)) + libsForTesting(kotlin("script-runtime", kotlinBaseVersion)) + libsForTestingCommon(kotlin("stdlib-common", kotlinBaseVersion)) +} - implementation(project(":api")) - implementation(project(":compiler-plugin")) +tasks.register("CopyLibsForTesting") { + from(configurations.get("libsForTesting")) + into("dist/kotlinc/lib") + val escaped = Regex.escape(kotlinBaseVersion) + rename("(.+)-$escaped\\.jar", "$1.jar") +} + +tasks.register("CopyLibsForTestingCommon") { + from(configurations.get("libsForTestingCommon")) + into("dist/common") + val escaped = Regex.escape(kotlinBaseVersion) + rename("(.+)-$escaped\\.jar", "$1.jar") +} + +fun Project.javaPluginConvention(): JavaPluginConvention = the() +val JavaPluginConvention.testSourceSet: SourceSet + get() = sourceSets.getByName("test") +val Project.testSourceSet: SourceSet + get() = javaPluginConvention().testSourceSet + +tasks.test { + dependsOn("CopyLibsForTesting") + dependsOn("CopyLibsForTestingCommon") + maxHeapSize = "2g" + + useJUnitPlatform() + + systemProperty("idea.is.unit.test", "true") + systemProperty("java.awt.headless", "true") + environment("NO_FS_ROOTS_ACCESS_CHECK", "true") + + testLogging { + events("passed", "skipped", "failed") + } + + lateinit var tempTestDir: File + doFirst { + val ideaHomeDir = buildDir.resolve("tmp/ideaHome").takeIf { it.exists() || it.mkdirs() }!! + jvmArgumentProviders.add(RelativizingPathProvider("idea.home.path", ideaHomeDir)) + + tempTestDir = createTempDir() + jvmArgumentProviders.add(RelativizingPathProvider("java.io.tmpdir", tempTestDir)) + } + + doLast { + delete(tempTestDir) + } } diff --git a/test-utils/dist/common/annotations-13.0.jar b/test-utils/dist/common/annotations-13.0.jar new file mode 100644 index 0000000000..fb794be912 Binary files /dev/null and b/test-utils/dist/common/annotations-13.0.jar differ diff --git a/test-utils/dist/common/kotlin-stdlib.jar b/test-utils/dist/common/kotlin-stdlib.jar new file mode 100644 index 0000000000..9640d756ac Binary files /dev/null and b/test-utils/dist/common/kotlin-stdlib.jar differ diff --git a/test-utils/dist/kotlinc/lib/annotations-13.0.jar b/test-utils/dist/kotlinc/lib/annotations-13.0.jar new file mode 100644 index 0000000000..fb794be912 Binary files /dev/null and b/test-utils/dist/kotlinc/lib/annotations-13.0.jar differ diff --git a/test-utils/dist/kotlinc/lib/kotlin-script-runtime.jar b/test-utils/dist/kotlinc/lib/kotlin-script-runtime.jar new file mode 100644 index 0000000000..073eaf6446 Binary files /dev/null and b/test-utils/dist/kotlinc/lib/kotlin-script-runtime.jar differ diff --git a/test-utils/dist/kotlinc/lib/kotlin-stdlib.jar b/test-utils/dist/kotlinc/lib/kotlin-stdlib.jar new file mode 100644 index 0000000000..9640d756ac Binary files /dev/null and b/test-utils/dist/kotlinc/lib/kotlin-stdlib.jar differ diff --git a/test-utils/dist/kotlinc/lib/kotlin-test.jar b/test-utils/dist/kotlinc/lib/kotlin-test.jar new file mode 100644 index 0000000000..4fbe4370df Binary files /dev/null and b/test-utils/dist/kotlinc/lib/kotlin-test.jar differ diff --git a/kotlin-analysis-api/src/test/kotlin/com/google/devtools/ksp/impl/test/AbstractKSPAATest.kt b/test-utils/src/test/kotlin/com/google/devtools/ksp/test/AbstractKSPAATest.kt similarity index 98% rename from kotlin-analysis-api/src/test/kotlin/com/google/devtools/ksp/impl/test/AbstractKSPAATest.kt rename to test-utils/src/test/kotlin/com/google/devtools/ksp/test/AbstractKSPAATest.kt index d42960e0f5..07b713741e 100644 --- a/kotlin-analysis-api/src/test/kotlin/com/google/devtools/ksp/impl/test/AbstractKSPAATest.kt +++ b/test-utils/src/test/kotlin/com/google/devtools/ksp/test/AbstractKSPAATest.kt @@ -15,13 +15,12 @@ * limitations under the License. */ -package com.google.devtools.ksp.impl.test +package com.google.devtools.ksp.test import com.google.devtools.ksp.impl.CommandLineKSPLogger import com.google.devtools.ksp.impl.KSPJvmConfig import com.google.devtools.ksp.impl.KotlinSymbolProcessing import com.google.devtools.ksp.processor.AbstractTestProcessor -import com.google.devtools.ksp.testutils.AbstractKSPTest import org.jetbrains.kotlin.cli.jvm.K2JVMCompiler import org.jetbrains.kotlin.cli.jvm.config.jvmClasspathRoots import org.jetbrains.kotlin.cli.jvm.config.jvmModularRoots diff --git a/compiler-plugin/src/test/kotlin/com/google/devtools/ksp/test/AbstractKSPCompilerPluginTest.kt b/test-utils/src/test/kotlin/com/google/devtools/ksp/test/AbstractKSPCompilerPluginTest.kt similarity index 98% rename from compiler-plugin/src/test/kotlin/com/google/devtools/ksp/test/AbstractKSPCompilerPluginTest.kt rename to test-utils/src/test/kotlin/com/google/devtools/ksp/test/AbstractKSPCompilerPluginTest.kt index dc86ccc307..5dc8255cd1 100644 --- a/compiler-plugin/src/test/kotlin/com/google/devtools/ksp/test/AbstractKSPCompilerPluginTest.kt +++ b/test-utils/src/test/kotlin/com/google/devtools/ksp/test/AbstractKSPCompilerPluginTest.kt @@ -5,7 +5,6 @@ import com.google.devtools.ksp.KotlinSymbolProcessingExtension import com.google.devtools.ksp.KspOptions import com.google.devtools.ksp.processing.impl.MessageCollectorBasedKSPLogger import com.google.devtools.ksp.processor.AbstractTestProcessor -import com.google.devtools.ksp.testutils.AbstractKSPTest import org.jetbrains.kotlin.cli.common.messages.MessageRenderer import org.jetbrains.kotlin.cli.common.messages.PrintingMessageCollector import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles diff --git a/test-utils/src/main/kotlin/com/google/devtools/ksp/testutils/AbstractKSPTest.kt b/test-utils/src/test/kotlin/com/google/devtools/ksp/test/AbstractKSPTest.kt similarity index 97% rename from test-utils/src/main/kotlin/com/google/devtools/ksp/testutils/AbstractKSPTest.kt rename to test-utils/src/test/kotlin/com/google/devtools/ksp/test/AbstractKSPTest.kt index b2d89bfb5d..0a74a05238 100644 --- a/test-utils/src/main/kotlin/com/google/devtools/ksp/testutils/AbstractKSPTest.kt +++ b/test-utils/src/test/kotlin/com/google/devtools/ksp/test/AbstractKSPTest.kt @@ -1,6 +1,6 @@ /* - * Copyright 2022 Google LLC - * Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Copyright 2023 Google LLC + * Copyright 2010-2023 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. @@ -15,7 +15,7 @@ * limitations under the License. */ -package com.google.devtools.ksp.testutils +package com.google.devtools.ksp.test import com.google.devtools.ksp.processor.AbstractTestProcessor import com.intellij.openapi.Disposable @@ -74,7 +74,7 @@ abstract class AbstractKSPTest(frontend: FrontendKind<*>) : DisposableTest() { val EXPECTED_RESULTS = "// EXPECTED:" } - val kspTestRoot = KtTestUtil.tmpDir("test") + val kspTestRoot = KtTestUtil.tmpDir("com/google/devtools/ksp/test/testgoogle/devtools/ksp/test/test") fun rootDirForModule(name: String) = File(kspTestRoot, name) fun outDirForModule(name: String) = File(rootDirForModule(name), "out") fun javaDirForModule(name: String) = File(rootDirForModule(name), "javaSrc") diff --git a/kotlin-analysis-api/src/test/kotlin/com/google/devtools/ksp/impl/test/KSPAATest.kt b/test-utils/src/test/kotlin/com/google/devtools/ksp/test/KSPAATest.kt similarity index 97% rename from kotlin-analysis-api/src/test/kotlin/com/google/devtools/ksp/impl/test/KSPAATest.kt rename to test-utils/src/test/kotlin/com/google/devtools/ksp/test/KSPAATest.kt index 01b1f9802d..ae7793eab2 100644 --- a/kotlin-analysis-api/src/test/kotlin/com/google/devtools/ksp/impl/test/KSPAATest.kt +++ b/test-utils/src/test/kotlin/com/google/devtools/ksp/test/KSPAATest.kt @@ -15,7 +15,7 @@ * limitations under the License. */ -package com.google.devtools.ksp.impl.test +package com.google.devtools.ksp.test import org.jetbrains.kotlin.test.TestMetadata import org.junit.jupiter.api.Disabled @@ -25,6 +25,7 @@ import org.junit.jupiter.api.condition.OS import org.junit.jupiter.api.parallel.Execution import org.junit.jupiter.api.parallel.ExecutionMode +@Disabled @Execution(ExecutionMode.SAME_THREAD) @DisabledOnOs(OS.WINDOWS) class KSPAATest : AbstractKSPAATest() { @@ -311,7 +312,7 @@ class KSPAATest : AbstractKSPAATest() { @TestMetadata("innerTypes.kt") @Test fun testInnerTypes() { - runTest("testData/innerTypes.kt") + runTest("../kotlin-analysis-api/testData/innerTypes.kt") } @TestMetadata("interfaceWithDefault.kt") @@ -323,7 +324,7 @@ class KSPAATest : AbstractKSPAATest() { @TestMetadata("javaModifiers.kt") @Test fun testJavaModifiers() { - runTest("testData/javaModifiers.kt") + runTest("../kotlin-analysis-api/testData/javaModifiers.kt") } @TestMetadata("javaNonNullTypes.kt") @@ -405,7 +406,7 @@ class KSPAATest : AbstractKSPAATest() { @TestMetadata("nestedClassType.kt") @Test fun testNestedClassType() { - runTest("testData/nestedClassType.kt") + runTest("../kotlin-analysis-api/testData/nestedClassType.kt") } @TestMetadata("nullableTypes.kt") @@ -430,7 +431,7 @@ class KSPAATest : AbstractKSPAATest() { @TestMetadata("javaAnno.kt") @Test fun testJavaAnno() { - runTest("testData/overridee/javaAnno.kt") + runTest("../kotlin-analysis-api/testData/overridee/javaAnno.kt") } @TestMetadata("javaOverrideInSource.kt") @@ -460,7 +461,7 @@ class KSPAATest : AbstractKSPAATest() { @TestMetadata("overrideOrder.kt") @Test fun testOverrideOrder() { - runTest("testData/overridee/overrideOrder.kt") + runTest("../kotlin-analysis-api/testData/overridee/overrideOrder.kt") } @TestMetadata("primaryConstructorOverride.kt") @@ -624,7 +625,7 @@ class KSPAATest : AbstractKSPAATest() { @TestMetadata("visibilities.kt") @Test fun testVisibilities() { - runTest("testData/visibilities.kt") + runTest("../kotlin-analysis-api/testData/visibilities.kt") } @TestMetadata("multipleround.kt") diff --git a/compiler-plugin/src/test/kotlin/com/google/devtools/ksp/test/KSPCompilerPluginTest.kt b/test-utils/src/test/kotlin/com/google/devtools/ksp/test/KSPCompilerPluginTest.kt similarity index 100% rename from compiler-plugin/src/test/kotlin/com/google/devtools/ksp/test/KSPCompilerPluginTest.kt rename to test-utils/src/test/kotlin/com/google/devtools/ksp/test/KSPCompilerPluginTest.kt