[JAVA] Automatically modify and save coding conventions in Eclipse
Overview
--A memorandum of how to automatically apply and save coding standards when developing in Eclipse
background
--It seems foolish to point out coding convention violations when reviewing source code
—— Source code review time wants to focus resources on something else
――Since programming habits are ten people and ten colors, even if you are careful, you will violate coding rules
solution
--I'll have it corrected when saving automatically in Eclipse (now!)
--Google has published a coding convention. For example, in Java like this
--Eclipse has a format function (shortcut key: Ctrl + Shift + F), which can be modified according to the specified coding standard (imported in xml format).
Environmental setting
- Eclipse 4.7 Oxygen(Pleiades)
- Java 1.8
- Git
procedure
- Window-> Perspective-> Open Perspective-> Other-> Git
- Duplicate Git repository → Duplicate URI → URI: Enter "https://github.com/google/styleguide.git" → Next → Next → "Local destination": Enter any destination for the directory → Done
- Click Window-> Settings-> Java-> Code Style-> Import with Formatter and select "eclipse-java-google-style.xml" from the directory cloned in 2.-> "Apply and Close"
- Window-> Settings-> Java-> Editor-> Save Action-> Check "Perform Selected Action on Save"-> Check "Format Source Code"-> "Apply and Close"
- Right-click the project (if you already have the source code) → Source → Format to format all files
- After that, the format function works every time you save the source code.