Of braces and parentheses

In Scala, you may often want to replace braces with parentheses and vice versa.

For example, imagine that you decided to use curly braces in the following statement:

It looks like not a big deal, but in practice it takes a lot of key presses, cursor positioning, and a fight with the automatic brace balancing. That’s now a thing of the past.

Just invoke an intention (Ctrl + Alt + Enter):

… and it’s done:

It’s possible to run it the other way:

produces:

Besides sequence comprehensions, there are similar intentions for converting method call arguments, like the following:

Run the intention:

The result:

Now let’s transform the braces back to parentheses:

Here they are:

Posted in Uncategorized | 1 Comment

Toggle Test

A few years back, I was working with a great team of Java developers who introduced me to IntelliJ. (Thanks!) The team used to even have a plugin, tailored to our coding practices. One indispensible feature was the ‘Toggle Test’, to flick between production code and the corresponding unit test.

That feature has long since been incorporated into IDEA, but has been sadly absent for Scala users. But as of tomorrow, the wait is over! You can use CTRL-SHIFT-T to generate tests, or  to navigate between a test and its subject.

Continue reading

Posted in Uncategorized | 3 Comments

Unused Symbol Detection

Unused Symbols

Invariably as  code evolves, some lonely unused definitions are are left around. To help you find and eradicate these, IDEA now highlights unused vals, vars, and defs.

You can use the quick fix to delete the unused symbol.

Needless Vars

Similarly, IDEA highlights needless vars, that is, ones that are never assigned to, with a quick fix to convert it to a val.

Limitations

Currently this reference checking is not enabled for cross-file references, you still need to use Find Usages for these. This means that only locals and private class members are highlighted.

It is also disabled for implicit members, and for methods with special names (apply/unapply/update/map/flatMap/filter/withFilter/foreach), for which the reference checking is not yet comprehensive.

Posted in Uncategorized | 3 Comments

Smart Strings

String Literals just got a little smarter!

You can now convert a normal strings to multiline (with triple quotes) string.  Notice how the special characters are escaped. (SCL-2991)

Screen shot 2011-04-28 at 10.52.12 PM.png

Screen shot 2011-04-28 at 10.52.18 PM.png

And back again:

Screen shot 2011-04-28 at 10.52.28 PM.png

Screen shot 2011-04-28 at 10.52.36 PM.png

Similarly, when you paste some text into a normal string (for example: C:\path\file.txt), the appropriate escaping is added. (SCL-3144)

Finally, you can now autocomplete, navigate, and rename-refactor references to classpath resources in string literals. (SCL-3138)

Screen shot 2011-04-28 at 8.22.38 AM.png

These features require a nightly build of the plugin, with the latest EAP build of IDEA 10.5.

Posted in Uncategorized | 3 Comments

Highlighting of arguments to by-name parameters

In Scala it’s not always obvious when some expression is an argument to a by-name parameter. New highlighting helps to easily spot such expression. Continue reading

Posted in Uncategorized | 1 Comment

Signature matters!

In Scala, method signature semantics goes beyond method name, parameters and result type. The signature can also tell about whether a method has side effects, or whether a method represents a property.

However, sometimes we forget about writing proper definitions or method calls. That’s where 15 new method signature inspections may help.  Continue reading

Posted in Uncategorized | 6 Comments

Type-aware highlighting

Type-aware highlighting is a part of error highlighting that relies on type system.

Some errors can be found without using type information, for example:

Other errors, however, require a knowledge of entities type:

Type-aware highlighting allows to spot such errors before compilation. Continue reading

Posted in Uncategorized | 5 Comments

Project configuration explained

Although the work on new Scala project configuration is still in progress, a brief clarification may come in handy. Continue reading

Posted in Uncategorized | 5 Comments

Type Info and Toggle Type Annotation

Type Info hint (Ctrl + Alt + Shift + T):

Toggle Type Annotation intention:

Posted in Uncategorized | 1 Comment