简体   繁体   English

如何在Eclipse中创建新类时更改自动生成的代码

[英]How to change auto-generated code when creating new class in Eclipse

Whenever I create a new Java file in Eclipse and check off the option to add public static void main(String args[]) , this code is generated: 每当我在Eclipse中创建一个新的Java文件并检查添加public static void main(String args[]) ,就会生成以下代码:

public class Test {

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub

    }

}

How do i: 我如何能:

  • Remove the @param args comment 删除@param args评论
  • Change the indentation so each { is on a line of its own 更改缩进,以便每个{都在它自己的行上
  • Remove the TODO auto generated comment 删除TODO自动生成的评论

The indention is a formatting issue while the comments is a template issue. 缩进是格式问题,而评论是模板问题。

The templates are in Window -> Preferences -> Java -> Code Style -> Code Templates . 模板位于窗口 - >首选项 - > Java - >代码样式 - >代码模板中 Browse all of them and look for the things you would like to change. 浏览所有这些并查找您想要更改的内容。

The Formatter is a little bit more complicated. Formatter有点复杂。 You find it under Window -> Preferences -> Java -> Code Style -> Formatter . 您可以在Window - > Preferences - > Java - > Code Style - > Formatter下找到它。 There are tons of options there but I'll just answer your question. 那里有很多选择,但我会回答你的问题。

  • Templates -> Comments -> Methods -> Edit and delete everything 模板 - >评论 - >方法 - >编辑和删除所有内容
  • Formatter -> Edit -> Braces Tab -> Change which situations you want 格式化程序 - >编辑 - >大括号选项卡 - >更改所需的情况
  • Templates -> Code -> Method Body -> Edit and delete everything 模板 - >代码 - >方法体 - >编辑并删除所有内容
  1. In Eclipse Go to Window->Preferences 在Eclipse中转到Window-> Preferences
  2. In Left Panel, Select Java->Code Style->Code Template 在左侧面板中,选择Java->代码样式 - >代码模板
  3. Under "Configure generated code and comments", Expand Comments-> select Methods,Click Edit Remove or replace the pattern ( * @param args),Click OK 在“配置生成的代码和注释”下,展开注释 - >选择方法,单击编辑删除或替换模式(* @param args),单击确定
  4. Under "Configure generated code and comments", Expand Code-> select Method Body,Click Edit Remove or replace the pattern ( // TODO Auto-generated...),Click OK 在“配置生成的代码和注释”下,展开代码 - >选择方法主体,单击编辑删除或替换模式(// TODO自动生成...),单击确定
  5. Click OK ! 单击确定!

要配置它,请转到:window-> preferences-> java-> code style-> code templates

The indention is a formatting issue while the comments is a template issue. 缩进是格式问题,而评论是模板问题。

The templates are in Window -> Preferences -> Java -> Code Style -> Code Templates. 模板位于窗口 - >首选项 - > Java - >代码样式 - >代码模板中。 Browse all of them and look for the things you would like to change. 浏览所有这些并查找您想要更改的内容。

The Formatter is a little bit more complicated. Formatter有点复杂。 You find it under Window -> Preferences -> Java -> Code Style -> Formatter. 您可以在Window - > Preferences - > Java - > Code Style - > Formatter下找到它。 There are tons of options there but I'll just answer your question. 那里有很多选择,但我会回答你的问题。

* Templates -> Comments -> Methods -> Edit and delete everything
* Formatter -> Edit -> Braces Tab -> Change which situations you want
* Templates -> Code -> Method Body -> Edit and delete everything

Eclipse has a lot of configuration options. Eclipse有很多配置选项。 Take a look in the Windows | 看一下Windows | Preferences dialog (or the Eclipse Preferences pan on OSX). 首选项对话框(或OSX上的Eclipse首选项平移)。

If you dig deep enough - you'll find the options under Java | 如果你深入挖掘 - 你会在Java下找到选项 Code Style. 代码风格。

还要确保在Java>编辑器>模板中选中“使用代码格式化程序”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM