IntelliJ structural search and replace problems

跟風遠走 提交于 2020-01-02 08:58:34

问题


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.


回答1:


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



来源:https://stackoverflow.com/questions/3302233/intellij-structural-search-and-replace-problems

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!