intellijent code completion

There's low traffic in the eap forum, so if you have some
time left, check this statement:

return format(rec.getMinX() + "," + format(rec.getMinY() + " - " +
format(rec.getMaxX() + "," + format(rec.getMaxY() +
" w=" + format(rec.getWidth() + " h=" + format(rec.getHeight();

obviously there are some closing brackets missing.
What I did was doing a replace on the original statement, which looked like this:

return (long) rec.getMinX() ...

So I replaced (long) by format(
which of coursed leaded to missing closing brackets.

-> so this leads to the first possible improvement that
comes to my mind: if I could make the replace like this:

replace "(long) $EXPRESSION" with "format($EXPRESSION)"

I guess it's not that trivial - but you get the IDEA ;)

-> second possible improvement:
if you take the first statement above and try shift-ctrl-enter (complete statement)I with it, you'll
see it fail gracefully ;) it just ends a lot of braces
at the very end of the statement.
So, what kind of intellig(j)ence would be required to
place the correct closing braces automatically?
I'm aware that it might not be 100% determinable.
But what about this: first do the current logic, then
find out that the resulting statement causes compiler failure. Then try the other logic = directly add a closing
bracket after each format(rec.getMinX()
-> find out that after it, the compiler is green and
leave it that way.

Would sth. like this be yet possible by current open APIs?

It can't be that difficult... ;)



3 comments
Comment actions Permalink

Michael Damberger wrote:

There's low traffic in the eap forum, so if you have some
time left, check this statement:

return format(rec.getMinX() + "," + format(rec.getMinY() + " - " +
format(rec.getMaxX() + "," + format(rec.getMaxY() +
" w=" + format(rec.getWidth() + " h=" + format(rec.getHeight();

obviously there are some closing brackets missing.
What I did was doing a replace on the original statement, which looked like this:

return (long) rec.getMinX() ...

So I replaced (long) by format(
which of coursed leaded to missing closing brackets.

-> so this leads to the first possible improvement that
comes to my mind: if I could make the replace like this:

replace "(long) $EXPRESSION" with "format($EXPRESSION)"


This first part is what Structured Search and Replace is for, I think.
It's a new feature. Haven't used it myself, but this is a clear case for it.

--
Rob Harwood
Software Developer
JetBrains Inc.
http://www.jetbrains.com
"Develop with pleasure!"

0
Comment actions Permalink

The first item could also be accomplished with regular expressions and replacement groups. I've used to often to handle just this case: converting one method call to another, preserving the arguments.

0
Comment actions Permalink

Michael Damberger wrote:

replace "(long) $EXPRESSION" with "format($EXPRESSION)"


Using Pallada you could do this with Strutural Search and Replace. Try
defining the template as "(long) $exp$" and the replacement as
"format($exp$)".

Ciao,
Gordon

--
Gordon Tyler (Software Developer)
Quest Software <http://java.quest.com/>
260 King Street East, Toronto, Ontario M5A 4L5, Canada
Voice: 416-643-4846 | Fax: 416-594-1919

0

Please sign in to leave a comment.