With the Extract Trait refactoring you can extract selected members from a Scala class, object, or a trait into a new trait. IntelliJ IDEA supports def, val, and var type members.
Extract trait
In the editor, select code members that you want to refactor.
From the main menu, select Refactor | Extract | Trait.
Alternatively, right-click anywhere in the editor to open the context menu and select Refactor | Trait.
In the dialog that opens, enter a new trait name and select members you want to extract.
If you need to select all of the listed members in the Members to extract section, press Ctrl+A first and then Space.
Click Refactor.
Example
Let's create a class Calculator with several methods and extract one of the methods (mul) into a trait.
Class Calculator
Method mul is extracted to a new trait Multiplier
Class Calculator after the refactoring
class Calculator {def add(a:Int, b:Int):Int= a + b
def mul(a:Int, b:Int):Int= a match{case0=>0case _ => add(b, mul(a-1, b))}}
IntelliJ IDEA creates a new trait Multiplier that contains the mul method with its definition body. The class Calculator extends the trait Multiplier.