@Nullable
  private ReferenceType findNested(final ReferenceType fromClass, final int currentDepth, final PsiClass classToFind, final int requiredDepth, final SourcePosition position) {
    final VirtualMachineProxyImpl vmProxy = myDebugProcess.getVirtualMachineProxy();
    if (fromClass.isPrepared()) {
      // if the depth is still less than required - search nested classes recursively
      if (currentDepth < requiredDepth) {
        final List<ReferenceType> nestedTypes = vmProxy.nestedTypes(fromClass);
        for (ReferenceType nested : nestedTypes) {
          final ReferenceType found = findNested(nested, currentDepth + 1, classToFind, requiredDepth, position);
          if (found != null) {
            return found;
          }
        }
        return null;
      }

      // reached the required depth - check if the position is contained within the fromClass locations
      int rangeBegin = Integer.MAX_VALUE;
      int rangeEnd = Integer.MIN_VALUE;
      List<Location> locations = DebuggerUtilsEx.allLineLocations(fromClass);
      if (locations != null) {
        for (Location location : locations) {
          final int lnumber = DebuggerUtilsEx.getLineNumber(location, false);
          if (lnumber <= 1) {
            // should be a native method, skipping
            // sometimes compiler generates location where line number is exactly 1 (e.g. GWT)
            // such locations are hardly correspond to real lines in code, so skipping them too
            continue;
          }
          final Method method = DebuggerUtilsEx.getMethod(location);
          if (method == null || DebuggerUtils.isSynthetic(method) || method.isBridge()) {
            // do not take into account synthetic stuff
            continue;
          }
          int locationLine = lnumber - 1;
          PsiFile psiFile = position.getFile().getOriginalFile();
          if (psiFile instanceof PsiCompiledFile) {
            locationLine = DebuggerUtilsEx.bytecodeToSourceLine(psiFile, locationLine);
            if (locationLine < 0) continue;
          }
          rangeBegin = Math.min(rangeBegin, locationLine);
          rangeEnd = Math.max(rangeEnd, locationLine);
        }
      }

      final int positionLine = position.getLine();
      if (positionLine >= rangeBegin && positionLine <= rangeEnd) {
        int finalRangeEnd = rangeEnd;
        Set<PsiClass> lineClasses = ReadAction.compute(() -> {
          // Now we use the last line to find the class, previously it was:
          // choose the second line to make sure that only this class' code exists on the line chosen
          // Otherwise the line (depending on the offset in it) can contain code that belongs to different classes
          // and JVMNameUtil.getClassAt(candidatePosition) will return the wrong class.
          // Example of such line:
          // list.add(new Runnable(){......
          // First offsets belong to parent class, and offsets inside te substring "new Runnable(){" belong to anonymous runnable.
          if (!classToFind.isValid()) {
            return Collections.emptySet();
          }
          return getLineClasses(position.getFile(), finalRangeEnd);
        });
        if (lineClasses.contains(classToFind)) {
          return fromClass;
        }
        return null;
      }
    }
    return null;
  }
@Nullable
  private ReferenceType findNested(final ReferenceType fromClass, final int currentDepth, final PsiClass classToFind, final int requiredDepth, final SourcePosition position)