IDEA插件开发入门

2,631 阅读1分钟

环境准备

  • IDEA:2020.3
  • JDK:15
  • IDEA社区版
    • 用商业版本在启动的时候也需要激活,这个比较麻烦。所以需要额外安装一个社区版本来做调试用。

SDK选择。

  • 新增SDK
    • 打开file->Project Structure->SDKs
    • 点击+号,Add IntelliJ Platform Plugin SDK
    • 选择IDEA社区版本的安装位置

万年hello world

  • 需求
    • 在tools菜单中增加一个按钮,点击右下角弹出hello idea的提示。
  • 创建项目
    • 创建InjelliJ Platform Plugin
    • 修改信息
    • 创建action
    • 编写代码
    package com.yuanshuai.tool.idea;
    
    import com.intellij.notification.*;
    import com.intellij.openapi.actionSystem.AnAction;
    import com.intellij.openapi.actionSystem.AnActionEvent;
    
    public class HelloAction extends AnAction {
    
        @Override
        public void actionPerformed(AnActionEvent e) {
            NotificationGroup notificationGroup = new NotificationGroup("hello", NotificationDisplayType.BALLOON, true);
            Notification notification = notificationGroup.createNotification("hello", NotificationType.ERROR);
            Notifications.Bus.notify(notification);
        }
    }
    
    • 运行测试

完毕