@Override
  public boolean processDeclarations(@NotNull PsiScopeProcessor processor,
                                     @NotNull ResolveState state,
                                     PsiElement lastParent,
                                     @NotNull PsiElement place) {
    ElementClassHint elementClassHint = processor.getHint(ElementClassHint.KEY);
    if (elementClassHint != null && !elementClassHint.shouldProcess(ElementClassHint.DeclarationKind.VARIABLE)) return true;
    PsiExpression condition = getCondition();
    if (condition != null) {
      PsiStatement thenBranch = getThenBranch();
      PsiStatement elseBranch = getElseBranch();
      if (lastParent == null) {
        if (state.get(PatternResolveState.KEY) == PatternResolveState.WHEN_NONE) return true;
        PsiScopeProcessor conditionProcessor;
        if (state.get(PatternResolveState.KEY) == PatternResolveState.WHEN_BOTH) {
          conditionProcessor = processor;
        }
        else {
          conditionProcessor = (element, s) -> {
            LOG.assertTrue(element instanceof PsiPatternVariable);
            final NameHint hint = processor.getHint(NameHint.KEY);
            if (hint != null && !((PsiPatternVariable)element).getName().equals(hint.getName(s))) {
              return true;
            }
            ControlFlow flow;
            try {
              flow = ControlFlowFactory.getControlFlow(
                this, new LocalsControlFlowPolicy(this), ControlFlowOptions.NO_CONST_EVALUATE);
            }
            catch (AnalysisCanceledException e) {
              return true;
            }
            boolean thenCompletesNormally = canCompleteNormally(thenBranch, flow);
            boolean elseCompletesNormally = canCompleteNormally(elseBranch, flow);
            if (thenCompletesNormally == elseCompletesNormally ||
                PatternResolveState.fromBoolean(thenCompletesNormally) !=
                PatternResolveState.stateAtParent((PsiPatternVariable)element, condition)) {
              return true;
            }
            return processor.execute(element, s);
          };
        }
        return condition.processDeclarations(conditionProcessor, PatternResolveState.WHEN_BOTH.putInto(state), null, place);
      }
      if (lastParent == thenBranch) {
        return condition.processDeclarations(processor, PatternResolveState.WHEN_TRUE.putInto(state), null, place);
      }
      if (lastParent == elseBranch) {
        return condition.processDeclarations(processor, PatternResolveState.WHEN_FALSE.putInto(state), null, place);
      }
    }
    return true;
  }
@Override
  public boolean processDeclarations(@NotNull PsiScopeProcessor processor,
                                     @NotNull ResolveState state,
                                     PsiElement lastParent,
                                     @NotNull PsiElement place)