From ac568bc0a4dfbbcf75badfa469931887b1a8dfd9 Mon Sep 17 00:00:00 2001 From: LlamaLad7 Date: Sun, 24 Sep 2023 17:19:21 +0100 Subject: [PATCH] Fix: Resolve DefaultAnnotationParamInspectionSuppressor not working for `remap = true` on injector `@At`s. (#2134) --- ...aultAnnotationParamInspectionSuppressor.kt | 45 ++++++++++--------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/src/main/kotlin/platform/mixin/inspection/suppress/DefaultAnnotationParamInspectionSuppressor.kt b/src/main/kotlin/platform/mixin/inspection/suppress/DefaultAnnotationParamInspectionSuppressor.kt index 21861c45e..6242a5083 100644 --- a/src/main/kotlin/platform/mixin/inspection/suppress/DefaultAnnotationParamInspectionSuppressor.kt +++ b/src/main/kotlin/platform/mixin/inspection/suppress/DefaultAnnotationParamInspectionSuppressor.kt @@ -20,16 +20,14 @@ package com.demonwav.mcdev.platform.mixin.inspection.suppress +import com.demonwav.mcdev.platform.mixin.handlers.MixinAnnotationHandler import com.demonwav.mcdev.platform.mixin.util.MixinConstants.Annotations.ACCESSOR import com.demonwav.mcdev.platform.mixin.util.MixinConstants.Annotations.AT import com.demonwav.mcdev.platform.mixin.util.MixinConstants.Annotations.CONSTANT -import com.demonwav.mcdev.platform.mixin.util.MixinConstants.Annotations.INJECT import com.demonwav.mcdev.platform.mixin.util.MixinConstants.Annotations.INVOKER import com.demonwav.mcdev.platform.mixin.util.MixinConstants.Annotations.MIXIN -import com.demonwav.mcdev.platform.mixin.util.MixinConstants.Annotations.MODIFY_ARG -import com.demonwav.mcdev.platform.mixin.util.MixinConstants.Annotations.MODIFY_ARGS -import com.demonwav.mcdev.platform.mixin.util.MixinConstants.Annotations.MODIFY_VARIABLE -import com.demonwav.mcdev.platform.mixin.util.MixinConstants.Annotations.REDIRECT +import com.demonwav.mcdev.platform.mixin.util.MixinConstants.Annotations.OVERWRITE +import com.demonwav.mcdev.platform.mixin.util.MixinConstants.Annotations.SHADOW import com.demonwav.mcdev.util.constantValue import com.demonwav.mcdev.util.findAnnotation import com.demonwav.mcdev.util.mapFirstNotNull @@ -41,6 +39,7 @@ import com.intellij.psi.PsiElement import com.intellij.psi.PsiModifierListOwner import com.intellij.psi.PsiNameValuePair import com.intellij.psi.util.parentOfType +import com.intellij.psi.util.parentsOfType class DefaultAnnotationParamInspectionSuppressor : InspectionSuppressor { override fun isSuppressedFor(element: PsiElement, toolId: String): Boolean { @@ -55,21 +54,23 @@ class DefaultAnnotationParamInspectionSuppressor : InspectionSuppressor { return true } - if (name == "remap" && REMAP_SUPPRESSED.any(annotation::hasQualifiedName)) { + if (name == "remap" && annotation.hasRemap) { val currentRemap = annotation.findAttributeValue("remap")?.constantValue as? Boolean ?: return false - val parentRemap = generateSequence(annotation) { elem -> + var parents = annotation.parentsOfType(withSelf = false).filter { it.hasRemap } + parents += generateSequence(annotation) { elem -> elem.parent?.takeIf { elem !is PsiClass } } .filterIsInstance() .drop(1) // don't look at our own owner .mapNotNull { annotationOwner -> - REMAP_SUPPRESSED.mapFirstNotNull { - annotationOwner.findAnnotation(it)?.findDeclaredAttributeValue("remap")?.constantValue - as? Boolean + HAS_REMAP.mapFirstNotNull { + annotationOwner.findAnnotation(it) } } - .firstOrNull() ?: true + val parentRemap = parents.firstNotNullOfOrNull { + it.findDeclaredAttributeValue("remap")?.constantValue as? Boolean + } ?: true if (currentRemap != parentRemap) { return true } @@ -78,22 +79,22 @@ class DefaultAnnotationParamInspectionSuppressor : InspectionSuppressor { return false } + private val PsiAnnotation.hasRemap get() = qualifiedName?.let { it in HAS_REMAP } == true + override fun getSuppressActions(element: PsiElement?, toolId: String): Array = SuppressQuickFix.EMPTY_ARRAY companion object { private const val INSPECTION = "DefaultAnnotationParam" - private val REMAP_SUPPRESSED = setOf( - AT, - INJECT, - MODIFY_ARG, - MODIFY_ARGS, - MODIFY_VARIABLE, - REDIRECT, - ACCESSOR, - INVOKER, - MIXIN, - ) + private val HAS_REMAP = buildSet { + add(MIXIN) + add(AT) + add(ACCESSOR) + add(INVOKER) + add(OVERWRITE) + add(SHADOW) + addAll(MixinAnnotationHandler.getBuiltinHandlers().map { it.first }) + } private val CONSTANT_SUPPRESSED = setOf( "intValue", "floatValue",