Skip to content

Commit c66b20b

Browse files
committed
KT-6795 J2K: When converting to type with projections, omit redundant use-site projections
#KT-6795 Fixed
1 parent 7e50f72 commit c66b20b

File tree

11 files changed

+19
-9
lines changed

11 files changed

+19
-9
lines changed

idea/src/org/jetbrains/kotlin/idea/j2k/J2kPostProcessor.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import org.jetbrains.kotlin.idea.intentions.RemoveExplicitTypeArguments
2626
import org.jetbrains.kotlin.idea.intentions.SimplifyNegatedBinaryExpressionIntention
2727
import org.jetbrains.kotlin.idea.intentions.branchedTransformations.intentions.IfThenToElvisIntention
2828
import org.jetbrains.kotlin.idea.intentions.branchedTransformations.intentions.IfThenToSafeAccessIntention
29+
import org.jetbrains.kotlin.idea.quickfix.RemoveModifierFix
2930
import org.jetbrains.kotlin.idea.quickfix.RemoveRightPartOfBinaryExpressionFix
3031
import org.jetbrains.kotlin.j2k.PostProcessor
3132
import org.jetbrains.kotlin.psi.*
@@ -54,6 +55,11 @@ public class J2kPostProcessor(override val contextToAnalyzeIn: PsiElement) : Pos
5455
}
5556
}
5657

58+
Errors.REDUNDANT_PROJECTION -> { ->
59+
val fix = RemoveModifierFix.createRemoveProjectionFactory(true).createActions(problem).single() as RemoveModifierFix
60+
fix.invoke()
61+
}
62+
5763
else -> super.fixForProblem(problem)
5864
}
5965
}

idea/src/org/jetbrains/kotlin/idea/quickfix/RemoveModifierFix.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@ public String getText() {
9494

9595
@Override
9696
public void invoke(@NotNull Project project, Editor editor, JetFile file) throws IncorrectOperationException {
97+
invoke();
98+
}
99+
100+
public void invoke() throws IncorrectOperationException {
97101
JetModifierListOwner newElement = (JetModifierListOwner) element.copy();
98102
element.replace(removeModifier(newElement, modifier));
99103
}

j2k/testData/fileOrElement/mutableCollections/Overrides.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import kotlinApi.KotlinClass
44

55
public abstract class C(field: Int) : KotlinClass(field) {
66

7-
override fun foo(mutableCollection: MutableCollection<String>, nullableCollection: Collection<out Int>?): MutableList<Any> {
7+
override fun foo(mutableCollection: MutableCollection<String>, nullableCollection: Collection<Int>?): MutableList<Any> {
88
return super.foo(mutableCollection, nullableCollection)
99
}
1010
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
fun pushAll(src: Collection<out E>) {
1+
fun pushAll(src: Collection<E>) {
22
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
list as List<out String>
1+
list as List<String>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
class CC<T : INode, K : Node> : A() where T : Comparable<in T>, K : Collection<in K>
1+
class CC<T : INode, K : Node> : A() where T : Comparable<T>, K : Collection<in K>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
class C<T : INode> where T : Comparable<in T>
1+
class C<T : INode> where T : Comparable<T>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
class C<T : INode> : A() where T : Comparable<in T>
1+
class C<T : INode> : A() where T : Comparable<T>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
fun <T : Any, K : Node> max(coll: Collection<out T>): T where T : Comparable<in T>, K : Collection<in K> {
1+
fun <T : Any, K : Node> max(coll: Collection<T>): T where T : Comparable<T>, K : Collection<in K> {
22
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
trait I<T : INode, K : Node> : II where T : Comparable<in T>, K : Collection<in K>
1+
trait I<T : INode, K : Node> : II where T : Comparable<T>, K : Collection<in K>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
fun <T : Any> max(coll: Collection<out T>): T where T : Comparable<in T> {
1+
fun <T : Any> max(coll: Collection<T>): T where T : Comparable<T> {
22
}

0 commit comments

Comments
 (0)