Browse Source

Fix deprecated Intellij API usages (#2554)

* Update Intellij Gradle plugin

* Drop support for Intellij < 2021.3

The latest stable Android Studio (Dolphin) is based on 2021.3,
so we can drop support for older versions.

* Remove usages of deprecated Intellij APIs

* Remove upper Intellij version limit
pull/2556/head v1.3.0-beta04-dev889
Alexey Tsvetkov 2 years ago committed by GitHub
parent
commit
d11cda865d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      idea-plugin/build.gradle.kts
  2. 7
      idea-plugin/gradle.properties
  3. 17
      idea-plugin/src/main/kotlin/org/jetbrains/compose/desktop/ide/preview/PreviewFloatingToolbarProvider.kt
  4. 1
      idea-plugin/src/main/kotlin/org/jetbrains/compose/desktop/ide/preview/editorUtils.kt
  5. 9
      idea-plugin/src/main/kotlin/org/jetbrains/compose/desktop/ide/preview/ijCompatibilityUtils.kt

4
idea-plugin/build.gradle.kts

@ -3,7 +3,7 @@ import org.jetbrains.kotlin.gradle.dsl.KotlinJvmCompile
plugins { plugins {
id("java") id("java")
id("org.jetbrains.kotlin.jvm") version "1.5.10" id("org.jetbrains.kotlin.jvm") version "1.5.10"
id("org.jetbrains.intellij") version "1.6.0" id("org.jetbrains.intellij") version "1.10.1"
id("org.jetbrains.changelog") version "1.3.1" id("org.jetbrains.changelog") version "1.3.1"
} }
@ -57,7 +57,6 @@ tasks {
patchPluginXml { patchPluginXml {
sinceBuild.set(projectProperties.pluginSinceBuild) sinceBuild.set(projectProperties.pluginSinceBuild)
untilBuild.set(projectProperties.pluginUntilBuild)
} }
runPluginVerifier { runPluginVerifier {
@ -72,7 +71,6 @@ class ProjectProperties(private val project: Project) {
val platformDownloadSources get() = stringProperty("platform.download.sources").toBoolean() val platformDownloadSources get() = stringProperty("platform.download.sources").toBoolean()
val pluginChannels get() = listProperty("plugin.channels") val pluginChannels get() = listProperty("plugin.channels")
val pluginSinceBuild get() = stringProperty("plugin.since.build") val pluginSinceBuild get() = stringProperty("plugin.since.build")
val pluginUntilBuild get() = stringProperty("plugin.until.build")
val pluginVerifierIdeVersions get() = listProperty("plugin.verifier.ide.versions") val pluginVerifierIdeVersions get() = listProperty("plugin.verifier.ide.versions")
private fun stringProperty(key: String): String = private fun stringProperty(key: String): String =

7
idea-plugin/gradle.properties

@ -5,11 +5,10 @@ kotlin.stdlib.default.dependency=false
deploy.version=0.1-SNAPSHOT deploy.version=0.1-SNAPSHOT
plugin.channels=snapshots plugin.channels=snapshots
plugin.since.build=203 plugin.since.build=213
plugin.until.build=233.*
## See https://jb.gg/intellij-platform-builds-list for available build versions. ## See https://jb.gg/intellij-platform-builds-list for available build versions.
plugin.verifier.ide.versions=2021.1, 2022.1, 2022.2 plugin.verifier.ide.versions=2021.3, 2022.1, 2022.2
platform.type=IC platform.type=IC
platform.version=2021.1 platform.version=2021.3
platform.download.sources=true platform.download.sources=true

17
idea-plugin/src/main/kotlin/org/jetbrains/compose/desktop/ide/preview/PreviewFloatingToolbarProvider.kt

@ -8,33 +8,18 @@ package org.jetbrains.compose.desktop.ide.preview
import com.intellij.openapi.Disposable import com.intellij.openapi.Disposable
import com.intellij.openapi.actionSystem.CommonDataKeys import com.intellij.openapi.actionSystem.CommonDataKeys
import com.intellij.openapi.actionSystem.DataContext import com.intellij.openapi.actionSystem.DataContext
import com.intellij.openapi.application.ReadAction
import com.intellij.openapi.editor.Editor import com.intellij.openapi.editor.Editor
import com.intellij.openapi.editor.event.CaretEvent import com.intellij.openapi.editor.event.CaretEvent
import com.intellij.openapi.editor.event.CaretListener import com.intellij.openapi.editor.event.CaretListener
import com.intellij.openapi.editor.toolbar.floating.AbstractFloatingToolbarProvider import com.intellij.openapi.editor.toolbar.floating.AbstractFloatingToolbarProvider
import com.intellij.openapi.editor.toolbar.floating.FloatingToolbarComponent import com.intellij.openapi.editor.toolbar.floating.FloatingToolbarComponent
import com.intellij.openapi.editor.toolbar.floating.FloatingToolbarComponentImpl
import com.intellij.openapi.project.Project import com.intellij.openapi.project.Project
import com.intellij.util.concurrency.AppExecutorUtil import com.intellij.util.concurrency.AppExecutorUtil
class PreviewFloatingToolbarProvider : AbstractFloatingToolbarProvider(PREVIEW_EDITOR_TOOLBAR_GROUP_ID) { class PreviewFloatingToolbarProvider : AbstractFloatingToolbarProvider(PREVIEW_EDITOR_TOOLBAR_GROUP_ID) {
override val autoHideable = false override val autoHideable = false
override val priority: Int = 100
// todo: disable if not in Compose JVM module // todo: disable if not in Compose JVM module
override fun register(toolbar: FloatingToolbarComponent, parentDisposable: Disposable) {
try {
// todo: use provided data context once 2020.3 is no longer supported
val toolbarClass = FloatingToolbarComponentImpl::class.java
val getDataMethod = toolbarClass.getMethod("getData", String::class.java)
val editor = getDataMethod.invoke(toolbar, CommonDataKeys.EDITOR.name) as? Editor ?: return
registerComponent(toolbar, editor, parentDisposable)
} catch (e: Exception) {
LOG.error(e)
}
}
override fun register(dataContext: DataContext, component: FloatingToolbarComponent, parentDisposable: Disposable) { override fun register(dataContext: DataContext, component: FloatingToolbarComponent, parentDisposable: Disposable) {
val editor = dataContext.getData(CommonDataKeys.EDITOR) ?: return val editor = dataContext.getData(CommonDataKeys.EDITOR) ?: return
registerComponent(component, editor, parentDisposable) registerComponent(component, editor, parentDisposable)
@ -59,7 +44,7 @@ internal class PreviewEditorToolbarVisibilityUpdater(
private val editor: Editor private val editor: Editor
) : CaretListener { ) : CaretListener {
override fun caretPositionChanged(event: CaretEvent) { override fun caretPositionChanged(event: CaretEvent) {
ReadAction.nonBlocking { updateVisibility() } runNonBlocking { updateVisibility() }
.inSmartMode(project) .inSmartMode(project)
.submit(AppExecutorUtil.getAppExecutorService()) .submit(AppExecutorUtil.getAppExecutorService())
} }

1
idea-plugin/src/main/kotlin/org/jetbrains/compose/desktop/ide/preview/editorUtils.kt

@ -9,7 +9,6 @@ import com.intellij.openapi.editor.Editor
import com.intellij.openapi.fileEditor.FileDocumentManager import com.intellij.openapi.fileEditor.FileDocumentManager
import com.intellij.psi.PsiFile import com.intellij.psi.PsiFile
import com.intellij.psi.PsiManager import com.intellij.psi.PsiManager
import com.intellij.testFramework.LightVirtualFile
import com.intellij.util.concurrency.annotations.RequiresReadLock import com.intellij.util.concurrency.annotations.RequiresReadLock
import org.jetbrains.kotlin.idea.KotlinFileType import org.jetbrains.kotlin.idea.KotlinFileType
import org.jetbrains.kotlin.psi.KtNamedFunction import org.jetbrains.kotlin.psi.KtNamedFunction

9
idea-plugin/src/main/kotlin/org/jetbrains/compose/desktop/ide/preview/ijCompatibilityUtils.kt

@ -6,10 +6,13 @@
package org.jetbrains.compose.desktop.ide.preview package org.jetbrains.compose.desktop.ide.preview
import com.intellij.ide.lightEdit.LightEdit import com.intellij.ide.lightEdit.LightEdit
import com.intellij.openapi.application.NonBlockingReadAction
import com.intellij.openapi.application.ReadAction
import com.intellij.openapi.externalSystem.model.Key import com.intellij.openapi.externalSystem.model.Key
import com.intellij.openapi.externalSystem.model.project.AbstractNamedData import com.intellij.openapi.externalSystem.model.project.AbstractNamedData
import com.intellij.openapi.project.Project import com.intellij.openapi.project.Project
import java.lang.reflect.Modifier import java.lang.reflect.Modifier
import java.util.concurrent.Callable
// todo: filter only Compose projects // todo: filter only Compose projects
internal fun isPreviewCompatible(project: Project): Boolean = internal fun isPreviewCompatible(project: Project): Boolean =
@ -34,3 +37,9 @@ internal val kotlinTargetDataKey: Key<out AbstractNamedData> = run {
@Suppress("UNCHECKED_CAST") @Suppress("UNCHECKED_CAST")
getKeyMethod.invoke(companionInstance) as Key<out AbstractNamedData> getKeyMethod.invoke(companionInstance) as Key<out AbstractNamedData>
} }
internal inline fun runNonBlocking(crossinline fn: () -> Unit): NonBlockingReadAction<Void?> =
ReadAction.nonBlocking(Callable<Void?> {
fn()
null
})
Loading…
Cancel
Save