Visual Studio Code Java格式文档用新行括起来 [英] Visual Studio Code java format document braces new line

查看:46
本文介绍了Visual Studio Code Java格式文档用新行括起来的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何获取Visual Studio Code以新的大括号格式格式化Java文档?

即:

  public static void main(String args []){} 

对此

  public static void main(String args []){} 

Yikes !!只要记住.vscode/extensions文件夹即可.然后我进入了/ryannaddy.vscode-format-0.0.6/package.json并将format.newLine更改为true.谢谢您的帮助.太高兴了!

解决方案

要使用"Red Hat Java语言支持"解决此问题,可以使用Eclipse格式化程序文件.这使您可以非常具体地为每种情况指定支撑位置.例如,显示所有下一行"设置的 formatting.xml :

 <?xml版本="1.0"编码="UTF-8"独立=否"?>< profiles version ="12">< profile kind ="CodeFormatterProfile" name =样式" version ="12">< setting id ="org.eclipse.jdt.core.formatter.brace_position_for_anonymous_type_declaration" value ="next_line"/>< setting id ="org.eclipse.jdt.core.formatter.brace_position_for_method_declaration" value ="next_line"/>< setting id ="org.eclipse.jdt.core.formatter.brace_position_for_block" value ="next_line"/>< setting id ="org.eclipse.jdt.core.formatter.brace_position_for_constructor_declaration" value ="next_line"/>< setting id ="org.eclipse.jdt.core.formatter.brace_position_for_lambda_body" value ="next_line"/>< setting id ="org.eclipse.jdt.core.formatter.brace_position_for_enum_declaration" value ="next_line"/>< setting id ="org.eclipse.jdt.core.formatter.brace_position_for_block_in_case" value ="next_line"/>< setting id ="org.eclipse.jdt.core.formatter.brace_position_for_annotation_type_declaration" value ="next_line"/>< setting id ="org.eclipse.jdt.core.formatter.brace_position_for_switch" value ="next_line"/>< setting id ="org.eclipse.jdt.core.formatter.brace_position_for_array_initializer" value ="next_line"/>< setting id ="org.eclipse.jdt.core.formatter.brace_position_for_enum_constant" value ="next_line"/>< setting id ="org.eclipse.jdt.core.formatter.brace_position_for_type_declaration" value ="next_line"/></profile></profiles> 

有效值是 next_line next_line_shifted next_line_on_wrap end_of_line .

然后在您的 settings.json 中查找Visual Studio代码:

  {"java.format.settings.url":"/formatting.xml","java.format.settings.profile":样式"} 

有关某些用法的详细信息,请参见本文档./p>

How can I get Visual Studio Code to format Java documents with braces in a new like?

i.e:

This

public static void main(String args[]) {
}

To this

public static void main(String args[])
{
}

Edit: Yikes!! Just remember .vscode/extensions folder. I went in there then /ryannaddy.vscode-format-0.0.6/package.json and changed format.newLine to true. Thanks for the help. So happy!!

解决方案

To solve this using "Language Support for Java(TM) by Red Hat" you can use an Eclipse formatter file. This allows you to specify brace position very specifically for each scenario. For example, formatting.xml showcasing all "next line" settings:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<profiles version="12">
    <profile kind="CodeFormatterProfile" name="style" version="12">
        <setting id="org.eclipse.jdt.core.formatter.brace_position_for_anonymous_type_declaration" value="next_line"/>
        <setting id="org.eclipse.jdt.core.formatter.brace_position_for_method_declaration" value="next_line"/>
        <setting id="org.eclipse.jdt.core.formatter.brace_position_for_block" value="next_line"/>
        <setting id="org.eclipse.jdt.core.formatter.brace_position_for_constructor_declaration" value="next_line"/>
        <setting id="org.eclipse.jdt.core.formatter.brace_position_for_lambda_body" value="next_line"/>
        <setting id="org.eclipse.jdt.core.formatter.brace_position_for_enum_declaration" value="next_line"/>
        <setting id="org.eclipse.jdt.core.formatter.brace_position_for_block_in_case" value="next_line"/>
        <setting id="org.eclipse.jdt.core.formatter.brace_position_for_annotation_type_declaration" value="next_line"/>
        <setting id="org.eclipse.jdt.core.formatter.brace_position_for_switch" value="next_line"/>
        <setting id="org.eclipse.jdt.core.formatter.brace_position_for_array_initializer" value="next_line"/>
        <setting id="org.eclipse.jdt.core.formatter.brace_position_for_enum_constant" value="next_line"/>
        <setting id="org.eclipse.jdt.core.formatter.brace_position_for_type_declaration" value="next_line"/>
    </profile>
</profiles>

Valid values are next_line, next_line_shifted, next_line_on_wrap and end_of_line.

And then in your settings.json for Visual Studio Code:

{
    "java.format.settings.url": "/formatting.xml",
    "java.format.settings.profile": "style"
}

See this documentation for some usage details.

这篇关于Visual Studio Code Java格式文档用新行括起来的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆