At the moment, I’m open sourcing two wheels on Github, a simple RPC framework and a lightweight HTTP framework. The code structure is clear, the implementation is elegant (this is a shameless boast), interested partners can take a look.

While writing code, there are several IDEA plugins that have worked wonderfully for me to standardize the code and get it done more efficiently.

Today, I will simply talk about the process of writing code, which IDEA plug-in to help me the most!

Codota: Code intelligence tips

A plugin I use all the time, and it works pretty well (and a lot of the big guys around me use it when they write code).

Codota is a plug-in for intelligent code completion, based on millions of Java programs that complete code based on context. Compared to the intelligent hints that come with IDEA, Codota’s hints are more comprehensive.

If you think the IDEA plug-in installation is too slow, don’t worry! The Codota plugin also has an online equivalent (www.codota.com/code) where you can search for code examples by code keywords. It’s great!

I often use it in my work. To be honest, it really brings me a lot of convenience. For example, when we search for the code related to files.readalllines, the search results are as follows:

In addition, the basic functionality of the Codota plug-in is free. Your code won’t get leaked either, so don’t worry about that.

Simple to look at Codota plugin SAO operation!

Intelligent code completion

This is true when we use HttpUrlConnection to establish a network connection:

The thread pool we created now looks like this:

Just to demonstrate the power of this plug-in, this is not recommended for creating a thread pool. Instead, use the ThreadPoolExecutor constructor to create a thread pool. The following Alibaba plugin -Alibaba Java Code Guidelines detected this problem, so, Executors followed by a wavy line marked.

Intelligent code search

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

Alibaba Java Code Guidelines: Alibaba Java Code Guidelines

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

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

According to the official description:

At present, the plug-in implements 53 rules in the development manual, most of which are based on PMD, and four rules are based on IDEA, and real-time Inspection is implemented based on IDEA Inspection. Part of the rules to implement the Quick Fix function, for Quick Fix can be provided but not provided, we will implement as soon as possible, also welcome interested students to join in the effort. At present, there are two modes of plug-in detection: real-time detection and manual triggering.

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

Manually configure detection rules

You can also manually configure related Inspection rules:

Use effect

The plug-in detects in real time where our code does not match its rules and suggests changes. For example, if we create a thread pool in the following way, the plugin will detect it for us, as shown in the figure below.

This can be found in the Alibaba Java Development Manual for how to create a thread pool.

CheckStyle: Java code format specification.

Why do you need the CheckStyle plugin?

CheckStyle is almost a must-have plug-in for Java projects. It helps you check Java code for formatting problems such as variable naming, a line of code that is too long, and so on.

On a project, it is impossible for the project developer to regulate the code format by self-restraint! Therefore, we really need such a tool to help us format our code.

If you’ve seen my wheels, I’ve integrated CheckStyle for every project and set up Git Commit hooks to ensure that the code is formatted properly before committing.

Guide brother built wheel (code concise, clear structure, welcome to learn, welcome to improve together) :

  1. Guide xml-rpc – framework: Implemented by Netty+Kyro+Zookeeper. A Custom RPC Framework implemented by Netty+Kyro+Zookeeper.
  2. Jsoncat: A lightweight HTTP framework that mimics But differs from Spring Boot

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

How to integrate Checksytle into a Maven/Gradle project?

Typically, we integrate it into a project and set up Git hooks accordingly. There are corresponding introduction articles on the Internet, here is not much to mention.

If you find online articles unintuitive, I mentioned the two wheels above:

  1. Guide-rpc-framework: Maven project integration with Checksytle.
  2. Jsoncat: Gradle project integrates Checksytle.

If you integrate Checksytle into your project, each inspection will generate an HTML file telling you where your code is formatted incorrectly, which is very unintuitive. The Checksytle plugin makes it very intuitive to show formatting problems in your project.

If you’re using it locally and don’t want to integrate Checksytle into your project, you can just download the Checksytle plugin.

How to install?

We can find this plugin directly in the plugin market of IDEA. I’ve already installed it here.

Restart IDEA after installing the plugin and you’ll find CheckStyle in the bottom menu bar.

How do I customize detection rules?

If you need custom code format detection rules, you can configure them as follows (you can import the checkstyle.xml file for custom detection rules).

Use effect

Once configured, use the plug-in as follows!

run-check-style

It is very clear that the CheckStyle plugin has detected any formatting problems in the project code according to our custom rules.

SonarLint: Helps you optimize your code

SonarLint helps you find bugs and bugs in your code. Just like a code spell checker, SonarLint can show problems in real time and provide clear fixes so you can fix them before you submit your code.

Also, many projects integrate with SonarQube, and SonarLint can easily integrate with SonarQube.

My open source project recommendation

  1. JavaGuide: “Java Learning + Interview Guide” covers the core knowledge most Java programmers need to know. Prepare for a Java interview with JavaGuide first!
  2. Guide xml-rpc – framework: Implemented by Netty+Kyro+Zookeeper. A Custom RPC Framework implemented by Netty+Kyro+Zookeeper.
  3. Jsoncat: A lightweight HTTP framework that mimics But differs from Spring Boot
  4. A programmer should have some good habits + interview must know things!
  5. Springboot – Guide: Not only SpringBoot but also important knowledge of Spring
  6. Awesome Java: Collection of Awesome Java Projects on Github

This article was typeset using MDNICE