private static Collection<PsiReference> findUsagesForLocal(GrClosableBlock initializer, final GrVariable var) {
    GrControlFlowOwner owner = ControlFlowUtils.findControlFlowOwner(initializer);
    if (owner == null) return Collections.emptyList();
    final GroovyControlFlow flow = ControlFlowUtils.getGroovyControlFlow(owner);
    final List<BitSet> writes = ControlFlowUtils.inferWriteAccessMap(flow, var);

    Instruction writeInstr = null;

    final PsiElement parent = initializer.getParent();
    if (parent instanceof GrVariable) {
      writeInstr = ContainerUtil.find(flow.getFlow(), instruction -> instruction.getElement() == var);
    }
    else if (parent instanceof GrAssignmentExpression) {
      final GrReferenceExpression refExpr = (GrReferenceExpression)((GrAssignmentExpression)parent).getLValue();
      final Instruction instruction = ContainerUtil.find(flow.getFlow(), instruction1 -> instruction1.getElement() == refExpr);

      LOG.assertTrue(instruction != null);
      final BitSet prev = writes.get(instruction.num());
      if (prev.cardinality() == 1) {
        writeInstr = flow.getFlow()[prev.nextSetBit(0)];
      }
    }

    LOG.assertTrue(writeInstr != null);

    Collection<PsiReference> result = new ArrayList<>();
    for (Instruction instruction : flow.getFlow()) {
      if (!(instruction instanceof ReadWriteVariableInstruction)) continue;
      if (((ReadWriteVariableInstruction)instruction).isWrite()) continue;

      final PsiElement element = instruction.getElement();
      if (element instanceof GrVariable && element != var) continue;
      if (!(element instanceof GrReferenceExpression ref)) continue;

      if (ref.isQualified() || ref.resolve() != var) continue;

      final BitSet prev = writes.get(instruction.num());
      if (prev.cardinality() == 1 && prev.get(writeInstr.num())) {
        result.add(ref);
      }
    }

    return result;
  }
private static Collection<PsiReference> findUsagesForLocal(GrClosableBlock initializer, final GrVariable var)