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
2222import reporting .*
2323import Constants .Constant
2424import cc .{stripCapturing , isUpdateMethod , CCState }
25+ import dotty .tools .dotc .util .Chars .{isLineBreakChar , isWhitespace }
2526
2627object RefChecks {
2728 import tpd .*
@@ -1278,7 +1279,7 @@ object RefChecks {
12781279 val classHasBraces = classText.contains(" {" ) && classText.contains(" }" )
12791280
12801281 // 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
12821283 val baseIndent = new String (content.slice(lineStart, span.end).takeWhile(c => c == ' ' || c == '\t ' ))
12831284 val indent = baseIndent + " "
12841285
@@ -1295,7 +1296,7 @@ object RefChecks {
12951296 val braceEnd = classText.lastIndexOf('}' )
12961297 val bodyBetweenBraces = classText.slice(braceStart + 1 , braceEnd)
12971298 val bodyIsEmpty = bodyBetweenBraces.forall(_.isWhitespace)
1298- val bodyContainsNewLine = bodyBetweenBraces.contains( System .lineSeparator() )
1299+ val bodyContainsNewLine = bodyBetweenBraces.exists(isLineBreakChar )
12991300
13001301 val prefix = if (bodyContainsNewLine) " " else System .lineSeparator()
13011302 val patchText =
Original file line number Diff line number Diff line change @@ -291,6 +291,36 @@ class CodeActionTest extends DottyTest:
291291 afterPhase= " erasure"
292292 )
293293
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+
294324 // Make sure we're not using the default reporter, which is the ConsoleReporter,
295325 // meaning they will get reported in the test run and that's it.
296326 private def newContext =
You can’t perform that action at this time.
0 commit comments