1. 配置文件下载地址
https://github.com/alibaba/p3c/tree/master/p3c-formatter
下载下面两个文件:
- eclipse-codestyle.xml
- eclipse-codetemplate.xml
2. 配置Eclipse
2.1 Set Window --> Preferences
2.1.1 General --> Select "Always run in background"、"Show heap status".
2.1.2 General --> Appearance --> Label Decorations
- Select Java Type Indicator
2.1.3 General --> Editors --> Text Editors
- Select Insert spaces for tabs、Show print margin、Show line numbers
- Set Print margin column value = 120
2.1.4 General --> Workspace
- Select Build automatically、Refresh using native hooks or polling;
- Set Text file encoding value= UTF-8
2.1.5 Ant --> Editor --> Formatter
- remove select Use tab character instead of spaces;
- set Maximum line width(characters) value 120;
- select Wrap long element tags ;
2.1.6 Java --> Code Style --> Code Templates
- Import template: eclipse-codetemplates.xml;
- Select "Automatically add comments for new methods and types"
2.1.7 Java --> Code Style --> Formatter
- Import template: eclipse-codestyle.xml
2.1.8 Java --> Complier --> Errors/Warnings
- Set Annotations Missing '@Override' annotation value =Error
2.1.9 Java --> Editor --> Save Actions
- Select Perform the selected actions on save、Format source code,Additional actions;
- Compare Additional actions, and if different, configure according to screenshots in next step:
- If Additional actions are different, then configure as below screenshots