IntelliJ IDEA 快捷输入模板
2015-11-26 11:30
447 查看
Code faster with Intellij IDEA live templates
Intellij IDEA –in my opinion the most productive IDE for Java – comes with bunch of features helping getting rid of writing repetitive code – which is a everyday business no matter what language you use. One of them is live templates.
Live templates contain predefined code fragments. You can use them to insert frequently-used or custom code constructs into your source code file quickly, efficiently, and accurately.
IDEA comes with a set of live templates for Java, Maven, HTML, CSS and more and also enables to create
custom templates.
Inserting live template
There are 2 ways to insert live template:Type live template abbreviation (for example dep) and next press TAB key
Use shortcut Command + J (Mac) / Ctrl + J (PC) to
popup list of available live templates in current context
At the beginning it’s quite difficult to remember all you wish to use and going back and forth from code to settings or browsing list is not very efficient – especially when you don’t know what you are looking for. That’s why I created gallery
of (in my opinion) most useful built-in live templates for Java and Maven that can be used as a cheat sheet:
Maven
dep – Inserts <dependency/>pl – Inserts <plugin/>
repo – Inserts <repo/>
Iterations
fori – creates iteration loopitar – iterates elements of array
itco – iterates elements of java.util.Collection
iter – iterates Iterable
itit – iterates java.util.Iterator
itli – iterates elements of java.util.List
Other
ifn – Inserts “if null” statementinn – Inserts “if not null” statement
inst – Checks object type with instanceof and down-casts it
lazy – Performs lazy initialization
Plain
psf – public static finalpsfi – public static final int
psfs – public static final String
thr – throw new
Summary
Using predefined Java templates is just a beginning. You can find ready to use templates for particular frameworks on Github and I really encourage you to create your custom, project specific ones.If you created interesting common use live templates for Java or related frameworks feel invited to post them in comments.
If you enjoyed this post, then make sure you subscribe to my RSS
feed
出自于:http://maciejwalkowiak.pl/blog/2014/01/14/code-faster-with-intellij-idea-live-templates/
相关文章推荐
- 使用C++实现JNI接口需要注意的事项
- Android IPC进程间通讯机制
- Android Manifest 用法
- [转载]Activity中ConfigChanges属性的用法
- Android之获取手机上的图片和视频缩略图thumbnails
- Android之使用Http协议实现文件上传功能
- Android学习笔记(二九):嵌入浏览器
- android string.xml文件中的整型和string型代替
- i-jetty环境搭配与编译
- android之定时器AlarmManager
- android wifi 无线调试
- Android Native 绘图方法
- Android java 与 javascript互访(相互调用)的方法例子
- android 代码实现控件之间的间距
- android FragmentPagerAdapter的“标准”配置
- Android"解决"onTouch和onClick的冲突问题
- android:installLocation简析
- android searchView的关闭事件
- SourceProvider.getJniDirectories