scala-ide/scala-refactoring

Redundant { in class with empty body after AddMethod

VladimirNik opened this issue · 5 comments

Additional brace is added to the class while using AddMethod refactoring.
Precondition: class/trait should have empty body and parents, braces should be on separate lines

Example:

trait Trait extends TestTrait {
}

the result for such case is:

trait Trait extends TestTrait { {
  def test: Unit = {
    ???
  }
}

For cases:

trait Trait extends TestTrait 
trait Trait extends TestTrait {  }

the result is correct.

it seems that the origin of the problem is in LayoutHelper - during the work of layoutForSingleChild -> splitLayoutBetweenLastChildAndParent (line where Layout is created based on Template and extended type).

Thanks for reporting, I'll look into it!

Fixed in the upcoming nightly build.

That's great, thank you! With this fix I can remove ugly hack from my code.

Reopening because of an additional case, reported by @skyluc in scala-ide/scala-ide#672:

I still see a problem with the extra {. If my concrete class extends a trait, or an abstract class and a trait, it works fine. But if the concrete class extends only the abstract class, the previous problem still appears.

abstract class absClass {
  def f: Int
}

class concClass extends absClass {
  ^
}

becomes

class concClass extends absClass { {
  def f: Int = {
    ???
  }
}

Ah, I only checked for TypeTree, but a super class is an Ident... anyway, it's fixed now :-)