IntelliJ 结构搜索和替换问题
有没有一种简单的方法来捕获类型?我似乎无法做一些基本的事情,例如并排使用变量表达式,例如 $mapType$$mapEnd$
来进行简单的替换。这可能有什么原因吗?也就是说,如果我有一个表达式,例如 .*\s*.*abc
,我将其分解为两个变量,.*\s*
和 .*abc
,表达式不匹配任何文本。可能出了什么问题?
Example template:
$var1$ = $impl$
Example second template:
$var1$ = $type$$implEnd$
如果 $impl$
是完整正则表达式,则将 $type$
和 $implEnd$
与一半匹配的正则表达式放在一起会导致模式不匹配匹配。可能出了什么问题?
我正在尝试进行此转换:
List<String,Object> list = new ArrayList<String,Object>();
List<String,Object> list = Lists.newArrayList();
显然,我需要以某种方式捕获“Array”,以及仅捕获那些没有参数的类型。
Is there an easy way to capture types? I can't seem to do basic things like use variable expressions side by side, such as $mapType$$mapEnd$
to do a simple replacement. Is there any reason this might be? That is, if I have a single expression, say .*\s*.*abc
, and I break it into two variables, .*\s*
and .*abc
, the expression does not match any text. What could be going wrong?
Example template:
$var1$ = $impl$
Example second template:
$var1$ = $type$implEnd$
If $impl$
is a full regular expression, placing $type$
and $implEnd$
together with half of the matching regex causes patterns not to match. What could be going wrong?
I'm trying to do this transformation:
List<String,Object> list = new ArrayList<String,Object>();
List<String,Object> list = Lists.newArrayList();
Clearly, I need to capture "Array" somehow, as well as only those types which have no arguments.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
SSR 匹配每个变量的一种或多种语言结构,它不会将多个变量 ($mapType$$mapEnd$) 捕获到类型引用(或任何语言词法)中。
的代码
对于像
List这样 someName = new ArrayList();
需要有搜索模式
List<$Type$>; $variable$ = new $ListType$<$Type$>()
并相应地替换它。
对于更复杂的泛型表达式,需要考虑几个泛型类型变量,例如
Map<$Key$, $Value$>
人们可能会发现这篇文章很有用(许多具体的 SSR 示例模式)
http://www.jetbrains .com/idea/documentation/ssr.html
SSR matches one or many language constructions per variable, it will NOT capture several variables ($mapType$$mapEnd$) into type reference (or whatever language lexem is).
For code like
List<String> someName = new ArrayList<String>();
one needs to have search pattern
List<$Type$> $variable$ = new $ListType$<$Type$>()
and replace it accordingly.
For more complex generic expressions one needs to consider several generic type variables like
Map<$Key$, $Value$>
One might find this article useful (many concrete SSR example patterns)
http://www.jetbrains.com/idea/documentation/ssr.html