8 Eclipse Shortcut Keys for Code Refactoring

本文介绍了8个Eclipse IDE中用于代码重构的快捷键,包括Alt+Shift+R用于重命名,Ctrl+2, R进行局部重命名,Alt+Shift+V移动类或方法,Alt+Shift+T显示重构菜单,Alt+Shift+C改变方法签名,Alt+Shift+M提取方法,Alt+Shift+L提取局部变量,以及Alt+Shift+I内联变量或方法。" 112520226,10553711,Android手机微信分身数据取证指南,"['Android开发', '移动开发', '数据安全', '手机取证']
摘要由CSDN通过智能技术生成

此功能的作用是:根据表达示计算结果,自动生成对应的变量及类型名

默认快捷键是 Alt+Shift+L

Alt+Shift+L快捷键:打开Extract Local Variable。
Extract Local Variable 起作用的前提是:表达式必须是正确的

参考其他网友的博客写的
示例1:输入光标停在saxReader.read(“src/cn/xml/schema/web.xml”);这行代码前面时用此键会生成
SAXReader saxReader2 = saxReader;
saxReader2.read(“src/cn/xml/schema/web.xml”);

示例2:输入光标停在saxReader.read(“src/cn/xml/schema/web.xml”);这行代码后面时用此键会生成
Document read = saxReader.read(“src/cn/xml/schema/web.xml”);

如果放在read中间就会报错

 

We do refactoring most of the time when writing code. Thus, using shortcut keys can boost your productivity. Here, we round up a list of shortcut keys used for code refactoring in Eclipse IDE.

 

1. Alt + Shift + R: Renames a variable, a method, a class or even a package name. This is the most frequently used shortcut in code refactoring. Select whole name of the class, method or variable you want to rename, and then press this shortcut:

 

rename

 

Type new name and press Enter when done, Eclipse automatically updates all related references for the new name, including ones found in other classes.

 

 

 

2. Ctrl + 2, R: Renames a variable, a method or a class name locally in the current file. Eclipse doesn’t search outside references hence this renaming is faster than the Alt + Shift +R shortcut. However, use this shortcut with care: only for names used locally in the current file:

 

rename locally

 

 

 

3. Alt + Shift + V: Moves a class, method to another destination. For example, select a class name and press this shortcut, the Move dialog appears. Choose a destination and then click OK:

 

move

 

 

 

 

 

4. Alt + Shift + T: Shows refactor context menu. This shortcut allows you to access a full list of refactoring operations which are possible for current context:

 

a refactor context menu

 

 

 

5. Alt + Shift + C: Changes signature of a method. Place the cursor inside a method or select method name, and then press this shortcut. The Change Method Signature dialog appears. You can change various elements of method signature such as access modifier, return type, parameters, exceptions, etc:

 

change method signature

 

 

 

 

 

 

6. Alt + Shift + M: Extracts a selection to a method. This helps you move a selected block of code to a separate method with ease. For example:

 

Extract selection

 

The Extract Method dialog appears. Enter new method name and specify access modifier, parameters list, and then click OK to do the refactoring:

 

Extract Method dialog

 

 

 

7. Alt + Shift + L: Extracts local variable from an expression. For example:

 

Extract local variable

 

Press this shortcut key brings the Extract Local Variable dialog which allows you to name the local variable:

 

Extract Local Variable dialog

 

Click OK to do the refactoring, and here’s the result:

 

Result of extract local variable

 

 

 

8. Alt + Shift + I: Inlines a selected local variable, method or constant if possible. Eclipse replaces the selection with its declaration and puts it directly into the statement. For example:

 

Inline local variable

 

If the selection is possible to inline, Eclipse will ask to confirm:

 

Inline variable confirm message

 

Click OK to do proceed, here’s the result:

 

Result of Inline

 

 

参考来源:https://www.codejava.net/ides/eclipse/8-eclipse-shortcut-keys-for-code-refactoring

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值