Java 在IntelliJ IDEA中查找注释
我可以使用SSR(structural search and replace)很容易地在我的项目中找到所有提到的注释。例如,我有以下基于spring的代码:Java 在IntelliJ IDEA中查找注释,java,annotations,intellij-idea,structural-search,Java,Annotations,Intellij Idea,Structural Search,我可以使用SSR(structural search and replace)很容易地在我的项目中找到所有提到的注释。例如,我有以下基于spring的代码: class DashboardController { @RequestMapping("/dashboard") public void doDashboard() { [...] } } 如果我按模式org.springframework.web.bind.annotation.RequestMapping搜索,
class DashboardController {
@RequestMapping("/dashboard")
public void doDashboard() {
[...]
}
}
如果我按模式org.springframework.web.bind.annotation.RequestMapping
搜索,我将找到我的代码。但是,如果我想查找带有参数化注释的方法,那么对于“/dashboard”url,只查找带有注释的方法@RequestMapping
我可以简单地通过@RequestMapping(“/dashboard”)
字符串进行搜索,但注释可以用几种方式编写:
@RequestMapping("/dashboard")
@RequestMapping(value = "/dashboard", method = {RequestMethod.POST})
@RequestMapping(headers = "content-type=application/*", value = "/dashboard")
等等。为什么不直接对
@RequestMapping(“/dashboard”)
进行文本搜索呢?它不太可能给出那么多误报。为什么不搜索这个:
@RequestMapping\(((.*?)value\s*=\s*)?"/dashboard"(.*?)\)
在IntelliJ IDEA 14中使用结构搜索和替换。复制现有模板注释的方法,并将“/dashboard”作为参数添加到注释中,如下所示:
class $Class$ {
@$Annotation$("/dashboard")
$MethodType$ $MethodName$($ParameterType$ $ParameterName$);
}
您可能还希望编辑$Annotation$变量,并将其命名为text/regexp“RequestMapping”
这应该可以找到注释的所有可能格式(仅在方法上) 有几种方法可以编写此注释。例如,
@RequestMapping(value=“/dashboard”,method={RequestMethod.POST})
等。然后使用正则表达式,类似于@RequestMapping(.*/dashboard.*)