If you want to write the code well, you can't live without these IDEA plug-ins!

Python combat community

Java combat community

Long press to identify the QR code below, add as required

Scan QR code to follow to add customer service

Enter the Python community▲

Scan QR code to follow to add customer service

Enter the Java community

Author丨Guide

Source丨JavaGuide (ID: JavaGuide)

At the moment, I ( Guide brother ) open sourced two wheels on Github, a simple RPC framework, and a lightweight HTTP framework. The code structure is clear and the implementation is elegant ( this boasting is shameless ), and interested friends can take a look.

When writing the code, there are several IDEA plug-ins that are very effective for me to standardize the code and complete the coding work more efficiently.

So today, I will briefly talk about which IDEA plugins have helped me the most in the process of writing code in my usual life!

01 Codota: Smart tips for code

I have been using a plug-in, it can be said to be very easy to use ( many big guys around me usually write code and use this plug-in ).

Codota is a plug-in for smart code completion. It is based on millions of Java programs and can prompt completion codes based on program context. Compared to IDEA's own smart prompts, Codota's prompts are more comprehensive.

If you think that the IDEA plug-in installation is too lagging, don't worry! The Codota plugin also has a corresponding online website (https://www.codota.com/code), on this website you can search for relevant code examples based on code keywords, which is very good!

I often used at work, to be honest really brought me a lot of convenience, such as we search Files.readAllLinesthe relevant code, search out the results as shown below:

In addition, the basic functions of the Codota plug-in are free. Your code will not be leaked, so don't worry about this.

Simply take a look at the operation of the Codota plug-in!

Code smart completion

We use to HttpUrlConnectionestablish a network connection is really like:

We create the thread pool now as follows:

The above are just to demonstrate the power of this plug-in, in fact, create a thread pool is not recommended for use in this way, it is recommended to use ThreadPoolExecutorthe constructor to create a thread pool. An Alibaba plug-in I will introduce below- Alibaba Java Code Guidelines has detected this problem, so it Executorsis marked with a wavy line below.

Code intelligent search

In addition to the intelligent prompt when writing code. You can also directly select the code and search for relevant code examples.

02 Alibaba Java Code Guidelines: Alibaba Java Code Guidelines

Alibaba Java code specification, the corresponding Github address is: https://github.com/alibaba/p3c. Installation is highly recommended!

After the installation is complete, it is recommended to replace the language with Chinese, and the prompt is more friendly.

According to the official description:

At present, this plug-in implements the 53 rules in the development manual, most of which are based on PMD. Among them, 4 rules are based on IDEA and real-time inspection based on IDEA Inspection. Some rules implement the Quick Fix function. For those that can provide Quick Fix but not, we will implement it as soon as possible. Interested students are also welcome to join in and work hard. Currently there are two modes for plug-in detection: real-time detection and manual triggering.

The development manual mentioned above is also the famous "Alibaba Java Development Manual" in the field of Java development.

Manually configure detection rules

You can also manually configure related inspection rules:

Effect

This plugin will detect where our code does not match its rules in real time, and will give suggestions for modification. For example, if we create a thread pool in the following way, this plugin will help us detect it, as shown in the figure below.

This can correspond to the book "Alibaba Java Development Manual" on how to create a thread pool.

03 CheckStyle: Java code format specification

Why do I need CheckStyle plug-in?

CheckStyle is almost a necessary plug-in for Java project development. It will help us check whether there is a problem with the format of the Java code, such as whether there is a problem with the variable naming format, whether the length of a line of code is too long, and so on.

On the project, it is not reliable to regulate the code format through the self-restraint of project developers! Therefore, we need such a tool to help us standardize the code format.

If you have seen the wheel I wrote, you can find that I have integrated CheckStyle for each project and set the Git Commit hook to ensure that there is no problem with the code format before submitting the code.

The wheels made by Guide ( concise code, clear structure, welcome to learn, welcome to improve together ):

  1. guide-rpc-framework : A custom RPC framework implemented by Netty+Kyro+Zookeeper. (A custom RPC framework based on Netty+Kyro+Zookeeper-with detailed implementation process and related tutorials)

  2. jsoncat : A lightweight HTTP framework that imitates Spring Boot but is different from Spring Boot

Git hook : Git can trigger custom scripts when certain important actions such as commit and push occur. Hooks are stored in the Git directory hookssubdirectory. That is, in most projects .git/hooks.

How to integrate Checksytle in Maven/Gradle project?

Generally, we integrate it into the project and set the corresponding Git hook. There are corresponding introduction articles on the Internet, so I won't mention it here.

If you think the online articles are not intuitive, you can refer to the two wheels I mentioned above:

  1. guide-rpc-framework: Checksytle integrated with Maven project.

  2. jsoncat: Gradle project integrates Checksytle.

If you integrate Checksytle in your project, an HTML format file will be generated for each test to tell you where the code format is wrong, which is very unintuitive. Through the Checksytle plug-in, it is very intuitive to display the formatting problems in the project.

If you just use it locally and don't want to integrate Checksytle in your project, you can just download a Checksytle plug-in.

how to install?

We can find this plug-in directly in IDEA's plug-in market. I have already installed it here.

After installing the plugin, restart IDEA, and you will find CheckStyle in the bottom menu bar.

How to customize detection rules?

If you need to customize the code format detection rules, you can configure it as follows (you can import files for custom detection rules CheckStyle.xml).

Effect

After the configuration is complete, use this plugin as follows!

run-check-style

It can be seen very clearly: CheckStyle plug-in has detected all the format problems in the code in the project according to our customized rules.

04 SonarLint: Help you optimize your code

SonarLint helps you find errors and vulnerabilities in the code, just like a code spelling checker, SonarLint can display code problems in real time and provide clear repair instructions so that you can solve them before submitting the code.

Moreover, many projects have integrated SonarQube, and SonarLint can be easily integrated with SonarQube.

程序员专栏 扫码关注填加客服 长按识别下方二维码进群

Recommended recent exciting content:  

 Comparison of programmer income in China, the United States, Japan and India

 A sad day for programmers

 SringMVC from entry to source code, this one is enough

 10 Python visual animations, carefully and beautifully


Watch the good article here to share it with more people↓↓

Guess you like

Origin blog.csdn.net/Px01Ih8/article/details/109252029