The IDEA plug-in development from zero single row is not as difficult as you think!

Java technology stack

www.javastack.cn

Open the website to see more quality articles

This article comes from the author's contribution:

Author: recklessly sleepwalking God  
https://www.jianshu.com/p/c18d1eacdb42

I posted an article about IDEA plugin development a few days ago: Write your first IDEA plugin from 0! It feels too simple to write, so this article explains the IDEA plug-in development process from a practical perspective.

The reason why it is called single row from zero, anyone who has played or watched others play League of Legends should understand that, in general, it is a matter of escaping a monster.

Positioning game, as the name suggests, is to understand your level through a series of battles. After the positioning game, you will be given a segment, so that you can compete with people of your level. In the positioning game developed by the IDEA plugin, I I will demonstrate the development of a plug-in through several practical examples, and let players have a general understanding of plug-in development through several practical examples. After the actual examples are completed, I will start with the black iron and analyze the IDEA plug-in a little bit. Connotation, as to whether it can rise to the strongest king then depends on fate.

Long-winded these words, let us start our positioning game.

1. IDEA plugin noun

First of all, I will introduce a few plug-in nouns, so as to ensure that there is no deviation in understanding in the context behind. I will make an analogy here, because the plug-in is developed in java, and those who know java must know the spring family bucket, so I I will make an analogy with the concepts in spring. Of course, I will not list all of them here. I will list the required parts first.

1) Actions: This product is similar to the controller . To put it simply, the method that will be called when the user clicks a certain button of the idea your own developed menu. All actions need to inherit the abstract class com.intellij.openapi.actionSystem.AnAction and implement the actionPerformed method. As for the position of the button, there are add-group related parameters for configuration. This will be explained in detail later in the serialization.

2) Services: This product is a bit similar to spring's ordinary classes. His definitions are divided into two types, namely application level and engineering level. In general, it is an ordinary bean in spring. Of course, the application level represents a singleton bean The engineering level is a multi-case Bean (it is not enough here, it can be understood as a single case first, wait for the later article to elaborate).

3) Demo configuration file (complete code address: https://gitee.com/yuanzizhenxin/PluginDemo)

2. The instance begins

Next, I will take the project https://gitee.com/yuanzizhenxin/PluginDemo as an example, and explain the simple example with what I just introduced. So, let ’s start the actual explanation.

1) Function introduction: pop up the current time, and understand the difference between application-level and project-level services.

2) Code download and IDEA development environment configuration:

First, you need to download the IDEA community version. Download gradle and configure it. Use git to download the project https://gitee.com/yuanzizhenxin/PluginDemo to the local and open it with idea.

3) Plug-in demo:

A. First of all, the entrance of the entire demo is in plugin.xml

I will explain the specific meaning of the parameters here in a separate chapter. First, I know that this is the configuration of the entrance action. His position is in the red box below.

B. The idea opens the project, after gradle initialization is complete, find the button below, and double-click to run, so that you can run a new idea, this is the idea in the sandbox (can be understood as a brand new idea). Pay attention to the WeChat public account: Java technology stack, reply in the background: idea, you can get the N latest IDEA dry goods I have compiled.

C. Click the position of the action described in step A, and click ActionDemo, you can see the idea popup in the middle of the idea.

4) Explain the plug-in code:

Here action first inherits the AnAction class and rewrites the actionPerformed method. Remember that all plugin actions are declared like this.

The method to get service in action is ServiceManager.getService (XXXX.class); or ServiceManager.getService (anActionEvent.getProject (), XXXX.class);

The pop-up window is Messages.showMessageDialog ("Content", "Title", Messages.getInformationIcon ());

In summary, a plug-in is nothing more than a few things, the rest is left to read the source code, it is very simple, I wish you all success! !

END

Learning materials:

Share a copy of the latest Java architect learning materials

Recent articles:

1. Heavy: Java 14 is officially released!

2. Java 14 pattern matching, very new feature!

3. How big should the database connection pool be?

4. Are you still using Date? Quickly use LocalDateTime!

5. A bloody case caused by the leak of the Druid connection pool!

6. 8 data structures that every programmer must master!

7. The 8 ways of writing the singleton mode are very complete!

8. How to use chase MM to understand 23 design patterns?

9. When I go, my colleague actually stores the password in plain text! ! !

10. Why do big companies have to use microservices?

There are too many dry goods in the public account. Scan the code to pay attention to the public account of the Java technology stack . Read more.

Click " Read Original " to take you to fly ~

Published 474 original articles · praised 1030 · 1.45 million views +

Guess you like

Origin blog.csdn.net/youanyyou/article/details/105445453