Structural Search question

If I want to replace all accesses of an array field, like this:

How could I do that? I can't replace array[$I$] with getThing($I$) because it produces code like this:

for array assignments. Is there a way to do this with structural search/replace?

7 comments
Comment actions Permalink

Sorry, formatting messed up my array code. I'll try again:

0
Comment actions Permalink

Hi,

You want replace all variable array accesses with indexed accessor
calls, right?
Search:
$array$[$i$], text for array variable: array, value is read
replacement
getArray($i$)

Testing the suggestion, I've found that read/write is not identified
properly in current build, so I will fix it ASAP


Keith Lea wrote:

Sorry, formatting messed up my array code. I'll try again:


0
Comment actions Permalink

Hi,

It turned out the things are even more simple:
First, we replace our assignment code by:
search
array[$1$] = $2$;
replace
setArray($1$,$2$);
Second, replace all other occurences as you described:
array[$1$] with getArray($1$)


Maxim Mossienko wrote:

Hi,

You want replace all variable array accesses with indexed accessor
calls, right?
Search:
$array$[$i$], text for array variable: array, value is read
replacement
getArray($i$)

Testing the suggestion, I've found that read/write is not identified
properly in current build, so I will fix it ASAP


Keith Lea wrote:

>> Sorry, formatting messed up my array code. I'll try again:

> = array[ i ];]]>



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

0
Comment actions Permalink

Thanks, that works.

That is one solution, but I think it shows a more general problem with structural search/replace. Sometimes syntax does not completely describe an operation, like in the case of array access.

I can't think of what could be done about this. Maybe when you type array[x], the search dialog could show a warning that says "array[x] could be used in array access and array assignment. Which would you like to use?" and let the user choose somehow. It could be used for other vague syntax such as "($X$1)" which could be either a method call "thing.run(x1);" or simply an expression "x = x + 1;".

0
Comment actions Permalink

Sorry, I meant "x = (x + 1);"

0
Comment actions Permalink

Hi,

I am not pretending that the solution is perfect but
nearly all syntax patterns (especially short) could require context
information that may be supplied by additional syntax patterns or
semantic constraints (as for array example).

Keith Lea wrote:

Thanks, that works.

That is one solution, but I think it shows a more general problem with structural search/replace. Sometimes syntax does not completely describe an operation, like in the case of array access.

I can't think of what could be done about this. Maybe when you type array[x], the search dialog could show a warning that says "array[x] could be used in array access and array assignment. Which would you like to use?" and let the user choose somehow. It could be used for other vague syntax such as "($X$1)" which could be either a method call "thing.run(x1);" or simply an expression "x = x + 1;".



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

0
Comment actions Permalink

By replacing the idea.exe (on the XP) with the 4.0 version, it starts
without this console.

Shaul

"Keith Lea" <keith@cs.oswego.edu> wrote in message
news:12383969.1089302970865.JavaMail.itn@is.intellij.net...

If I want to replace all accesses of an array field, like this:


How could I do that? I can't replace array[$I$] with

getThing($I$) because it produces code like this:

for array assignments. Is there a way to do this with structural
search/replace?


0

Please sign in to leave a comment.