Skip to content

Commit

Permalink
Handle parentheses on methods without arguments correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthias Langer committed Oct 17, 2014
1 parent 539abd5 commit e820e27
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
Expand Up @@ -933,10 +933,8 @@ trait ReusingPrinter extends TreePrintingTraversals with AbstractPrinter {
val modsAndName = pp(mods ::: nameTree :: Nil, separator = Requisite.Blank)

val parameters = {
// The `)` is always removed from the layout, so if we have an empty
// parameter list and `()` in the source, we need to insert it here.
if (vparamss == List(List()) && modsAndName.asText.endsWith("(")) {
Fragment(")")
if (vparamss == List(List())) {
Fragment("()")
} else {
tree.explicitVParamss.map { vparams =>
pp(vparams, before = "(", separator = ", ", after = ")")
Expand Down
Expand Up @@ -59,6 +59,21 @@ class ReusingPrinterTest extends TestHelper with SilentTracing {
d.copy(tpt = newTpt) replaces d
}}}

@Test
def add_return_type_to_def_with_brace() = """
package add_return_type_to_def
object X {
def sideEffect() = 3
}""" becomes """
package add_return_type_to_def
object X {
def sideEffect(): Int = 3
}""" after topdown { matchingChildren { transform {
case d @ DefDef(_, _, _, _, tpt: TypeTree, _) =>
val newTpt = tpt setOriginal mkReturn(List(tpt.tpe.typeSymbol))
d.copy(tpt = newTpt) replaces d
}}}

@Test
def add_return_type_to_val() = """
package add_return_type_to_val
Expand Down

0 comments on commit e820e27

Please sign in to comment.