public static String cleanBlockComments()

in codeanalyzer/src/main/java/nl/obren/sokrates/sourcecode/cleaners/CommentsCleanerUtils.java [29:60]


    public static String cleanBlockComments(String content, String commentBlockStart, String commentBlockEnd) {
        StringBuilder cleanedContent = new StringBuilder(
                content.replace(getReplaceForRegex(commentBlockStart) + ".*?" + getReplaceForRegex(commentBlockEnd), ""));

        int commentStartIndex = 0;
        while (true) {
            commentStartIndex = cleanedContent.indexOf(commentBlockStart, commentStartIndex);
            if (commentStartIndex >= 0) {
                int indexOfNewLineBefore = cleanedContent.substring(0, commentStartIndex).lastIndexOf("\n");
                int indexOfQuoteBefore = cleanedContent.substring(0, commentStartIndex).indexOf("\"");
                int indexOfNewLineAfter = cleanedContent.indexOf("\n", commentStartIndex + 1);
                int indexOfQuoteAfter = cleanedContent.indexOf("\"", commentStartIndex + 1);
                if (indexOfNewLineBefore != -1 && indexOfNewLineBefore < indexOfQuoteBefore && indexOfQuoteAfter != -1
                        && indexOfQuoteAfter < indexOfNewLineAfter) {
                    commentStartIndex = indexOfNewLineAfter + 1;
                    continue;
                }
                int commentEndIndex = cleanedContent.indexOf(commentBlockEnd, commentStartIndex + commentBlockStart.length());
                if (commentEndIndex > commentStartIndex) {
                    String comment = cleanedContent.substring(commentStartIndex, commentEndIndex + commentBlockEnd.length());
                    String replacement = StringUtils.repeat("\n", StringUtils.countMatches(comment, "\n"));
                    cleanedContent.replace(commentStartIndex, commentEndIndex + commentBlockEnd.length(), replacement);
                } else {
                    break;
                }
            } else {
                break;
            }
        }

        return cleanedContent.toString();
    }