diff --git a/ChangeLog.md b/ChangeLog.md
index 6075806e10c..2ab6a05bffb 100644
--- a/ChangeLog.md
+++ b/ChangeLog.md
@@ -105,6 +105,7 @@ These artifacts include extensions for the types available in the latter JDKs, s
- [`KT-13630`](https://youtrack.jetbrains.com/issue/KT-13630) Do not show Change Signature dialog when applying "Remove parameter" quick-fix
- Re-highlight only single function after local modifications
- [`KT-13474`](https://youtrack.jetbrains.com/issue/KT-13474) Fix performance of typing super call lambda
+- Show "Variables and values captured in a closure" highlighting only for usages
#### Intention actions, inspections and quickfixes
diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/highlighter/KotlinChangeLocalityDetector.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/highlighter/KotlinChangeLocalityDetector.kt
index adede6ab4d4..ab1090272c2 100644
--- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/highlighter/KotlinChangeLocalityDetector.kt
+++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/highlighter/KotlinChangeLocalityDetector.kt
@@ -25,8 +25,6 @@ class KotlinChangeLocalityDetector : ChangeLocalityDetector {
override fun getChangeHighlightingDirtyScopeFor(element: PsiElement): PsiElement? {
val parent = element.parent
if (element is KtBlockExpression && parent is KtNamedFunction && parent.name != null) {
- // Do nothing for local functions because of at least WRAPPED_INTO_REF highlighting
-
if (parent.parents.all { it is KtClassBody || it is KtClassOrObject || it is KtFile || it is KtScript }) {
return parent
}
diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/highlighter/VariablesHighlightingVisitor.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/highlighter/VariablesHighlightingVisitor.kt
index 105cdccd6d4..205f3f1d9bd 100644
--- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/highlighter/VariablesHighlightingVisitor.kt
+++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/highlighter/VariablesHighlightingVisitor.kt
@@ -18,6 +18,7 @@ package org.jetbrains.kotlin.idea.highlighter
import com.intellij.lang.annotation.AnnotationHolder
import com.intellij.psi.PsiElement
+import com.intellij.psi.PsiNameIdentifierOwner
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor
import org.jetbrains.kotlin.descriptors.VariableDescriptor
@@ -145,7 +146,11 @@ internal class VariablesHighlightingVisitor(holder: AnnotationHolder, bindingCon
"Wrapped into a reference object to be modified when captured in a closure"
else
"Value captured in a closure"
- holder.createInfoAnnotation(elementToHighlight, msg).textAttributes = WRAPPED_INTO_REF
+
+ val parent = elementToHighlight.parent
+ if (!(parent is PsiNameIdentifierOwner && parent.nameIdentifier == elementToHighlight)) {
+ holder.createInfoAnnotation(elementToHighlight, msg).textAttributes = WRAPPED_INTO_REF
+ }
}
if (descriptor is LocalVariableDescriptor && descriptor !is SyntheticFieldDescriptor) {
diff --git a/idea/src/org/jetbrains/kotlin/idea/highlighter/KotlinColorSettingsPage.kt b/idea/src/org/jetbrains/kotlin/idea/highlighter/KotlinColorSettingsPage.kt
index 3a4ea6a8f75..3715e121076 100644
--- a/idea/src/org/jetbrains/kotlin/idea/highlighter/KotlinColorSettingsPage.kt
+++ b/idea/src/org/jetbrains/kotlin/idea/highlighter/KotlinColorSettingsPage.kt
@@ -48,7 +48,7 @@ class KotlinColorSettingsPage : ColorSettingsPage {
val ints = java.util.ArrayList(2)
ints[0] = 102 + f() + fl()
val myFun = {-> "" };
- var ref = ints.size
+ var ref = ints.size
ints.lastIndex + globalCounterints.forEach{
if (it == null) return
diff --git a/idea/testData/checker/infos/CapturedConstructorParameter.kt b/idea/testData/checker/infos/CapturedConstructorParameter.kt
index f1fa2f51dc5..800961a10dc 100644
--- a/idea/testData/checker/infos/CapturedConstructorParameter.kt
+++ b/idea/testData/checker/infos/CapturedConstructorParameter.kt
@@ -30,10 +30,10 @@ class A2(x: Int, y: Int, t: T) {
//captured
class B(
- x: Int,
- y: Int,
- t: Int,
- d: Int
+ x: Int,
+ y: Int,
+ t: Int,
+ d: Int
) {
init {
class C(a: Int = x): T by T1(t) {
@@ -43,7 +43,7 @@ class B(
}
}
-class B2(x: Int, y: Int) {
+class B2(x: Int, y: Int) {
val x1 = { x }()
init {
diff --git a/idea/testData/checker/infos/CapturedInInlinedClosure.kt b/idea/testData/checker/infos/CapturedInInlinedClosure.kt
index fd43e2c133b..c292c765c4b 100644
--- a/idea/testData/checker/infos/CapturedInInlinedClosure.kt
+++ b/idea/testData/checker/infos/CapturedInInlinedClosure.kt
@@ -20,45 +20,45 @@ fun inline() {
}
fun notInline() {
- val y2 = 1
+ val y2 = 1
run { y2 }
run2 { y2 }
- val y3 = 1
+ val y3 = 1
run2 { y3 }
run { y3 }
// wrapped, using in not inline
- val z = 2
+ val z = 2
{ z }()
- val z1 = 3
+ val z1 = 3
run2 { z1 }
}
fun nestedDifferent() { // inline within non-inline and vice-versa
- val y = 1
+ val y = 1
{
run {
y
}
}()
- val y1 = 1
+ val y1 = 1
run {
{ y1 }()
}
}
fun localFunctionAndClass() {
- val u = 1
+ val u = 1
fun localFun() {
run {
u
}
}
- val v = 1
+ val v = 1
class LocalClass {
fun f() {
run {
@@ -69,7 +69,7 @@ fun localFunctionAndClass() {
}
fun objectExpression() {
- val u1 = 1
+ val u1 = 1
object : Any() {
fun f() {
run {
@@ -78,14 +78,14 @@ fun objectExpression() {
}
}
- val u2 = 1
+ val u2 = 1
object : Any() {
val prop = run {
u2
}
}
- val u3 = ""
+ val u3 = ""
object : Throwable(run { u3 }) {
}
}
@@ -95,7 +95,7 @@ fun objectExpression() {
task2()
}
-fun usage(param1: Int, param2: Int) {
+fun usage(param1: Int, param2: Int) {
withNoInlineParam({ println(param1) }, { println(param2) })
}
diff --git a/idea/testData/checker/infos/SmartCasts.kt b/idea/testData/checker/infos/SmartCasts.kt
index a3024e6236e..24ff66f5828 100644
--- a/idea/testData/checker/infos/SmartCasts.kt
+++ b/idea/testData/checker/infos/SmartCasts.kt
@@ -184,11 +184,11 @@ fun vars(a: Any?) {
b =a
}
}
-fun returnFunctionLiteralBlock(a: Any?): Function0 {
+fun returnFunctionLiteralBlock(a: Any?): Function0 {
if (a is Int) return { a }
else return { 1 }
}
-fun returnFunctionLiteral(a: Any?): Function0 =
+fun returnFunctionLiteral(a: Any?): Function0 =
if (a is Int) (fun (): Int = a)
else { -> 1 }
@@ -212,7 +212,7 @@ fun mergeSmartCasts(a: Any?) {
//mutability
fun f(): String {
- var a: Any = 11
+ var a: Any = 11
if (a is String) {
val i: String = aa.compareTo("f")
diff --git a/idea/testData/checker/infos/WrapIntoRef.kt b/idea/testData/checker/infos/WrapIntoRef.kt
index 93458833d84..94fcb64eb9a 100644
--- a/idea/testData/checker/infos/WrapIntoRef.kt
+++ b/idea/testData/checker/infos/WrapIntoRef.kt
@@ -1,36 +1,36 @@
fun refs() {
- var a = 1
+ var a = 1
val v = {
a = 2
}
- var x = 1
+ var x = 1
val b = object {
fun foo() {
x = 2
}
}
- var y = 1
+ var y = 1
fun foo() {
y = 1
}
}
fun refsPlusAssign() {
- var a = 1
+ var a = 1
val v = {
a += 2
}
- var x = 1
+ var x = 1
val b = object {
fun foo() {
x += 2
}
}
- var y = 1
+ var y = 1
fun foo() {
y += 1
}