From c66b20b2044f08ea057c04cf0abf17c6e4df73b3 Mon Sep 17 00:00:00 2001 From: Valentin Kipyatkov Date: Mon, 30 Mar 2015 13:50:23 +0300 Subject: [PATCH] KT-6795 J2K: When converting to type with projections, omit redundant use-site projections #KT-6795 Fixed --- idea/src/org/jetbrains/kotlin/idea/j2k/J2kPostProcessor.kt | 6 ++++++ .../jetbrains/kotlin/idea/quickfix/RemoveModifierFix.java | 4 ++++ j2k/testData/fileOrElement/mutableCollections/Overrides.kt | 2 +- .../fileOrElement/outProjectionType/methodParams.kt | 2 +- .../fileOrElement/typeCastExpression/extendsWildcardCast.kt | 2 +- .../classDoubleParametrizationWithTwoBoundsWithExtending.kt | 2 +- .../typeParameters/classParametrizationWithTwoBounds.kt | 2 +- .../classParametrizationWithTwoBoundsWithExtending.kt | 2 +- .../methodDoubleParametrizationWithTwoBounds.kt | 2 +- .../traitDoubleParametrizationWithTwoBoundsWithExtending.kt | 2 +- j2k/testData/fileOrElement/typeParameters/where.kt | 2 +- 11 files changed, 19 insertions(+), 9 deletions(-) diff --git a/idea/src/org/jetbrains/kotlin/idea/j2k/J2kPostProcessor.kt b/idea/src/org/jetbrains/kotlin/idea/j2k/J2kPostProcessor.kt index 53a2d15b504..ba58da54733 100644 --- a/idea/src/org/jetbrains/kotlin/idea/j2k/J2kPostProcessor.kt +++ b/idea/src/org/jetbrains/kotlin/idea/j2k/J2kPostProcessor.kt @@ -26,6 +26,7 @@ import org.jetbrains.kotlin.idea.intentions.RemoveExplicitTypeArguments import org.jetbrains.kotlin.idea.intentions.SimplifyNegatedBinaryExpressionIntention import org.jetbrains.kotlin.idea.intentions.branchedTransformations.intentions.IfThenToElvisIntention import org.jetbrains.kotlin.idea.intentions.branchedTransformations.intentions.IfThenToSafeAccessIntention +import org.jetbrains.kotlin.idea.quickfix.RemoveModifierFix import org.jetbrains.kotlin.idea.quickfix.RemoveRightPartOfBinaryExpressionFix import org.jetbrains.kotlin.j2k.PostProcessor import org.jetbrains.kotlin.psi.* @@ -54,6 +55,11 @@ public class J2kPostProcessor(override val contextToAnalyzeIn: PsiElement) : Pos } } + Errors.REDUNDANT_PROJECTION -> { -> + val fix = RemoveModifierFix.createRemoveProjectionFactory(true).createActions(problem).single() as RemoveModifierFix + fix.invoke() + } + else -> super.fixForProblem(problem) } } diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/RemoveModifierFix.java b/idea/src/org/jetbrains/kotlin/idea/quickfix/RemoveModifierFix.java index 6008320b3e2..95bea2c59ae 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/RemoveModifierFix.java +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/RemoveModifierFix.java @@ -94,6 +94,10 @@ public class RemoveModifierFix extends JetIntentionAction @Override public void invoke(@NotNull Project project, Editor editor, JetFile file) throws IncorrectOperationException { + invoke(); + } + + public void invoke() throws IncorrectOperationException { JetModifierListOwner newElement = (JetModifierListOwner) element.copy(); element.replace(removeModifier(newElement, modifier)); } diff --git a/j2k/testData/fileOrElement/mutableCollections/Overrides.kt b/j2k/testData/fileOrElement/mutableCollections/Overrides.kt index 695936d66d6..fb200792300 100644 --- a/j2k/testData/fileOrElement/mutableCollections/Overrides.kt +++ b/j2k/testData/fileOrElement/mutableCollections/Overrides.kt @@ -4,7 +4,7 @@ import kotlinApi.KotlinClass public abstract class C(field: Int) : KotlinClass(field) { - override fun foo(mutableCollection: MutableCollection, nullableCollection: Collection?): MutableList { + override fun foo(mutableCollection: MutableCollection, nullableCollection: Collection?): MutableList { return super.foo(mutableCollection, nullableCollection) } } diff --git a/j2k/testData/fileOrElement/outProjectionType/methodParams.kt b/j2k/testData/fileOrElement/outProjectionType/methodParams.kt index f04b37cf5ce..9e8fa1aba61 100644 --- a/j2k/testData/fileOrElement/outProjectionType/methodParams.kt +++ b/j2k/testData/fileOrElement/outProjectionType/methodParams.kt @@ -1,2 +1,2 @@ -fun pushAll(src: Collection) { +fun pushAll(src: Collection) { } \ No newline at end of file diff --git a/j2k/testData/fileOrElement/typeCastExpression/extendsWildcardCast.kt b/j2k/testData/fileOrElement/typeCastExpression/extendsWildcardCast.kt index 18a29d02359..fdc3e717b2a 100644 --- a/j2k/testData/fileOrElement/typeCastExpression/extendsWildcardCast.kt +++ b/j2k/testData/fileOrElement/typeCastExpression/extendsWildcardCast.kt @@ -1 +1 @@ -list as List \ No newline at end of file +list as List \ No newline at end of file diff --git a/j2k/testData/fileOrElement/typeParameters/classDoubleParametrizationWithTwoBoundsWithExtending.kt b/j2k/testData/fileOrElement/typeParameters/classDoubleParametrizationWithTwoBoundsWithExtending.kt index aeb0a6a77e2..69cf490e5d4 100644 --- a/j2k/testData/fileOrElement/typeParameters/classDoubleParametrizationWithTwoBoundsWithExtending.kt +++ b/j2k/testData/fileOrElement/typeParameters/classDoubleParametrizationWithTwoBoundsWithExtending.kt @@ -1 +1 @@ -class CC : A() where T : Comparable, K : Collection \ No newline at end of file +class CC : A() where T : Comparable, K : Collection \ No newline at end of file diff --git a/j2k/testData/fileOrElement/typeParameters/classParametrizationWithTwoBounds.kt b/j2k/testData/fileOrElement/typeParameters/classParametrizationWithTwoBounds.kt index 0ec861c5e35..c3a5dc8940c 100644 --- a/j2k/testData/fileOrElement/typeParameters/classParametrizationWithTwoBounds.kt +++ b/j2k/testData/fileOrElement/typeParameters/classParametrizationWithTwoBounds.kt @@ -1 +1 @@ -class C where T : Comparable \ No newline at end of file +class C where T : Comparable \ No newline at end of file diff --git a/j2k/testData/fileOrElement/typeParameters/classParametrizationWithTwoBoundsWithExtending.kt b/j2k/testData/fileOrElement/typeParameters/classParametrizationWithTwoBoundsWithExtending.kt index 9b484da7ed7..ddbd28056f1 100644 --- a/j2k/testData/fileOrElement/typeParameters/classParametrizationWithTwoBoundsWithExtending.kt +++ b/j2k/testData/fileOrElement/typeParameters/classParametrizationWithTwoBoundsWithExtending.kt @@ -1 +1 @@ -class C : A() where T : Comparable \ No newline at end of file +class C : A() where T : Comparable \ No newline at end of file diff --git a/j2k/testData/fileOrElement/typeParameters/methodDoubleParametrizationWithTwoBounds.kt b/j2k/testData/fileOrElement/typeParameters/methodDoubleParametrizationWithTwoBounds.kt index ea8e4426ebb..6a7b22e6666 100644 --- a/j2k/testData/fileOrElement/typeParameters/methodDoubleParametrizationWithTwoBounds.kt +++ b/j2k/testData/fileOrElement/typeParameters/methodDoubleParametrizationWithTwoBounds.kt @@ -1,2 +1,2 @@ -fun max(coll: Collection): T where T : Comparable, K : Collection { +fun max(coll: Collection): T where T : Comparable, K : Collection { } \ No newline at end of file diff --git a/j2k/testData/fileOrElement/typeParameters/traitDoubleParametrizationWithTwoBoundsWithExtending.kt b/j2k/testData/fileOrElement/typeParameters/traitDoubleParametrizationWithTwoBoundsWithExtending.kt index c7a4593dd43..3f3a12bdfbb 100644 --- a/j2k/testData/fileOrElement/typeParameters/traitDoubleParametrizationWithTwoBoundsWithExtending.kt +++ b/j2k/testData/fileOrElement/typeParameters/traitDoubleParametrizationWithTwoBoundsWithExtending.kt @@ -1 +1 @@ -trait I : II where T : Comparable, K : Collection \ No newline at end of file +trait I : II where T : Comparable, K : Collection \ No newline at end of file diff --git a/j2k/testData/fileOrElement/typeParameters/where.kt b/j2k/testData/fileOrElement/typeParameters/where.kt index 347e80c1306..4c6e6f81c15 100644 --- a/j2k/testData/fileOrElement/typeParameters/where.kt +++ b/j2k/testData/fileOrElement/typeParameters/where.kt @@ -1,2 +1,2 @@ -fun max(coll: Collection): T where T : Comparable { +fun max(coll: Collection): T where T : Comparable { } \ No newline at end of file