I am trying to search static concatenation of strings and combine them into single string using Structural Search Replace.
For instance
I want to search replace "String1"+"String2"+"String3"
and replace with "String1String2String3"
.But it should not replace strings in comments.
public class Main {
public static void main(String[] args) {
String s = "String1"+"String2"
+"String3";
System.out.println(CONSTANT);
}
// private static final String CONSTANT ="String1"
// +"String2"+"String3"
}
If I search for
"$String1$"
It results in 1 occurrences for above string However
"$String1$"+"$String2$"
Doesn't match above string
How does Structural Search Replace work?
How to refer to variables found in Search string
in Replace String
It looks like Structural Search does not currently support your use case exactly. You can match your string using the query:
and replace with:
But this will only find string concatenations of three string literals. You may want to file a bug report at http://youtrack.jetbrains.com