One, foreword

Yesterday (October 14), Alibaba in Hangzhou cloud conference, officially released by the Alibaba P3C project team, after 247 days of continuous research and development, officially released the expected “Alibaba Java development protocol” scanning plug-in!

The P3C is a world-renowned anti-submarine aircraft designed to attack underwater submarines, and is meant to scan for potential code problems. This project group is a virtual project group organized spontaneously by Alibaba development enthusiasts. It converts the mandatory items in The Alibaba Java Development Statute into automatic plug-ins and realizes some automatic coding.

The plugin is open source on Github, so anyone interested can check it out.

github.com/alibaba/p3c

Or just search for P3C on Github

Two, the main functions of the plug-in

/WechatIMG57.jpeg

This plug-in is mainly released this year “Alibaba Java development statute” an extension, it exists with an IDE plug-in, can automatically on the manual of Java non-standard problems prompt. The main support is now (IDEA, Eclipse), Android Studio is idea-based, so it also supports Android developers.

After the code is scanned, the code that does not conform to the code will be displayed in Blocker/Critical/Major level. Even in IDEA, it can also provide real-time Inspection function based on Inspection mechanism, which can quickly find the code that does not conform to the code. For the historical code, part of the rules to achieve a batch of one-key repair function, for the first time in the mature project, the use of plug-ins, made a very friendly support.

Three, how to install

From an Android development perspective, here’s just how to use the Alibaba Java Coding Guidelines in Android Studio. For other tools, consult the documentation.

3.1 Searching for Plug-ins

Select Setting >> Plugins >> Browse Repositories.

install_1.png

3.2 Installing Plug-ins

Search for the keyword “alibaba” and in the results, find alibaba Java Coding Guidelines and install it.

/install-plugin.png

After the installation is complete, we will be prompted to restart Android Studio, and clicking the restart button will help us automatically restart it, or we can restart it manually.

4. How to use it

4.1 Switching Languages

The use of Ali statute plug-in is very simple, and the plug-in itself is the completion of Chinese development, so the support for Chinese is very good.

Once installed, it will default to the language you have selected for your device, but you can switch the language. For now, only Chinese and English are supported.

You can Switch to Tools >> Alibaba Coding Guidelines >> Switch Language to Xxx.

switch-language

After switching here, you also need to restart the IDEA to take effect.

/smartfox-restart.png

4.2 Inspections support

Inspections aren’t new to most of us. It automatically does fast, flexible static code analysis while we’re coding, automatically detects compiler and runtime errors, and prompts developers to do effective fixes and improvements before we compile.

Here’s a simple example.

/thread-factory-wraning.png

As you can see, it tells me to point out the irregularities in my writing here, and if you want to see more details, just click the More button.

/wraning-more.png

Of course, all specifications can be seen in Inspections.

/insp-dialog.png

To look at frames, you can click on them one by one to see the details. On the right side is a prompt for checking out problems. If you don’t want to Check out criteria, you can uncheck them.

4.3 Static analysis of code

In addition to supporting Inspections, the Ali Specification plugin allows you to do static code analysis on existing projects.

/code-any.png

The results of the analysis are divided into Blocker, Critical and Major levels. The result is very intuitive, and if your current plugin language is Chinese, you can see at a glance what the problem is and suggest a fix.

/code-result.png

4.4 VCS support

In Android Stuido, VCS support is provided by default. We only need simple configuration to support Git, SVN, etc.

Android Studio, with Git use, don’t know can see my previous article. AS and Git are better at work.

Ali specification plug-in also supports this part of verification. It can perform specification inspection on the submitted code before we submit the code.

/analyze_before_checkin.png

In my opinion, this function is very useful. After meeting the test results, the quality of your own Code and the efficiency of your team’s Code Review will be improved.

Five, statute source code

Finally, as an aside, a simple look at the statute of the source code is what structure.

/project.png

Structurally, different plug-ins are maintained by different projects, which is not to be questioned, and they are not universal.

Interestingly, the Ali Protocol plugin was developed entirely using Kotlin.

/idea-plugin.png

As you can see, the structure is also very clear, support for inspection, in compatible/ Inspection and in Inspection, support for VCS, in VCS.

We will not see more details, interested to read the source code.

summary

Ali specification plug-in, plug-in main situation, this article has explained clearly.

However, it is mainly based on the previously released “Alibaba Java Development Manual Ultimate Edition”, it is recommended to read this document in advance, you can reply “Ali Protocol” in the xiangxiang ink shadow, you can view the complete document.

Today in the background of the official account of Chengxiang ink shadow, reply “growth”. I will send you some study materials I collated, including: Android decompilation, algorithm. Web project source code.

Recommended Reading:

  • Glide with this, more save!!
  • Before job-hopping, do not think about these is equal to white jump!!
  • Those nights will pay off in the end
  • How do you do screen adaptation when you only have one device
  • Android source code, more convenient to read online!!

Like or share