views:

31

answers:

2

I can easily find all mentions of some annotation in my project using SSR (structural search and replace). For example I have following spring based code:

class DashboardController {

  @RequestMapping("/dashboard")
  public void doDashboard() {
    [...]
  }
}

If I search by pattern org.springframework.web.bind.annotation.RequestMapping than I will find my code. But what if I want to find methods annotated with parametrized annotation, so find only method with annotations @RequestMapping for "/dashboard" url?

I can simply search by @RequestMapping("/dashboard") string, but annotation can be written in several ways:

@RequestMapping("/dashboard")
@RequestMapping(value = "/dashboard", method = {RequestMethod.POST})
@RequestMapping(headers = "content-type=application/*", value = "/dashboard")

etc.

A: 

Why not just do a text search for @RequestMapping("/dashboard"), its unlikely to give that many false positives.

Jon Freedman
There is several ways how this annotation can be written. For example, `@RequestMapping(value = "/dashboard", method = {RequestMethod.POST})` etc.
dotsid
Then use a regex, something like `@RequestMapping(.*"/dashboard".*)`
Jon Freedman
+1  A: 

Why don't you search this :

@RequestMapping\(((.*?)value\s*=\s*)?"/dashboard"(.*?)\)
Colin Hebert