mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-58664 Blank Lines Before method body also appear inside try/catch/finally's {}
Refined appliance conditions for 'blank lines before method body' setting
This commit is contained in:
@@ -683,8 +683,18 @@ public class JavaSpacePropertyProcessor extends JavaElementVisitor {
|
||||
}
|
||||
else if (myRole1 == ChildRole.LBRACE) {
|
||||
if (!keepInOneLine) {
|
||||
int blankLines = 1;
|
||||
if (myParent != null) {
|
||||
ASTNode parentNode = myParent.getNode();
|
||||
if (parentNode != null) {
|
||||
ASTNode grandPa = parentNode.getTreeParent();
|
||||
if (grandPa != null && grandPa.getElementType() == JavaElementType.METHOD) {
|
||||
blankLines += mySettings.BLANK_LINES_BEFORE_METHOD_BODY;
|
||||
}
|
||||
}
|
||||
}
|
||||
myResult = Spacing.createSpacing(
|
||||
0, 0, mySettings.BLANK_LINES_BEFORE_METHOD_BODY + 1, mySettings.KEEP_LINE_BREAKS, mySettings.KEEP_BLANK_LINES_IN_CODE
|
||||
0, 0, blankLines, mySettings.KEEP_LINE_BREAKS, mySettings.KEEP_BLANK_LINES_IN_CODE
|
||||
);
|
||||
}
|
||||
else {
|
||||
|
||||
+27
@@ -350,4 +350,31 @@ public class JavaFormatterBlankLinesTest extends AbstractJavaFormatterTest {
|
||||
"}"
|
||||
);
|
||||
}
|
||||
|
||||
public void testBeforeMethodBodyWithCodeBlockInside() {
|
||||
// Inspired by IDEA-54747
|
||||
getSettings().BLANK_LINES_BEFORE_METHOD_BODY = 3;
|
||||
doTextTest(
|
||||
"public class FormattingTest {\n" +
|
||||
" public void foo() {\n" +
|
||||
" System.out.println(\"\");\n" +
|
||||
" try {\n" +
|
||||
" } catch (Exception e) {\n" +
|
||||
" }\n" +
|
||||
" }\n" +
|
||||
"}",
|
||||
|
||||
"public class FormattingTest {\n" +
|
||||
" public void foo() {\n" +
|
||||
"\n" +
|
||||
"\n" +
|
||||
"\n" +
|
||||
" System.out.println(\"\");\n" +
|
||||
" try {\n" +
|
||||
" } catch (Exception e) {\n" +
|
||||
" }\n" +
|
||||
" }\n" +
|
||||
"}"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user