File tree 3 files changed +24
-2
lines changed
test/dotty/tools/dotc/reporting
3 files changed +24
-2
lines changed Original file line number Diff line number Diff line change @@ -3028,7 +3028,7 @@ object Parsers {
3028
3028
val name = in.name
3029
3029
val mod = atSpan(in.skipToken()) { modOfToken(tok, name) }
3030
3030
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 ))
3032
3032
addMod(mods, mod)
3033
3033
}
3034
3034
Original file line number Diff line number Diff line change @@ -33,6 +33,7 @@ import dotty.tools.dotc.rewrites.Rewrites.ActionPatch
33
33
import dotty .tools .dotc .util .Spans .Span
34
34
import dotty .tools .dotc .util .SourcePosition
35
35
import scala .jdk .CollectionConverters .*
36
+ import dotty .tools .dotc .util .SourceFile
36
37
37
38
/** Messages
38
39
* ========
@@ -497,7 +498,7 @@ extends SyntaxMsg(ObjectMayNotHaveSelfTypeID) {
497
498
}
498
499
}
499
500
500
- class RepeatedModifier (modifier : String )(implicit ctx: Context )
501
+ class RepeatedModifier (modifier : String , source : SourceFile , span : Span )(implicit ctx: Context )
501
502
extends SyntaxMsg (RepeatedModifierID ) {
502
503
def msg (using Context ) = i """ Repeated modifier $modifier"""
503
504
@@ -516,6 +517,16 @@ extends SyntaxMsg(RepeatedModifierID) {
516
517
|
517
518
| """
518
519
}
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
519
530
}
520
531
521
532
class InterpolatedStringError ()(implicit ctx: Context )
Original file line number Diff line number Diff line change @@ -44,6 +44,17 @@ class CodeActionTest extends DottyTest:
44
44
45
45
)
46
46
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
+
47
58
// Make sure we're not using the default reporter, which is the ConsoleReporter,
48
59
// meaning they will get reported in the test run and that's it.
49
60
private def newContext =
You can’t perform that action at this time.
0 commit comments