Merge branch 'chainedMethodsWithComments' of https://github.com/paplorinc/intellij-community

This commit is contained in:
Yaroslav Lepenkin
2015-09-02 12:44:08 +03:00
3 changed files with 46 additions and 9 deletions
@@ -702,9 +702,9 @@ public abstract class AbstractJavaBlock extends AbstractBlock implements JavaBlo
ASTNode child = node.getFirstChildNode();
while (child != null) {
if (!FormatterUtil.containsWhiteSpacesOnly(child)) {
if (child.getElementType() == JavaElementType.METHOD_CALL_EXPRESSION || child.getElementType() ==
JavaElementType
.REFERENCE_EXPRESSION) {
IElementType type = child.getElementType();
if (type == JavaElementType.METHOD_CALL_EXPRESSION ||
type == JavaElementType.REFERENCE_EXPRESSION) {
collectNodes(nodes, child);
}
else {
@@ -75,8 +75,10 @@ class ChainMethodCallsBlockBuilder {
for (int i = 0; i < methodCall.size(); i++) {
ChainedCallChunk currentCallChunk = methodCall.get(i);
if (isMethodCall(currentCallChunk)) {
if (myWrap == null) myWrap = createCallChunkWrap(i, methodCall);
if (myChainedCallsAlignment == null) myChainedCallsAlignment = createCallChunkAlignment(i, methodCall);
if (myWrap == null)
myWrap = createCallChunkWrap(i, methodCall);
if (myChainedCallsAlignment == null)
myChainedCallsAlignment = createCallChunkAlignment(i, methodCall);
}
else {
myWrap = null;
@@ -137,7 +139,7 @@ class ChainMethodCallsBlockBuilder {
private boolean isMethodCall(@NotNull ChainedCallChunk callChunk) {
List<ASTNode> nodes = callChunk.nodes;
return !nodes.isEmpty() && nodes.get(nodes.size() - 1).getElementType() == JavaElementType.EXPRESSION_LIST;
return nodes.size() >= 3 && nodes.get(2).getElementType() == JavaElementType.EXPRESSION_LIST;
}
}
@@ -48,7 +48,42 @@ public class JavaFormatterAlignmentTest extends AbstractJavaFormatterTest {
" .foo();"
);
}
public void testChainedMethodWithComments() throws Exception {
getSettings().ALIGN_MULTILINE_CHAINED_METHODS = true;
doMethodTest("AAAAA.b()\n" +
".c() // comment after line\n" +
".d()\n" +
".e();",
"AAAAA.b()\n" +
" .c() // comment after line\n" +
" .d()\n" +
" .e();");
}
public void testChainedMethodWithBlockComment() {
getSettings().ALIGN_MULTILINE_CHAINED_METHODS = true;
doTextTest("class X {\n" +
" public void test() {\n" +
" AAAAAA.b()\n" +
".c()\n" +
".d()\n" +
" /* simple block comment */\n" +
".e();\n" +
" }\n" +
"}",
"class X {\n" +
" public void test() {\n" +
" AAAAAA.b()\n" +
" .c()\n" +
" .d()\n" +
" /* simple block comment */\n" +
" .e();\n" +
" }\n" +
"}");
}
public void testMultipleMethodAnnotationsCommentedInTheMiddle() throws Exception {
getSettings().BLANK_LINES_AFTER_CLASS_HEADER = 1;
getSettings().getRootSettings().getIndentOptions(StdFileTypes.JAVA).INDENT_SIZE = 4;
@@ -256,7 +291,7 @@ public class JavaFormatterAlignmentTest extends AbstractJavaFormatterTest {
"}"
);
}
public void testAnnotatedAndNonAnnotatedFieldsInColumnsAlignment() {
// Inspired by IDEA-60237
@@ -281,10 +316,10 @@ public class JavaFormatterAlignmentTest extends AbstractJavaFormatterTest {
"}"
);
}
public void testAlignThrowsKeyword() throws Exception {
// Inspired by IDEA-63820
getSettings().ALIGN_THROWS_KEYWORD = true;
doClassTest(
"public void test()\n" +