IntelliJ IDEA 使用技巧

IntelliJ IDEA 使用技巧

一,高效定位代码

一切忘记的找 navigate

  1. 项目跳转: ctrl+alt+[ ]
  2. 文件跳转:
    ctrl+e (最近的文件)ctrl+shift+e(最近编辑的文件)
  3. 浏览修改位置: ctrl+shift+backspace
  4. 浏览位置的跳转:(光标)
    ctrl+shif+←或者ctrl+shift+→
  5. 打开project侧栏: alt+1
  6. 快速查找文件: ctrl+shift+A
  7. 另起一行: shift+enter

二,精准搜索

  1. **定位类:**ctrl+n
  2. 定位文件 ctrl+shift+n
  3. 定位函数或者属性 ctrl+shift+alt+n
  4. 字符串: ctrl+ shift+f

三,代码小助手

1 live template :活动模板

  • main
  • psfi,psfs

2 postfix

  • fori
100.fori
// for (int i = 0; i < 100; i++) {
//
//        }
  • sout
new Date().sout
//System.out.println(new Date());
  • field
public User(string name){
    name.field
}
//    private final string name;
//
//    public User(string name){
//        this.name = name;
//    }
  • return
    public User getUser(){
        User user = new User(name:"shan");
        //....
        user.r
     //retrn user
    }
  • nn
    public void valid(User user){
       user.nn
//        if (user !=NULL){
//            //...
//        }

    }

3 alt+enter###一个很强大的快捷键

  • 自动创建函数
  • list replace
  • 字符串 format 或者 build
  • 实现接口
public interface UserService {
    void say();
}
//public class UserServiceImpl implements UserService {
//    @Override
//    public void say() {
//
//    }
//}
  • 单词拼写
  • 导包

四 编写高质量代码

重构

忘记找 Refactor

  • 重命变量 ctrl+F6
  • 重构类名 ctrl+

    抽取

  • 抽取变量
  • 抽取静态变量
  • 抽取成员变量
  • 抽取方法参数
  • 收取函数
public class User {
    private String lastName;

    public String getFullName(String lastName){
        String fullName =this.firstName + ","+lastName;

        return fullName;
    }
    public void foo(){
        getFullName(lastName:"san");
        getFullName(lastName:"san");
        getFullName(lastName:"san");
        getFullName(lastName:"san");
        getFullName(lastName:"san");

    }

}

你可能感兴趣的:(Java)