Explore Your Program with Static Analysis
When writing code, we constantly receive assistance from static analysis. Invisible mechanisms work behind the scenes to provide us with all sorts of suggestions and warnings. It would not be an exaggeration to say that IntelliJ IDEA knows more about our code than we do. Now what if we could access the static analysis data, either to examine how the program works or to debug complex issues? Actual
Loads of Small Improvements in IntelliJ IDEA 2017.2
Many of the features we're going to talk about in this post have been mentioned elsewhere in this blog, but here we're going to bring them all together and show how to use them. Better Warnings You'll have seen before that IntelliJ IDEA can analyse your code and tell you if something isn't needed, or perhaps doesn't make sense. IntelliJ IDEA 2017.2 has even better analysis in several areas.
IntelliJ IDEA 2017.2 EAP, with Smarter Control Flow Analysis
Earlier we mentioned that IntelliJ IDEA 2017.2 EAP features improved control flow analysis that infers the contracts of certain methods of String, Array, Collection and Map classes. With today’s EAP build, this analysis becomes even smarter. If that sounds like something you might be interested in, read on and see how the new checks are going to work. (more…)
IntelliJ IDEA 15 EAP Adds On-the-Fly Code Duplicates Detection
It's been a while since we added the Analyze → Locate Duplicates feature. If you've had a chance to use it, you know how helpful it is: by eliminating duplicates in your code, you make it more concise and stable. If you've never used it, you definitely should; it's truly surprising how many duplicates an average codebase usually contains. The fresh IntelliJ IDEA 15 EAP build released today take
The Inspection Connection – Issue #4, Duplication Detection
One of the core principles of computer programming is eliminating manual repetition. Not only is repeated code time-consuming to read and review, it is disproportionately complex to maintain and provides a ready source of bugs when one copy changes. Yet in spite of this, duplicating some code in a large project may be inevitable. IntelliJ IDEA offers a powerful inspection for detecting and dedupli
Automatic @NotNull/@Nullable/@Contract inference in IntelliJ IDEA 14
Java annotations are awesome and helpful, but you need to add them by hand. Well, not anymore, because IntelliJ IDEA will do that for you in some quite important cases. Jars in your dependencies are stuffed with methods and sometimes it may be difficult to tell whether you can pass null there without blowing things up, or whether you should be ready to get null as a method result. If you're
The Inspection Connection – Issue #1, Migration Translation
The release of JDK 8 has introduced a number of new language features into Java vernacular. In this issue of The Inspection Connection, we will examine eight useful inspections that IntelliJ IDEA provides to help you become more fluent in functional programming on Java 8, migrate your legacy code, detect bugs sooner, and develop with pleasure. 1. Anonymous type can be replaced with lambda As a
Better Control Flow Analysis with Contract Annotations and IntelliJ IDEA 13
As we're closing in on the release date, we're going to publish more details on the new features of IntelliJ IDEA 13. Today we'd like to tell you about the new @Contract annotation. If you are aware of @Nullable/@NotNull annotations, you probably know how helpful they are against NullPointerException. The new @Contract annotation brings one more layer of safety for your code by defining depende
30 Days with IntelliJ IDEA. Inspections
We continue to publish new articles from the 30 Day Guide for learning the fundamental features of IntelliJ IDEA. Today we will talk about such basic thing as inspections. As you know inspections are built-in tools that help you find probable bugs, locate dead code, detect performance issues and improve the overall code structure. Navigate to the next/previous problem Did you know that you can
Java 8 and Method References in IntelliJ IDEA 12
As you might know IntelliJ IDEA 12 will bring support for new features of Java 8 language. Though this is still in progress, you can try some of these features now in IntelliJ IDEA 12 EAP. Here we would like to provide some details on method and constructor refereces support. IntelliJ IDEA as always provides a way to transform existing code to use new features. Dedicated inspection finds and hig
Validation of unknown tags and attributes in Android XML files
In the latest IntelliJ IDEA 11.1 EAP we've added 2 new inspections that warn you about unknown attributes and tags in Android XML resource files and AndroidManifest.xml: IntelliJ IDEA can validate both system attributes and local ones defined in attrs.xml file in your project. Of course, you can disable or tune these inspections according to your needs in the IDE settings.
Integration with Android Lint tool in IntelliJ IDEA 11.1
In IntelliJ IDEA 11.1 we've added many inspections based on Android Lint tool, which reports many kinds of potential problems in the sources of your Android project. For example IntelliJ IDEA will notify you about useless views in layout xml files and will offer to remove it: Another example is that IDE warns you about hardcoded text and offer to extract a new string resource: Some issues (su
New “Magic Constant” Inspection
Have you ever cursed an API which uses magic integer constants instead of the proper enumeration? What should I pass as the titleJustification parameter here? 0 or 1? Can I pass "42" for the titlePosition parameter? Even Javadoc won't know. Actually, you must use one of the constants in the TitledBorder class to make the code correct: I call these constants "magic" because sometimes it is fa
How to check your RegExps in IntelliJ IDEA 11?
In IntelliJ IDEA 11 you can check your Regular Expressions while coding without leaving the IDE. Just invoke the 'Check RegExp' intention action on a regular expression and play! Tip: You can turn any string into a regular expression by injecting RegExp language. Try the 'Inject Language' intention action.
Better Spring with IntelliJ IDEA 10.5
Yes! The sunny Spring has finally come to St.Petersburg too. However, it's not that "Spring" we want to talk now... We realize that many of you use the Spring framework in your every day work. So, many should be interested in the new Spring-related features that can be found in the upcoming IntelliJ IDEA 10.5 release. 1. Better navigation between xml configs and annotated stereotype components
Quick prototyping in Groovy with “Convert Map to Class” intention
Sometimes it is helpful to use a Map for fast prototyping of classes with some properties but without any logic. But in the end it would be nice to have a real class. In IntelliJ IDEA you can get it by invoking "Convert Map to Class" intention on a map. You only need to type a name and a package for a new class: And you'll get something like this... and a UserInfo class: Quick and easy, r
Java 7. @SafeVarargs
Java 7 provides a way to remove a compiler warning about generics vararg invocation. With Java 7 you can annotate your vararg method with SafeVararg annotation and your clients won't get these nasty warnings any more. IntelliJ IDEA 10.5 will help you to perform this migration. It will find for you all the places where @SafeVarargs annotation is applicable and suggest you to add this annotation. Of
More flexible and configurable @Nullable/@NotNull annotations
For quite a while IntelliJ IDEA can detect probable NPE’s in your code. But you have to annotate it with JetBrains' @Nullable/@NotNull. In order to leave your code free from JetBrains' annotations you could use external annotations, but they were not so convenient to use as they were not visible in the code. With libraries and SDK code, however, there is no other way except using the external anno
Auto-infer @Nullable/@NotNull Annotations
For a long time already IntelliJ IDEA can detect probable NPE's in your code. You need to annotate your methods/fields/variables with @Nullable/@NotNull annotations and IntelliJ IDEA will highlight possible contract violations. Good. But the annotations only begin to work when there is enough of them in the code. You do need to annotate your code to get the benefits. IntelliJ IDEA 10 can do it fo
How to Run a Single Inspection in IDEA X?
To run a single inspection in previous versions of IntelliJ IDEA you had to create a dedicated inspection profile for that or use "Run inspection on..." from inspection's quick fix list. In IntelliJ IDEA X you can find and run inspection by its name on any scope without creating an inspection profile. Use Run Inspection by Name (Ctrl+Alt+Shift+I) action anywhere to choose a desired inspection from