jeudi 1 juillet 2021

Play: Get information if Action is deprecated inside of itself

I have a situation like this:

@Singleton
class FooController @Inject() () {
   @deprecated("Use bar instead", "22.10.2020")
   def getFoo(param: Int): Action[AnyContent] =
      userAction { ... }
}

Somewhere else:

def userAction(f: (Request[AnyContent], UserInfo) => Future[Result]): Action[AnyContent] =
   simpleAction { ... }

def simpleAction(f: Request[AnyContent] => Future[Result]): Action[AnyContent] =
   ...

The simpleAction takes care of things like logging, de- and serialization and some other metadata related stuff. It isn't only used by userAction, but I added this as an example that shows the layering of methods isn't flat.

What I need to find out in simpleAction, for purposes of logging, is if one of the callers (in this case getFoo) has been marked as @deprecated.

I think it's possible by parsing the stack trace, and then reflecting on the method to find all annotations. But this solution isn't perfect.





Aucun commentaire:

Enregistrer un commentaire