天天看点

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.

给方法的设定挖除断株插入能在密码型板上被配置偏爱页。