mirror of
https://github.com/JetBrains/intellij-sdk-code-samples.git
synced 2025-07-27 08:47:50 +08:00
* switch to 243, update gh-ic links * code samples: build against 2024.1 * action_basics: mute warning in PopupDialogAction * GH build: mute invalid plugin ID on CI * GH build: mute invalid plugin ID on CI * final 2024.3, regen EP-lists * code samples: 2024.3
Conditional Operator Converter 
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