Skip to content

Commit

Permalink
fix: fix format issues
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Jul 13, 2023
1 parent ea6c87a commit 6fce6f7
Showing 1 changed file with 5 additions and 5 deletions.
Expand Up @@ -26,6 +26,11 @@ class JavaCodePostProcessor(
val prefixLastLine = prefixCode.split("\n").last()
val lastLineSpaceCount = spaceRegex.find(prefixLastLine)?.value?.length ?: 0

// if suffix ends with "}", and complete code ends with "}\n}", then remove complete code's last "}"
if (result.endsWith("}\n}") and (suffixCode.endsWith("}") || suffixCode.endsWith("}\n"))) {
result = result.substring(0, result.length - 1)
}

// if complete Code is method, not start with tab/space, add 4 spaces for each line
if (result.startsWith("public ") || result.startsWith("private ") || result.startsWith("protected ")) {
result = result.split("\n").joinToString("\n") { " $it" }
Expand All @@ -36,11 +41,6 @@ class JavaCodePostProcessor(
result = result.split("\n").joinToString("\n") { " $it" }
}

// if suffix ends with "}", and complete code ends with "}\n}", then remove complete code's last "}"
if (result.endsWith("}\n}") and suffixCode.endsWith("}")) {
result = result.substring(0, result.length - 1)
}

// if lastLineSpaceCount > 0, then remove same space in result begin if exists
if (lastLineSpaceCount > 0) {
val spaceRegex = Regex("^\\s{$lastLineSpaceCount}")
Expand Down

0 comments on commit 6fce6f7

Please sign in to comment.