Introduce UNUSED_ANONYMOUS_PARAMETER for anonymous functions
It is not reported for 1.0 language version because renaming to _ is not possible. It has weak warning severity So #KT-8813 Fixed So #KT-16875 Fixed
This commit is contained in:
@@ -239,11 +239,16 @@ private class ElementAnnotator(private val element: PsiElement,
|
||||
|
||||
AnnotationPresentationInfo(
|
||||
ranges,
|
||||
textAttributes = if (factory == Errors.DEPRECATION) CodeInsightColors.DEPRECATED_ATTRIBUTES else null,
|
||||
highlightType = if (factory in Errors.UNUSED_ELEMENT_DIAGNOSTICS)
|
||||
ProblemHighlightType.LIKE_UNUSED_SYMBOL
|
||||
else
|
||||
null
|
||||
textAttributes = when (factory) {
|
||||
Errors.DEPRECATION -> CodeInsightColors.DEPRECATED_ATTRIBUTES
|
||||
Errors.UNUSED_ANONYMOUS_PARAMETER -> CodeInsightColors.WEAK_WARNING_ATTRIBUTES
|
||||
else -> null
|
||||
},
|
||||
highlightType = when (factory) {
|
||||
in Errors.UNUSED_ELEMENT_DIAGNOSTICS -> ProblemHighlightType.LIKE_UNUSED_SYMBOL
|
||||
Errors.UNUSED_ANONYMOUS_PARAMETER -> ProblemHighlightType.WEAK_WARNING
|
||||
else -> null
|
||||
}
|
||||
)
|
||||
}
|
||||
Severity.INFO -> return // Do nothing
|
||||
@@ -278,14 +283,22 @@ private class AnnotationPresentationInfo(
|
||||
val ranges: List<TextRange>,
|
||||
val nonDefaultMessage: String? = null,
|
||||
val highlightType: ProblemHighlightType? = null,
|
||||
val textAttributes: TextAttributesKey? = null) {
|
||||
val textAttributes: TextAttributesKey? = null
|
||||
) {
|
||||
|
||||
fun create(diagnostic: Diagnostic, range: TextRange, holder: AnnotationHolder): Annotation {
|
||||
val defaultMessage = nonDefaultMessage ?: getDefaultMessage(diagnostic)
|
||||
|
||||
val annotation = when (diagnostic.severity) {
|
||||
Severity.ERROR -> holder.createErrorAnnotation(range, defaultMessage)
|
||||
Severity.WARNING -> holder.createWarningAnnotation(range, defaultMessage)
|
||||
Severity.WARNING -> {
|
||||
if (highlightType == ProblemHighlightType.WEAK_WARNING) {
|
||||
holder.createWeakWarningAnnotation(range, defaultMessage)
|
||||
}
|
||||
else {
|
||||
holder.createWarningAnnotation(range, defaultMessage)
|
||||
}
|
||||
}
|
||||
else -> throw IllegalArgumentException("Only ERROR and WARNING diagnostics are supported")
|
||||
}
|
||||
|
||||
|
||||
@@ -284,8 +284,8 @@ class QuickFixRegistrar : QuickFixContributor {
|
||||
TOO_MANY_ARGUMENTS.registerFactory(ChangeFunctionSignatureFix)
|
||||
NO_VALUE_FOR_PARAMETER.registerFactory(ChangeFunctionSignatureFix)
|
||||
UNUSED_PARAMETER.registerFactory(RemoveUnusedFunctionParameterFix)
|
||||
UNUSED_PARAMETER.registerFactory(RenameToUnderscoreFix.Factory)
|
||||
UNUSED_PARAMETER.registerFactory(RemoveSingleLambdaParameterFix)
|
||||
UNUSED_ANONYMOUS_PARAMETER.registerFactory(RenameToUnderscoreFix.Factory)
|
||||
UNUSED_ANONYMOUS_PARAMETER.registerFactory(RemoveSingleLambdaParameterFix)
|
||||
EXPECTED_PARAMETERS_NUMBER_MISMATCH.registerFactory(ChangeFunctionLiteralSignatureFix)
|
||||
|
||||
EXPECTED_PARAMETER_TYPE_MISMATCH.registerFactory(ChangeTypeFix)
|
||||
|
||||
@@ -36,7 +36,7 @@ class RenameToUnderscoreFix(element: KtCallableDeclaration) : KotlinQuickFixActi
|
||||
companion object Factory : KotlinSingleIntentionActionFactory() {
|
||||
override fun createAction(diagnostic: Diagnostic): IntentionAction? {
|
||||
val declaration: KtCallableDeclaration? = when (diagnostic.factory) {
|
||||
Errors.UNUSED_PARAMETER -> {
|
||||
Errors.UNUSED_ANONYMOUS_PARAMETER -> {
|
||||
val parameter = diagnostic.psiElement as? KtParameter
|
||||
val owner = parameter?.parent?.parent
|
||||
|
||||
|
||||
+1
-1
@@ -3,6 +3,6 @@ fun foo1() : (Int) -> Int = { x: Int -> x }
|
||||
fun foo() {
|
||||
val h : (Int) -> Int = foo1();
|
||||
h(1)
|
||||
val m : (Int) -> Int = {<warning descr="[UNUSED_PARAMETER] Parameter 'a' is never used">a</warning> : Int -> 1}//foo1()
|
||||
val m : (Int) -> Int = {a : Int -> 1}//foo1()
|
||||
m(1)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user