public boolean isAvailable()

in conditional_operator_intention/src/main/java/org/intellij/sdk/intention/ConditionalOperatorConverter.java [35:54]


  public boolean isAvailable(@NotNull Project project, Editor editor, @Nullable PsiElement element) {
    // Quick sanity check
    if (element == null) {
      return false;
    }

    // Is this a token of type representing a "?" character?
    if (element instanceof PsiJavaToken token) {
      if (token.getTokenType() != JavaTokenType.QUEST) {
        return false;
      }
      // Is this token part of a fully formed conditional, i.e. a ternary?
      if (token.getParent() instanceof PsiConditionalExpression conditionalExpression) {
        // Satisfies all criteria; call back invoke method
        return conditionalExpression.getThenExpression() != null && conditionalExpression.getElseExpression() != null;
      }
      return false;
    }
    return false;
  }