简体   繁体   English

在创建新项目时在Java Eclipse中的行中编写默认代码

[英]Write default code in lines in Java Eclipse on creating new project

While solving coding competitions in java it becomes very tedious to write initialization of BufferedReader , PrintWriter and introducing variables (or copy pasting )every time I create a new project for a new problem. 在解决java中的编码竞争时,每次为新问题创建新项目时,编写BufferedReader,PrintWriter的初始化并引入变量(或复制粘贴)变得非常繁琐。 Is it possible in eclipse that when I create a new project I automatically get the template which already contains the variables introduced and initialized as described by me in the template. 是否有可能在eclipse中,当我创建一个新项目时,我会自动获取模板,该模板已经包含了我在模板中描述的引入和初始化的变量。 I looked for templates but wasn't able to figure out how to do it. 我寻找模板,但无法弄清楚如何做到这一点。 Thank You. 谢谢。

Go to Window -> Preferences and then Java -> Code Style -> Code Templates (or just paste Code templates into the Preference filter field). 转到Window -> Preferences ,然后转到Java -> Code Style -> Code Templates (或者只是将Code templates粘贴到首选项过滤器字段中)。

Now expand Code and select Class body . 现在展开Code并选择Class body Click edit and add your code. 单击edit并添加代码。

Maybe you are looking for the Window -> Preferences -> Java -> Code Style Code Templates . 也许您正在寻找Window - > Preferences - > Java - > Code Style Code Templates

if you want to write your own templates that should be available through content assist (ctrl + space) then you should take a look at Window -> Preferences -> Java -> Editor -> Templates 如果你想编写自己应该通过内容辅助(ctrl + space)提供的模板,那么你应该看一下Window - > Preferences - > Java - > Editor - > Templates

In Eclipse there are many items under the Source menu that generate templated code for you. 在Eclipse中, Source菜单下有许多项可以为您生成模板化代码。

Also if you right click on selected lines of code the popup menu also has a Source submenu and a Refactor submenu with content sensitive code generation options. 此外,如果右键单击选定的代码行,弹出菜单还有一个Source子菜单和一个带有内容敏感代码生成选项的Refactor子菜单。

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

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