Skip to content

Files

conditional_operator_intention

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
May 22, 2023
Apr 28, 2025
Jun 24, 2024
Nov 8, 2021
May 15, 2025
Jul 10, 2023
Apr 28, 2025
Apr 28, 2025
Mar 24, 2022

Conditional Operator Converter JetBrains IntelliJ Platform SDK Docs

Reference: Code Intentions in IntelliJ SDK Docs

Quickstart

Conditional Operator Converter provides an intention for converting the ternary operator into the if statement, i.e.:

public class X {
  void f(boolean isMale) {
    String title = isMale ? "Mr." : "Ms.";
    System.out.println("title = " + title);
 }
}

will become:

public class X {
  void f(boolean isMale) {
    String title;
    if (isMale) {
      title = "Mr.";
    } else {
      title = "Ms.";
    }
    System.out.println("title = " + title);
  }
}

To invoke the intention action, it is necessary to place the caret on the ? character of the ternary operator. The converter in the isAvailable method, has defined the token check to match JavaTokenType.QUEST, which is ? character.

Extension Points

Name Implementation Extension Point Class
com.intellij.intentionAction ConditionalOperatorConverter PsiElementBaseIntentionAction

Reference: Plugin Extension Points in IntelliJ SDK Docs