Skip to content

Commit

Permalink
Test against 2023.2 (#4446)
Browse files Browse the repository at this point in the history
* Test against 2023.2

* Update dependency mkdocs-material-extensions to v1.3.1 (#4832)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* Update dependency com.squareup:kotlinpoet to v1.15.2 (#4855)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* Bump sql-psi to 0.5.0 (#4794)

* Bump sql-psi to 0.5.0-SNAPSHOT

* Use published loadFolderFromResources function

* Expose HSQL test-fixtures

* Expose MySql test-fixtures

* Move timber from sql-psi to sqldelight

* Expose Sqlite Json test-fixtures

* Expose Sqlite 3.18 test-fixtures

* Expose Sqlite 3.24 test-fixtures

* Expose Sqlite 3.25 test-fixtures

* Expose Sqlite 3.30 test-fixtures

* Expose Sqlite 3.33 test-fixtures

* Expose Sqlite 3.35 test-fixtures

* Expose Sqlite 3.38 test-fixtures

* Spotless

* Adopt changed sql-psi api

* Add snapshot repo to test snapshot

* Fix Infer between

* Add missing snapshot repo

* Add missing snapshot repo

* Switch to the release version

* Use new loadFolderFromResources shortcut

---------

Co-authored-by: hfhbd <hfhbd@users.noreply.github.com>

* Add TRUNCATE to postgres dialect (#4817)

Co-authored-by: Alec Kazakova <1675456+AlecKazakova@users.noreply.github.com>

* feat: add initialOffset for OffsetQueryPagingSource (#4802)

* feat: add initialOffset for OffsetQueryPagingSource

* apply spotless check

* binary compatibility overload

* typo

* add @jvmoverloads for ABI compatibility

* add @jvmoverloads for ABI compatibility

* Update agp to v8.2.0 (#4861)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* Update plugin intellij to v1.16.1 (#4862)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* Fix compatibility issues

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Philip Wedemann <22521688+hfhbd@users.noreply.github.com>
Co-authored-by: hfhbd <hfhbd@users.noreply.github.com>
Co-authored-by: Bastien de Luca <de-luca@users.noreply.github.com>
Co-authored-by: Mohamad Jaara <jaara.moh@gmail.com>
  • Loading branch information
6 people authored Dec 1, 2023
1 parent 882d47e commit 471afc4
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 9 deletions.
1 change: 1 addition & 0 deletions sqldelight-compiler/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ dependencies {

testImplementation libs.kotlin.test.junit
testImplementation libs.truth
testImplementation projects.sqldelightGradlePlugin
testImplementation projects.testUtil
testImplementation projects.dialects.hsql
testImplementation projects.dialects.mysql
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import app.cash.sqldelight.core.lang.SqlDelightFileType
import app.cash.sqldelight.core.lang.SqlDelightParserDefinition
import app.cash.sqldelight.core.lang.SqlDelightQueriesFile
import app.cash.sqldelight.core.lang.util.migrationFiles
import app.cash.sqldelight.core.lang.util.sqFile
import app.cash.sqldelight.core.lang.validation.OptimisticLockValidator
import app.cash.sqldelight.core.psi.SqlDelightImportStmt
import app.cash.sqldelight.dialect.api.SqlDelightDialect
Expand Down Expand Up @@ -137,7 +136,7 @@ class SqlDelightEnvironment(
annotate(
extraAnnotators,
) { element, message ->
val key = element.sqFile().order ?: Long.MAX_VALUE
val key = (element.containingFile as SqlDelightFile).order ?: Long.MAX_VALUE
errors.putIfAbsent(key, ArrayList())
errors[key]!!.add(errorMessage(element, message))
}
Expand Down
1 change: 1 addition & 0 deletions sqldelight-idea-plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ tasks.named('runPluginVerifier') {
"IC-2022.2.4", // AS: Flamingo | 2022.2.1
"IC-2022.3.1", // IC
"IC-2023.1", // IC
"IC-2023.2", // IC
]

def customFailureLevel = FailureLevel.ALL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import app.cash.sqldelight.core.lang.psi.ImportStmtMixin
import app.cash.sqldelight.core.lang.psi.JavaTypeMixin
import app.cash.sqldelight.core.lang.util.findChildrenOfType
import app.cash.sqldelight.core.psi.SqlDelightImportStmt
import app.cash.sqldelight.intellij.util.compatibleKey
import com.intellij.patterns.PlatformPatterns.psiElement
import com.intellij.psi.JavaPsiFacade
import com.intellij.psi.PsiElement
Expand Down Expand Up @@ -65,7 +66,7 @@ internal class SqlDelightReferenceContributor : PsiReferenceContributor() {
val project = element.project
val scope = GlobalSearchScope.allScope(project)
val ktClass = { KotlinFullClassNameIndex[qName, project, scope].firstOrNull() }
val indexKey = getKotlinTopLevelTypeAliasFqNameIndex()
val indexKey = KotlinTopLevelTypeAliasFqNameIndex::class.compatibleKey()
val typeAlias = {
StubIndex.getElements(indexKey, qName, project, scope, KtTypeAlias::class.java).firstOrNull()
}
Expand Down Expand Up @@ -98,7 +99,10 @@ private fun getKotlinTopLevelTypeAliasFqNameIndex(): StubIndexKey<String, KtType
val instanceField = KotlinTopLevelTypeAliasFqNameIndex::class.java.getField("INSTANCE")
val instance = instanceField.get(null)
if (instance is KotlinTopLevelTypeAliasFqNameIndex) {
return instance.KEY
val keyMethod = instance.javaClass.getMethod("getKEY")
val key = keyMethod.invoke(instance)
@Suppress("UNCHECKED_CAST") // Reflection that will go away when our minimum version is >= 2023.2
if (key != null) return key as StubIndexKey<String, KtTypeAlias>
}
} catch (e: Exception) {
/* intentionally empty, fall back to getInstance() call in case of errors */
Expand All @@ -107,8 +111,10 @@ private fun getKotlinTopLevelTypeAliasFqNameIndex(): StubIndexKey<String, KtType
// Call the method getInstance on the companion type.
val companionMethod =
KotlinTopLevelTypeAliasFqNameIndex::class.companionObject!!.java.getMethod("getInstance")
return (
companionMethod.invoke(KotlinTopLevelTypeAliasFqNameIndex::class.companionObjectInstance!!)
as KotlinTopLevelTypeAliasFqNameIndex
).KEY
val instance = companionMethod.invoke(KotlinTopLevelTypeAliasFqNameIndex::class.companionObjectInstance!!)
as KotlinTopLevelTypeAliasFqNameIndex
val keyMethod = instance.javaClass.getMethod("getKEY")
val key = keyMethod.invoke(instance)
@Suppress("UNCHECKED_CAST") // Reflection that will go away when our minimum version is >= 2023.2
return key as StubIndexKey<String, KtTypeAlias>
}
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ internal class FileIndexMap {
?: ExternalSystemJdkUtil.getJavaHome()
)?.let { File(it) }

Timber.i("Using java home $javaHome")

val properties =
connection.action(FetchProjectModelsBuildAction).setJavaHome(javaHome).run()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.intellij.openapi.project.Project
import com.intellij.psi.PsiClass
import com.intellij.psi.search.GlobalSearchScope
import com.intellij.psi.search.PsiShortNamesCache
import com.intellij.psi.stubs.StubIndex
import com.intellij.psi.util.PsiTreeUtil
import javax.swing.Icon
import org.jetbrains.kotlin.idea.stubindex.KotlinClassShortNameIndex
Expand All @@ -14,7 +15,8 @@ import org.jetbrains.kotlin.psi.KtClassOrObject
internal object PsiClassSearchHelper {

fun getClassesByShortName(shortName: String, project: Project, scope: GlobalSearchScope): List<ImportableType> {
val kotlinClasses = KotlinClassShortNameIndex.get(shortName, project, scope)
val indexKey = KotlinClassShortNameIndex::class.compatibleKey()
val kotlinClasses = StubIndex.getElements(indexKey, shortName, project, scope, KtClassOrObject::class.java)
.map(::KotlinType)
.sortedBy { it.qualifiedName }

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package app.cash.sqldelight.intellij.util

import com.intellij.psi.PsiElement
import com.intellij.psi.stubs.AbstractStubIndex
import com.intellij.psi.stubs.StubIndexKey
import kotlin.reflect.KClass
import kotlin.reflect.full.companionObject
import kotlin.reflect.full.companionObjectInstance

internal inline fun <P : PsiElement, reified T : AbstractStubIndex<String, P>> KClass<T>.compatibleKey(): StubIndexKey<String, P> {
// read the HELPER variable reflectively (2023.2)
try {
val helperField = this.java.getField("Helper")
val helper = helperField.get(null)
if (helper != null) {
val keyMethod = helper.javaClass.getMethod("getIndexKey")
val key = keyMethod.invoke(helper)
@Suppress("UNCHECKED_CAST") // Reflection that will go away when our minimum version is >= 2023.2
if (key != null) return key as StubIndexKey<String, P>
}
} catch (e: Exception) {
/* intentionally empty, fall back to getInstance() call in case of errors */
}

// read the INSTANCE variable reflectively first (newer Kotlin plugins)
try {
val instanceField = this.java.getField("INSTANCE")
val instance = instanceField.get(null)
if (instance is T) {
val keyMethod = instance.javaClass.getMethod("getKey")
val key = keyMethod.invoke(instance)
@Suppress("UNCHECKED_CAST") // Reflection that will go away when our minimum version is >= 2023.2
if (key != null) return key as StubIndexKey<String, P>
}
} catch (e: Exception) {
/* intentionally empty, fall back to getInstance() call in case of errors */
}

// Call the method getInstance on the companion type.
val companionMethod =
this.companionObject!!.java.getMethod("getInstance")
val instance = companionMethod.invoke(this.companionObjectInstance!!)
as T
val keyMethod = instance.javaClass.getMethod("getKey")
val key = keyMethod.invoke(instance)
@Suppress("UNCHECKED_CAST") // Reflection that will go away when our minimum version is >= 2023.2
return key as StubIndexKey<String, P>
}
1 change: 1 addition & 0 deletions test-util/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ dependencies {
implementation(projects.sqldelightCompiler.environment) {
targetConfiguration = "shadow"
}
implementation projects.sqldelightGradlePlugin
implementation libs.junit
}

0 comments on commit 471afc4

Please sign in to comment.