List<String> (@Nullable String s, @Nullable List<Boolean> markers) { if (s == null) return null; s = s.trim(); if (s.isEmpty()) return null; boolean p2nl = markers != null && mySettings.JD_P_AT_EMPTY_LINES; List<String> list = new ArrayList<>(); StringTokenizer st = new StringTokenizer(s, "\n", true); boolean first = true; int preCount = 0; int curPos = 0; int firstLineToKeepIndents = -1; int minIndentWhitespaces = Integer.MAX_VALUE; boolean isInMultilineTodo = false; boolean isInSnippet = false; int snippetBraceBalance = 0; while (st.hasMoreTokens()) { String token = st.nextToken(); curPos += token.length(); String lineWithoutAsterisk = getLineWithoutAsterisk(token); if (!isInMultilineTodo) { if (isMultilineTodoStart(lineWithoutAsterisk)) { isInMultilineTodo = true; } else if (containsTagToKeepIndentsAfter(lineWithoutAsterisk) && firstLineToKeepIndents < 0) { firstLineToKeepIndents = list.size(); } } if (firstLineToKeepIndents >= 0) { minIndentWhitespaces = Math.min(getIndentWhitespaces(token), minIndentWhitespaces); } if ("\n".equals(token)) { if (!first) { list.add(""); if (markers != null) markers.add(preCount > 0 || firstLineToKeepIndents >= 0 || isInMultilineTodo); } first = false; } else { first = true; if (isInMultilineTodo && StringUtil.isEmpty(lineWithoutAsterisk)) { isInMultilineTodo = false; } if (p2nl && isParaTag(token) && s.indexOf(P_END_TAG, curPos) < 0) { list.add(isSelfClosedPTag(token) ? SELF_CLOSED_P_TAG : P_START_TAG); markers.add(preCount > 0 || firstLineToKeepIndents >= 0); continue; } if (preCount == 0 && firstLineToKeepIndents < 0 && !isInMultilineTodo && snippetBraceBalance == 0) token = token.trim(); list.add(token); if (markers != null) { if (snippetBraceBalance == 0) { if (lineHasUnclosedSnippetTag(token)) snippetBraceBalance = 1; } else { snippetBraceBalance += getLineSnippetTagBraceBalance(token); } if (lineHasUnclosedPreTag(token)) preCount++; markers.add(preCount > 0 || firstLineToKeepIndents >= 0 || isInMultilineTodo || snippetBraceBalance != 0); if (lineHasClosingPreTag(token)) preCount--; } } } if (minIndentWhitespaces > 0 && minIndentWhitespaces < Integer.MAX_VALUE) { for (int i = firstLineToKeepIndents; i < list.size(); i ++) { String line = list.get(i); if (!line.trim().isEmpty()) { if (line.length() > minIndentWhitespaces) { list.set(i, line.substring(minIndentWhitespaces)); } } } } return list; }