1. 程式人生 > >eclipse的配置詳解和程式碼的格式詳解Ctrl+Shift+F格式化內容設定

eclipse的配置詳解和程式碼的格式詳解Ctrl+Shift+F格式化內容設定

eclipse或MyEclipse的路徑:Window->Preferences->Java->Code Style->Formatter->點選右圖的Edit
或者直接在配置中搜索:Formatter

Edit中的內容詳解如下:
Formatter 格式調整
Code style:
Formatter: 格式化
Project properties Java code style Formatter
1. Enable project specific settings… 當前專案程式碼格式
2. configure workspace setting… 所有的系統檔案格式
[built-in]: 自帶
new 可以new自己設定需要的程式碼格式,選擇Eclipse[built-in]
在Edit裡可以進行設定(如下):


Profile
Indentation(縮排)
General settings(一般設定)
Tab policy: 1.spaces only:w檔案格式自動轉換spaces(單獨空格)
2.tab only:檔案格式自動轉換成tab鍵
3.Mixed:混合
Indentation size:縮排大小
Tab size:Tab鍵大小
Alignment of fields in class declaration: 在類的聲明裡校正
Align fields in columns: 排列對齊
Indent(縮排)
1. Declarations within class body: 給類的body裡縮排
2. Declarations within enum declaration: 列舉裡縮排
3. Declarations within enum constants: 列舉裡的方法縮排
4. Declarations within annotation declaration: 註釋縮排
5. Statements within method/constructor body: 縮排方法體力的構造器
6. Statements whthin blocks: 區段裡面的陳述的縮排
7. Statements whthin ‘switch’ body: switch方法體內縮排
8. Statements whthin ‘case’ body: case裡的縮排
9. ‘break’ statements: 縮排break.
10. Empty lines: 空格排列的縮排

Braces
Class or interface declaration 修改介面後的大括號格式
Anonymous class declaration 修改例項化操作後的大括號格式
Constructor declaration 修改構造方法後的大括號格式
Method declaration 修改方法後大括號格式
Enum declaration 修改列舉大括號格式
Enum constant body 修改列舉常數大括號格式
Annotation type declaration 修改註釋型別後大括號格式
Blocks 修改for迴圈大括號格式
Blocks in case statement 修改case後大括號格式
Switch statement 修改switch後大括號格式
Array initializar 修改初始化陣列大括號格式
white space(空白)
Declarations
Classes


before opening brace of a class 普通類括號前要不要空格
before opening brace of an anonymous class 內部類括號前面要不要空格
before camma in implements clause 逗號前面要不要空格。
after comma in implements clause 逗號後面要不要空格。

Fields
befort comma in multiple field declarations 宣告一個變數的時候逗號前面要不要空格
after camma in multiple field declarations 宣告一個變數的時候逗號後面要不要空格
Local variables
before comma in multiple local declarations 本地類的宣告變數的時候逗號前面要不要空格
after comma in multiple local declarations 本地類的宣告變數的時候逗號後面要不要空格
Constructors
before opening parenthesis 方法名字前面的空格
after opening parenthesis 括號裡面型別前面的空格
before closing parenthesis 括號裡面宣告的末尾要不要空格
between empty parenthesis 宣告的空的方法裡面要不要空格
befor opening brace [throws] 丟擲異常末尾要不要空格
befor comma in parameters 方法裡面逗號前面是否要空格
after comma in parameters 變數與變數之間要不要空格
before comma in ‘throws’ clause 丟擲的異常與異常之間的逗號前面要不要空格
after comma in ‘throws’ clause 丟擲的一次與異常之間的逗號後面要不要空格。
Methods
before opening parenthesis 括號前面要不要空格
after opening parenthesis 方法在開啟括弧之後的空格
before closing parenthesis 方法在關閉括弧之前的空格
between empty parenthesis 方法在空的括弧之間的空格
before opening brace 方法在開啟支柱之前 的空格
before comma in parameters 在叄數中的逗點前的方法 空格
after comma in parameters 在叄數中的逗點後的方法 空格
before ellipsis in vararg parameters 在 vararg 叄數中的省略前的方法 空格
agter ellipsis in vararg parameters 在 vararg 叄數中的方法 agter 省略空格
before comma in ‘throws’ clause 逗點前的方法在 ” 丟 ” 條款空格
after comma in ‘throws’ clause 逗點後的方法在 ” 丟 ” 條款 空格
Labels//標籤
1:before colon(在冒號之前)
2:after colon(在冒號之後)
Annotations//註解
1:after(在最前往後縮)
2:before opening parenthesis (在開啟括弧之前)
3:after opening parenthesis (在開啟括弧之後)
4:before comma (在逗點之前)
5:after comma (在逗點之後)
6:before closing parenthesis (在關閉括弧之前)
Enum types (Enum 打字)
before opening brace in declaration (括號前是空格)
before comma between constants (逗號前是空格)
afte command (逗號後是空格)
before opening parenthesis in constant arguments (在開啟持續的爭論的括號之前空格)
after opening parenthesis in constant arguments (在開啟持續的爭論的括號之後空格)
between empty parenthesis in constant arguments (在空的括號之間空格)
before comma in constant arguments (在持續的爭論的逗點之前空格)
after comma in constant arguments (在持續的爭論的逗點之後空格)
before clsing parenthesis in constant arguments (在持續的爭論的 clsing 括弧之前空格)
befor opening brace of constant body (befor 開啟持續身體的支柱)
Annotation types//註解打字
1:before(以前)
2:after(在每行得最前)
3:before opening brace (大括號前單行往後縮)
4:before opening parenthesis in annotation type members (在註解型別成員中開啟括弧之前)
5:between parenthesis in annotation type members (在括弧之間在註解型別成員中)

Control statements
Blocks:
before opening brace: 大括號之前空格
after closing breace: 大括號之後空格

if else:
before opening parenthesis: 小括號之前空格
after opening parenthesis: 前小括號後空格
before closing parenthesis: 後小括號前空格

for:
before opening parenthesis: for後面空格
after opening parenthesis: 前小括號後空格
before closing parenthesis: 後小括號前空格
befor comma in initialization : 逗號空格
after comma in initialization: 逗號後空格
befor comma in increments : 加號(增量)前空格
after comma in increments : 加號(曾量)後空格
befor semicolon: 分號前空格
after semicolon: 分號後空格
befor colon: 冒號前空格
after colon: 冒號後空格
switch:
befor colon in case : case 後空格
befor colon in default: default (預設)後空格
befor opening brace: 大括號前空格
befor opening parenthesis: 小括號前空格
after opening parenthesis: 前小括號後空格
befor closing parenthesis: 後小括號前空格
throw^-^
before parenthesized expaessions 【在throws語句後括號表示式前加空格】
return
before parenthesized expaessions 【在return語句後括號表示式前加空格】
assert^-^
before colon 【在assert語句後面的冒號前加空格】
assert^-^after colon 【在assert語句後面的冒號後加空格】
catch
before opening parenthesis 【在catch語句後面的括號前加空格】
after opening parenthesis 【在catch語句後面的括號里語句開端加空格】
closing parenthesis 【在catch語句後面的括號里語句結束的地方加空格】
try-with-resources
before opening parenthesis 【在try語句後面的括號前面加空格】
after opening parenthesis 【在try語句後面的括號里語句開端加空格】
before semicolon 【在try語句後面的分號前加空格】
after semicolon 【在try語句後面分號後加空格】
before closing parenthesis 【在try語句後面的括號里語句結束的地方加空格】
synchronized^-^
before opening parenthesis 【在synchronized語句後面的括號前加空格】
after opening parenthesis 【在synchronized語句後面的括號里語句開端加空格】
before closing parenthesis 【在synchronized語句後面的括號里語句結束的地方加空格】
while-do while^-^
before opening parenthesis 【在while語句後面的括號前面加空格】
after opening parenthesis 【在while語句後面的括號里語句開端加空格】
before closing parenthesis 【在while語句後面的括號里語句結束的地方加空格】
Expressios(表示式的空格)
Function invocations ()
before opening parenthesis (在圓括號之前是否要加空格)
after opening parenthesis (在圓括號之後是否要加空格)
before closing parenthesis (在圓括號結束時是否要加空格)
between empty parenthesis (在圓括號之間是否要加空格)
before comma in method arguments (在方法引數逗號前是否要空格)
after comma in method arguments (在方法引數逗號後是否要空格)
before comma in object allocation arguments (在new 物件時引數逗號前是否加空格)
after comma in object allocation aruguments (在new 物件時引數逗號後是否加空格)
before comma in explicit constructor call (在構造方法裡的逗號前是否加空格)
after comma in explicit constructor call (在構造方法裡的逗號後是否加空格)
Assignments ()
before assignments operator (在任務操作員之前 或翻譯成在運算子號之前是否加空格)
after assignments operator 在任務操作員之後 或翻譯成在運算子號之後是否加空格();
Operators ()
before binary operators (在二進位的操作員之前 或在成對的資料之前)
after binary operators (在二進位的操作員之後 或在成對的資料之後)
before unary operators (在一元的操作員之前)
after unary operators (在一元的操作員之後)
before prefix operators (在字首操作員之前)
after prefix operators (在字首操作員之後)
before postfix operators (在詞尾操作員之前)
after postfix operators (在詞尾操作員之後)
parenthesized expressions
before opening parenthesis (-在開啟括弧之前)
after opening parenthesis (-在開啟括弧之後)
before closing parenthesis (在關閉括弧之前)
type casts
after opening parenthesis (-在開啟括弧之後)
before closing parenthesis (-在開啟括弧之前)
after closing parenthesis (在關閉括弧之後; );
Conditionals
before question mark (在問號之前)
after question mark ()在問號之後
before colon (在冒號之前)
after colon (在冒號之後)
Arrays
Declarations(陣列說明)
1:before opening bracket (陣列前括號往後縮)
2:between empty brackets (陣列前括號的單行後往後縮)
Allocation(陳列結構)
1:before opening bracket (陣列後括號往後縮)
2:after opening bracket (數組裡標明瞭行數的往單行前括號後縮)
3:before closing bracket (陣列標明行數的單行後括號往元素後縮)
4:between empty brackets (陣列沒有行數的單行後括號往後縮)
Initializers(陣列表)
1:before opening brace (所有大括號往後縮)
2:after opening brace (大括號裡有元素的,元素往後縮)
3:before opening brace (大括號裡有元素的,後行括號往後縮)
4:before comma (大括號裡有元素的,所有逗號往後縮)
5:after comma (大括號裡有元素的,所有元素往後縮)
6:between empty braces (空大括號的後行往後縮)
element access(陣列元素後繼函式)
1:before opening bracket (陣列括號往後縮)
2:after opening bracket (陣列前單行括號裡的下標往後縮)
3:before closing bracket (陣列後單行括號往後縮)
BlankLines( 空白的行)
Before package declaration 在包的上面空幾行
After package declaration 在包的下面空幾行
Before import declaration 在import的上面空幾行
Between import declaration 在import的之間空幾行
After import declaration 在import的下面空幾行
Between class declaration 在class的之間空幾行

Before first declaration 在類巢狀中第一個類上面空幾行
Before declaration of the same kind 在構造方法的上面空幾行
Bwfore member class declaration 在class成員宣告之前空幾行
Bwfore field declaration 在private 成員之前空幾行
Bwfore method declaration 在方法之前空幾行
At beginning of method body 在方法的第一行程式碼與方法之間空幾行
Number of empty lines to preserve 在兩個註釋間空幾行
New Lines( 新行操作)
In empty class body 在空類方法體裡面大括號之間換行
In empty anonymous class body 在空類方法體匿名裡面大括號之間換行
In empty method body 在空方法體裡面大括號之間換行
In empty block 在空迴圈裡面大括號之間換行
after labels 在迴圈標誌之後大括號之間回撤
In empty enum declaration 在空的列舉裡面大括號之間換行
In empty enum constant body 在空的列舉方法體裡面大括號之間換行
In empty annotation body 在空的接口裡面註釋方法
at end of file 結束的時候空一行
Array initializers 對陣列元素的開頭和結尾之間是否換行
Insert new line after opening brace of array initializers 對陣列元素開頭第一個括號後面是否要換行
Insert new line before closeing brace of array initializers 對陣列元素結尾的括號前面是否要換行
Empty statements 空宣告的操作
Put empty statements on new line 兩個空白的語句之間的換行 如:;;
Annotations 註釋操作
Insert new line after annotations on packages 在註釋包的後面插入一行
Insert new line after annotations on types 在註釋類的後面插入一行
Insert new line after annotations on fields 在註釋宣告的後面插入一行
Insert new line after annotations on methos 在註釋方法的後面插入一行
Insert new line after annotations on parameters 在註釋引數的後面插入一行
Insert new line after annotations on local varliables 在註釋區域性變數的後面插入一行
Genearl statements
一.General
1. Insert new line before ‘else’ in an ‘if’ statement (插入新的一行之前在“別人的“如果”的宣告)else 在上一個if括號之後的下一行
2.Insert new line before ‘catch’ int a ‘try’ statement(插入新的一行之前的捕捉的智力“試”的宣告)Catch 在上一個括號之後的下一行
3.Insert new line before ‘finally’ int a ‘try’ statement(插入新的一行在“終於”智力“試著說‘宣告)Finally 在上一個括號的下一行
4.Insert new line before ‘while’ int a ‘do’ statement(插入新的一行”而“智力前一個“做”的宣告)While 在上一個括號的下一行
二.’if else’
1.Keep ‘then’ statement on same line(‘然後’宣告在保持相同的路線)If後面只有一條語句且沒帶括號時和if放在一行
(1).Keep simple ‘if’ on one line(保持簡單的“如果”在一行)單個if後面只有一條語句且沒帶括號時和if放在一行
2.Keep ‘else’ statement on same line(保持相同的別人的宣告線)單個else後面只有一條語句時和else放在一行
3.Keep ‘else if’ on one line(保持“else if ‘一行。)If巢狀時else後的if在else的下一行且縮排
4.Keep ‘return’ or ‘throw’ clause on one line(保持‘迴歸”或“扔”條款在一行)單個if後面只有一條語句且帶括號時和if放在一行
Line Wrapping
Maximum line width 每行容納的字元個數。
Default indentation for wrapped lines 大致設定。預設壓痕為陣列的初始化。
Default indentation for array initializers lines給排列 initializers 的假設值壓痕排成一行。
Never join already wrapped lines 預設壓痕包裝線。
Prefer warpping outer expressions(keep nested expression on one line) 選擇外部表示式的包。

Annotations 註解 。
Element-value 元素-價值。
Class Declarations 階級宣告。
extends clause 繼承子句。
implements clause 工具子句。
constructor declarations 構造器宣告。
Parameters 引數。
throws clause 拋子句。
method declarations 方法宣告。
declaration 公告。
parameters 引數。
throws clause 拋子句。
enum declaration 列舉公告。
Constants 常量。
implements clause 工具子句。
constant arguments 不變的引數。
function calls 函式呼叫。
Arguments 引數。
qualified invocations 合格的祈禱。
explicit constructor invocations 明確的構造器祈禱。
object allocation arguments 目標分配引數。
qualified object allocation arguments 合格的目標分配引數。
expressions 表示式。
binary expressions 二進位制的表示式。
Conditionals 有條件的。
array initializers 排列初始化軟體。
Assignments 分配。
statements 宣告
compact if else 使裝滿如果別的。
try-with-resources 試驗支援資源。
multi catch 捕捉多個異常。

Line Wrapping policy 換行政策。
Do not wrap 不包。
Wrap where necessary 在必要時包裝。
Wrap first element, others where necessary 在必要時包裝第一個元素。
Wrap all elements, every element on a new line 包裝所有元素,每個元素在一個新的行。
Wrap all elements, indent all but the first element 包裝所有元素,但第一個元素縮排。
Wrap all elements, except first element if not necessary 包裝所有元素,如果不是必要的除了第一個元素。

Indentation policy : 縮排方針。
Default Indentation: 預設縮排。
indent on column : 在列上縮排。
Indent by column : 根據列縮排。
General settings(一般的設定)
Enable javadoc comment formatting 促使 javadoc 評論格式
Enable block comment formatting 促使區段評論格式
Enable line comment formatting 促使線評論格式
Enable header comment formatting 促使首領評論格式
Preserve white space between code and line comments 在密碼之間保護白色空間而且排成一行評論
Never indent line comments on first column 在第一個專欄上不要切割成鋸齒狀線評論
Never indent block comments on first column 在第一個專欄上不要切割成鋸齒狀區段評論
Never join line 從不接合處排成一行
javadoc comment settings javadoc 批評設定

Format HTML tags 格式 HTML 附以籤條
Format java code snippets inside ‘pre’tags 格式新型的計算機語言程式碼片斷在’之內pre’tags
Blank line before javadoc tags javadoc 前的空白的線附以籤條
Indent javadoc tags 契約 javadoc 附以籤條
Indent description after @param 在切割成鋸齒狀描述之後@param
New line after @param tags 新線在@之後param 附以籤條
/*and/on separate lines
/**和*/在分開的線上
Remove blank lines 除去空格線
3 Block comment settings區段評論設定
/and/on separate lines /*和*/在分開的線上
Remove blank lines 除去空格線
4 Line width線寬度
Maximum line width for comments: 最大線寬度為評論:
Clean Up
Code Organizing: 編碼組織
formatter: 格式化
remove trailing whitespace: 刪除行尾部的空格
all lines: 所有的類
ignore empty lines: 不顧其他的類
correct indentation: 正確縮排
The settings for the formatter can be changed on the formatter preference page:
給格式化的設定能在格式化上被改變偏愛頁
imports: 匯入
organize imports: 組織匯入
The settings for organizing imports can be changed on the Orgainze Imports preference page:
組織進口貨的設定能被改變
members: 成員
sort members: 種類成員
sort all members:
all: 所有
ignore fields and enum constants:
ignore: 不顧
fields: 田;場所
and: 與
enum: 列舉
constants: 不變的;連續發生的
Code Style
control statements (控制語句括號)
Use blocks in if/while/for/do statements
Always (總是)
Always except for single ‘return’ or ‘throw’ statements
(除了return ” 或 ” throw ” 以外 ” 總是加括號)
only if necessary (只有當如果必需的)
convert for loops to enhanced
Expressions (表示式)
Use parentheses in expressions (表示式使用圓括號)
Always (總是)
only if necessary (只有當如果必需的)
Variable declarations (變數宣告)
Use modifler ‘final’ where possible (哪裡使用修飾語 ” final ” )
private fields (私有的屬性)
parameter (引數屬性) local bariables(區域性的變數)
Member Accesses: 成員存取
Non static accesses: 非靜態存取
Use ‘this’ qualifier for field accesses: 強制性的在屬性前新增this.
Use ‘this’ qualifier for method accesses: 強制性的在方法裡取消this.
Static accesses: 靜態存取
Use declaring cass as qualifier: 使用宣佈 cass 為給與資格的人
Qualify field accesses: 給屬性添加個類名。
Qualify method accesses: 給方法里加上類名。
Change all accesses through subtypes: 在字類裡給父類的屬性加上類名。
Change all accesses through instances: 使用屬性的時候新增方法名。
Missing Code密碼不見的
Annotations註解
Add missing Annotations 增加不見的註解
‘@Override’
“@ 棄絕 ”
Implementations of interface methods (1.6 or higher) 介面方法的落實(1.6 或比較高的)
‘@Deprecated’”@ 宣告不贊成 ”
Potential programming problems 潛能規畫問題
Add serial version ID 增加連續的版本身份證
Generated 產生
Default(1L) 假設值(1L)
Unimplemented code 不實現密碼
Add unimplemented methods 增加不實現方法
The settings for the method stub to insert can be configured on the Code Templates preference page.
給方法的設定挖除斷株插入能在密碼型板上被配置偏愛頁。
Missing Code密碼不見的
Annotations 註解
Add missing Annotations 增加不見的註解
‘@Override’ ” @ 棄絕 ”
Implementations of interface methods (1.6 or higher) 介面方法的落實(1.6 或比較高的)
‘@Deprecated’” @ 宣告不贊成 ”
Potential programming problems 潛能規畫問題
Add serial version ID 增加連續的版本身份證
Generated 產生
Default(1L) 假設值(1L)
Unimplemented code 不實現密碼
Add unimplemented methods 增加不實現方法
The settings for the method stub to insert can be configured on the Code Templates preference page.
給方法的設定挖除斷株插入能在密碼型板上被配置偏愛頁。