'it' parameter highlighting fixed for chain usage.
#KT-31037 Fixed
This commit is contained in:
committed by
Vladimir Ilmov
parent
fb9fb2e048
commit
46423443e9
+10
-2
@@ -27,6 +27,14 @@ abstract class HighlightingVisitor protected constructor(
|
||||
private val holder: AnnotationHolder
|
||||
) : KtVisitorVoid() {
|
||||
|
||||
protected fun createInfoAnnotation(element: PsiElement, textAttributes: TextAttributesKey, message: String? = null) {
|
||||
createInfoAnnotation(element.textRange, textAttributes, message)
|
||||
}
|
||||
|
||||
protected fun createInfoAnnotation(range: TextRange, textAttributes: TextAttributesKey, message: String? = null) {
|
||||
createInfoAnnotation(range, message).textAttributes = textAttributes
|
||||
}
|
||||
|
||||
protected fun createInfoAnnotation(element: PsiElement, message: String? = null): Annotation =
|
||||
createInfoAnnotation(element.textRange, message)
|
||||
|
||||
@@ -35,13 +43,13 @@ abstract class HighlightingVisitor protected constructor(
|
||||
|
||||
protected fun highlightName(element: PsiElement, attributesKey: TextAttributesKey, message: String? = null) {
|
||||
if (NameHighlighter.namesHighlightingEnabled && !element.textRange.isEmpty) {
|
||||
createInfoAnnotation(element, message).textAttributes = attributesKey
|
||||
createInfoAnnotation(element, attributesKey, message)
|
||||
}
|
||||
}
|
||||
|
||||
protected fun highlightName(textRange: TextRange, attributesKey: TextAttributesKey, message: String? = null) {
|
||||
if (NameHighlighter.namesHighlightingEnabled) {
|
||||
createInfoAnnotation(textRange, message).textAttributes = attributesKey
|
||||
createInfoAnnotation(textRange, attributesKey, message)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -79,7 +79,7 @@ public class KotlinHighlightingColors {
|
||||
public static final TextAttributesKey PACKAGE_PROPERTY_CUSTOM_PROPERTY_DECLARATION = createTextAttributesKey("KOTLIN_PACKAGE_PROPERTY_CUSTOM_PROPERTY_DECLARATION", PACKAGE_PROPERTY);
|
||||
|
||||
// functions
|
||||
public static final TextAttributesKey FUNCTION_LITERAL_DEFAULT_PARAMETER = createTextAttributesKey("KOTLIN_CLOSURE_DEFAULT_PARAMETER");
|
||||
public static final TextAttributesKey FUNCTION_LITERAL_DEFAULT_PARAMETER = createTextAttributesKey("KOTLIN_CLOSURE_DEFAULT_PARAMETER", PARAMETER);
|
||||
public static final TextAttributesKey FUNCTION_DECLARATION = createTextAttributesKey("KOTLIN_FUNCTION_DECLARATION", DefaultLanguageHighlighterColors.FUNCTION_DECLARATION);
|
||||
public static final TextAttributesKey FUNCTION_CALL = createTextAttributesKey("KOTLIN_FUNCTION_CALL", DefaultLanguageHighlighterColors.FUNCTION_CALL);
|
||||
public static final TextAttributesKey PACKAGE_FUNCTION_CALL = createTextAttributesKey("KOTLIN_PACKAGE_FUNCTION_CALL", DefaultLanguageHighlighterColors.STATIC_METHOD);
|
||||
|
||||
+4
-9
@@ -42,14 +42,9 @@ internal class VariablesHighlightingVisitor(holder: AnnotationHolder, bindingCon
|
||||
|
||||
override fun visitSimpleNameExpression(expression: KtSimpleNameExpression) {
|
||||
val target = bindingContext.get(REFERENCE_TARGET, expression) ?: return
|
||||
if (target is ValueParameterDescriptor) {
|
||||
if (bindingContext.get(AUTO_CREATED_IT, target) == true) {
|
||||
createInfoAnnotation(expression, "Automatically declared based on the expected type")
|
||||
.textAttributes = FUNCTION_LITERAL_DEFAULT_PARAMETER
|
||||
}
|
||||
}
|
||||
|
||||
if (expression.parent !is KtValueArgumentName) { // highlighted separately
|
||||
if (target is ValueParameterDescriptor && bindingContext.get(AUTO_CREATED_IT, target) == true) {
|
||||
createInfoAnnotation(expression, FUNCTION_LITERAL_DEFAULT_PARAMETER, "Automatically declared based on the expected type")
|
||||
} else if (expression.parent !is KtValueArgumentName) { // highlighted separately
|
||||
highlightVariable(expression, target)
|
||||
}
|
||||
|
||||
@@ -156,7 +151,7 @@ internal class VariablesHighlightingVisitor(holder: AnnotationHolder, bindingCon
|
||||
|
||||
val parent = elementToHighlight.parent
|
||||
if (!(parent is PsiNameIdentifierOwner && parent.nameIdentifier == elementToHighlight)) {
|
||||
createInfoAnnotation(elementToHighlight, msg).textAttributes = WRAPPED_INTO_REF
|
||||
createInfoAnnotation(elementToHighlight, WRAPPED_INTO_REF, msg)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
Generated
+5
@@ -33,6 +33,11 @@ public class PerformanceHighlightingTestGenerated extends AbstractPerformanceHig
|
||||
runTest("idea/testData/highlighter/Annotations.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("AutoCreatedItParameter.kt")
|
||||
public void testAutoCreatedItParameter() throws Exception {
|
||||
runTest("idea/testData/highlighter/AutoCreatedItParameter.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("Destructuring.kt")
|
||||
public void testDestructuring() throws Exception {
|
||||
runTest("idea/testData/highlighter/Destructuring.kt");
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
fun <info textAttributesKey="KOTLIN_FUNCTION_DECLARATION">test</info>() {
|
||||
val <info textAttributesKey="KOTLIN_LOCAL_VARIABLE">vect</info> = <info textAttributesKey="KOTLIN_CONSTRUCTOR">MyIterable</info><<info textAttributesKey="KOTLIN_CLASS">Int</info>>()
|
||||
<info textAttributesKey="KOTLIN_LOCAL_VARIABLE">vect</info>.<info textAttributesKey="KOTLIN_FUNCTION_CALL">filter</info> { <info textAttributesKey="KOTLIN_CLOSURE_DEFAULT_PARAMETER">it</info> != 2 }.<info textAttributesKey="KOTLIN_FUNCTION_CALL">forEach</info> { <info textAttributesKey="KOTLIN_CLOSURE_DEFAULT_PARAMETER">it</info>.<info textAttributesKey="KOTLIN_FUNCTION_CALL">toString</info>() }
|
||||
}
|
||||
|
||||
class <info textAttributesKey="KOTLIN_CLASS">MyIterable</info><<info textAttributesKey="KOTLIN_TYPE_PARAMETER">T</info>> {
|
||||
fun <info textAttributesKey="KOTLIN_FUNCTION_DECLARATION">filter</info>(<warning textAttributesKey="NOT_USED_ELEMENT_ATTRIBUTES"><info textAttributesKey="KOTLIN_PARAMETER">function</info></warning>: (<info textAttributesKey="KOTLIN_TYPE_PARAMETER">T</info>) -> <info textAttributesKey="KOTLIN_CLASS">Boolean</info>) = this
|
||||
fun <info textAttributesKey="KOTLIN_FUNCTION_DECLARATION">forEach</info>(<warning textAttributesKey="NOT_USED_ELEMENT_ATTRIBUTES"><info textAttributesKey="KOTLIN_PARAMETER">action</info></warning>: (<info textAttributesKey="KOTLIN_TYPE_PARAMETER">T</info>) -> <info textAttributesKey="KOTLIN_OBJECT">Unit</info>) {
|
||||
}
|
||||
}
|
||||
+5
@@ -33,6 +33,11 @@ public class HighlightingTestGenerated extends AbstractHighlightingTest {
|
||||
runTest("idea/testData/highlighter/Annotations.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("AutoCreatedItParameter.kt")
|
||||
public void testAutoCreatedItParameter() throws Exception {
|
||||
runTest("idea/testData/highlighter/AutoCreatedItParameter.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("Destructuring.kt")
|
||||
public void testDestructuring() throws Exception {
|
||||
runTest("idea/testData/highlighter/Destructuring.kt");
|
||||
|
||||
Reference in New Issue
Block a user