File tree Expand file tree Collapse file tree 3 files changed +24
-2
lines changed
test/dotty/tools/dotc/reporting Expand file tree Collapse file tree 3 files changed +24
-2
lines changed Original file line number Diff line number Diff line change @@ -3028,7 +3028,7 @@ object Parsers {
30283028 val name = in.name
30293029 val mod = atSpan(in.skipToken()) { modOfToken(tok, name) }
30303030
3031- if (mods.isOneOf(mod.flags)) syntaxError(RepeatedModifier (mod.flags.flagsString))
3031+ if (mods.isOneOf(mod.flags)) syntaxError(RepeatedModifier (mod.flags.flagsString, source, mod.span ))
30323032 addMod(mods, mod)
30333033 }
30343034
Original file line number Diff line number Diff line change @@ -33,6 +33,7 @@ import dotty.tools.dotc.rewrites.Rewrites.ActionPatch
3333import dotty .tools .dotc .util .Spans .Span
3434import dotty .tools .dotc .util .SourcePosition
3535import scala .jdk .CollectionConverters .*
36+ import dotty .tools .dotc .util .SourceFile
3637
3738/** Messages
3839 * ========
@@ -497,7 +498,7 @@ extends SyntaxMsg(ObjectMayNotHaveSelfTypeID) {
497498 }
498499}
499500
500- class RepeatedModifier (modifier : String )(implicit ctx: Context )
501+ class RepeatedModifier (modifier : String , source : SourceFile , span : Span )(implicit ctx: Context )
501502extends SyntaxMsg (RepeatedModifierID ) {
502503 def msg (using Context ) = i """ Repeated modifier $modifier"""
503504
@@ -516,6 +517,16 @@ extends SyntaxMsg(RepeatedModifierID) {
516517 |
517518 | """
518519 }
520+
521+ override def actions (using Context ) =
522+ List (
523+ CodeAction (title = s """ Remove repeated modifier: " $modifier" """ ,
524+ description = java.util.Optional .empty(),
525+ patches = List (
526+ ActionPatch (SourcePosition (source, span), " " )
527+ ).asJava
528+ )
529+ ).asJava
519530}
520531
521532class InterpolatedStringError ()(implicit ctx: Context )
Original file line number Diff line number Diff line change @@ -44,6 +44,17 @@ class CodeActionTest extends DottyTest:
4444
4545 )
4646
47+ @ Test def removeRepeatModifier =
48+ checkCodeAction(
49+ """ |final final class Test
50+ |""" .stripMargin,
51+ """ Remove repeated modifier: "final"""" ,
52+ // TODO look into trying to remove the extra space that is left behind
53+ """ |final class Test
54+ |""" .stripMargin
55+
56+ )
57+
4758 // Make sure we're not using the default reporter, which is the ConsoleReporter,
4859 // meaning they will get reported in the test run and that's it.
4960 private def newContext =
You can’t perform that action at this time.
0 commit comments