【转】LAMBDAFICATOR: Crossing the gap from imperative to functional programming through refactorings...

LambdaFicator是一款针对Java 8的自动化重构工具,能够将匿名内部类转换为Lambda表达式,并将for循环重构为使用Lambda表达式的功能性操作。该工具极大提升了代码简洁性和并行处理能力。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Link: http://refactoring.info/tools/LambdaFicator/ 

 

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 JDK8

 

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.

 

转载于:https://www.cnblogs.com/buhaiqing/p/5058055.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值