天天看點

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 附以簽條

on separate lines

/**和*/在分開的線上

Remove blank lines 除去空格線

3  Block comment settings區段評論設定

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.

給方法的設定挖除斷株插入能在密碼型闆上被配置偏愛頁。