mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-11 18:25:40 +02:00
Bug 564273 - Fix format lambda expressions without parenthesis
Change-Id: I918ca05d75ca4e8cba7501e232d4e6b05e434f06
This commit is contained in:
parent
72bf8216d8
commit
f4bed34dd0
2 changed files with 25 additions and 6 deletions
|
@ -1032,9 +1032,11 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
|
||||||
|
|
||||||
// declarator
|
// declarator
|
||||||
final ICPPASTFunctionDeclarator declarator = node.getDeclarator();
|
final ICPPASTFunctionDeclarator declarator = node.getDeclarator();
|
||||||
|
if (declarator != null) {
|
||||||
skipNonWhitespaceToNode(declarator);
|
skipNonWhitespaceToNode(declarator);
|
||||||
|
}
|
||||||
boolean hasSpace = scribe.printComment();
|
boolean hasSpace = scribe.printComment();
|
||||||
boolean hasPointerOps = declarator.getPointerOperators().length > 0;
|
boolean hasPointerOps = declarator != null ? declarator.getPointerOperators().length > 0 : false;
|
||||||
boolean needSpace = (hasPointerOps && hasSpace) || (!hasPointerOps && peekNextToken() == Token.tIDENTIFIER);
|
boolean needSpace = (hasPointerOps && hasSpace) || (!hasPointerOps && peekNextToken() == Token.tIDENTIFIER);
|
||||||
if (needSpace) {
|
if (needSpace) {
|
||||||
scribe.space();
|
scribe.space();
|
||||||
|
@ -1047,12 +1049,14 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
|
||||||
preferences.insert_space_before_opening_brace_in_method_declaration, false);
|
preferences.insert_space_before_opening_brace_in_method_declaration, false);
|
||||||
scribe.setTailFormatter(tailFormatter);
|
scribe.setTailFormatter(tailFormatter);
|
||||||
}
|
}
|
||||||
|
if (declarator != null) {
|
||||||
declarator.accept(this);
|
declarator.accept(this);
|
||||||
|
|
||||||
IASTAttributeSpecifier[] attributes = declarator.getAttributeSpecifiers();
|
IASTAttributeSpecifier[] attributes = declarator.getAttributeSpecifiers();
|
||||||
if (attributes.length > 0) {
|
if (attributes.length > 0) {
|
||||||
formatAttributes(declarator, true, false);
|
formatAttributes(declarator, true, false);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (tailFormatter != null) {
|
if (tailFormatter != null) {
|
||||||
scribe.runTailFormatter();
|
scribe.runTailFormatter();
|
||||||
|
|
|
@ -4825,4 +4825,19 @@ public class CodeFormatterTest extends BaseUITestCase {
|
||||||
public void testVariadicFunction_Bug487990() throws Exception {
|
public void testVariadicFunction_Bug487990() throws Exception {
|
||||||
assertFormatterResult();
|
assertFormatterResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//int main() {
|
||||||
|
// const int a = []{return 12;}();
|
||||||
|
// return 0;
|
||||||
|
//}
|
||||||
|
|
||||||
|
//int main() {
|
||||||
|
// const int a = [] {
|
||||||
|
// return 12;
|
||||||
|
// }();
|
||||||
|
// return 0;
|
||||||
|
//}
|
||||||
|
public void testLambdaWithoutParens_Bug564273() throws Exception {
|
||||||
|
assertFormatterResult();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue