Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/397.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
VSCode Redhat语言支持Java';s格式化程序强制最大行长度_Java_Visual Studio Code_Redhat - Fatal编程技术网

VSCode Redhat语言支持Java';s格式化程序强制最大行长度

VSCode Redhat语言支持Java';s格式化程序强制最大行长度,java,visual-studio-code,redhat,Java,Visual Studio Code,Redhat,我正在使用VS代码IDE进行Java项目。我安装了格式化代码 settings.json: "java.format.settings.url": "<local path to java-google-style.xml>", { “java.configuration.updateBuildConfiguration”:“自动”, “java.debug.settings.hotCodeReplace”:“自动”, “java.forma

我正在使用VS代码IDE进行Java项目。我安装了格式化代码

settings.json:

"java.format.settings.url": "<local path to java-google-style.xml>",
{
“java.configuration.updateBuildConfiguration”:“自动”,
“java.debug.settings.hotCodeReplace”:“自动”,
“java.format.settings.url”:”https://raw.githubusercontent.com/google/styleguide/gh-pages/eclipse-java-google-style.xml",
“java.format.settings.profile”:“GoogleStyle”,
}
我在写这样一节课:

公共类Foo{
private int第一个变量、第二个变量、第三个变量、第四个变量、第五个变量、第六个变量;
福(
int第一个变量,
int第二个变量,
在第三个变量中,
int第四个变量,
int第五个变量,
int-thesixth变量
) {
this.theFirstVariable=theFirstVariable;
this.theSecondVariable=theSecondVariable;
this.thethird variable=third variable;
this.theFourthVariable=theFourthVariable;
这个。第五变量=第五变量;
this.theSixthVariable=theSixthVariable;
}
}
当我格式化代码(按Ctrl+s)时,它变成:

公共类Foo{
private int第一个变量、第二个变量、第三个变量、第四个变量,
第五个变量为第六个变量;
Foo(第一个变量int,第二个变量int,第三个变量int,第四个变量int,
输入第五个变量,输入第六个变量){
this.theFirstVariable=theFirstVariable;
this.theSecondVariable=theSecondVariable;
this.thethird variable=third variable;
this.theFourthVariable=theFourthVariable;
这个。第五变量=第五变量;
this.theSixthVariable=theSixthVariable;
}
}

在构造函数中,似乎格式化程序试图将每个参数填充到一行中,直到超过最大行长度。我们可以保留fommer的格式吗?如果可以,我们如何保存格式?

无法保存您想要的格式样式。但是有可选的设置

下载GoogleStyle.xml并更改设置:

<setting id="org.eclipse.jdt.core.formatter.join_wrapped_lines" value="false"/>

然后在Settings.json中:

"java.format.settings.url": "<local path to java-google-style.xml>",
“java.format.settings.url”:“,
这不会让你的代码和你写下来的代码一样,但至少参数被分成了几行。虽然不是那么好:


我尝试创建定制的
EclipseJavaGoogleStyle.xml
,并按照@MollyWang的建议进行修改。我发现了一些修改,可以得到我想要的结果:


格式化后,代码变为:

公共类Foo{
private int第一个变量、第二个变量、第三个变量、第四个变量、第五个变量、第六个变量;
福(
int第一个变量,
int第二个变量,
在第三个变量中,
int第四个变量,
int第五个变量,
int(第六个变量){
this.theFirstVariable=theFirstVariable;
this.theSecondVariable=theSecondVariable;
this.thethird variable=third variable;
this.theFourthVariable=theFourthVariable;
这个。第五变量=第五变量;
this.theSixthVariable=theSixthVariable;
}
}
如果希望构造函数的关闭参数位于下一行中,请添加如下空白行:

公共类Foo{
private int第一个变量、第二个变量、第三个变量、第四个变量,
第五个变量为第六个变量;
福(
int第一个变量,
int第二个变量,
在第三个变量中,
int第四个变量,
int第五个变量,
int-thesixth变量
) {
this.theFirstVariable=theFirstVariable;
this.theSecondVariable=theSecondVariable;
this.thethird variable=third variable;
this.theFourthVariable=theFourthVariable;
这个。第五变量=第五变量;
this.theSixthVariable=theSixthVariable;
}
}