File tree Expand file tree Collapse file tree 2 files changed +33
-2
lines changed
src/dotty/tools/dotc/typer
test/dotty/tools/dotc/reporting Expand file tree Collapse file tree 2 files changed +33
-2
lines changed Original file line number Diff line number Diff line change @@ -22,6 +22,7 @@ import config.Printers.refcheck
22
22
import reporting .*
23
23
import Constants .Constant
24
24
import cc .{stripCapturing , isUpdateMethod , CCState }
25
+ import dotty .tools .dotc .util .Chars .{isLineBreakChar , isWhitespace }
25
26
26
27
object RefChecks {
27
28
import tpd .*
@@ -1278,7 +1279,7 @@ object RefChecks {
1278
1279
val classHasBraces = classText.contains(" {" ) && classText.contains(" }" )
1279
1280
1280
1281
// Indentation for inserted methods
1281
- val lineStart = content.lastIndexWhere(c => c == ' \n ' , end = span.end - 1 ) + 1
1282
+ val lineStart = content.lastIndexWhere(isLineBreakChar , end = span.end - 1 ) + 1
1282
1283
val baseIndent = new String (content.slice(lineStart, span.end).takeWhile(c => c == ' ' || c == '\t ' ))
1283
1284
val indent = baseIndent + " "
1284
1285
@@ -1295,7 +1296,7 @@ object RefChecks {
1295
1296
val braceEnd = classText.lastIndexOf('}' )
1296
1297
val bodyBetweenBraces = classText.slice(braceStart + 1 , braceEnd)
1297
1298
val bodyIsEmpty = bodyBetweenBraces.forall(_.isWhitespace)
1298
- val bodyContainsNewLine = bodyBetweenBraces.contains( System .lineSeparator() )
1299
+ val bodyContainsNewLine = bodyBetweenBraces.exists(isLineBreakChar )
1299
1300
1300
1301
val prefix = if (bodyContainsNewLine) " " else System .lineSeparator()
1301
1302
val patchText =
Original file line number Diff line number Diff line change @@ -291,6 +291,36 @@ class CodeActionTest extends DottyTest:
291
291
afterPhase= " erasure"
292
292
)
293
293
294
+ @ Test def insertMissingMethodsIntoMultilineClassDefinition =
295
+ checkCodeAction(
296
+ code =
297
+ """ trait Animal {
298
+ | def name: String
299
+ |}
300
+ |trait Car {
301
+ | def wheels: Int
302
+ |}
303
+ |class Dog extends Animal
304
+ | with Car {
305
+ |}
306
+ |""" .stripMargin,
307
+ title = " Add missing methods" ,
308
+ expected =
309
+ """ trait Animal {
310
+ | def name: String
311
+ |}
312
+ |trait Car {
313
+ | def wheels: Int
314
+ |}
315
+ |class Dog extends Animal
316
+ | with Car {
317
+ | def name: String = ???
318
+ | def wheels: Int = ???
319
+ |}
320
+ |""" .stripMargin,
321
+ afterPhase= " erasure"
322
+ )
323
+
294
324
// Make sure we're not using the default reporter, which is the ConsoleReporter,
295
325
// meaning they will get reported in the test run and that's it.
296
326
private def newContext =
You can’t perform that action at this time.
0 commit comments