Skip to content

Add utility to get enclosing method name reliably #102

@evis

Description

@evis

Currently, we're able to get enclosing method args with sourcecode.Args. Also, in some cases we can get enclosing method name:

def printMethodName()(implicit name: Name) =
  println(name.value)

def myMethod() = 
  printMethodName() // prints "myMethod"

But if there is a local val declared, then implicitly[Name] returns the val's name:

def myMethod() =
  val breakPrinting = printMethodName() // prints "breakPrinting"

It would be convenient to have something like this:

def printMethodName()(implicit method: Method) =
  println(method.value)

def myMethod() = 
  printMethodName() // prints "myMethod"

def myMethod() =
  val breakPrinting = printMethodName() // prints "myMethod"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions