LoginSignup
11
10

More than 5 years have passed since last update.

IntelliJ IDEA pluginのStream Debuggerについて

Last updated at Posted at 2017-08-31

概要

IntelliJ IDEAのStream DebuggerというStream APIのデータの流れを可視化してくれるプラグインがありましたので使用してみました。

環境

  • Windows10 Professional
  • Java 1.8.0_144
  • IntelliJ IDEA Ultimate 2017.2
    • Java Stream Debugger 0.1.4

参考

Java Stream Debugger

使い方

デバッグしたいstreamにブレークポイントを設定しdebugモードで実行します。

s1.png

Debugパネルに"Trace Current Stream Chain"というアイコンが追加されているのでクリックします。

s2.png

Stream Trace画面が立ち上がりデータの流れが確認できます。(データ量などによっては表示に時間がかかる場合があります)
表示モードには"Flat Mode"と"Split Mode"があり、画面下のボタンで切り替えができます。
下図は"Flat Mode"です。

サンプルコード
List<String> colors = Arrays.asList(
    "pink", "red", "orange", "brown", "yellow", "green", "blue", "gray", "white", "black", "purple",
    "red", "white", "brown", "pink", "white", "orange", "yellow", "blue", "gray"
);

colors.stream()
    .peek(System.out::println)
    .distinct()
    .sorted(Comparator.comparing(String::length))
    .map(String::toUpperCase)
    .forEach(System.out::println);

この図のように中間処理でどのようにデータが扱われているか画面で確認することができます。

s3.png

インストール

Pluginsを開き、画面下の【Browse Repositories...】ボタンをクリックします。

p1.png

検索フィールドに"Stream Debugger"と入力してPluginを絞り込みます。
Stream Debuggerが見つかったら、Installボタンをクリックしてインストールします。

p2.png

インストールできたらRestartします。

Kotlin Sequence Debugger

A Kotlin extension for Java Stream Debugger plugin.

Stream DebuggerのKotlin拡張pluginもあります。
使い方は同じでデバッグしたいSequenceにブレークポイントを付けてdebugモードで実行し、Debugパネルの"Trace Current Stream Chain"アイコンをクリックします。

listOf(5, 5, 2, 1, 6, 4, 3, 2, 4, 3).asSequence()
    .filter { it % 2 == 0 }
    .distinct()
    .sorted()
    .forEach { println(it) }

st.png

11
10
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11
10