【转】LAMBDAFICATOR: Crossing the gap from imperative to functional programming through refactorings
2015-12-18 19:38
531 查看
Link: http://refactoring.info/tools/LambdaFicator/
Here is a cool YouTube demo of some features.
Below is a screenshot of running the AnonymousToLambda refactoring in batch mode, identifying an anonymous inner class that can be refactored to a lambda expression.
Below is a screenshot of applying the ForLoopToFunctional refactoring in batch mode and identifying one loop that can be refactored to three operations on collections using lambda expressions.
Problem Description
Java 8 will support lambda expressions and will extend the Collections APIs with functional operations like map or filter that apply a lambda expression over the elements of a collection. Refactoring existing code to use these new extensions enables explicit but unobtrusive parallelism and makes the code more succinct. However, refactoring is tedious (it requires changing many lines of code) and error-prone (the programmer must reason about the control-flow, data-flow, and side-effects). Fortunately, these refactorings can be automated. We present LAMBDAFICATOR, a tool which automates two refactorings. The first refactoring converts anonymous inner classes to lambda expressions. The second refactoring converts for loops that iterate over collections to functional operations that use lambda expressions. In 9 open-source projects we have applied these two refactorings 1263 and 1709 times, respectively. The results show that LAMBDAFICATOR is useful. First, 55% of anonymous inner classes and 42% of for loops pass the preconditions, thus the refactorings are widely applicable. Second, converting anonymous to lambda decreases the code size by 2213 lines while converting for loops expressed 2382 operations, thus the refactorings provide real value to the projects. Third, the tool saved the programmer from changing 16020 lines, thus it reduces the programmer's burden.Here is a cool YouTube demo of some features.
Use Lambdaficator
LAMBDAFICATOR is implemented as a NetBeans refactoring plugin. The tool provides two main workflow options, a QuickHint option and a batch option. The quick hint option scans the file that is open in the editor in real-time. If LAMBDAFICATOR finds a valid conversion, it underlines the code and displays a hint in the sidebar indicating this annonymous inner class can be converted into a lambda expression. If the programmer clicks the hint indicator, LAMBDAFICATOR applies the refactoring. This option allows the programmer to perform the refactoring without deviating from her normal workflow. The batch option allows the programmer to invoke the refactoring automatically by selecting any file, folder, or project open in the IDE. LAMBDAFICATOR can automatically apply the refactoring on all files or optionally generate a preview which lists the valid conversions and provides finegrain control over which conversions should take place. With the batch option, LAMBDAFICATOR can discover and apply hundreds of conversions in a matter of seconds. LAMBDAFICATOR is available in the JDK8-lambda branch of NetBeans. Instructions to get and build the JDK8-lambda branch of NetBeans are found here. In order to be able to run any of the refactorings you will need to install the lambda branch of JDK8Below is a screenshot of running the AnonymousToLambda refactoring in batch mode, identifying an anonymous inner class that can be refactored to a lambda expression.
Below is a screenshot of applying the ForLoopToFunctional refactoring in batch mode and identifying one loop that can be refactored to three operations on collections using lambda expressions.
相关文章推荐
- 2015年大二上-数据结构-数组与广义表(4)-广义表算法库及应用
- Web窗体开发
- 南邮编程在线编程题六:数列求和
- DiskLruCache 源码解析
- mysql的基本操作
- HDU 3255 Farming
- javascript大神修炼记(5)——OOP思想(封装)
- 源码安装nginx
- linux内核3.4基于wakeup_source的autosleep机制分析
- linux内核3.4基于wakeup_source的autosleep机制分析
- android expandablelistview使用小结
- 黑马程序员——Java之反射
- UVALive-3972 March of the Penguins (最大流:节点容量)
- poj3126Prime Path(bfs)
- java中Ping++退款
- eclipse luna版本安装svn
- Sublime Text2 新建文件快速生成Html头部信息和炫酷的代码补全
- 原创简单php框架源码
- android创建数据库及adb查看数据库
- ARC下内存管理