diff options
| author | Matthew Gharrity <gharrma@google.com> | 2021-07-21 13:31:22 -0400 |
|---|---|---|
| committer | Matthew Gharrity <gharrma@google.com> | 2021-07-22 03:49:28 +0000 |
| commit | 98e0cf1f34fd9faf8696ec578394e953a895b8e2 (patch) | |
| tree | 2696543d7b92f9078ae4423896196fbe24446929 | |
| parent | 28d8eb0086e675146b192f3705d96292ffdaddb2 (diff) | |
| download | platform_tools_adt_idea-98e0cf1f34fd9faf8696ec578394e953a895b8e2.tar.gz platform_tools_adt_idea-98e0cf1f34fd9faf8696ec578394e953a895b8e2.tar.bz2 platform_tools_adt_idea-98e0cf1f34fd9faf8696ec578394e953a895b8e2.zip | |
Hotfix for kt version warning in Compose projects
Compose projects must currently use Kotlin 1.5.10, but Android Studio
bundles Kotlin IDE plugin 1.5.20, and so the IDE warns that the IDE
version does not match the compiler version. This change suppresses
that warning.
The warning is only suppressed in projects which used Compose.
Bug: 194313332
Test: manual
Change-Id: Ia257aa64803b4326b9b1cf31ce62a5feaf6e8e0a
| -rw-r--r-- | compose-ide-plugin/src/META-INF/plugin.xml | 1 | ||||
| -rw-r--r-- | compose-ide-plugin/src/com/android/tools/compose/ComposeGradleInspectionSuppressor.kt | 42 |
2 files changed, 43 insertions, 0 deletions
diff --git a/compose-ide-plugin/src/META-INF/plugin.xml b/compose-ide-plugin/src/META-INF/plugin.xml index beaaec8e733..136422b3f60 100644 --- a/compose-ide-plugin/src/META-INF/plugin.xml +++ b/compose-ide-plugin/src/META-INF/plugin.xml @@ -96,6 +96,7 @@ order="first"/> <lang.inspectionSuppressor language="kotlin" implementationClass="com.android.tools.compose.ComposeSuppressor"/> + <lang.inspectionSuppressor language="Groovy" implementationClass="com.android.tools.compose.ComposeGradleInspectionSuppressor"/> <postFormatProcessor implementation="com.android.tools.compose.formatting.ComposePostFormatProcessor"/> diff --git a/compose-ide-plugin/src/com/android/tools/compose/ComposeGradleInspectionSuppressor.kt b/compose-ide-plugin/src/com/android/tools/compose/ComposeGradleInspectionSuppressor.kt new file mode 100644 index 00000000000..758af4b467d --- /dev/null +++ b/compose-ide-plugin/src/com/android/tools/compose/ComposeGradleInspectionSuppressor.kt @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2021 The Android Open Source Project + * + * 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.android.tools.compose + +import com.android.tools.idea.flags.StudioFlags +import com.android.tools.idea.projectsystem.getModuleSystem +import com.intellij.codeInspection.InspectionSuppressor +import com.intellij.codeInspection.SuppressQuickFix +import com.intellij.openapi.module.ModuleManager +import com.intellij.openapi.project.Project +import com.intellij.psi.PsiElement + +// TODO: This is a hotfix for b/194313332 and should be removed eventually. +class ComposeGradleInspectionSuppressor : InspectionSuppressor { + override fun isSuppressedFor(element: PsiElement, toolId: String): Boolean { + return StudioFlags.COMPOSE_EDITOR_SUPPORT.get() && + toolId == "DifferentKotlinGradleVersion" && + usesComposeInProject(element.project) + } + + private fun usesComposeInProject(project: Project): Boolean { + val modules = ModuleManager.getInstance(project).modules + return modules.any { it.getModuleSystem().usesCompose } + } + + override fun getSuppressActions(element: PsiElement?, toolId: String): Array<SuppressQuickFix> { + return SuppressQuickFix.EMPTY_ARRAY + } +} |
