mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[devKit] MismatchedLightServiceLevelAndCtorInspection: get rid of kotlin dependency
IJ-CR-102194 GitOrigin-RevId: 4b7eea3c968a7273b1d438f5b90441d772328d43
This commit is contained in:
committed by
intellij-monorepo-bot
parent
3f67f5fe7e
commit
ba1b002ee6
+15
-18
@@ -8,7 +8,6 @@ import com.intellij.lang.jvm.annotation.JvmAnnotationArrayValue
|
||||
import com.intellij.lang.jvm.annotation.JvmAnnotationConstantValue
|
||||
import com.intellij.lang.jvm.annotation.JvmAnnotationEnumFieldValue
|
||||
import com.intellij.openapi.components.Service
|
||||
import com.intellij.openapi.fileTypes.FileType
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.psi.PsiAnnotation.DEFAULT_REFERENCED_METHOD_NAME
|
||||
import com.intellij.psi.PsiElementFactory
|
||||
@@ -17,9 +16,6 @@ import com.intellij.psi.PsiType
|
||||
import com.intellij.psi.search.GlobalSearchScope
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import org.jetbrains.idea.devkit.DevKitBundle
|
||||
import org.jetbrains.kotlin.idea.KotlinFileType
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
|
||||
internal class MismatchedLightServiceLevelAndCtorInspection : DevKitJvmInspection() {
|
||||
|
||||
@@ -32,7 +28,7 @@ internal class MismatchedLightServiceLevelAndCtorInspection : DevKitJvmInspectio
|
||||
val file: PsiFile = method.sourceElement?.containingFile ?: return true
|
||||
val containingClass = method.containingClass ?: return true
|
||||
val serviceAnnotation = containingClass.annotations.find { it.qualifiedName == Service::class.java.canonicalName } ?: return true
|
||||
val level = getLevel(serviceAnnotation, file.fileType)
|
||||
val level = getLevel(serviceAnnotation)
|
||||
if (level !in listOf(Level.PROJECT, Level.APP_AND_PROJECT)) {
|
||||
val isProjectParamCtor = (method.parameters.singleOrNull()?.type as? PsiType)?.canonicalText == Project::class.java.canonicalName
|
||||
if (isProjectParamCtor) {
|
||||
@@ -69,20 +65,19 @@ internal class MismatchedLightServiceLevelAndCtorInspection : DevKitJvmInspectio
|
||||
return method.parameters.isEmpty() || (method.parameters.singleOrNull()?.type as? PsiType)?.canonicalText == CoroutineScope::class.java.canonicalName
|
||||
}
|
||||
|
||||
private fun getLevel(annotation: JvmAnnotation, fileType: FileType): Level {
|
||||
private fun getLevel(annotation: JvmAnnotation): Level {
|
||||
val levels = when (val attributeValue = annotation.findAttribute(DEFAULT_REFERENCED_METHOD_NAME)?.attributeValue) {
|
||||
is JvmAnnotationArrayValue ->
|
||||
if (fileType == KotlinFileType.INSTANCE)
|
||||
attributeValue.values
|
||||
.filterIsInstance<JvmAnnotationConstantValue>()
|
||||
.map { it.constantValue }
|
||||
.filterIsInstance<Pair<ClassId, Name>>()
|
||||
.filter { (classId, name) ->
|
||||
classId.asFqNameString() == Service.Level::class.java.canonicalName &&
|
||||
name.identifier in listOf(Service.Level.APP.name, Service.Level.PROJECT.name)
|
||||
}
|
||||
.map { (_, name) -> name.identifier }
|
||||
else
|
||||
is JvmAnnotationArrayValue -> {
|
||||
val kotlinLevels = attributeValue.values
|
||||
.filterIsInstance<JvmAnnotationConstantValue>()
|
||||
.map { it.constantValue }
|
||||
.filterIsInstance<Pair<*, *>>()
|
||||
.filter { (first, second) ->
|
||||
first.toString() == Service.Level::class.java.name.replace('.', '/').replace('$', '.') &&
|
||||
second.toString() in listOf(Service.Level.APP.name, Service.Level.PROJECT.name)
|
||||
}
|
||||
.map { (_, second) -> second.toString() }
|
||||
kotlinLevels.ifEmpty {
|
||||
attributeValue.values
|
||||
.filterIsInstance<JvmAnnotationEnumFieldValue>()
|
||||
.filter {
|
||||
@@ -90,6 +85,8 @@ internal class MismatchedLightServiceLevelAndCtorInspection : DevKitJvmInspectio
|
||||
it.fieldName in listOf(Service.Level.APP.name, Service.Level.PROJECT.name)
|
||||
}
|
||||
.map { it.fieldName!! }
|
||||
}
|
||||
}
|
||||
is JvmAnnotationEnumFieldValue -> {
|
||||
if (attributeValue.containingClassName == Service.Level::class.java.canonicalName &&
|
||||
attributeValue.fieldName in listOf(Service.Level.APP.name, Service.Level.PROJECT.name))
|
||||
|
||||
Reference in New Issue
Block a user