IntelliJ suppress warnings for unchanged lines - java

is it possible to suppress all warnings in IntelliJ for all unchanged lines? I am working in a project with java files larger than 2000 lines and there are warnings everywhere. To get a better overview of my code I want to only inspect my changed or added lines.

Summary from comment conversation:
Bad luck. Turning warnings off is the only solution (no one care about them anyway).

I don't think there is a way to do this. However, going forward you can use the annotation #SuppressWarnings( "unchecked" ) to suppress warnings that you do not care about. This does nothing for existing code unless you apply it to each warning (not what I would recommend), but will achieve the desired effect going forward.

Related

Eclipse source code warnings

Below you can see an image of the source code (in eclipse) where the warnings are occurring. I am new to this, and am therefore unaware of how to solve this.
Source code image
Thanks
Andrew
Your example of warnings is related to usage of deprecated classes.
If you have the need to use that deprecated class (for a big reason) in that case you can add this:
#SuppressWarnings( "deprecation" )
That will remove the warnings.
But, ... Here is big but...
You should to avoid usage of deprecated classes/methods because of every part which is marked as deprecated is marked as deprecated for a reason. For example, some code (method, class, etc) is marked as deprecated because it is planned to be removed, have better solution, works non-predictive or some other reason.
From other side, everything what is annotated as #Deprecated have to discourage all the programmers using it and try to implement his replacement or another solution.
Like Felix mentioned, hover over those "warnings/messages" and it will show you a hint.
In this case, you are calling a deprecated class:
https://developer.android.com/reference/android/support/v7/app/ActionBarActivity.html

Intellij, disable inspection/suggestion only for file

It's annoying and attention grabbing when Intellij will highlight all kinds of stuff like simplify something or a suggestion, or a warning of some kind.
Many times, I like the thank you mam, but stop bothering me. This is not relevant.
However, Intellij will only allow you to ignore the type of warning globally, which is kind of dangerous to do.
I am aware that you can add an annotation, but I don't want to pollute my classes with annotations and comments everywhere. Also, #SuppressWarnings("ALL") is applied even suggestions, not even on warnings.
Can't Intellij manage this using a project file ? Also, Intellij should add a line to the right to show where such a supression has been done.
Problem right now, is that once you supress globally it's almost impossible to undo, or revise.
I mean #SuppressWarnings({"PointlessBooleanExpression", "ConstantConditions"}) is hardly Java related, and should not be added to the code.
It should be managed by the editor. It must also be made so that it's easily editable and an overview can be seen for the entire project files.
Is this possible already?
If enabled in the settings somewhere, you can use //#formatter:off to turn off formatter and //#formatter:on to turn on formatter. Afaik it requires that you turn on the formatter before the end of the file.

What would be happen if used lot of #SuppressWarnings in my java file?

In my application lot of warnings are coming. For removing that warnings I'm using #SuppressWarnings annotations, anything would be happen in my code if I used several suppress warning annotations.
The #SuppressWarnings annotation does not change anything to the way your code works. The only thing it does is not make your compiler or IDE complain about specific warnings.
If you feel you need to use #SuppressWarnings a lot, then you should take a close look at why you get those warnings. It's a sign that you might be doing things incorrectly - you get warnings for a reason.
The #SuppressWarnings annotation disables certain compiler warnings. In this case, the warning about deprecated code ("deprecation") and unused local variables or unused private methods ("unused"). This article explains the possible values.
Depends on what warnings you are suppressing. If they are related to APIs that available only in new versions, your app will crash on older versions. Some warnings on the other hand are informational and point to common causes of bugs, so it really depends on what warning you are suppressing.
If you mean will my project break? or will it run slower most probably the answer is no. You can be fine suppressing warnings if they are trivial and you understand what are they signaling you and why are they there.
For example, an unused variable warning. Maybe you have defined it and plan to use in the near future, but the warning annoys you. Although I strongly suggest you to use a Source Code Version Control System like Git/Mercurial so you can safely delete code and recover a few days later.
But always check every warning you're suppressing: they are there for a purpose. For example, deprecated warnings: maybe your code runs fine, but in the next version of the JVM that deprecated method/class may have disappeared.
Always understand what you're doing

Find all unused variable

Normally it's easy to see unused variables in Netbeans, just a grey squiggly line.
But how would I find all of these unused variables in my project or of a single class?
Reason: I'm debugging a code base which had lots of copy and paste, but it wasn't done carefully. There's many bug of not replacing with the right variable after copy and paste.
You could run something like FindBugs on it.
FindBugs
Looking at the bug list it has
UuF: Unused field (UUF_UNUSED_FIELD)
This field is never used. Consider removing it from the class.
You could filter on just this, but it is a good idea to run this on all code all the time, it is amazing what it finds.
PMD will find unused local variables for you (among many other things). There's a NetBeans plugin that I give installation instructions for here (Warning: Shameless Plug, that links to my blog).
In Eclipse, that gray squiggly line is a yellow squiggly line called a Warning. Then the warning is propagated up to the package level, and up to the project level (such that your project is almost always underlined in yellow with a warning icon). Anyway it really helps you see which source files have warnings in them.
Then your task is to solve every warning in the entire project, and you will have caught the unhandled variables.
I assume netbeans has the same feature somewhere.
The compiler will warn about unused variables giving you your list.
Unused method variables will be removed by the compiler but unused member variables remain, which depending on the state of your codebase may make this a cosmetic problem that can be handled as and when each file is modified rather than a conserted effort to remove all unused variables in one go.
Saying that, I generally like my builds to run with no warnings, so that when I genuinely break something I notice the warning. Maybe this is the clean-up you are looking for ;-)

Is it possible to obtain warnings from javadoc when something missed in javadoc-comments?

Accidentally I may forget to describe some parameters or exception throwing (or something else) when documenting methods or classes, etc.
Is it possible to run javadoc in such a way that it warns me about missing documentation items?
(I use ant script for generating documentation)
I do not know of any javadoc option that will issue a warning about non-documented items.
However, if You happen to use Eclipse, take a look at the settings in
Window -> Preferences -> Java -> Compiler -> Javadoc
There, You can tell Eclipse to issue warnings on undocumented items.
Use Checkstyle! It has awesome Ant integration and supports 100s of other important checks to your source code too.
The JavadocType checker is what you'll need though.
We used Doc Check Doclet for an earlier project. It can be integrated with the build and generates useful reports that tell you which code has poor documentation.
NOTE: The tool is beta and no longer supported by Sun.
Yes it is, in Eclipse you have incorporate check for everything what you define, so it is possible to put this missing into "warnings" and than you will e able to see where you make mistakes.

Categories