Structural Search: Bug or Feature?

Hi,

I was trying to eliminate StringBuffer.append() calls that simply
append String literals by joining the literals together. However, I
didn't manage to do that because I hit the following problem:

Search template:
$sb$.append("$S1$").append("$S2$")

Replacement template:
$sb$.append("$S1$$S2$")

Executed on the code:
sb.append("a").append("b")

Suggests this replacement:
sb.append(""a""b"")

Looks like the variables contain more than they matched, i.e. not just the
content of the string literal but the literal itself. This makes it impossible
to do a "$S1$$S2$" replacement which I originally wanted to do. Is this behavior
intentional and/or is there another way to accomplish the desired effect?

Thanks,
Sascha

2 comments
Comment actions Permalink

Hi,

That was the bug fixed in 2234.

Some ~ work around could be the following:
Search template:
$sb$.append($S1$).append($S2$)

// S1, S2 have expression type String, text constraint = \".*\"

Replacement template:
$sb$.append($S1$+$S2$)

// constant + are resolved by javac

Sascha Weinreuter wrote:

Hi,

I was trying to eliminate StringBuffer.append() calls that simply
append String literals by joining the literals together. However, I
didn't manage to do that because I hit the following problem:

Search template:
$sb$.append("$S1$").append("$S2$")

Replacement template:
$sb$.append("$S1$$S2$")

Executed on the code:
sb.append("a").append("b")

Suggests this replacement:
sb.append(""a""b"")

Looks like the variables contain more than they matched, i.e. not just the
content of the string literal but the literal itself. This makes it
impossible
to do a "$S1$$S2$" replacement which I originally wanted to do. Is this
behavior
intentional and/or is there another way to accomplish the desired effect?

Thanks,
Sascha



--
Best regards,
Maxim Mossienko
IntelliJ Labs / JetBrains Inc.
http://www.intellij.com
"Develop with pleasure!"

0
Comment actions Permalink


Maxim Mossienko wrote:

Hi,

That was the bug fixed in 2234.


Ah, I had a feeling that I saw this somewhere before but did not find it.
Sorry about that. :(

Sascha

0

Please sign in to leave a comment.