public static @NotNull PatternResolveState stateAtParent(PsiPatternVariable element, PsiExpression parent) {
    PsiPattern pattern = element.getPattern();
    PatternResolveState state = WHEN_TRUE;
    for (PsiElement prev = pattern, current = prev.getParent(); prev != parent; prev = current, current = current.getParent()) {
      if (current instanceof PsiInstanceOfExpression || current instanceof PsiParenthesizedExpression ||
          current instanceof PsiDeconstructionList || current instanceof PsiDeconstructionPattern ||
          current instanceof PsiPolyadicExpression &&
          (((PsiPolyadicExpression)current).getOperationTokenType() == JavaTokenType.ANDAND ||
           ((PsiPolyadicExpression)current).getOperationTokenType() == JavaTokenType.OROR)) {
        continue;
      }
      if (current instanceof PsiPrefixExpression &&
          ((PsiPrefixExpression)current).getOperationTokenType() == JavaTokenType.EXCL) {
        state = state.invert();
        continue;
      }
      return WHEN_NONE;
    }
    return state;
  }
public static @NotNull PatternResolveState stateAtParent(PsiPatternVariable element, PsiExpression parent)