Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

disable KSPAATest on release branch #1532

Merged
merged 5 commits into from
Sep 13, 2023
Merged
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
5 changes: 0 additions & 5 deletions common-util/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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")
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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<T>(private val k: T) {
override fun equals(other: Any?): Boolean = if (other is IdKey<*>) k === other.k else false
Expand All @@ -22,8 +20,6 @@ class IdKeyTriple<T, P, Q>(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<KSType> {
return annotated.annotations
Expand Down
79 changes: 0 additions & 79 deletions common-util/src/main/kotlin/com/google/devtools/ksp/PsiUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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<Modifier> {
if (this == null)
return emptySet()
val modifiers = mutableSetOf<Modifier>()
modifiers.addAll(
modifierMap.entries
.filter { hasModifier(it.key) }
.map { it.value }
)
return modifiers
}

fun KtModifierListOwner.toKSModifiers(): Set<Modifier> {
val modifierList = this.modifierList
return modifierList.toKSModifiers()
}

fun PsiModifierListOwner.toKSModifiers(): Set<Modifier> {
val modifiers = mutableSetOf<Modifier>()
modifiers.addAll(
Expand Down Expand Up @@ -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 <reified T> PsiElement.findParentOfType(): T? {
var parent = this.parent
while (parent != null && parent !is T) {
Expand Down
74 changes: 0 additions & 74 deletions compiler-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import com.google.devtools.ksp.RelativizingPathProvider
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

evaluationDependsOn(":common-util")
Expand All @@ -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<KotlinCompile> {
compilerOptions.freeCompilerArgs.add("-Xjvm-default=all-compatibility")
Expand Down Expand Up @@ -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<Copy>("CopyLibsForTesting") {
from(configurations.get("libsForTesting"))
into("dist/kotlinc/lib")
val escaped = Regex.escape(kotlinBaseVersion)
rename("(.+)-$escaped\\.jar", "$1.jar")
}

tasks.register<Copy>("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<Jar>("dokkaJavadocJar") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<KspOptions.Builder>("Ksp options")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -123,15 +124,6 @@ fun FunctionDescriptor.toFunctionKSModifiers(): Set<Modifier> {
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.
Expand Down
Original file line number Diff line number Diff line change
@@ -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<Modifier> {
val modifierList = this.modifierList
return modifierList.toKSModifiers()
}

fun KtModifierList?.toKSModifiers(): Set<Modifier> {
if (this == null)
return emptySet()
val modifiers = mutableSetOf<Modifier>()
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")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading
Loading