Akka support
Akka is a toolkit for building highly concurrent, distributed, and resilient message-driven applications for Scala. IntelliJ IDEA supports the latest stable Akka version.
Add the Akka support to a project
The easiest way to add the Akka support to IntelliJ IDEA is to use the sbt project.
Open the build.sbt file in the editor.
Add the following code to build.sbt:
libraryDependencies += "com.typesafe.akka" %% "akka-actor" % "2.3.8"If you need, reimport the changes made to the build.sbt file.
After you finish setting up the Akka support, you can develop your application further the same way you do with any other project.
Work with Akka code in the editor
Besides basic code completion, code generation, and code navigation support, IntelliJ IDEA supports Akka inspections, find usages with Akka context, and specific code generation actions for Akka.
Use Akka code inspections
You can check the list of available Akka inspections and their descriptions in the Editor | Inspections page of the IDE settings Ctrl+Alt+S.
In the editor, IntelliJ IDEA displays suggestion hints where the inspections could work, and you can check the following examples with suggested changes that might improve your code:
Replace dynamic invocation with a constructor invocation: part of code could be simplified with a replacement.
Code example:
import akka.actor._ abstract class Foo extends AbstractActor object Foo { def props: Props = Props(classOf[Foo]) }import akka.actor._ abstract class Foo extends AbstractActor object Foo { def props: Props = Props(new Foo()) }Replace with a factory method call: dynamic constructor call could be safely replaced with a factory method call.
Code example:
import akka.actor._ abstract class Foo(foo: String, bar: Int) extends AbstractActor object Foo { def props(foo: String, bar: Int): Props = { Props(new Foo(foo)) } } Props(classOf[Foo], "foo", 42)import akka.actor._ abstract class Foo(foo: String, bar: Int) extends AbstractActor object Foo { def props(foo: String, bar: Int): Props = { Props(new Foo(foo)) } } Foo.props("foo", 42)Appropriate actor constructor not found: the inspection will work in a place where a constructor with inappropriate arguments is called.
Akka mutable state: the inspection detects if the Actor has a mutable state.
Code example:
import scala.collection.mutable class MyActor extends Actor { val isInSet = mutable.Set.empty[String] def receive = { case Add(key) => isInSet += key case Contains(key) => sender() ! isInSet(key) } }import collection.immutable.Set class MyActor extends Actor { def receive = active(Set.empty) def active(isInSet: Set[String]): Receive = { case Add(key) => context become active(isInSet + key) case Contains(key) => sender() ! isInSet(key) } }
Use intentions in Akka
You can check the list of available intention actions for Scala and Akka in the Editor | Inspections page of the IDE settings Ctrl+Alt+S.
In the editor, IntelliJ IDEA displays the popup with suggestions to improve your code. Check the following examples of the related intentions for Akka:
Generate actor factory methods: IntelliJ IDEA supports the automatic generation of factory methods. In the editor, place the caret inside the companion object of an
Actor
, press Alt+Insert and select the intention.Create a corresponding factory method: IntelliJ IDEA supports the automatic generation of the corresponding factory methods.
IntelliJ IDEA supports intentions for refactorings. For example, when you extract variable Ctrl+Alt+V, IntelliJ IDEA will suggest a name and a type for the inline refactoring.
Find usages in Akka
When you search for usages, IntelliJ IDEA can classify usages of a Message
class based on the context. IntelliJ IDEA displays the context as nodes depending on the position of the message. For example, Receiver position, Ask position, or Send position.
In the editor, select a message class for which you want to find usages.
Right-click the element and from the context menu, select Find Usages Alt+F7.
Check the results in the Find tool window.