@@ -4,6 +4,7 @@ import dotty.tools.DottyTest
4
4
import dotty .tools .dotc .rewrites .Rewrites
5
5
import dotty .tools .dotc .rewrites .Rewrites .ActionPatch
6
6
import dotty .tools .dotc .util .SourceFile
7
+ import dotty .tools .dotc .core .Contexts ._
7
8
8
9
import scala .annotation .tailrec
9
10
import scala .jdk .CollectionConverters .*
@@ -149,14 +150,43 @@ class CodeActionTest extends DottyTest:
149
150
afterPhase = " patternMatcher"
150
151
)
151
152
153
+ @ Test def removeNN =
154
+ val ctxx = newContext
155
+ ctxx.setSetting(ctxx.settings.YexplicitNulls , true )
156
+ checkCodeAction(
157
+ code =
158
+ """ |val s: String|Null = "foo".nn
159
+ |""" .stripMargin,
160
+ title = " Remove unnecessary .nn" ,
161
+ expected =
162
+ """ |val s: String|Null = "foo"
163
+ |""" .stripMargin,
164
+ ctxx = ctxx
165
+ )
166
+
167
+
168
+ @ Test def removeNN2 =
169
+ val ctxx = newContext
170
+ ctxx.setSetting(ctxx.settings.YexplicitNulls , true )
171
+ checkCodeAction(
172
+ code =
173
+ """ val s: String|Null = null.nn
174
+ |""" .stripMargin,
175
+ title = " Remove unnecessary .nn" ,
176
+ expected =
177
+ """ val s: String|Null = null
178
+ |""" .stripMargin,
179
+ ctxx = ctxx
180
+ )
181
+
152
182
// Make sure we're not using the default reporter, which is the ConsoleReporter,
153
183
// meaning they will get reported in the test run and that's it.
154
184
private def newContext =
155
185
val rep = new StoreReporter (null ) with UniqueMessagePositions with HideNonSensicalMessages
156
186
initialCtx.setReporter(rep).withoutColors
157
187
158
- private def checkCodeAction (code : String , title : String , expected : String , afterPhase : String = " typer" ) =
159
- ctx = newContext
188
+ private def checkCodeAction (code : String , title : String , expected : String , afterPhase : String = " typer" , ctxx : Context = newContext ) =
189
+ ctx = ctxx
160
190
val source = SourceFile .virtual(" test" , code).content
161
191
val runCtx = checkCompile(afterPhase, code) { (_, _) => () }
162
192
val diagnostics = runCtx.reporter.removeBufferedMessages
0 commit comments