From 8d718402552e842dbced79f9cd1e1f397a616b38 Mon Sep 17 00:00:00 2001 From: Jack Zhou Date: Sat, 19 Jan 2013 15:33:38 -0800 Subject: [PATCH] Added QuickFix for redundant type projections. --- .../jet/plugin/quickfix/QuickFixes.java | 1 + .../jet/plugin/quickfix/RemoveModifierFix.java | 18 ++++++++++++++++++ .../afterRemoveRedundantProjection1.kt | 8 ++++++++ .../afterRemoveRedundantProjection2.kt | 8 ++++++++ .../beforeRemoveRedundantProjection1.kt | 8 ++++++++ .../beforeRemoveRedundantProjection2.kt | 8 ++++++++ 6 files changed, 51 insertions(+) create mode 100644 idea/testData/quickfix/typeProjection/afterRemoveRedundantProjection1.kt create mode 100644 idea/testData/quickfix/typeProjection/afterRemoveRedundantProjection2.kt create mode 100644 idea/testData/quickfix/typeProjection/beforeRemoveRedundantProjection1.kt create mode 100644 idea/testData/quickfix/typeProjection/beforeRemoveRedundantProjection2.kt diff --git a/idea/src/org/jetbrains/jet/plugin/quickfix/QuickFixes.java b/idea/src/org/jetbrains/jet/plugin/quickfix/QuickFixes.java index 03c32c160ca..a5ad9eb0a9a 100644 --- a/idea/src/org/jetbrains/jet/plugin/quickfix/QuickFixes.java +++ b/idea/src/org/jetbrains/jet/plugin/quickfix/QuickFixes.java @@ -102,6 +102,7 @@ public class QuickFixes { factories.put(ABSTRACT_MODIFIER_IN_TRAIT, RemoveModifierFix.createRemoveModifierFromListOwnerFactory(ABSTRACT_KEYWORD, true)); factories.put(OPEN_MODIFIER_IN_TRAIT, RemoveModifierFix.createRemoveModifierFromListOwnerFactory(OPEN_KEYWORD, true)); factories.put(TRAIT_CAN_NOT_BE_FINAL, removeFinalModifierFactory); + factories.put(REDUNDANT_PROJECTION, RemoveModifierFix.createRemoveProjectionFactory()); JetIntentionActionFactory removeOpenModifierFactory = RemoveModifierFix.createRemoveModifierFromListOwnerFactory(OPEN_KEYWORD); factories.put(NON_FINAL_MEMBER_IN_FINAL_CLASS, AddModifierFix.createFactory(OPEN_KEYWORD, JetClass.class)); diff --git a/idea/src/org/jetbrains/jet/plugin/quickfix/RemoveModifierFix.java b/idea/src/org/jetbrains/jet/plugin/quickfix/RemoveModifierFix.java index 35a5b313da8..4ed4609320f 100644 --- a/idea/src/org/jetbrains/jet/plugin/quickfix/RemoveModifierFix.java +++ b/idea/src/org/jetbrains/jet/plugin/quickfix/RemoveModifierFix.java @@ -29,6 +29,7 @@ import org.jetbrains.annotations.Nullable; import org.jetbrains.jet.lang.diagnostics.Diagnostic; import org.jetbrains.jet.lang.psi.JetModifierList; import org.jetbrains.jet.lang.psi.JetModifierListOwner; +import org.jetbrains.jet.lang.psi.JetTypeProjection; import org.jetbrains.jet.lexer.JetKeywordToken; import org.jetbrains.jet.lexer.JetToken; import org.jetbrains.jet.lexer.JetTokens; @@ -135,4 +136,21 @@ public class RemoveModifierFix extends JetIntentionAction } }; } + + public static JetIntentionActionFactory createRemoveProjectionFactory() { + return new JetIntentionActionFactory() { + @Nullable + @Override + public JetIntentionAction createAction(Diagnostic diagnostic) { + JetTypeProjection projection = QuickFixUtil.getParentElementOfType(diagnostic, JetTypeProjection.class); + if (projection == null) return null; + ASTNode projectionAstNode = projection.getProjectionNode(); + if (projectionAstNode == null) return null; + IElementType elementType = projectionAstNode.getElementType(); + if (!(elementType instanceof JetKeywordToken)) return null; + JetKeywordToken variance = (JetKeywordToken) elementType; + return new RemoveModifierFix(projection, variance, true); + } + }; + } } diff --git a/idea/testData/quickfix/typeProjection/afterRemoveRedundantProjection1.kt b/idea/testData/quickfix/typeProjection/afterRemoveRedundantProjection1.kt new file mode 100644 index 00000000000..61c029632ec --- /dev/null +++ b/idea/testData/quickfix/typeProjection/afterRemoveRedundantProjection1.kt @@ -0,0 +1,8 @@ +// "Remove redundant 'out' modifier" "true" +class Foo { + val x = 0 +} + +fun bar(x : Foo) { + +} diff --git a/idea/testData/quickfix/typeProjection/afterRemoveRedundantProjection2.kt b/idea/testData/quickfix/typeProjection/afterRemoveRedundantProjection2.kt new file mode 100644 index 00000000000..e16e7af24cd --- /dev/null +++ b/idea/testData/quickfix/typeProjection/afterRemoveRedundantProjection2.kt @@ -0,0 +1,8 @@ +// "Remove redundant 'in' modifier" "true" +class Foo { + val x = 0 +} + +fun bar(x : Foo) { + +} diff --git a/idea/testData/quickfix/typeProjection/beforeRemoveRedundantProjection1.kt b/idea/testData/quickfix/typeProjection/beforeRemoveRedundantProjection1.kt new file mode 100644 index 00000000000..c0d6c5b4a7a --- /dev/null +++ b/idea/testData/quickfix/typeProjection/beforeRemoveRedundantProjection1.kt @@ -0,0 +1,8 @@ +// "Remove redundant 'out' modifier" "true" +class Foo { + val x = 0 +} + +fun bar(x : Foo< out Any>) { + +} diff --git a/idea/testData/quickfix/typeProjection/beforeRemoveRedundantProjection2.kt b/idea/testData/quickfix/typeProjection/beforeRemoveRedundantProjection2.kt new file mode 100644 index 00000000000..22f4e728a9e --- /dev/null +++ b/idea/testData/quickfix/typeProjection/beforeRemoveRedundantProjection2.kt @@ -0,0 +1,8 @@ +// "Remove redundant 'in' modifier" "true" +class Foo { + val x = 0 +} + +fun bar(x : Foo< in Any>) { + +}