Skip to content

Commit

Permalink
Bump Kotlin to 2.0.0-Beta1 (apollographql#5373)
Browse files Browse the repository at this point in the history
  • Loading branch information
BoD authored Nov 17, 2023
1 parent 608e15e commit 4b4b253
Show file tree
Hide file tree
Showing 11 changed files with 216 additions and 165 deletions.
10 changes: 5 additions & 5 deletions gradle/libraries.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,21 @@ apollo = "4.0.0-beta.3-SNAPSHOT"
apollo-published = "4.0.0-beta.2"
cache = "2.0.2"
# See https://developer.android.com/jetpack/androidx/releases/compose-kotlin
compose-compiler = "1.5.4-dev-k1.9.20-50f08dfa4b4"
compose-compiler = "1.5.5-dev-k2.0.0-Beta1-06b8ae672a4"
compose = "1.5.1"
dokka = "1.9.0"
guava = "31.1-jre"
javaPoet = "1.13.0"
jetbrains-annotations = "24.0.1"
junit = "4.13.2"
kotlin-plugin-min = "1.8.0"
kotlin-plugin = "1.9.20"
kotlin-plugin-max = "1.9.20"
kotlin-stdlib = "1.9.20"
kotlin-plugin = "2.0.0-Beta1"
kotlin-plugin-max = "2.0.0-Beta1"
kotlin-stdlib = "2.0.0-Beta1"
kotlinx-coroutines = "1.7.3"
kotlinx-datetime = "0.4.1"
kotlinx-serialization-runtime = "1.5.0"
ksp = "1.9.20-1.0.13"
ksp = "2.0.0-Beta1-1.0.14"
ktor = "2.3.3"
okhttp = "4.11.0"
rx-android = "2.0.1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import org.jetbrains.annotations.PropertyKey
@NonNls
private const val BUNDLE = "messages.ApolloBundle"

@Suppress("SpreadOperator", "unused")
@Suppress("SpreadOperator")
object ApolloBundle : DynamicBundle(BUNDLE) {
@JvmStatic
fun message(@PropertyKey(resourceBundle = BUNDLE) key: String, vararg params: Any) =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.apollographql.ijplugin.util.capitalizeFirstLetter
import com.apollographql.ijplugin.util.containingKtFile
import com.apollographql.ijplugin.util.findChildrenOfType
import com.apollographql.ijplugin.util.resolveKtName
import com.apollographql.ijplugin.util.type
import com.intellij.lang.jsgraphql.GraphQLFileType
import com.intellij.lang.jsgraphql.psi.GraphQLDefinition
import com.intellij.lang.jsgraphql.psi.GraphQLElement
Expand All @@ -23,13 +24,13 @@ import com.intellij.lang.jsgraphql.psi.GraphQLTypeNameDefinition
import com.intellij.openapi.project.Project
import com.intellij.psi.PsiComment
import com.intellij.psi.PsiManager
import com.intellij.psi.PsiNamedElement
import com.intellij.psi.search.FileTypeIndex
import com.intellij.psi.search.GlobalSearchScope
import com.intellij.psi.util.descendantsOfType
import org.jetbrains.kotlin.idea.base.psi.kotlinFqName
import org.jetbrains.kotlin.idea.base.utils.fqname.fqName
import org.jetbrains.kotlin.idea.base.utils.fqname.getKotlinFqName
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.nj2k.postProcessing.type
import org.jetbrains.kotlin.psi.KtClass
import org.jetbrains.kotlin.psi.KtElement
import org.jetbrains.kotlin.psi.KtEnumEntry
Expand Down Expand Up @@ -66,29 +67,29 @@ fun KtElement.isApolloModelField() = topMostContainingClass()

fun KtClass.isApolloOperation(): Boolean {
return superTypeListEntries.any {
val superType = it.typeAsUserType?.referenceExpression?.resolveKtName()?.getKotlinFqName()
val superType = it.typeAsUserType?.referenceExpression?.resolveKtName()?.kotlinFqName
superType in APOLLO_OPERATION_TYPES
}
}

fun KtClass.isApolloFragment(): Boolean {
return superTypeListEntries.any {
val superType = it.typeAsUserType?.referenceExpression?.resolveKtName()?.getKotlinFqName()
val superType = it.typeAsUserType?.referenceExpression?.resolveKtName()?.kotlinFqName
superType == APOLLO_FRAGMENT_TYPE
} ||
// Fallback for fragments in responseBased codegen: they are interfaces generated in a .fragment package.
// This can lead to false positives, but consequences are not dire.
isInterface() && getKotlinFqName()?.parent()?.shortName()?.asString() == "fragment" && hasGeneratedByApolloComment()
isInterface() && kotlinFqName?.parent()?.shortName()?.asString() == "fragment" && hasGeneratedByApolloComment()
}

fun KtClass.isApolloOperationOrFragment(): Boolean {
return superTypeListEntries.any {
val superType = it.typeAsUserType?.referenceExpression?.resolveKtName()?.getKotlinFqName()
val superType = it.typeAsUserType?.referenceExpression?.resolveKtName()?.kotlinFqName
superType in APOLLO_OPERATION_TYPES || superType == APOLLO_FRAGMENT_TYPE
} ||
// Fallback for fragments in responseBased codegen: they are interfaces generated in a .fragment package.
// This can lead to false positives, but consequences are not dire.
isInterface() && getKotlinFqName()?.parent()?.shortName()?.asString() == "fragment" && hasGeneratedByApolloComment()
isInterface() && kotlinFqName?.parent()?.shortName()?.asString() == "fragment" && hasGeneratedByApolloComment()
}

fun KtNameReferenceExpression.isApolloEnumClassReference(): Boolean {
Expand Down Expand Up @@ -118,7 +119,7 @@ fun KtClass.isApolloInputClass(): Boolean {
// Apollo input classes are data classes, generated in a package named "type", and we also look at the header comment.
// This can lead to false positives, but consequences are not dire.
return isData() &&
getKotlinFqName()?.parent()?.shortName()?.asString() == "type" &&
kotlinFqName?.parent()?.shortName()?.asString() == "type" &&
hasGeneratedByApolloComment()
}

Expand Down Expand Up @@ -264,7 +265,7 @@ private fun KtClass.elementPath(element: KtElement): List<String> {
// For lists
parameterType?.arguments?.firstOrNull()?.type?.fqName == modelClass.fqName
) {
parameterPath.add(0, property.name!!)
parameterPath.add(0, (property as PsiNamedElement).name!!)
modelClass = candidateModelClass
found = true
break@findClass
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.apollographql.ijplugin.navigation

import com.apollographql.ijplugin.util.capitalizeFirstLetter
import com.apollographql.ijplugin.util.cast
import com.apollographql.ijplugin.util.decapitalizeFirstLetter
import com.apollographql.ijplugin.util.findChildrenOfType
import com.apollographql.ijplugin.util.type
import com.intellij.lang.jsgraphql.psi.GraphQLElement
import com.intellij.lang.jsgraphql.psi.GraphQLEnumTypeDefinition
import com.intellij.lang.jsgraphql.psi.GraphQLEnumValue
Expand All @@ -16,12 +18,12 @@ import com.intellij.lang.jsgraphql.psi.GraphQLTypedOperationDefinition
import com.intellij.openapi.project.Project
import com.intellij.psi.PsiClass
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiNamedElement
import com.intellij.psi.search.GlobalSearchScope
import com.intellij.psi.search.PsiShortNamesCache
import com.intellij.psi.util.parentOfType
import org.jetbrains.kotlin.asJava.classes.KtUltraLightClass
import org.jetbrains.kotlin.idea.base.utils.fqname.fqName
import org.jetbrains.kotlin.nj2k.postProcessing.type
import org.jetbrains.kotlin.psi.KtClass
import org.jetbrains.kotlin.psi.KtEnumEntry
import org.jetbrains.kotlin.psi.KtNamedDeclaration
Expand All @@ -47,14 +49,14 @@ fun findKotlinFieldDefinitions(graphQLField: GraphQLField): List<PsiElement> {
val ktClasses = findKotlinClassOfParent(graphQLField)
return ktClasses?.mapNotNull { ktClass ->
// Try Data class first (operations)
var c = ktClass.findChildrenOfType<KtClass> { it.name == "Data" }.firstOrNull()
var c = ktClass.findChildrenOfType<KtClass> { (it as PsiNamedElement).name == "Data" }.firstOrNull()
// Fallback to class itself (fragments)
?: ktClass
var ktFieldDefinition: KtNamedDeclaration? = null
for ((i, pathElement) in path.withIndex()) {
// Look for the element in the constructor parameters (for data classes) and in the properties (for interfaces)
val properties = c.primaryConstructor?.valueParameters.orEmpty() + c.getProperties()
ktFieldDefinition = properties.firstOrNull { it.name == pathElement } ?: continue
ktFieldDefinition = properties.firstOrNull { (it as PsiNamedElement).name == pathElement } ?: continue
val parameterType = ktFieldDefinition.type()
val parameterTypeFqName =
// Try Lists first
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import com.apollographql.ijplugin.refactoring.findReferences
import com.apollographql.ijplugin.refactoring.migration.item.MigrationItem
import com.apollographql.ijplugin.refactoring.migration.item.MigrationItemUsageInfo
import com.apollographql.ijplugin.refactoring.migration.item.toMigrationItemUsageInfo
import com.apollographql.ijplugin.util.type
import com.intellij.openapi.project.Project
import com.intellij.psi.PsiMigration
import com.intellij.psi.PsiReference
import com.intellij.psi.search.GlobalSearchScope
import org.jetbrains.kotlin.idea.base.utils.fqname.fqName
import org.jetbrains.kotlin.nj2k.postProcessing.type
import org.jetbrains.kotlin.psi.KtClass
import org.jetbrains.kotlin.psi.KtClassOrObject
import org.jetbrains.kotlin.psi.KtParameter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ package com.apollographql.ijplugin.refactoring.migration.v2tov3.item
import com.apollographql.ijplugin.refactoring.findMethodReferences
import com.apollographql.ijplugin.refactoring.migration.item.MigrationItem
import com.apollographql.ijplugin.refactoring.migration.item.MigrationItemUsageInfo
import com.apollographql.ijplugin.util.resolve
import com.intellij.openapi.project.Project
import com.intellij.psi.PsiMigration
import com.intellij.psi.search.GlobalSearchScope
import com.intellij.psi.util.parentOfType
import org.jetbrains.kotlin.nj2k.postProcessing.resolve
import org.jetbrains.kotlin.psi.KtCallExpression
import org.jetbrains.kotlin.psi.KtDotQualifiedExpression
import org.jetbrains.kotlin.psi.KtEnumEntry
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import com.apollographql.ijplugin.refactoring.findMethodReferences
import com.apollographql.ijplugin.refactoring.migration.item.DeletesElements
import com.apollographql.ijplugin.refactoring.migration.item.MigrationItem
import com.apollographql.ijplugin.refactoring.migration.item.MigrationItemUsageInfo
import com.apollographql.ijplugin.util.resolve
import com.intellij.openapi.project.Project
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiMigration
import com.intellij.psi.search.GlobalSearchScope
import org.jetbrains.kotlin.nj2k.postProcessing.resolve
import org.jetbrains.kotlin.psi.KtCallExpression
import org.jetbrains.kotlin.psi.KtNameReferenceExpression
import org.jetbrains.kotlin.psi.KtProperty
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,20 @@ package com.apollographql.ijplugin.util
import com.intellij.openapi.diagnostic.ControlFlowException
import com.intellij.psi.PsiElement
import com.intellij.psi.util.PsiTreeUtil
import org.jetbrains.kotlin.descriptors.CallableDescriptor
import org.jetbrains.kotlin.idea.caches.resolve.resolveToDescriptorIfAny
import org.jetbrains.kotlin.idea.references.KtSimpleNameReference
import org.jetbrains.kotlin.idea.references.mainReference
import org.jetbrains.kotlin.psi.KtBlockExpression
import org.jetbrains.kotlin.psi.KtCallExpression
import org.jetbrains.kotlin.psi.KtClass
import org.jetbrains.kotlin.psi.KtConstructor
import org.jetbrains.kotlin.psi.KtDeclaration
import org.jetbrains.kotlin.psi.KtFile
import org.jetbrains.kotlin.psi.KtImportList
import org.jetbrains.kotlin.psi.KtLambdaArgument
import org.jetbrains.kotlin.psi.KtNameReferenceExpression
import org.jetbrains.kotlin.psi.KtReferenceExpression
import org.jetbrains.kotlin.psi.psiUtil.containingClass
import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType
import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull
Expand Down Expand Up @@ -66,3 +71,7 @@ fun PsiElement.originalClassName(): String? = resolveKtName()?.asKtClass()?.name
fun KtCallExpression.getMethodName(): String? = calleeExpression.cast<KtNameReferenceExpression>()?.getReferencedName()

fun KtCallExpression.lambdaBlockExpression(): KtBlockExpression? = valueArguments.firstIsInstanceOrNull<KtLambdaArgument>()?.getLambdaExpression()?.bodyExpression

fun KtDeclaration.type() = (resolveToDescriptorIfAny() as? CallableDescriptor)?.returnType

fun KtReferenceExpression.resolve() = mainReference.resolve()
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,9 @@ fs.realpath@^1.0.0:
integrity sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==

fsevents@~2.3.2:
version "2.3.2"
resolved "https://registry.yarnpkg.com/fsevents/-/fsevents-2.3.2.tgz#8a526f78b8fdf4623b709e0b975c52c24c02fd1a"
integrity sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==
version "2.3.3"
resolved "https://registry.yarnpkg.com/fsevents/-/fsevents-2.3.3.tgz#cac6407785d03675a2a5e1a5305c697b347d90d6"
integrity sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==

get-caller-file@^2.0.5:
version "2.0.5"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
plugins {
alias(libs.plugins.kotlin.multiplatform)
// Using a version < 2.0 of the Kotlin plugin because LEGACY js target is no longer supported in 2.0+
id("org.jetbrains.kotlin.multiplatform").version("1.9.20")
alias(libs.plugins.apollo)
}

Expand Down
Loading

0 comments on commit 4b4b253

Please sign in to comment.