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 ...
随机推荐
- eclipse使用内置tomcat和使用外部tomcat的设置
近期由于项目中jsp发请求要訪问项目以外的文件.直接訪问写成"c:\xxx\xxx.mp4"来訪问是没有权限的.不能完毕现有要求.经查询后发现能够在tomcat中配置虚拟文件夹将本 ...
- C#编程(小结)---------- 小总结
总结 概括 委托是寻址方法的.NET版本,类似于C++中的指针.委托可以理解为指向函数的指针,它是类型安全的,定义了具体的参数和返回值. 定义一个委托,实际上是定义一个类,委托是对方法的引用,如方法F ...
- FAQ:如何提高编译速度?
问: 如何提高编译速度? 答: 减少一次需要编译的代码量,目前想到的有两种思路: 1:修改解决方案的属性配置,取消勾选不常修改的项目的“生成”复选框. 2:采用插件化的架构,每一个插件弄一个解决方案, ...
- AOP拦截器 表达式写法
Pointcut 是指那些方法需要被执行"AOP",是由"Pointcut Expression"来描述的.Pointcut可以有下列方式来定义或者通过& ...
- Objective-C 入门笔记
简介 建立在C语言之上,可以混编C/C++代码,编写一个类需要二个文件: .h的头文件 .m的实现文件(如果是C/C++混编文件,文件后缀为.mm) 既然有头文件,所以很多人会拿它与C++进行类比,它 ...
- 多个so中模板单例的多次实例化
在Android打包项目时,发现登录功能不能使用了,logcat中也没发现什么问题,最后一行一行log定位到了问题.原来是一个so文件中的构造函数被初始化二次! 这个单例是通过继承模板来实现的(暂 ...
- 实用ExtJS教程100例-010:ExtJS Form异步加载和提交数据
ExtJS Form 为我们提供了两个方法:load 和 submit,分别用来加载和提交数据,这两个方法都是异步的. 系列ExtJS教程持续更新中,点击查看>>最新ExtJS教程目录 F ...
- Java SPI机制原理和使用场景
SPI的全名为Service Provider Interface.这个是针对厂商或者插件的.一般来说对于未知的实现或者对扩展开放的系统,通常会把一些东西抽象出来,抽象的各个模块,往往有很多不同的实现 ...
- CentOS 7 在vmware中的网络设置
一环境说明 二centos在vmware中的安装 三NAT网络设置 四设置固定IP 1修改网卡配置说明 2修改etcresolvconf 实现域名解析 五设置防火墙iptables 1 centos安 ...
- jquery fullPage
FROM : http://www.dowebok.com/77.html 应用: http://txhd.163.com/