-
Notifications
You must be signed in to change notification settings - Fork 0
IntelliJ
Austin Guest edited this page Jan 11, 2015
·
7 revisions
n# Getting Started with IntelliJ
## Docs-
Basics
-
Scala
-
Android
Below getting started steps are culled from this tutorial and this video from the Functional Programming in Scala Coursera
An example project that resulted from my implementing the below steps can be found in here on the TLC Github
- Click
File/New Project
from menu - Select
Scala
from left pane,SBT
in main pane, clickNext
- name project, select location, set JDK version (if not pre-filled), click
Finish
- in the lefthand pane (
Project
), navigate to thesrc/main/scala
folder and select it - create new package by:
- either clicking
Ctrl-N
or right-clicking then mousing overNew
in the contextual menu, then: - selecting
New Package
- name it something descriptive (
main
orexample
)
- either clicking
- right click-on package you just created
- select
New/Scala Class
from contextual menu - name the class with the same name as the file its in
- give the class some methods (for example Talker.sayHello)
- eg: file named
Talker.scala
with classTalker
and methodsayHello
- eg: file named
- right click on package (or use
Ctrl-N
) create Scala class - change the class declaration to an object declaration
- add
extends App
to class declaration (ie:object Main extends App {
- add some code you want to execute to the body of the object (ie:
import example.Talker; val talker = new Talker; talker.sayHello
) - assuming main loop object is named
Main
, run the main loop by either:- right clicking anywhere in the window of the main loop declaration and selecting
run Main
from the contextual menu - selecting
Main
from the dropdown in the upper right-hand corner, then clicking the play-shapedrun
button next to the dropdown - clicking
Shift-Fn-F10
- right clicking anywhere in the window of the main loop declaration and selecting
- add test suite dependency to
build.sbt
file- for standard scala test library, insert:
libraryDependencies += "org.scalatest" % "scalatest_2.11" % "2.2.1" % "test"
- for specs2 library(recommended), insert:
libraryDependencies ++= Seq( "org.specs2" %% "specs2-core" % "2.4.15" % "test" ) scalacOptions in Test ++= Seq("-Yrangepos") // Read here for optional jars and dependencies: // http://etorreborre.github.io/specs2/guide/org.specs2.guide.Runners.html#Dependencies resolvers ++= Seq("snapshots", "releases").map(Resolver.sonatypeRepo)
- this will prompt you to re-import the project
- after you do: you should be able to click on
External Libraries
in the left-hand pane and see the test libraries
- for standard scala test library, insert:
- create new test placing cursor in class you wish to test then either:
- pressing
Cmd-Shift-T
- selecting
Navigate/Test
from the menu
- pressing
- name the test
- select the testing library you want to use
- default is
ScalaTest
, others might have more fluent syntax - optionally: select a method you want a test generated for
- default is
- run the test by either:
- pressing
Ctrl-Shift-Fn-F10
- right-clicking anywhere in file and selecting
run <test class name>
from contextual menu
- pressing
- start up a Scala console with
Cmd-Shift-D
- select a snippet you'd like to run
- right-click and select
send to Scala Console
from contextual menu - if more code is required to invoke your snippet, enter it
- click
Cmd-Enter
to run your code and see a return value printed to the screen - (unlike in scala REPL from the command line,
Enter
won't trigger evaluation, you have to hitCmd-Enter
to do that)
- select the location in the right-hand nav pane where you'd like to worksheet to live
- use
Ctrl-N
to bring up a generation menu, select "Scala Worksheet" from dropdown - enter in code you'd like to evaluate in the file that is created
- as you type, every line that can be evaluated will be evaluated in another pane on the right-hand side of the screen
-
renaming stuff
-
Alt-F7
rename -
Shift-F6
rename everywhere
-
-
extracting stuff
- extract variable
Ctrl-Cmd-V
- extract field
- extract param
- extract variable
-
selection
-
Cmd-D
duplicate selection -
Ctrl-G
add next occurrence to selection -
Cmd-Alt-Shift-J
select all occurences (& create multiple cursors) -
Ctrl-Ctrl <up,down>
enter multiple cursor mode -
Cmd-Alt-I
auto-correct indentation of selection -
Cmd-W
expand selection by 1 tree syntax pair -
Shift-Ctrl-W
shrink selection by 1 tree synatax pair
-
-
find & replace
- find in path
Shift-Cmd-F
- replace in path
Shift-Cmd-R
- find in path
-
Cmd-Y
kill line -
move stuff up/down
-
Cmd-Shift-Up/Down
move selection up
-
-
Ctrl-Shift P
show type of highlighted expression -
Ctrl-J
show API docs for selected Type -
Cmd <hover>
will produce hyperlink to source code, definition of Class, package, etc. -
Ctrl-Space
invoke auto-complete
-
Shift-Cmd-T
create new test -
Shift-Fn-F10
run executable object -
Shift-Cmd-Fn-F9
compile current file### testing - use specs2 library
- menu:
File/Project Structure
- this is just a view on your .sbt file. don't edit it because those changes won't stick!