Lines 829-835
Link Here
|
829 |
} |
829 |
} |
830 |
return; |
830 |
return; |
831 |
} |
831 |
} |
832 |
this.scribe.printModifiers(); |
832 |
|
|
|
833 |
/* |
834 |
* Print comments to get proper line number |
835 |
*/ |
836 |
this.scribe.printComment(); |
837 |
final int line = scribe.line; |
838 |
|
839 |
this.scribe.printModifiers(); |
833 |
/* |
840 |
/* |
834 |
* Type name |
841 |
* Type name |
835 |
*/ |
842 |
*/ |
Lines 916-921
Link Here
|
916 |
*/ |
923 |
*/ |
917 |
String class_declaration_brace = this.preferences.type_declaration_brace_position; |
924 |
String class_declaration_brace = this.preferences.type_declaration_brace_position; |
918 |
|
925 |
|
|
|
926 |
formatLeftCurlyBrace(line, this.preferences.type_declaration_brace_position); |
919 |
formatTypeOpeningBrace(class_declaration_brace, this.preferences.insert_space_before_type_open_brace, typeDeclaration); |
927 |
formatTypeOpeningBrace(class_declaration_brace, this.preferences.insert_space_before_type_open_brace, typeDeclaration); |
920 |
|
928 |
|
921 |
if (this.preferences.indent_body_declarations_compare_to_type_header) { |
929 |
if (this.preferences.indent_body_declarations_compare_to_type_header) { |
Lines 1423-1428
Link Here
|
1423 |
this.scribe.printTrailingComment(); |
1431 |
this.scribe.printTrailingComment(); |
1424 |
} |
1432 |
} |
1425 |
|
1433 |
|
|
|
1434 |
private void formatLeftCurlyBrace(final int line, final String bracePosition) { |
1435 |
/* |
1436 |
* deal with (quite unexpected) comments right before lcurly |
1437 |
*/ |
1438 |
this.scribe.printComment(); |
1439 |
if (DefaultCodeFormatterConstants.NEXT_LINE_ON_WRAP.equals(bracePosition) |
1440 |
&& (scribe.line > line || scribe.column >= this.preferences.page_width)) |
1441 |
{ |
1442 |
scribe.printNewLine(); |
1443 |
} |
1444 |
} |
1445 |
|
1426 |
private void formatStatements(BlockScope scope, final Statement[] statements, boolean insertNewLineAfterLastStatement) { |
1446 |
private void formatStatements(BlockScope scope, final Statement[] statements, boolean insertNewLineAfterLastStatement) { |
1427 |
int statementsLength = statements.length; |
1447 |
int statementsLength = statements.length; |
1428 |
for (int i = 0; i < statementsLength; i++) { |
1448 |
for (int i = 0; i < statementsLength; i++) { |
Lines 2813-2819
Link Here
|
2813 |
public boolean visit(ForStatement forStatement, BlockScope scope) { |
2833 |
public boolean visit(ForStatement forStatement, BlockScope scope) { |
2814 |
|
2834 |
|
2815 |
this.scribe.printNextToken(TerminalTokens.TokenNamefor); |
2835 |
this.scribe.printNextToken(TerminalTokens.TokenNamefor); |
2816 |
this.scribe.printNextToken(TerminalTokens.TokenNameLPAREN, this.preferences.insert_space_before_for_paren); |
2836 |
final int line = scribe.line; |
|
|
2837 |
this.scribe.printNextToken(TerminalTokens.TokenNameLPAREN, this.preferences.insert_space_before_for_paren); |
2817 |
|
2838 |
|
2818 |
if (this.preferences.insert_space_in_for_parens) { |
2839 |
if (this.preferences.insert_space_in_for_parens) { |
2819 |
this.scribe.space(); |
2840 |
this.scribe.space(); |
Lines 2864-2869
Link Here
|
2864 |
final Statement action = forStatement.action; |
2885 |
final Statement action = forStatement.action; |
2865 |
if (action != null) { |
2886 |
if (action != null) { |
2866 |
if (action instanceof Block) { |
2887 |
if (action instanceof Block) { |
|
|
2888 |
formatLeftCurlyBrace(line, this.preferences.block_brace_position); |
2867 |
action.traverse(this, scope); |
2889 |
action.traverse(this, scope); |
2868 |
} else if (action instanceof EmptyStatement && !this.preferences.put_empty_statement_on_new_line) { |
2890 |
} else if (action instanceof EmptyStatement && !this.preferences.put_empty_statement_on_new_line) { |
2869 |
action.traverse(this, scope); |
2891 |
action.traverse(this, scope); |
Lines 2895-2901
Link Here
|
2895 |
public boolean visit(IfStatement ifStatement, BlockScope scope) { |
2917 |
public boolean visit(IfStatement ifStatement, BlockScope scope) { |
2896 |
|
2918 |
|
2897 |
this.scribe.printNextToken(TerminalTokens.TokenNameif); |
2919 |
this.scribe.printNextToken(TerminalTokens.TokenNameif); |
2898 |
this.scribe.printNextToken(TerminalTokens.TokenNameLPAREN, this.preferences.insert_space_before_if_condition); |
2920 |
final int line = scribe.line; |
|
|
2921 |
this.scribe.printNextToken(TerminalTokens.TokenNameLPAREN, this.preferences.insert_space_before_if_condition); |
2899 |
if (this.preferences.insert_space_in_if_condition) { |
2922 |
if (this.preferences.insert_space_in_if_condition) { |
2900 |
this.scribe.space(); |
2923 |
this.scribe.space(); |
2901 |
} |
2924 |
} |
Lines 2916-2921
Link Here
|
2916 |
formatGuardClauseBlock((Block) thenStatement, scope); |
2939 |
formatGuardClauseBlock((Block) thenStatement, scope); |
2917 |
} else { |
2940 |
} else { |
2918 |
if (thenStatement instanceof Block) { |
2941 |
if (thenStatement instanceof Block) { |
|
|
2942 |
formatLeftCurlyBrace(line, this.preferences.block_brace_position); |
2919 |
thenStatement.traverse(this, scope); |
2943 |
thenStatement.traverse(this, scope); |
2920 |
} else { |
2944 |
} else { |
2921 |
this.scribe.printNewLine(); |
2945 |
this.scribe.printNewLine(); |
Lines 3196-3202
Link Here
|
3196 |
this.scribe.printTrailingComment(); |
3220 |
this.scribe.printTrailingComment(); |
3197 |
return false; |
3221 |
return false; |
3198 |
} |
3222 |
} |
3199 |
this.scribe.printModifiers(); |
3223 |
|
|
|
3224 |
/* |
3225 |
* Print comments to get proper line number |
3226 |
*/ |
3227 |
this.scribe.printComment(); |
3228 |
final int line = scribe.line; |
3229 |
|
3230 |
this.scribe.printModifiers(); |
3200 |
this.scribe.space(); |
3231 |
this.scribe.space(); |
3201 |
|
3232 |
|
3202 |
/* |
3233 |
/* |
Lines 3243-3248
Link Here
|
3243 |
* Method body |
3274 |
* Method body |
3244 |
*/ |
3275 |
*/ |
3245 |
String method_declaration_brace = this.preferences.method_declaration_brace_position; |
3276 |
String method_declaration_brace = this.preferences.method_declaration_brace_position; |
|
|
3277 |
formatLeftCurlyBrace(line, method_declaration_brace); |
3246 |
formatOpeningBrace(method_declaration_brace, this.preferences.insert_space_before_method_open_brace); |
3278 |
formatOpeningBrace(method_declaration_brace, this.preferences.insert_space_before_method_open_brace); |
3247 |
final int numberOfBlankLinesAtBeginningOfMethodBody = this.preferences.number_of_blank_lines_to_insert_at_beginning_of_method_body; |
3279 |
final int numberOfBlankLinesAtBeginningOfMethodBody = this.preferences.number_of_blank_lines_to_insert_at_beginning_of_method_body; |
3248 |
if (numberOfBlankLinesAtBeginningOfMethodBody > 0) { |
3280 |
if (numberOfBlankLinesAtBeginningOfMethodBody > 0) { |
Lines 3926-3932
Link Here
|
3926 |
public boolean visit(WhileStatement whileStatement, BlockScope scope) { |
3958 |
public boolean visit(WhileStatement whileStatement, BlockScope scope) { |
3927 |
|
3959 |
|
3928 |
this.scribe.printNextToken(TerminalTokens.TokenNamewhile); |
3960 |
this.scribe.printNextToken(TerminalTokens.TokenNamewhile); |
3929 |
this.scribe.printNextToken(TerminalTokens.TokenNameLPAREN, this.preferences.insert_space_before_while_condition); |
3961 |
final int line = scribe.line; |
|
|
3962 |
this.scribe.printNextToken(TerminalTokens.TokenNameLPAREN, this.preferences.insert_space_before_while_condition); |
3930 |
|
3963 |
|
3931 |
if (this.preferences.insert_space_in_while_condition) { |
3964 |
if (this.preferences.insert_space_in_while_condition) { |
3932 |
this.scribe.space(); |
3965 |
this.scribe.space(); |
Lines 3938-3943
Link Here
|
3938 |
final Statement action = whileStatement.action; |
3971 |
final Statement action = whileStatement.action; |
3939 |
if (action != null) { |
3972 |
if (action != null) { |
3940 |
if (action instanceof Block) { |
3973 |
if (action instanceof Block) { |
|
|
3974 |
formatLeftCurlyBrace(line, this.preferences.block_brace_position); |
3941 |
action.traverse(this, scope); |
3975 |
action.traverse(this, scope); |
3942 |
} else { |
3976 |
} else { |
3943 |
this.scribe.printNewLine(); |
3977 |
this.scribe.printNewLine(); |