feature proposal - autofix

there are quickfixes i want to apply always without exception, like "this could be final - quickfix?" and "fix implicit numeric conversions" (forgot the exact name). there should be way to tell the quickfixes to apply themselves automatically.

Message was edited by:
HamsterofDeath

5 comments
Comment actions Permalink

I proposed something similar called Code->Quickfix Code (or Code->Cleanup Code). Invoking this action would popup a dialog asking for an inspection profile and scope. After selecting a profile and pressing 'quickfix' button, IDEA would automatically apply all quickfixes for all inspections in the selected profile for the selected scope.

It is almost the same as what you are asking for. The differenence is similar to the difference between manually invoking 'Code->Optimize Imports' versus enabling "Optimize Imports on the fly" option.

See further dicussion in the Jira request:
http://www.jetbrains.net/jira/browse/IDEADEV-17781

and the last summary I made of Inspection UI feedback:
(Search for "New Feature Request: Code->QuickFix Code")

Inspection UI Feedback (As of build 6951)
http://www.intellij.net/forums/thread.jspa?threadID=267328

0
Comment actions Permalink

Hello Alex,

Thare are some problems:

Inspection can provide a number of quick fixes. E.g. I18N inspection provides
internationalize string, annotate as @NonNls (if available) and introduce
a constant. Which quickfix should I apply?

Different inspections can find problem on the same element: after applying
the first quick fix it would be impossible to detect where the second problem
is without inspection rerun. But different inspections can provide opposite
quick fixes (it is strange to switch them both but if they are switched we
can get infinite recursion - e.g. with autoboxing inspections)

There are a lot of quick fixes with questions such as a new name etc. I can't
guarantee that there won't be any interactions with user.

Thus IDEA will ask a lot of questions or will operate by default wich may
be not appropriate for some situations.

What do you think?

Thank you.

-


Anna Kozlova
JetBrains Inc.
http://www.intellij.com
"Develop with pleasure!"

I proposed something similar called Code->Quickfix Code (or
Code->Cleanup Code). Invoking this action would popup a dialog asking
for an inspection profile and scope. After selecting a profile and
pressing 'quickfix' button, IDEA would automatically apply all
quickfixes for all inspections in the selected profile for the
selected scope.

It is almost the same as what you are asking for. The differenence is
similar to the difference between manually invoking 'Code->Optimize
Imports' versus enabling "Optimize Imports on the fly" option.

See further dicussion in the Jira request:
http://www.jetbrains.net/jira/browse/IDEADEV-17781
and the last summary I made of Inspection UI feedback: (Search for
"New Feature Request: Code->QuickFix Code")

Inspection UI Feedback (As of build 6951)
http://www.intellij.net/forums/thread.jspa?threadID=267328



0
Comment actions Permalink

Inspection can provide a number of quick fixes. E.g. I18N inspection provides
internationalize string, annotate as @NonNls (if available) and introduce
a constant. Which quickfix should I apply?


idea knows where it could apply more than one quickfix. in this case, it should do nothing. it may ask the user once which quickfix is "better" and apply that one from then on, but this might not be a good idea always.

But different inspections can provide opposite
quick fixes (it is strange to switch them both but if they are switched we
can get infinite recursion - e.g. with autoboxing inspections)


see above - no problem

There are a lot of quick fixes with questions such as a new name etc. I can't
guarantee that there won't be any interactions with user.

Thus IDEA will ask a lot of questions or will operate by default wich may
be not appropriate for some situations.

What do you think?


this would be the users choice. like enabling inspections, according to my humble proposal, he would enable the auto-quickfix. if he enables one that asks for a name, so be it.
you could also:
a) put the quickfixes into a quickfix queue and let the user decide when to give his input (this on felt strange to think at first)
b) offer auto-quickfixes only for user independent quickfixes. (i like that one)

0
Comment actions Permalink

>

Inspection can provide a number of quick fixes. E.g.
I18N inspection provides
internationalize string, annotate as @NonNls (if
available) and introduce
a constant. Which quickfix should I apply?

>
1. Most inspections aren't like this, esp. the ones you would likelly apply automatically, so this isn't that big a deal i.e. the feature will still have 99% no matter how you solve this issue, as long as it's reasonable and consistent.
2. Most extreme solution is to just ignore all inspecxtions with multiple quickfixes.
3. You could ignore quickfixes which are interactive. It doesn't make sense to be invoking interactive quickfixes automatically.
4. You could always use the first quickfix for an inspection. This assmes that there is an order to the quickfixes,, and the inspection author puts the most likely/common fix first.
5. You could enhance the Errors Configuration dialog to display available quickfixes and allow the user to choose the preferred quickfix for an inspection.

Different inspections can find problem on the same
element: after applying
the first quick fix it would be impossible to detect
where the second problem
is without inspection rerun. But different
inspections can provide opposite
quick fixes (it is strange to switch them both but if
they are switched we
can get infinite recursion - e.g. with autoboxing
inspections)


I think it is important that IDEA re-evaulating code blocks until no more quickfixes can be applied. Here are a few ideas:
1. I think it would be rare to run into this problem, since the user would have to select contradictory combinations of inspecxtions, so I'm not particularly worried about potential problem.
2. Ideally, inspections which are the direct opposite of each other, e.g. autobox and auto-unbox, should have been merged into a single inspection and then in the inspection properties the user chooses what they want. That way contradictory combinations of inspections are avoided.
3. I am assumming this Code->Quickfix Code will be run as a background task. In that case, you should be able to Cancel it if it appears to be taking forever.


There are a lot of quick fixes with questions such as
a new name etc. I can't
guarantee that there won't be any interactions with
user.

Thus IDEA will ask a lot of questions or will operate
by default wich may
be not appropriate for some situations.


1. I think all interactive quickfixes should be ignored when running Code->Quickfix Code action. I view it as similar to Reformat Code or Optimmize Imports which are non-interactxive. I wouldn't want to complicate the functionality by trying to handle user interaction with interactive quickfixes. The intent of this feature was to allow you to apply automatied quicfixes quickly and easily. I think for interactive quickfixes, you will just use Analyze->Inspect Code.

0
Comment actions Permalink

Hamster,

I like the idea of autofix happening automatically, but I am unsure whether it would help more than annoy.

The only thing similar that we have now is the "Auto-import Unambiguous Imports On the Fly". That feature works quite well, but keep in mind that it is only modifying lines at the top of the file comtaining the import statements.

Inspection quickfixes could autofix code as soon as you type it!. For example, as soon as I type a missorted modifier, e.g. "static final public", IDEA would autofix it to "public static final". As soon as I type "name.equals("")" IDEA would autofix it to name.length() == 0, etc.

It is kind of like auto-correcting spelling errors, although in many cases it's more like auto-correcting grammar errors.

Now with everyone having a dual-core machine and now quad-core starting to become mainstream, our workstations have the hosepower of these kinds of autofixes to be running in the background.

I'm just not sure I would like code auto-magically changing as I am typing it. I think I would be more comfortable selecting a block of code (or the whole file) and invoking Code>Quickfix Code as I have proposed. One analogy I can think of is the difference between the user manually invoking Code->Reformat Code versus IDEA automatically reformatting misaligned/misformatted code as you type.

One approach to interactive autofixes could be the same as done for ambiguous imports. A lttle tooltip pops up prompting you to press ALT+ENTER to see a list of the possible imports for a class name. You could do the same thing for autofixes when they are interactive and/or when there are multiple quickfixes to choose from. But I'm not sure that is an improvement since mr. inspector is already highlighting code blocks flagged by the inspection, so why do we need a little tooltip popup too?

So, this autofix feature you suggested might be better to just support the non-interactxive quickfixes, since the user can already press ALT+ENTER on a highlighted piece of code to invoke a quickfix intention today.

0

Please sign in to leave a comment.