IndentGuideTestData (@NotNull String text, Project project) { StringBuilder sb = new StringBuilder(); List<Guide> guides = new ArrayList<>(); Map<Integer, Integer> prevLineIndents = new HashMap<>(); String[] lines = text.split("\n"); for (int nLine = 0; nLine < lines.length; nLine++) { String line = lines[nLine]; int shift = 0; int textStart = 0; Map<Integer, Integer> endedGuides = new HashMap<>(prevLineIndents); int tabSize = CodeStyle.getSettings(project).getTabSize(JavaFileType.INSTANCE); int tabs = 0; for (int i = 0; i < line.length(); i++) { char c = line.charAt(i); if (c == '\t') { // i was already incremented, so we need to decrement tab size tabs += (tabSize - 1); continue; } if (c != '|') continue; int indent = i + tabs - shift; if (prevLineIndents.containsKey(indent)) endedGuides.remove(indent); else prevLineIndents.put(indent, nLine - 1); shift++; sb.append(line, textStart, i); textStart = i + 1; } for (Map.Entry<Integer, Integer> endedGuide : endedGuides.entrySet()) { guides.add(new Guide(endedGuide.getValue(), nLine, endedGuide.getKey())); prevLineIndents.remove(endedGuide.getKey()); } if (textStart < line.length()) sb.append(line.substring(textStart)); sb.append("\n"); } prevLineIndents.entrySet().stream().map(e -> new Guide(e.getValue(), lines.length, e.getKey())).forEach(guides::add); return new IndentGuideTestData(sb.toString(), guides); }