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 ...
随机推荐
- WebLogic使用总结(七)——WebLogic部署Web应用并绑定域名
一.在WebLogic中创建一个虚拟主机 找到虚拟主机面板,如下图所示:
- WebLogic使用总结(六)——WebLogic创建虚拟主机和修改启动端口号
一.在WebLogic中创建一个虚拟主机 找到虚拟主机面板,如下图所示:
- 对一个前端使用AngularJS后端使用ASP.NET Web API项目的理解(1)
chsakell分享了一个前端使用AngularJS,后端使用ASP.NET Web API的项目. 源码: https://github.com/chsakell/spa-webapi-angula ...
- 多用StringBuilder,少用字符串拼接
在C#中,在处理字符串拼接的时候,使用StringBuilder的效率会比硬拼接字符串高很多.到底有多高,如下: static void Main(string[] args) { string st ...
- iOS 获取本地视频的缩略图
+(UIImage *)getImage:(NSString *)videoURL { AVURLAsset *asset = [[AVURLAsset alloc] initWithURL:[NSU ...
- Unity3D 经常使用库
JSON.NET:http://james.newtonking.com/json LitJSON: http://lbv.github.io/litjson/ ProtoBuf - net:htt ...
- MySQL递归查询树状表的子节点、父节点具体实现
mysql版本(5.5.6等等)尚未支持循环递归查询,和sqlserver.oracle相比,mysql难于在树状表中层层遍历的子节点.本程序重点参考了下面的资料,写了两个sql存储过程,子节点查询算 ...
- Leetcode刷题记录:编码并解码短网址
题目要求 编写一个类,提供两个方法.一个可以将普通的网址编码成短网址,一个可以将短网址还原为普通网址. 参考题解 # 使用随机函数,生成短网址,保存在dict中,避免重复 import random ...
- Chocolatey 简介(软件自动化管理工具)
一.Chocolatey 管理Windows软件的明智方法 1.建立在技术的无人值守安装和PowerShell.建立在技术的无人值守安装和PowerShell. 2.轻松管理Windows软件的所有方 ...
- Asp.Net Mvc控制器重名问题整理
一.关于控制器重名问题 1.没有区域的时候控制器不能重名 2.有区域的时候,外部控制器和区域中的控制器重名,访问外部控制器异常,访问区域控制器正常. 3.区域和区域之间的控制器重名,互不影响.区域从某 ...