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

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.

Related

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: Highlight current block of code

I was wondering if it is possible to highlight the block of code you are working on in Intellij Idea.
There was a similar question here: Is there a way to highlight the currently active code block in Visual Studio 2010? .
So what I mean is that if you have clicked into e.g. a method or a while loop... ,the background of the whole block becomes a bit lighter or whatever.
There's already one such feature, but it's more subtle, in the form of a vertical line inside the left gutter... I can't recall whether it's enabled by default or not, but you can activate it by File -> Settings -> Editor -> General, scroll to the Highlight on Caret Movement section (about half of the page).
I looked around for a while but I have not yet found a way to change its appearance to match your description, although I personally prefer this less intrusive highlight than having all the background changed.
P.S. Not sure this is relevant or useful to you, but there was a plugin I tried a while ago called CodeGlance which offered a scrollable-map of the class:
I don't know when this feature was implemented. As of 2021, if you double click anywhere in the scope ( but not on text ), Intellij selects the current block of code ( text within two curly braces ).

Ignore whitespace changes in IntelliJ changebars

I have a file from our repository where I ran auto-indent (because it was a mess), and now the whole file is marked by blue changebars (down the right hand side of the editor window), making it difficult to find my changes.
I am already ignoring whitespace changes in the diff window (as described here: Intellij and changes tab), is there a way to also do this in the editor window?
I couldn't find a way to completely ignore whitespaces, but IntelliJ (I'm using version 2016) lets you set an option to color whitespace-only changes differentely:
Editor -> General -> Different color for lines with whitespace-only modifications
which helps tremendously.
At the moment [idea 13.5] it seems that is not possible to ignore spaces in the standard editor. You can open a support ticket
We also faced this in the company due the different codestyles used, at the end we settle for:
setting a common codestyle that everyone editing the code should [actually must] follow
reformat the whole codebase to the given codestyle
recommit the formatted code [without any addition or deletion, just the reformat]
It took just a bit of time, but at the end now we are working far better. In this way from that moment onward, we would have all the time the code that would aesthetically the same trough next versions.
You can completely disable the highlight of whitespace modified lines in :
Settings -> Editor -> Color Scheme -> VSC -> Editor Gutter -> Whitespace-modified lines
And then uncheck the background color :
Essentially, you want Intellij to use the --ignore-all-space or --ignore-space-change upon a merge.
My developer team also deals with this challenge because we have different code formatting preferences. The result is every merge is painful for no reason. The team loves being able to have their code formatting, but this negates it.
As of now there is no solution. Intellij has the technology to ignore whitespace, so fixing this is really just adding a check box on the merge diff screen or even in the version control settings.
There is a feature requests IDEA-107714
Please up vote it!
https://youtrack.jetbrains.com/issue/IDEA-107714
Try this,
View --> Active Editor --> Show whitespaces
this is guaranteed to solve your problem

Race conditions in AnnotationModel? Error annotations lost in Reconciler

I have an Eclipse custom editor and I implemented 'report errors as you type', but every now and then my error squigglies (using JFace annotations) are not shown or linger after they should be removed.
I am using MonoReconciler with my implementation of IReconcilingStrategy. During the reconcile step I call annotationModel.replaceAnnotations to remove the old errors and add the new ones. Most of the times this works fine. Every now and then the updates are lost, and I notice the following:
the red stamp on the left ruler disappears, but the red underlines stay
on the next character I type, the underline disappears
I verified in the debugger that the annotations are correctly calculated. The underline disappears immediately after typing a character, and not after the 500ms delay of the reconciler. It looks like a lost UI update/redraw.
There must be a race condition somewhere (the reconciler runs in its own thread). What am I doing wrong? I couldn't find any documentation about this use-case.
Edit: To reproduce, checkout the scala-worksheet and create a new one. Type
object Test {
val m = Map( 't' -> 1 )
}
Now edit the arrow: remove the >. The underline is missing. Type a space, it comes back. Add it back, the underline is still there until you type another space.
I fixed it by calling invalidateTextPresentation on the underling SourceViewer, but it seems to me that shouldn't be necessary. I'd like to understand what is the correct way to use editor annotations.
PS. The lost updates can also be seen in this screencast.
It's hard to tell from a distance, typically in eclipse, any changes that impact the ui should be executed on the ui thread (and eclipse will not always warn about this).
Normally you use Display.getDefault().asyncExec(...) to execute something on the ui thread but you probably already know this. It can happen that 2 queued up changes cause a race.
(I have implemented semantic highlighting, error highlighting etc several times for the company I work for, Sigasi. If you can point me to your implementation I may be able to figure out what's going wrong.)

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...