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 loop
- itar – 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” statement
- inn – Inserts “if not null” statement
- inst – Checks object type with instanceof and down-casts it
- lazy – Performs lazy initialization
Plain
- psf – public static final
- psfi – 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.
Code faster with Intellij IDEA live templates的更多相关文章
- Error during generated code invocation: com.intellij.debugger.engine.evaluation.EvaluateException: Method threw 'java.lang.IllegalAccessError' exception.
场景描述: 再从该数据库中读取数据进行处理的时候,需要将某个字段加入到一个动态的map中,然后需要对该map进行filter过滤,在执行过滤方法的时候报错 Error during generated ...
- 在IntelliJ IDEA中配置Google Java Code Style及代码格式化快捷键
google-java-format plugin should intercept the “Reformat Code” action in IDEA (Ctrl+Alt+L) and apply ...
- Code Complete阅读笔记(三)
2015-05-26 628 Code-Tuning Techniques ——Even though a particular technique generally represen ...
- 使用IntelliJ IDEA开发前的基本设置,有助于提高开发效率
2.界面字体大小设置 File菜单->Settings->Appearance->Override default fonts by(not recommended): Name:宋 ...
- Code Complete阅读笔记(二)
2015-03-06 328 Unusual Data Types ——You can carry this technique to extremes,putting all the ...
- Java Code Style
近期困惑于团队成员代码风格迥异,代码质量不可控,作为一名老司机,忧患于后期服务的可维护性,多次一对一的代码Review,耗时耗力不说,效果也不明显.痛定思痛,多次反思之后得出结论:无规矩不成方圆,可靠 ...
- PatentTips - Method and Apparatus to Support Virtualization with Code Patches
BACKGROUND As recognized in Revision 2.0 of the Intel® Virtualization Technology Specification for t ...
- R-CNN, Fast R-CNN, Faster R-CNN, Mask R-CNN
最近在看 Mask R-CNN, 这个分割算法是基于 Faster R-CNN 的,决定看一下这个 R-CNN 系列论文,好好理一下 R-CNN 2014 1. 论文 Rich feature hie ...
- IntelliJ IDEA 配置《算法》(第四版)
红皮的算法一书,内部代码的实现调用了作者写的一个包.为了运行书内代码,需要配置相应的环境. 准备 网站:https://algs4.cs.princeton.edu/code/ 工具:IntelliJ ...
随机推荐
- Android笔记之 网络http通信
0.在认识HTTP前先认识URL 在我们认识HTTP之前,有必要先弄清楚URL的组成,比如: http://www.******.com/china/index.htm 它的含义例如以下: 1. ht ...
- delphi shr和shl的作用
x:=x shl 1 二进制数向左移1位,尾部补1个零,相当于x:=x*2;x:=x shl 2 二进制数向左移2位,尾部补2个零,相当于x:=x*4;...x:=x shl n 二进制数向左移n位, ...
- 下载企业级证书打包的app 出现“正在下载”或“等待中”的图标并且无法删除的问题
下载企业级证书打包的app 出现“正在下载”或“等待中”的图标并且无法删除的问题: 原因分析:手机上的bundleid 与后台plist文件中的bundleid不一致导致的. 解决方案:用plist文 ...
- i386、i586、i686、noarch、x86_64
xxxxxxxxx.rpm <== RPM的格式,已经经过编译且包装完成的rpm文件. xxxxxx.src.rpm <== SRPM的格式,包含未编译的源代码信息. 例如rp-p ...
- android 读取 raw 中的文件。
file.getParentFile().mkdir(); file.createNewFile(); InputStream inputStream = context.getResources() ...
- 从零開始学android<使用嵌套布局实现计算器界面.十七.>
所谓的嵌套布局就是在一个文件里嵌套多个布局文件 <span style="font-size:18px;"> <LinearLayout android:layo ...
- 用SDWebImage加载FLAnimatedImage
用SDWebImage加载FLAnimatedImage 效果 源码 https://github.com/YouXianMing/Animations // // GifPictureControl ...
- 血族第四季/全集The Strain迅雷下载
当第四季开始时,故事时间已经过去九个月.世界陷入黑暗,斯特里高伊吸血鬼控制了一切.第三季结尾的爆炸引发了一场全球核灾难,核冬天的到来令地表变得暗无天日,斯特里高伊获得解放.它们大白天也能出来活动,帮助 ...
- 详细解释如何通过Android自带的方式来实现图片的裁剪——原理分析+解决方案
我们很多时候需要进行图片的裁剪,其实这个功能在android系统中已经有一套解决方案了,虽然界面和效果并不是很优秀但功能毫无疑问是完美实现了.至于,不用自带的方案怎么做自定义,这个就是后话了.本篇主要 ...
- [Android Security] Smali和逆向分析
copy : https://blog.csdn.net/u012573920/article/details/44034397 1.Smali简介 Smali是Dalvik的寄存器语言,它与Java ...