我的clang-format样式文件如下:
BasedOnStyle: Google
---
Language: Java
ColumnLimit: 100
BreakStringLiterals: true
BreakAfterJavaFieldAnnotations: false
BraceWrapping:
AfterCaseLabel: true
AfterClass: true
AfterControlStatement: true
AfterEnum: true
AfterFunction: true
AfterNamespace: true
AfterObjCDeclaration: true
AfterStruct: true
AfterUnion: true
AfterExternBlock: true
BeforeCatch: true
BeforeElse: true
IndentBraces: true
SplitEmptyFunction: false
SplitEmptyRecord: false
SplitEmptyNamespace: false
Run Code Online (Sandbox Code Playgroud)
考虑以下输入java代码:
public class Lambda {
void handle() {
// TODO Try a compiling example next to see if it's different with clang-format.
try {
updateTranscriptResponse = Utils.doWithRetry(
/* task */
() -> {
System.out.println("This is a bit long-winded sentence so it keeps going on and on.");
System.out.println("This is a bit long-winded sentence so it keeps going on and on.");
},
/* task 2 */
() -> {
System.out.println("This is a bit long-winded sentence so it keeps going on and on and on and on and on.");
System.out.println("This is a bit long-winded sentence so it keeps going on and on.");
},
/* task 3 */
() -> {
System.out.println("This is a bit long-winded sentence so it keeps going on and on and on and on and on.");
System.out.println("This is a bit long-winded sentence so it keeps going on and on.");
}
);
} catch (Exception e) {
}
}
}
Run Code Online (Sandbox Code Playgroud)
我试图clang-format缩进 lambdas 的主体,但保持() -> {在一行上。不幸的是,它给了我以下输出:
public class Lambda {
void handle() {
// TODO Try a compiling example next to see if it's different with clang-format.
try {
updateTranscriptResponse = Utils.doWithRetry(
/* task */
()
-> {
System.out.println("This is a bit long-winded sentence so it keeps going on and on.");
System.out.println("This is a bit long-winded sentence so it keeps going on and on.");
},
/* task 2 */
()
-> {
System.out.println(
"This is a bit long-winded sentence so it keeps going on and on and on and on and on.");
System.out.println("This is a bit long-winded sentence so it keeps going on and on.");
},
/* task 3 */
() -> {
System.out.println(
"This is a bit long-winded sentence so it keeps going on and on and on and on and on.");
System.out.println("This is a bit long-winded sentence so it keeps going on and on.");
});
} catch (Exception e) {
}
}
}
Run Code Online (Sandbox Code Playgroud)
如何配置clang-format不在任务 1 和任务 2 中引入额外的换行符?
我正在运行 clang-format 9。