diff --git a/plugins/devkit/devkit-core/src/inspections/MismatchedLightServiceLevelAndCtorInspection.kt b/plugins/devkit/devkit-core/src/inspections/MismatchedLightServiceLevelAndCtorInspection.kt index 03d7fea71104..ab6ca80dcf00 100644 --- a/plugins/devkit/devkit-core/src/inspections/MismatchedLightServiceLevelAndCtorInspection.kt +++ b/plugins/devkit/devkit-core/src/inspections/MismatchedLightServiceLevelAndCtorInspection.kt @@ -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() - .map { it.constantValue } - .filterIsInstance>() - .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() + .map { it.constantValue } + .filterIsInstance>() + .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() .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))