mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Do not expand indents for group of blocks with smart indent, if each one of them has no linefeed before, and block going right after group has linefeed and has smaller indent than any new line children of any block in the group. This will prevent from inserting double continuation indents when it is not needed (see tests)
This commit is contained in:
+26
-1
@@ -29,7 +29,7 @@ public class JavaFormatterMultilineMethodCallParamsTest extends AbstractJavaForm
|
||||
);
|
||||
}
|
||||
|
||||
public void IGNORED_testChainedMethodInsideCall_WithRParenOnNewLine() {
|
||||
public void testChainedMethodInsideCall_WithRParenOnNewLine() {
|
||||
doMethodTest(
|
||||
"call(new StringBuilder()\n" +
|
||||
".append(\"aaa\")\n" +
|
||||
@@ -41,6 +41,31 @@ public class JavaFormatterMultilineMethodCallParamsTest extends AbstractJavaForm
|
||||
");"
|
||||
);
|
||||
}
|
||||
|
||||
public void testLambdas() {
|
||||
doTextTest(
|
||||
"public class Main {\n" +
|
||||
" public static void main(String... args) throws Exception {\n" +
|
||||
" RatpackServer.start(server -> server\n" +
|
||||
" .handlers(chain -> chain\n" +
|
||||
" .get(ctx -> ctx.render(\"Hello World!\"))\n" +
|
||||
" .get(\":name\", ctx -> ctx.render(\"Hello \" + ctx.getPathTokens().get(\"name\") + \"!\"))\n" +
|
||||
" )\n" +
|
||||
" );\n" +
|
||||
" }\n" +
|
||||
"}",
|
||||
"public class Main {\n" +
|
||||
" public static void main(String... args) throws Exception {\n" +
|
||||
" RatpackServer.start(server -> server\n" +
|
||||
" .handlers(chain -> chain\n" +
|
||||
" .get(ctx -> ctx.render(\"Hello World!\"))\n" +
|
||||
" .get(\":name\", ctx -> ctx.render(\"Hello \" + ctx.getPathTokens().get(\"name\") + \"!\"))\n" +
|
||||
" )\n" +
|
||||
" );\n" +
|
||||
" }\n" +
|
||||
"}"
|
||||
);
|
||||
}
|
||||
|
||||
public void testChainedMethodInsideCall_Shifted() {
|
||||
doMethodTest(
|
||||
|
||||
@@ -1629,14 +1629,48 @@ public class FormatProcessor {
|
||||
}
|
||||
|
||||
if (last != null) {
|
||||
AbstractBlockWrapper prev = getPreviousBlock(last);
|
||||
return prev != null && prev.getWhiteSpace().containsLineFeeds();
|
||||
AbstractBlockWrapper next = getNextBlock(last);
|
||||
if (next != null && next.getWhiteSpace().containsLineFeeds()) {
|
||||
int nextNewLineBlockIndent = next.getNumberOfSymbolsBeforeBlock().getTotalSpaces();
|
||||
if (nextNewLineBlockIndent >= finMinNewLineIndent(blocksToExpandIndent)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private int finMinNewLineIndent(@NotNull Collection<AbstractBlockWrapper> wrappers) {
|
||||
int totalMinimum = Integer.MAX_VALUE;
|
||||
for (AbstractBlockWrapper wrapper : wrappers) {
|
||||
int minNewLineIndent = findMinNewLineIndent(wrapper);
|
||||
if (minNewLineIndent < totalMinimum) {
|
||||
totalMinimum = minNewLineIndent;
|
||||
}
|
||||
}
|
||||
return totalMinimum;
|
||||
}
|
||||
|
||||
private AbstractBlockWrapper getPreviousBlock(AbstractBlockWrapper block) {
|
||||
private int findMinNewLineIndent(@NotNull AbstractBlockWrapper block) {
|
||||
if (block instanceof LeafBlockWrapper && block.getWhiteSpace().containsLineFeeds()) {
|
||||
return block.getNumberOfSymbolsBeforeBlock().getTotalSpaces();
|
||||
}
|
||||
else if (block instanceof CompositeBlockWrapper) {
|
||||
List<AbstractBlockWrapper> children = ((CompositeBlockWrapper)block).getChildren();
|
||||
int currentMin = Integer.MAX_VALUE;
|
||||
for (AbstractBlockWrapper child : children) {
|
||||
int childIndent = findMinNewLineIndent(child);
|
||||
if (childIndent < currentMin) {
|
||||
currentMin = childIndent;
|
||||
}
|
||||
}
|
||||
return currentMin;
|
||||
}
|
||||
return Integer.MAX_VALUE;
|
||||
}
|
||||
|
||||
private AbstractBlockWrapper getNextBlock(AbstractBlockWrapper block) {
|
||||
List<AbstractBlockWrapper> children = block.getParent().getChildren();
|
||||
int nextBlockIndex = children.indexOf(block) + 1;
|
||||
if (nextBlockIndex < children.size()) {
|
||||
|
||||
Reference in New Issue
Block a user