New Quick Assist's [message #171004] |
Sun, 01 August 2004 00:39  |
Eclipse User |
|
|
|
Originally posted by: scheglov_ke.nlmk.ru
I've added several new useful (at least for me) quick assist's in class
QuickAssistProcessor (from 3.0 release). Here i list of them:
1. Split condition.
For example you have following code:
if (condition_1 && condition_2) {
do_something2();
}
Now you decide that you need also execute do_something3() when
condition_1 && condition_3. I.e. you want following code:
if (condition_1) {
if (condition_2)
do_something2();
if (condition_3)
do_something3();
}
Currently you will need to copy condition_2 by hands. I don't know how
all other, but I am very lazy. With new quick assist you can position
caret on condition (for example on &&) and transform initial code in:
if (condition_1) {
if (condition_2)
do_something2();
}
2. Join 'if' statements.
This is reverse operation to "split condition". You can point on inner
or outer "if" statement and ask for joining. Depending on context, quick
assist will suggest to join outer "if" to inner or inner to outer, or
both, if possible. Join can be used only if there are no "else" parts in
"if" statements.
3. Add paranoidal parenthesis for conditions.
I don't like to look on conditions and think "And what is order of
executing these conditions?", so usually add parenthesis around each
expression like: "collection.size() == 1" or (object == null), etc.
However sometimes I have to change someone else code and would like to
change source to make it more readable for me. So, I've added quick assist
for adding parenthesis in such cases. For example this:
list.size() == 3 && list instanceof List && c
will be converted to:
(list.size() == 3) && (list instanceof List) && c
Just select block of code and invoke quick asisst, it will change all
conditions in selected code.
4. Remove extra parenthesis.
One more reverse operation.
If you don't like extra parenthesis in your code, you can remove all of
them and keep them only where required. For example this:
(list.size() == 2) && (a || b)
will be converted to:
list.size() == 2 && (a || b)
As you can see, it keeps parenthesis where needed. It uses precedence
table for operators, so knows, where to keep parenthesis.
5. Inverse condition.
Select condition and inverse it, for example when you see that there are
too many "not" operators or want to exchange "then" and "else" branches in
"if" statement (BTW, may be such quick assist also required?...). For
example, this:
a || !b && !c
will be converted to:
!a && (b || c)
BTW, I often use what I call "fail fast" checking. I.e. when you do chain
of checks, each next can be executed only if previous were successful,
instead of writing deep chain of "if" statements:
prepare_1;
if (condition_1) {
prepare_2;
if (condition_2) {
prepare_3;
if (condition_3) {
...
}
}
}
I prefer to have
prepare_1;
if (!condition_1)
return false; // or may be 'continue'
prepare_2;
if (!condition_2)
return false;
prepare_3;
if (!condition_3)
return false;
...
So, condition inversing could be useful to implement assists for
changing from one style of chain checking to another...
Ok, now when I've described them, does anybody need these quick assists?
Do you have more ideas? I would like to have them in Eclipse, so would
like to contribute them to Eclipse. But I am not sure how to do this. Open
feature request? Write in jdt-ui-dev?
--
SY, Kosta.
|
|
|
|
|
|
Re: New Quick Assist's [message #171271 is a reply to message #171180] |
Tue, 03 August 2004 03:22  |
Eclipse User |
|
|
|
Sam Mesh wrote:
[..]
> Is there more non-intrusive and convenient way to contribute to ^1?
Yes, your plug-in can extend the org.eclipse.jdt.ui.quickAssistProcessors
extension point.
Markus
|
|
|
Powered by
FUDForum. Page generated in 0.28323 seconds