Refactoring: convert problemHighlightType to function with parameter
This commit is contained in:
+3
-3
@@ -124,15 +124,15 @@ abstract class IntentionBasedInspection<TElement : PsiElement>(
|
||||
additionalFixes(targetElement)?.let { allFixes.addAll(it) }
|
||||
if (!allFixes.isEmpty()) {
|
||||
holder.registerProblem(targetElement, problemText ?: allFixes.first().name,
|
||||
problemHighlightType, range, *allFixes.toTypedArray())
|
||||
problemHighlightType(targetElement), range, *allFixes.toTypedArray())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected open val problemHighlightType: ProblemHighlightType
|
||||
get() = ProblemHighlightType.GENERIC_ERROR_OR_WARNING
|
||||
protected open fun problemHighlightType(element: TElement): ProblemHighlightType =
|
||||
ProblemHighlightType.GENERIC_ERROR_OR_WARNING
|
||||
|
||||
private fun createQuickFix(
|
||||
intention: SelfTargetingRangeIntention<TElement>,
|
||||
|
||||
@@ -20,16 +20,12 @@ import com.intellij.codeInspection.IntentionWrapper
|
||||
import com.intellij.codeInspection.LocalQuickFix
|
||||
import com.intellij.codeInspection.ProblemHighlightType
|
||||
import com.intellij.codeInspection.ui.MultipleCheckboxOptionsPanel
|
||||
import com.intellij.openapi.util.TextRange
|
||||
import org.jetbrains.kotlin.idea.intentions.SpecifyTypeExplicitlyIntention
|
||||
import org.jetbrains.kotlin.idea.intentions.isFlexibleRecursive
|
||||
import org.jetbrains.kotlin.idea.quickfix.AddExclExclCallFix
|
||||
import org.jetbrains.kotlin.lexer.KtTokens
|
||||
import org.jetbrains.kotlin.psi.KtCallableDeclaration
|
||||
import org.jetbrains.kotlin.psi.psiUtil.endOffset
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getNextSiblingIgnoringWhitespaceAndComments
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getStartOffsetIn
|
||||
import org.jetbrains.kotlin.psi.psiUtil.startOffset
|
||||
import org.jetbrains.kotlin.types.TypeUtils
|
||||
import javax.swing.JComponent
|
||||
|
||||
@@ -45,7 +41,7 @@ class HasPlatformTypeInspection(
|
||||
}
|
||||
) {
|
||||
|
||||
override val problemHighlightType = ProblemHighlightType.WEAK_WARNING
|
||||
override fun problemHighlightType(element: KtCallableDeclaration) = ProblemHighlightType.WEAK_WARNING
|
||||
|
||||
override val problemText = "Declaration has type inferred from a platform call, which can lead to unchecked nullability issues. " +
|
||||
"Specify type explicitly as nullable or non-nullable."
|
||||
|
||||
@@ -27,9 +27,10 @@ import org.jetbrains.kotlin.psi.KtSecondaryConstructor
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getNextSiblingIgnoringWhitespaceAndComments
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType
|
||||
|
||||
class RemoveEmptyClassBodyInspection : IntentionBasedInspection<KtClassBody>(RemoveEmptyClassBodyIntention::class), CleanupLocalInspectionTool {
|
||||
override val problemHighlightType: ProblemHighlightType
|
||||
get() = ProblemHighlightType.LIKE_UNUSED_SYMBOL
|
||||
class RemoveEmptyClassBodyInspection :
|
||||
IntentionBasedInspection<KtClassBody>(RemoveEmptyClassBodyIntention::class), CleanupLocalInspectionTool {
|
||||
override fun problemHighlightType(element: KtClassBody): ProblemHighlightType =
|
||||
ProblemHighlightType.LIKE_UNUSED_SYMBOL
|
||||
}
|
||||
|
||||
class RemoveEmptyClassBodyIntention : SelfTargetingOffsetIndependentIntention<KtClassBody>(KtClassBody::class.java, "Remove empty class body") {
|
||||
|
||||
+3
-2
@@ -26,8 +26,9 @@ import org.jetbrains.kotlin.psi.KtCallExpression
|
||||
import org.jetbrains.kotlin.psi.KtValueArgumentList
|
||||
|
||||
class RemoveEmptyParenthesesFromLambdaCallInspection : IntentionBasedInspection<KtValueArgumentList>(
|
||||
RemoveEmptyParenthesesFromLambdaCallIntention::class), CleanupLocalInspectionTool{
|
||||
override val problemHighlightType: ProblemHighlightType get() = ProblemHighlightType.LIKE_UNUSED_SYMBOL
|
||||
RemoveEmptyParenthesesFromLambdaCallIntention::class), CleanupLocalInspectionTool {
|
||||
override fun problemHighlightType(element: KtValueArgumentList): ProblemHighlightType =
|
||||
ProblemHighlightType.LIKE_UNUSED_SYMBOL
|
||||
}
|
||||
|
||||
class RemoveEmptyParenthesesFromLambdaCallIntention : SelfTargetingRangeIntention<KtValueArgumentList>(
|
||||
|
||||
+5
-3
@@ -23,9 +23,11 @@ import org.jetbrains.kotlin.idea.inspections.IntentionBasedInspection
|
||||
import org.jetbrains.kotlin.psi.KtPrimaryConstructor
|
||||
import org.jetbrains.kotlin.psi.psiUtil.containingClass
|
||||
|
||||
class RemoveEmptyPrimaryConstructorInspection : IntentionBasedInspection<KtPrimaryConstructor>(RemoveEmptyPrimaryConstructorIntention::class), CleanupLocalInspectionTool {
|
||||
override val problemHighlightType: ProblemHighlightType
|
||||
get() = ProblemHighlightType.LIKE_UNUSED_SYMBOL
|
||||
class RemoveEmptyPrimaryConstructorInspection : IntentionBasedInspection<KtPrimaryConstructor>(
|
||||
RemoveEmptyPrimaryConstructorIntention::class
|
||||
), CleanupLocalInspectionTool {
|
||||
override fun problemHighlightType(element: KtPrimaryConstructor): ProblemHighlightType =
|
||||
ProblemHighlightType.LIKE_UNUSED_SYMBOL
|
||||
}
|
||||
|
||||
class RemoveEmptyPrimaryConstructorIntention : SelfTargetingOffsetIndependentIntention<KtPrimaryConstructor>(KtPrimaryConstructor::class.java, "Remove empty primary constructor") {
|
||||
|
||||
+5
-3
@@ -23,9 +23,11 @@ import org.jetbrains.kotlin.idea.inspections.IntentionBasedInspection
|
||||
import org.jetbrains.kotlin.psi.KtBlockExpression
|
||||
import org.jetbrains.kotlin.psi.KtSecondaryConstructor
|
||||
|
||||
class RemoveEmptySecondaryConstructorBodyInspection : IntentionBasedInspection<KtBlockExpression>(RemoveEmptySecondaryConstructorBodyIntention::class), CleanupLocalInspectionTool {
|
||||
override val problemHighlightType: ProblemHighlightType
|
||||
get() = ProblemHighlightType.LIKE_UNUSED_SYMBOL
|
||||
class RemoveEmptySecondaryConstructorBodyInspection : IntentionBasedInspection<KtBlockExpression>(
|
||||
RemoveEmptySecondaryConstructorBodyIntention::class
|
||||
), CleanupLocalInspectionTool {
|
||||
override fun problemHighlightType(element: KtBlockExpression): ProblemHighlightType =
|
||||
ProblemHighlightType.LIKE_UNUSED_SYMBOL
|
||||
}
|
||||
|
||||
class RemoveEmptySecondaryConstructorBodyIntention : SelfTargetingOffsetIndependentIntention<KtBlockExpression>(KtBlockExpression::class.java, "Remove empty constructor body") {
|
||||
|
||||
+5
-3
@@ -34,9 +34,11 @@ import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall
|
||||
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
|
||||
import org.jetbrains.kotlin.types.ErrorUtils
|
||||
|
||||
class RemoveExplicitSuperQualifierInspection : IntentionBasedInspection<KtSuperExpression>(RemoveExplicitSuperQualifierIntention::class), CleanupLocalInspectionTool {
|
||||
override val problemHighlightType: ProblemHighlightType
|
||||
get() = ProblemHighlightType.LIKE_UNUSED_SYMBOL
|
||||
class RemoveExplicitSuperQualifierInspection : IntentionBasedInspection<KtSuperExpression>(
|
||||
RemoveExplicitSuperQualifierIntention::class
|
||||
), CleanupLocalInspectionTool {
|
||||
override fun problemHighlightType(element: KtSuperExpression): ProblemHighlightType =
|
||||
ProblemHighlightType.LIKE_UNUSED_SYMBOL
|
||||
}
|
||||
|
||||
class RemoveExplicitSuperQualifierIntention : SelfTargetingRangeIntention<KtSuperExpression>(KtSuperExpression::class.java, "Remove explicit supertype qualification") {
|
||||
|
||||
+2
-2
@@ -35,8 +35,8 @@ import org.jetbrains.kotlin.types.TypeUtils
|
||||
import org.jetbrains.kotlin.types.checker.KotlinTypeChecker
|
||||
|
||||
class RemoveExplicitTypeArgumentsInspection : IntentionBasedInspection<KtTypeArgumentList>(RemoveExplicitTypeArgumentsIntention::class) {
|
||||
override val problemHighlightType: ProblemHighlightType
|
||||
get() = ProblemHighlightType.LIKE_UNUSED_SYMBOL
|
||||
override fun problemHighlightType(element: KtTypeArgumentList): ProblemHighlightType =
|
||||
ProblemHighlightType.LIKE_UNUSED_SYMBOL
|
||||
}
|
||||
|
||||
class RemoveExplicitTypeArgumentsIntention : SelfTargetingOffsetIndependentIntention<KtTypeArgumentList>(KtTypeArgumentList::class.java, "Remove explicit type arguments") {
|
||||
|
||||
@@ -28,7 +28,7 @@ class RemoveSetterParameterTypeInspection : IntentionBasedInspection<KtCallableD
|
||||
RemoveExplicitTypeIntention::class,
|
||||
{ it -> RemoveExplicitTypeIntention.isSetterParameter(it) }
|
||||
) {
|
||||
override val problemHighlightType = ProblemHighlightType.LIKE_UNUSED_SYMBOL
|
||||
override fun problemHighlightType(element: KtCallableDeclaration) = ProblemHighlightType.LIKE_UNUSED_SYMBOL
|
||||
|
||||
override fun inspectionTarget(element: KtCallableDeclaration) = (element as? KtParameter)?.typeReference
|
||||
}
|
||||
|
||||
@@ -35,8 +35,7 @@ class RemoveForLoopIndicesInspection : IntentionBasedInspection<KtForExpression>
|
||||
RemoveForLoopIndicesIntention::class,
|
||||
"Index is not used in the loop body"
|
||||
) {
|
||||
override val problemHighlightType: ProblemHighlightType
|
||||
get() = ProblemHighlightType.LIKE_UNUSED_SYMBOL
|
||||
override fun problemHighlightType(element: KtForExpression): ProblemHighlightType = ProblemHighlightType.LIKE_UNUSED_SYMBOL
|
||||
}
|
||||
|
||||
class RemoveForLoopIndicesIntention : SelfTargetingRangeIntention<KtForExpression>(KtForExpression::class.java, "Remove indices in 'for' loop") {
|
||||
|
||||
+4
-2
@@ -28,8 +28,10 @@ import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall
|
||||
import org.jetbrains.kotlin.resolve.calls.callUtil.getType
|
||||
import org.jetbrains.kotlin.types.isFlexible
|
||||
|
||||
class RemoveRedundantCallsOfConversionMethodsInspection : IntentionBasedInspection<KtQualifiedExpression>(RemoveRedundantCallsOfConversionMethodsIntention::class) {
|
||||
override val problemHighlightType = ProblemHighlightType.LIKE_UNUSED_SYMBOL
|
||||
class RemoveRedundantCallsOfConversionMethodsInspection : IntentionBasedInspection<KtQualifiedExpression>(
|
||||
RemoveRedundantCallsOfConversionMethodsIntention::class
|
||||
) {
|
||||
override fun problemHighlightType(element: KtQualifiedExpression) = ProblemHighlightType.LIKE_UNUSED_SYMBOL
|
||||
}
|
||||
|
||||
class RemoveRedundantCallsOfConversionMethodsIntention : SelfTargetingRangeIntention<KtQualifiedExpression>(KtQualifiedExpression::class.java, "Remove redundant calls of the conversion method") {
|
||||
|
||||
Reference in New Issue
Block a user