IDEA插件开发初体验之(GET/SET自动生成带模版注释插件的开发与使用)
来源:互联网 发布:文件夹定时拷贝软件 编辑:程序博客网 时间:2024/05/18 13:43
1.准备环境,添加IDEA插件需要的SDK
2.新增Plugins的Module
3.创建Plugins的项目目录如下:
4.Plugins相关介绍
(1).三种组件类型:Application、Project、Module Component。
(2).创建一个Action
Action:让使用我们插件的用户通过菜单或其他方式点击进插件。创建一个插件如下:Action ID:指Action的唯一IDAdd to Group:选择在那个菜单下显示
当新建一个Action的同时,IDEA会帮你在plugin.xml配置改Aciton,如下:
5.插件配置面板
1.创建一个配置项的类,实现Configurable(或SearchableConfigurable),实现里面的一个createComponent方法,返回一个JComponent面板对象,这样就会显示在Settings里。
2.IDEA提供的Swing Designer设计器,创建一个GUI FORM
创建后就可以通过拖拽的形式来修改setting的配置面板,创建的GUI FORM 如下图:
我写的GET/SET插件的配置类代码如下:(isModified方法用来判断是否已经修改,apply在配置文件应用的时候会调用,reset在撤回reset会调用)
package com.ctt.format.setting;import com.intellij.openapi.options.ConfigurationException;import com.intellij.openapi.options.SearchableConfigurable;import org.jetbrains.annotations.Nls;import org.jetbrains.annotations.NotNull;import org.jetbrains.annotations.Nullable;import javax.swing.*;/** * Created by admin on 2016/12/18. */public class FormatConfigurable implements SearchableConfigurable { private FormatForm formatForm; private FormatSetting formatSetting = FormatSetting.getInstance(); public FormatConfigurable() { } @NotNull public String getId() { return "DocFormat"; } @Nls public String getDisplayName() { return this.getId(); } @Nullable public String getHelpTopic() { return this.getId(); } @Nullable public JComponent createComponent() { if(null == this.formatForm) { this.formatForm = new FormatForm(); } return this.formatForm.mainPanel; } public boolean isModified() { return !this.formatSetting.getGetFormat().equals(this.formatForm.getFormatTextArea.getText()) || !this.formatSetting.getSetFormat().equals(this.formatForm.setFormatTextArea.getText()); } public void apply() throws ConfigurationException { this.formatSetting.setGetFormat(this.formatForm.getFormatTextArea.getText()); this.formatSetting.setSetFormat(this.formatForm.setFormatTextArea.getText()); } public void reset() { this.formatForm.getFormatTextArea.setText(this.formatSetting.getGetFormat()); this.formatForm.setFormatTextArea.setText(this.formatSetting.getSetFormat()); }}
3.配置文件持久化,创建一个时间了PersistentStateComponent<Element>类,用于讲配置持久化到.xml文件里。其中当保存配置文件的时候会调用getState方法讲配置之久到到配置文件里。创建的FormatSetting如下
package com.ctt.format.setting;/** * Created by admin on 2016/12/18. */import com.intellij.openapi.components.PersistentStateComponent;import com.intellij.openapi.components.ServiceManager;import com.intellij.openapi.components.State;import com.intellij.openapi.components.Storage;import org.jdom.Element;import org.jetbrains.annotations.Nullable;@State( name = "FormatSetting", storages = {@Storage( id = "other", file = "$APP_CONFIG$/format.xml" )})public class FormatSetting implements PersistentStateComponent<Element> { private String setFormat; private String getFormat; public FormatSetting() { } public static FormatSetting getInstance() { return (FormatSetting) ServiceManager.getService(FormatSetting.class); } @Nullable public Element getState() { Element element = new Element("FormatSetting"); element.setAttribute("setFormat", this.getSetFormat()); element.setAttribute("getFormat", this.getGetFormat()); return element; } public void loadState(Element state) { this.setSetFormat(state.getAttributeValue("setFormat")); this.setGetFormat(state.getAttributeValue("getFormat")); } public String getSetFormat() { return this.setFormat == null ? StatementGenerator.defaultSetFormat : this.setFormat; } public void setSetFormat(String setFormat) { this.setFormat = setFormat; } public String getGetFormat() { return this.getFormat == null ? StatementGenerator.defaultGetFormat : this.getFormat; } public void setGetFormat(String getFormat) { this.getFormat = getFormat; }}
6.插件实现后的效果如下:
1.配置面板如下:
2.使用插件的菜单是在java类里调用快捷键ALT+INSERT。如下:
3.自动生成GET/SET并带上注释模版上的注释,效果如下:
7.插件的GIT地址和插件的下载地址
1.插件的GIT地址:https://git.oschina.net/cttcu/IDEA-Plugins2.插件下载地址:https://git.oschina.net/cttcu/IDEA-Plugins/blob/master/generateGSDoc/generateGSDoc.zip?dir=0&filepath=generateGSDoc%2FgenerateGSDoc.zip&oid=4ecc84f7b127b76c367296e0d6a33b576f42fb95&sha=463a19bd008eb19882962ca6438b5c2151bc499c
参考资料和博客:
1.IntelliJ IDEA插件开发入门指南:http://www.doc88.com/p-7758859318883.html
2.IntelliJ IDEA插件结构 : http://blog.csdn.net/hawkdowen/article/details/41213001
3.Intellij IDEA插件开发入门 : http://blog.csdn.net/dc_726/article/details/14139155
4.IntelliJ IDEA 英文文档 : http://www.jetbrains.org/intellij/sdk/docs/index.html
- IDEA插件开发初体验之(GET/SET自动生成带模版注释插件的开发与使用)
- idea自动解析set/get方法的插件
- Idea 自动生成变量set方法插件
- vs2005 自动生成get,set插件
- OpenRS插件开发之自动生成菜单
- [iOS开发]Xcode自动注释插件:VVDocumenter使用和安装
- Firefox插件开发初体验
- 编写IDEA插件之初体验
- eclipse生成带注释的set、get方法
- idea 自定解析set/get方法的插件
- 《阿里巴巴Java开发规约》IDEA插件下载与安装使用
- Netbeans 自带注释插件的使用
- Myeclipse自动生成的get set方法 加上文本注释
- Myeclipse自动生成的get set方法 加上文本注释
- eclipse自动生成get、set方法的文档注释
- IDEA中自动生成get/set的方式
- IDEA中自动生成get/set的方式
- IDEA中自动生成get/set的方式
- Android数据库的基本使用,增删改查!
- KinectV2+Ubuntu 14.04+Ros 安装教程
- Thinking in Java(9)-closures and callbacks
- android设置白天模式和夜间模式
- Kurento-room-demo 模块图
- IDEA插件开发初体验之(GET/SET自动生成带模版注释插件的开发与使用)
- axis2 WebService的发布与调用
- 基于react+redux+webpack的前端框架
- 关于Databinding的使用
- 开发工具-Fiddler的介绍
- Android 如何让app自行处理power key
- 【error】LINK1123: failure during conversion to COFF: file invalid or corrupt
- jbpm部署流程定义到MySql报乱码解决方案
- Android 面试题总结之View(一)