<commit_before>// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.siyeh.ipp.expression;

import com.intellij.psi.*;
import com.intellij.psi.tree.IElementType;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.util.ArrayUtil;
import com.intellij.util.ObjectUtils;
import com.siyeh.ig.psiutils.ParenthesesUtils;
import com.siyeh.ipp.base.PsiElementPredicate;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public class ExpandBracketsPredicate implements PsiElementPredicate {

  private final IElementType[] supportedOperations;
  private final IElementType[] prefixes;

  public ExpandBracketsPredicate(@NotNull IElementType[] operations, @NotNull IElementType[] prefixes) {
    this.supportedOperations = operations;
    this.prefixes = prefixes;
  }

  @Override
  public boolean satisfiedBy(PsiElement element) {
    if (!(element instanceof PsiJavaToken)) return false;

    final PsiParenthesizedExpression expression = PsiTreeUtil.getParentOfType(element, PsiParenthesizedExpression.class);
    if (expression == null) return false;

    return isSupportedInnerExpression(expression) && isSupportedOuterExpression(expression);
  }

  private boolean isSupportedInnerExpression(@Nullable PsiExpression expression) {
    expression = ParenthesesUtils.stripParentheses(expression);<commit_msg>ExpandBracketsIntention: suggest to expand brackets even if closest parenthesized expression cannot be expanded (IDEA-206609)<commit_after>// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.siyeh.ipp.expression;

import com.intellij.psi.*;
import com.intellij.psi.tree.IElementType;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.util.ArrayUtil;
import com.intellij.util.ObjectUtils;
import com.siyeh.ig.psiutils.ParenthesesUtils;
import com.siyeh.ipp.base.PsiElementPredicate;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public class ExpandBracketsPredicate implements PsiElementPredicate {

  private final IElementType[] supportedOperations;
  private final IElementType[] prefixes;

  public ExpandBracketsPredicate(@NotNull IElementType[] operations, @NotNull IElementType[] prefixes) {
    this.supportedOperations = operations;
    this.prefixes = prefixes;
  }

  @Override
  public boolean satisfiedBy(PsiElement element) {
    if (!(element instanceof PsiJavaToken)) return false;

    while ((element = PsiTreeUtil.getParentOfType(element, PsiParenthesizedExpression.class)) != null) {
      PsiParenthesizedExpression expression = (PsiParenthesizedExpression)element;
      if (isSupportedInnerExpression(expression) && isSupportedOuterExpression(expression)) return true;
    }

    return false;
  }

  private boolean isSupportedInnerExpression(@Nullable PsiExpression expression) {
    expression = ParenthesesUtils.stripParentheses(expression);
{'fraction_non_alphanumeric': 0.0818122555410691, 'fraction_numerical': 0.00847457627118644, 'mean_word_length': 5.789823008849558, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5031507', 'n_tokens_mistral': 886, 'n_tokens_neox': 837, 'n_words': 215}