Change text color of commented program code? - intellij-idea

I'm looking for a simple feature or work-around that can highlight commented program code as opposed to technical notes. Is there such a feature or other way to do it?
I want this to appear in light gray, as normal:
//avoids a ClassCastException. See bugfix #123
I want this to appear in orange so that it can safely be removed (the history for which would be under version control):
//public static void method() {
//}
I searched SO but no luck.

There is no such feature in IntelliJ Idea. Fortunately, there is even better way to avoid commented-out sections of code in your project.
The best option is to use Static Code Analysis tool such as Sonar - it has a rule which detects commented-out lines of code and reports the issue to you. After running such tool you can be certain you have no commented-out dead code in your project.
See the post about Commented-out code eradication with Sonar.

Related

How can I force intellij to check all files?

When I'm using intellij sometimes I do very large refactors that the IDE can't help with. This often breaks a lot of files, but since I'm using either Typescript or Java it's relatively easy to find the problems.
My issue is that I can't seem to get Intellij to check those files unless I open them specifically.
The kind of checking I'm talking about isn't a specific inspection, it's just like the normal compilation problems.
So for example, I have a typescript project and I modified some stuff. When I open some of my React components intellij waits a second, and then highlights parts of it in red. I can go to those parts and see what the issue is.
I've tried forcing the inspector to run, and I've tried building the project, but neither one gives me the red squiggly love I need :^(
It feels like the project->build should force intellij to highlight all this stuff, but it seems to have no effect.

Highlight things marked as obsolete

I recently did some refactoring in our code and marked some widely-used functions as obsolete. The problem now is, that I get not visual indicator when I use an obsolete function right away. I have to hover over the function call to get the popup with further information about that function, and even there the "deprecated" warning is not very prominent. As these functions are to widely-used and cause no real treat, setting the isError property is not an option.
I know that somewhere I saw obsolete functions that were highlighted with some kind of underlining, but I can not find an option that does that. Where is that option, or how else can I achieve a more eye-catching indication?
I have created a simple toy VB.Net console application in MSVS, as you can see in the image the items marked obsolete are underlined in green where they are used.
If you are not seeing this then you will need to provide some more details on your solution's settings - what type of project is it, what version of visual studio are you opening it in, is it the same version it was created in, do you have any third party code linter (eg ReSharper) in use... etc
EDIT: As you mention in your comment, the project's properties, including the Code Analysis settings, will affect whether this underlining show's correctly or not; you will need to ensure the correct rule-set is selected there.

Intellij adding extra line in new blocks

When I'm writing code in Intellij, I often create new blocks by typing these types of sequences:
if (test) {
Typing that open curly brace causes Intellij to automatically insert a closing brace and move the cursor between the two braces:
if (test) {|}
At this point, I simply press Enter and get a nicely formatted block with the cursor right where it should be:
if (test) {
|
}
However, today Intellij is adding an extra line to the block, like this:
if (test) {
|
}
I've looked all over the project and IDE settings, but I'm not sure what to change. FYI, it's happening in various file types (.java, .js, .css) across different types of projects (Spring/Java, Node/Express). Anyone know how to fix this little annoyance?
Just got this error myself. Weirdly enough, for me it turned out to be the AWS Toolkit plugin.
If you have the same problem, it is most likely something with one of your other plugins if not the one mentioned above. I went through tons of IDE settings, and believe me, I wouldn't wish that upon anyone ;)
As of 5MAR2015 the solution is to disable the Gauge plugin. Credit for this goes to #KaPaHgaIII

Disable IntelliJ Warnings

It really annoys me that IntelliJ highlights certain 'errors' (that don't prevent successful compilation) the same way that real errors are highlighted. For example, a magic number is not really an error, but it will be flagged in exactly the same way as an incompatible type error.
How can I change this?
Go to Settings -> Inspections. Then you need to search through the long list for the offending inspection, which you can get the name of by hovering on the warning marker in the margin. You can change the severity of the inspection, whether it's an error, warning, etc. or just disable it altogether.
Edit: if you search for "magic" in Settings, you get the following, which should be helpful:
Whenever you see an inspection warning/error you can place the caret on it and press Alt+Enter (a light bulb also appears that tells you that). A menu will appear with suggested quick fixes. You may need to open a submenu by pressing Right, and you'll find "Edit inspection settings" there. Having invoked that, you may proceed as in hvgotcodes's answer :), it's just a faster way of getting to those settings.
As Michael Calvin said you can use the SuppressWarnings annotation. For example:
#SuppressWarnings("OptionalUsedAsFieldOrParameterType")
See https://github.com/JetBrains/intellij-community/blob/master/plugins/InspectionGadgets/src/inspectionDescriptions/OptionalUsedAsFieldOrParameterType.html
Usually searching the internet for the exact description leads me to this.
Not directly relevant to the OP, but may be of use to future Googlers
I got to this question while trying to figure out how to disable IntelliJ IDEA's warnings about Guava functionalities that have been replaced by Java 8 features. I'm not able to use the Java 8 versions of these features in my case because of a library we're using that was built with Guava (despite being a Java 8 project). So to solve that, I added a SuppressWarnings annotation before any class using Guava:
#SuppressWarnings(Guava)
public final class...

Does IntelliJ IDEA reveal the method body when folding anonymous classes?

Based on IntelliJ's documentation, when folding an anonymous class you should still be able to see the contents of the inner method. See image below taken from their documentation:
This isn't the behavior I'm seeing though. Here is what I see:
I can only seem to collapse the inner method contents or the entire anonymous class body. Is this just an error in their documentation or is there a way to actually achieve this behavior?
======= UPDATE =========
I've accepted the answer from Peter Gromov, but there still seems to be something amiss with my version. When I have files open and set folding closures by default (File -> Settings -> Editor -> Code Folding -> Select 'Closures' under 'Collapse by default:'), it does seem to fold correctly as seen in the following image:
Notice that the expanded Because shows a single collapsible region in the margin. Closing the file and reopening produces the following (after I collapse the first one):
When first opening the file, both of these statements are expanded (issue #1). After collapsing the outer most region for the first statement, it folds over the entire anonymous class (issue #2) rather than how it worked before I closed the file. Notice also that the second statement that I've left open has an additional collapsible region for the method of the anonymous class (issue #3). This is how it behaves with the default folding settings for closures are turned off. There's definitely something buggy here. Since I've posted this question, there has been a new version released so perhaps the issue is only with the version I have (10.0.3), but as far as I know this is a fairly old feature. I'd welcome any explanation as to why I might be seeing these issues (including "Works on my machine").
What you want is called 'Closure folding' and can be turned on in the Code Folding settings.