Skip to content

Commit

Permalink
Simplify "add missing override" save action
Browse files Browse the repository at this point in the history
  • Loading branch information
kiritsuku committed Sep 2, 2014
1 parent 353f378 commit 1122743
Showing 1 changed file with 14 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,28 +33,21 @@ trait AddMissingOverride extends SaveAction with CompilerSupport {
d.symbol.isOverridingSymbol && !d.symbol.isOverride
}

/**
* Alternative (preferred) implementation:
* {{{
* mods.copy().withPosition(Flag.OVERRIDE, pos)
* }}}
* The above does not work due to a limitation in scala-refactoring.
*/
def modsWithOverrideKeyword(mods: Modifiers, pos: Position): Modifiers =
mods.copy() setPositions Map(Flag.OVERRIDE -> pos) ++ mods.positions

val addOverrideKeyword = transform {
case d: DefDef =>
val mods = modsWithOverrideKeyword(d.mods, d.pos)
d.copy(mods = mods | Flag.OVERRIDE) replaces d

case d: ValDef =>
val mods = modsWithOverrideKeyword(d.mods, d.pos)
d.copy(mods = mods | Flag.OVERRIDE) replaces d

case d: TypeDef =>
val mods = modsWithOverrideKeyword(d.mods, d.pos)
d.copy(mods = mods | Flag.OVERRIDE) replaces d
case d: MemberDef =>
/**
* Alternative (preferred) implementation:
* {{{
* mods.copy().withPosition(Flag.OVERRIDE, pos)
* }}}
* The above does not work due to a limitation in scala-refactoring.
*/
val mods = d.mods.copy() setPositions Map(Flag.OVERRIDE -> d.pos) ++ d.mods.positions
d match {
case d: DefDef => d.copy(mods = mods | Flag.OVERRIDE) replaces d
case d: ValDef => d.copy(mods = mods | Flag.OVERRIDE) replaces d
case d: TypeDef => d.copy(mods = mods | Flag.OVERRIDE) replaces d
}
}

val refactoring = topdown {
Expand Down

0 comments on commit 1122743

Please sign in to comment.