Inspection Connection – Issue #5, Encapsulation Examination

Encapsulation is a simple but powerful concept in software engineering that often goes hand-in hand with abstraction. In OOP, we use these two principles to help model mundane and complex systems, from physical processes to digital transactions, however these terms can often mean different things to different people.

Encapsulation often refers to information hiding, a key principle of OOP that seeks to collect and contain common data and functionality, effectively hiding those internal components, while exposing methods to interact with them in a safe and well-defined manner. This reflects how we interact with the world around us.

Continue reading

Posted in Tips & Tricks | Tagged | Leave a comment

Touring Plugins – String Manipulation

The String Manipulation plugin allows us to perform a variety of tasks on strings, from capitalizing, converting to camel case, to escaping strings in Java, JavaScript, XML or HTML amongst others.

The plugin itself is pretty straightforward. Once installed, it creates a new entry under the Edit menu as well as a contextual popup.

context-menu-1

Operating on it is merely a matter of selecting the string (defaults to current line if no text is selected) and choosing the operation.

Escaping HTMl

Important: The default key binding for the popup is Shift+Alt+M which doesn’t work well with MacOS, but it can be mapped to some other keyboard binding, such as Ctrl+Alt+M, easily via Preferences | Keymaps . Using the context menu is key to efficiency with this plugin so it’s highly recommended to make this change.

Posted in Tips & Tricks | 3 Comments

IntelliJ IDEA 14 EAP 139.69 is Out

If you haven’t noticed yet, a freshly-baked IntelliJ IDEA 14 EAP build is already here with new portion of bugfixes and enhancements.

Hurry and give IntelliJ IDEA 14 EAP a try before its official release. Then share your feedback with us via our discussion forum or the issue tracker!

Develop with Pleasure!

Posted in EAP Releases | 1 Comment

IntelliJ IDEA 14 Will Detect Code Styles on the Fly

If you’ve already tried the latest IntellIJ IDEA 14 EAP build, you might’ve noticed that the Code Style settings offers a new option: Detect and use existing file indents for editing (enabled by default.)

This new option lets IntelliJ IDEA detect certain Code Style settings (such as Use Tab character and Indent size) in the currently edited file on the fly. It means that even if a file has a code style different from your current settings, they will still be preserved.

So now you don’t need to worry about losing the formatting in files that are specific to certain files in your project that differ from the others.

We hope you’ll find these improvements useful. Your feedback as always is welcome, so don’t hesitate to share it in our discussion forum as well as report any bugs directly to the issue tracker.

Develop with Pleasure!

Posted in New Features | Tagged , , | 13 Comments

Live Webinar: IntelliJ IDEA and Vaadin, October 21st

We are pleased to invite you to join Breandan Considine from JetBrains and Matti Tahvonen from Vaadin on how to use the full power of Vaadin and IDEA together. Learn all the tips and tricks and get started with your new IDE in no time!

Sign up and we’ll email you instructions on how to join the webinar closer to the event – all you need is your web browser. Yes, it’s completely free to join.

Matti TahvonenMatti Tahvonen is a Vaadin “R&D veteran” who has been working with our products for over 6 years. His current responsibility is to keep you up to date with latest and greatest Vaadin related technologies. You can follow him on Twitter – @MattiTahvonen
Breandan ConsidineAs a Java developer and technical evangelist at JetBrains, Breandan Considine is interested in human computer interaction, natural language processing, particularly in low-power applications such as mobile phones and wearable devices. You can follow him on Twitter – @breandan

Develop with Pleasure!

Posted in Webinars | Tagged | Leave a comment

Touring Plugins – GitIgnore

I always have a .gitignore file in my Dropbox folder that I copy over for new projects, knowing that any subsequent update to the copy isn’t always synced with the original. Of course, it’s not always necessary either, but it’s something that’s always bugged me.

Recently I ran across a plugin for IntelliJ IDEA (and family) that solves my issue with ignore files.

It’s called GitIgnore Support and as its name suggests it provides support for .gitignore files, but it goes way beyond what you’d imagine at first. Let’s take a look. Continue reading

Posted in Featured Plugins, Tips & Tricks | Tagged | Leave a comment

IntelliJ IDEA 14 EAP 139.1 available, from a release branch already

A fresh update to IntelliJ IDEA 14 EAP is released and you may note we’ve switched to a “release” branch (139) already, so the release is not far away already and we’re in a “stabilization phase” mostly.

We urge you to check the full release notes to compare this build to the previous one.

A number of not so big but important features for everyone was added recently to the editor, including “Go to Next Edit” command, which is the opposite to a very useful “Go to Last Edit”, an additional options to show white-spaces only in front and/or behind and a number of other changes.

We need your feedback now even more than before. It is very welcome in our discussion forum or directly in the issue tracker.

Develop with Pleasure!

Posted in Beta Releases | Tagged , | 13 Comments

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 deduplicating repetitive code. You can activate this inspection by navigating to the menu entry Analyze|Locate Duplicates, or by pressing Ctrl/⌘+Alt/⌥+Shift+I then typing, “Duplicated Code.”

As it turns out, “Don’t Repeat Yourself” has some notable exceptions, especially when writing unit tests, and occasionally in some rare cases when attempting to outsmart the compiler. IntelliJ IDEA gives you the opportunity to exclude test sources, since many prefer a little duplication in their tests to improve overall readability. Nevertheless, the choice is yours.

duplicates_scopeWhen analyzing a large set of files, you should carefully consider the scope of the inspection you are going to apply. There are a number of algorithms for detecting duplicate code – this one will scan for duplicates by comparing AST fragments. On an Intel i7-2640M with 8GB of RAM, scanning a codebase with 53,000 LOC will take about 3 minutes, or ~300 LOC/second. However your mileage may vary depending on the minimum duplicates length, line density and other factors. When searching for exact matches, the time complexity is effectively linear w.r.t. the number of nodes in your AST.

duplication_analysis_settingsWhen searching for duplicate code, we may want to discard duplicates shorter than some minimum threshold or add a similarity metric in order to detect fuzzy-matches. IntelliJ IDEA lets us define these values, but keep in mind they do not correspond to characters or lines, but rather arbitrary weights. If “Visible from outside of the current scope only” is selected, only subexpressions which are valid outside of their parent construct are anonymized. If you would like to learn more how all of this works, head over to the source.

duplicates_viewAfter scanning, the Duplicates Tool Window is a convenient area to browse through duplicate regions and view a side-by-side diff at each location. From here you can clearly see which sections are structurally similar and flag them for review or refactor them immediately. The highlighter will help you quickly identify which blocks are different.

duplicates_focus

When you have found a duplicate block of code, it can be easily simplified by pressing Ctrl/⌘+Alt/⌥+M to apply the Extract → Method refactoring. IntelliJ IDEA will transform all inbound variables inside the selected region with parameters and provide a helpful dialog to extract the method, which you can use to replace any other duplicates inside the analysis scope.

extract_method_windowThis inspection is also available in TeamCity, where you can assign a dedicated build runner to periodically scan your project for duplicate code. This may be an even better option if your organization needs regular assurance audits for clean-room engineering. Plagiarism detection is another important use case for the academic community, and if you are a student or teacher, IntelliJ IDEA is now completely free.

Posted in Tips & Tricks | Tagged , , | Leave a comment

The Inspection Connection – Issue #3, Annotation Validation

Android developers will be familiar with the concept of resource IDs, which are unique integers generated by the Android Asset Packaging Tool (aapt) for accessing resources within your application through the static class, R. Resource IDs are assigned to all resources defined inside your project’s /res directory.

In the past, it was common to inadvertently pass one resource type into a parameter that expected another, since they are both integers. IntelliJ IDEA now offers improved support for detecting mismatched resource types, thanks to some resourceful developers on the Android Tools Team. Tor Norbye explains.

Not only is it possible to detect mismatched resource types in Android’s APIs, now you too can leverage resource type checking in your own libraries and APIs on Android 19+, with resource type annotations. Like type annotations in Java 8+, these annotations will help validate parameter values at compile time:

This inspection will detect two forms of resource type mismatches. The first is when you pass one type of resource into a parameter that expects another type, like above. The second will notify you when you have passed a constant into a type that only accepts a specific set of values. Let us consider the following example:

IntelliJ IDEA will detect both of these cases with the inspection Constant and Resource Type Mismatches, enabled by default under Inspections|Android. In order to use support annotations on Android 19+, you can add the following dependency to the dependencies section of your build.gradle file.

In addition to Nullness Annotations available in Android, IntelliJ IDEA 14 now offers a brand new, fully automatic nullity inference inspection based on bytecode analysis, to help you identify sites that may cause NPEs. Together, these features will help you identify bugs much sooner and develop with pleasure!

Posted in Tips & Tricks | Tagged , , | Leave a comment

Touring Plugins – Floobits

Software has become an increasingly cooperative process, both for applications themselves and for those who build them. With today’s developer teams spanning classrooms and continents, good interprocess communication is critical, and Floobits can help.

Floobits is a real-time collaborative editor, a sort of “shared memory” for developers around the corner, or around the globe. We can imagine a few activities where this type of communication is especially useful: interviewing, reviewing and pair programming.

First you will need a Floobits account in order to get started, which is available through Floobits’ website or via your on-premises provider. Next, add a configuration file in your home directory, then install the Floobits’ plugin, as described below.

Once you have configured your development environment and shared a project with the Floobits server, go ahead and add a contributor via your Floobits account. Take some time to explore the browser features. When you’re ready for a real IDE, fire up IntelliJ IDEA.

Here at JetBrains, we have been happily using Floobits for a while and thought we would share an example of how you can use Floobits to collaborate on IntelliJ IDEA or any of the platforms which Floobits supports. Maarten and I take Floobits for a spin.

In SICP, Abelson and Sussman write, “Programs must be written for people to read, and only incidentally for machines to execute.” IntelliJ IDEA gives us the tools to help build and maintain code. Together, with best practices like pairing and regular reviews, we can achieve both.

Special thanks to Geoff Greer, Matt Kaniaris, and Bjorn Tipling for helping fix the bugs.

Posted in Demos, Tips & Tricks | Tagged | Leave a comment