Skip to content

Commit

Permalink
Handle Java's synchronized(foo){ ... } construction
Browse files Browse the repository at this point in the history
Add a new CT for `synchronized` for java, which behaves like a vanilla
if/for/while/switch construction if a parenthesis follows the keyword
(otherwise, tokenize_cleanup reverts it to being a qualifier). This
adds options `nl_synchronized_brace`, `nl_before_synchronized`, and
`nl_after_synchronized`, which work in the obvious way. Since
`synchronized` requires braces, no special handling of braceless code
is necessary.

Also update defaults.cfg by update-default-cfg.sh to appropriately
handle these new options and add tests 80060 and 80061.
  • Loading branch information
Gilles committed Jul 10, 2015
1 parent b6593c1 commit 55581c4
Show file tree
Hide file tree
Showing 19 changed files with 261 additions and 19 deletions.
73 changes: 68 additions & 5 deletions documentation/htdocs/config.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Uncrustify 0.60.194-g5b1183a
# Uncrustify 0.61
#
# General options
#
Expand All @@ -18,11 +18,20 @@ string_escape_char Number
string_escape_char2 Number
Alternate string escape char for Pawn. Only works right before the quote char.

string_replace_tab_chars { False, True }
Replace tab characters found in string literals with the escape sequence \t instead.

tok_split_gte { False, True }
Allow interpreting '>=' and '>>=' as part of a template in 'void f(list<list<B>>=val);'.
If true (default), 'assert(x<0 && y>=3)' will be broken.
Improvements to template detection may make this option obsolete.

disable_processing_cmt String
Override the default ' *INDENT-OFF*' in comments for disabling processing of part of the file.

enable_processing_cmt String
Override the default ' *INDENT-ON*' in comments for enabling processing of part of the file.

utf8_bom { Ignore, Add, Remove, Force }
Control what to do with the UTF-8 BOM (recommend 'remove')

Expand Down Expand Up @@ -85,6 +94,10 @@ indent_paren_open_brace { False, True }
indent_namespace { False, True }
Whether the 'namespace' body is indented

indent_namespace_single_indent { False, True }
Only indent one namespace and no sub-namespaces.
Requires indent_namespace=true.

indent_namespace_level Number
The number of spaces to indent a namespace block

Expand All @@ -101,6 +114,10 @@ indent_class { False, True }
indent_class_colon { False, True }
Whether to indent the stuff after a leading base class colon

indent_class_on_colon { False, True }
Indent based on a class colon instead of the stuff after the colon.
Requires indent_class_colon=true. Default=false

indent_constr_colon { False, True }
Whether to indent the stuff after a leading class initializer colon

Expand All @@ -121,6 +138,10 @@ indent_var_def_blk Number
indent_var_def_cont { False, True }
Indent continued variable declarations instead of aligning.

indent_shift { False, True }
Indent continued shift expressions ('<<' and '>>') instead of aligning.
Turn align_left_shift off when enabling this.

indent_func_def_force_col1 { False, True }
True: force indentation of function definition to start in column 1
False: use the default behavior
Expand Down Expand Up @@ -249,6 +270,12 @@ indent_oc_block_msg_from_caret { False, True }
indent_oc_block_msg_from_brace { False, True }
If indent_oc_block_msg and this option are on, blocks will be indented from where the brace is.

indent_min_vbrace_open Number
When identing after virtual brace open and newline add further spaces to reach this min. indent.

indent_vbrace_open_on_tabstop { False, True }
TRUE: When identing after virtual brace open and newline add further spaces after regular indent to reach next tabstop.

#
# Spacing options
#
Expand All @@ -274,6 +301,9 @@ sp_before_assign { Ignore, Add, Remove, Force }
sp_after_assign { Ignore, Add, Remove, Force }
Add or remove space after assignment operator '=', '+=', etc. Overrides sp_assign.

sp_enum_paren { Ignore, Add, Remove, Force }
Add or remove space in 'NS_ENUM ('

sp_enum_assign { Ignore, Add, Remove, Force }
Add or remove space around assignment '=' in enum

Expand Down Expand Up @@ -326,6 +356,9 @@ sp_between_ptr_star { Ignore, Add, Remove, Force }
sp_after_ptr_star { Ignore, Add, Remove, Force }
Add or remove space after pointer star '*', if followed by a word.

sp_after_ptr_star_qualifier { Ignore, Add, Remove, Force }
Add or remove space after pointer star '*', if followed by a qualifier.

sp_after_ptr_star_func { Ignore, Add, Remove, Force }
Add or remove space after a pointer star '*', if followed by a func proto/def.

Expand Down Expand Up @@ -384,7 +417,7 @@ sp_permit_cpp11_shift { False, True }
sp_angle_shift cannot remove the space without this option.

sp_before_sparen { Ignore, Add, Remove, Force }
Add or remove space before '(' of 'if', 'for', 'switch', and 'while'
Add or remove space before '(' of 'if', 'for', 'switch', 'while', etc.

sp_inside_sparen { Ignore, Add, Remove, Force }
Add or remove space inside if-condition '(' and ')'
Expand Down Expand Up @@ -443,6 +476,15 @@ sp_after_comma { Ignore, Add, Remove, Force }
sp_before_comma { Ignore, Add, Remove, Force }
Add or remove space before ','

sp_after_mdatype_commas { Ignore, Add, Remove, Force }
Add or remove space between ',' and ']' in multidimensional array type 'int[,,]'

sp_before_mdatype_commas { Ignore, Add, Remove, Force }
Add or remove space between '[' and ',' in multidimensional array type 'int[,,]'

sp_between_mdatype_commas { Ignore, Add, Remove, Force }
Add or remove space between ',' in multidimensional array type 'int[,,]'

sp_paren_comma { Ignore, Add, Remove, Force }
Add or remove space between an open paren and comma: '(,' vs '( ,'

Expand Down Expand Up @@ -526,6 +568,9 @@ sp_square_fparen { Ignore, Add, Remove, Force }
sp_fparen_brace { Ignore, Add, Remove, Force }
Add or remove space between ')' and '{' of function

sp_fparen_dbrace { Ignore, Add, Remove, Force }
Java: Add or remove space between ')' and '{{' of double brace initializer.

sp_func_call_paren { Ignore, Add, Remove, Force }
Add or remove space between function name and '(' on function calls

Expand Down Expand Up @@ -744,12 +789,18 @@ sp_extern_paren { Ignore, Add, Remove, Force }
sp_cmt_cpp_start { Ignore, Add, Remove, Force }
Control the space after the opening of a C++ comment '// A' vs '//A'

sp_cmt_cpp_doxygen { False, True }
TRUE: If space is added with sp_cmt_cpp_start, do it after doxygen sequences like '///', '///<', '//!' and '//!<'.

sp_endif_cmt { Ignore, Add, Remove, Force }
Controls the spaces between #else or #endif and a trailing comment

sp_after_new { Ignore, Add, Remove, Force }
Controls the spaces after 'new', 'delete', and 'delete[]'

sp_between_new_paren { Ignore, Add, Remove, Force }
Controls the spaces between new and '(' in 'new()'

sp_before_tr_emb_cmt { Ignore, Add, Remove, Force }
Controls the spaces before a trailing or embedded comment

Expand Down Expand Up @@ -1093,6 +1144,9 @@ nl_brace_while { Ignore, Add, Remove, Force }
nl_switch_brace { Ignore, Add, Remove, Force }
Add or remove newline between 'switch' and '{'

nl_synchronized_brace { Ignore, Add, Remove, Force }
Add or remove newline between 'synchronized' and '{'

nl_multi_line_cond { False, True }
Add a newline between ')' and '{' if the ')' is on a different line than the if/for/etc.
Overrides nl_for_brace, nl_if_brace, nl_switch_brace, nl_while_switch, and nl_catch_brace.
Expand Down Expand Up @@ -1199,6 +1253,9 @@ nl_return_expr { Ignore, Add, Remove, Force }
nl_after_semicolon { False, True }
Whether to put a newline after semicolons, except in 'for' statements

nl_paren_dbrace_open { Ignore, Add, Remove, Force }
Java: Control the newline between the ')' and '{{' of the double brace initializer.

nl_after_brace_open { False, True }
Whether to put a newline after brace open.
This also adds a newline before the matching brace close.
Expand Down Expand Up @@ -1231,7 +1288,7 @@ nl_define_macro { False, True }
Whether to alter newlines in '#define' macros

nl_squeeze_ifdef { False, True }
Whether to not put blanks after '#ifxx', '#elxx', or before '#endif'
Whether to not put blanks after '#ifxx', '#elxx', or before '#endif'. Does not affect the whole-file #ifdef.

nl_before_if { Ignore, Add, Remove, Force }
Add or remove blank line before 'if'
Expand All @@ -1257,6 +1314,12 @@ nl_before_switch { Ignore, Add, Remove, Force }
nl_after_switch { Ignore, Add, Remove, Force }
Add or remove blank line after 'switch' statement

nl_before_synchronized { Ignore, Add, Remove, Force }
Add or remove blank line before 'synchronized'

nl_after_synchronized { Ignore, Add, Remove, Force }
Add or remove blank line after 'synchronized' statement

nl_before_do { Ignore, Add, Remove, Force }
Add or remove blank line before 'do'

Expand Down Expand Up @@ -1378,8 +1441,8 @@ nl_before_cpp_comment Number
nl_after_multiline_comment { False, True }
Whether to force a newline after a multi-line comment.

nl_after_label_colon { False, True}
Whether to force a newline after a label (outside of a switch, as for goto)
nl_after_label_colon { False, True }
Whether to force a newline after a label's colon.

nl_after_struct Number
The number of newlines after '}' or ';' of a struct/enum/union definition
Expand Down
3 changes: 3 additions & 0 deletions documentation/paren_stack.txt
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ WHILE-PAREN1, WHILE-BRACE2
switch
SWITCH-PAREN1, SWITCH-BRACE2

synchronized
SYNCHRONIZED-PAREN1

do/while
DO-BRACE_DO, DO-WHILE, WHILE-PAREN2

Expand Down
55 changes: 49 additions & 6 deletions etc/defaults.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,20 @@ string_escape_char = 92 # number
# Alternate string escape char for Pawn. Only works right before the quote char.
string_escape_char2 = 0 # number

# Replace tab characters found in string literals with the escape sequence \t instead.
string_replace_tab_chars = false # false/true

# Allow interpreting '>=' and '>>=' as part of a template in 'void f(list<list<B>>=val);'.
# If true (default), 'assert(x<0 && y>=3)' will be broken.
# Improvements to template detection may make this option obsolete.
tok_split_gte = false # false/true

# Override the default ' *INDENT-OFF*' in comments for disabling processing of part of the file.
disable_processing_cmt = "" # string

# Override the default ' *INDENT-ON*' in comments for enabling processing of part of the file.
enable_processing_cmt = "" # string

# Control what to do with the UTF-8 BOM (recommend 'remove')
utf8_bom = ignore # ignore/add/remove/force

Expand Down Expand Up @@ -86,7 +95,7 @@ indent_paren_open_brace = false # false/true
# Whether the 'namespace' body is indented
indent_namespace = false # false/true

# Only indent one namespace and no sub-namepaces.
# Only indent one namespace and no sub-namespaces.
# Requires indent_namespace=true.
indent_namespace_single_indent = false # false/true

Expand All @@ -106,8 +115,8 @@ indent_class = false # false/true
# Whether to indent the stuff after a leading base class colon
indent_class_colon = false # false/true

# Indent based on a class colon instead of the stuff after the colon.
# Requires indent_class_colon=true.
# Indent based on a class colon instead of the stuff after the colon.
# Requires indent_class_colon=true. Default=false
indent_class_on_colon = false # false/true

# Whether to indent the stuff after a leading class initializer colon
Expand All @@ -129,6 +138,10 @@ indent_var_def_blk = 0 # number
# Indent continued variable declarations instead of aligning.
indent_var_def_cont = false # false/true

# Indent continued shift expressions ('<<' and '>>') instead of aligning.
# Turn align_left_shift off when enabling this.
indent_shift = false # false/true

# True: force indentation of function definition to start in column 1
# False: use the default behavior
indent_func_def_force_col1 = false # false/true
Expand Down Expand Up @@ -257,6 +270,12 @@ indent_oc_block_msg_from_caret = false # false/true
# If indent_oc_block_msg and this option are on, blocks will be indented from where the brace is.
indent_oc_block_msg_from_brace = false # false/true

# When identing after virtual brace open and newline add further spaces to reach this min. indent.
indent_min_vbrace_open = 0 # number

# TRUE: When identing after virtual brace open and newline add further spaces after regular indent to reach next tabstop.
indent_vbrace_open_on_tabstop = false # false/true

#
# Spacing options
#
Expand Down Expand Up @@ -397,7 +416,7 @@ sp_angle_shift = add # ignore/add/remove/force
# sp_angle_shift cannot remove the space without this option.
sp_permit_cpp11_shift = false # false/true

# Add or remove space before '(' of 'if', 'for', 'switch', and 'while'
# Add or remove space before '(' of 'if', 'for', 'switch', 'while', etc.
sp_before_sparen = ignore # ignore/add/remove/force

# Add or remove space inside if-condition '(' and ')'
Expand Down Expand Up @@ -457,6 +476,15 @@ sp_after_comma = ignore # ignore/add/remove/force
# Add or remove space before ','
sp_before_comma = remove # ignore/add/remove/force

# Add or remove space between ',' and ']' in multidimensional array type 'int[,,]'
sp_after_mdatype_commas = ignore # ignore/add/remove/force

# Add or remove space between '[' and ',' in multidimensional array type 'int[,,]'
sp_before_mdatype_commas = ignore # ignore/add/remove/force

# Add or remove space between ',' in multidimensional array type 'int[,,]'
sp_between_mdatype_commas = ignore # ignore/add/remove/force

# Add or remove space between an open paren and comma: '(,' vs '( ,'
sp_paren_comma = force # ignore/add/remove/force

Expand Down Expand Up @@ -760,12 +788,18 @@ sp_extern_paren = ignore # ignore/add/remove/force
# Control the space after the opening of a C++ comment '// A' vs '//A'
sp_cmt_cpp_start = ignore # ignore/add/remove/force

# TRUE: If space is added with sp_cmt_cpp_start, do it after doxygen sequences like '///', '///<', '//!' and '//!<'.
sp_cmt_cpp_doxygen = false # false/true

# Controls the spaces between #else or #endif and a trailing comment
sp_endif_cmt = ignore # ignore/add/remove/force

# Controls the spaces after 'new', 'delete', and 'delete[]'
sp_after_new = ignore # ignore/add/remove/force

# Controls the spaces between new and '(' in 'new()'
sp_between_new_paren = ignore # ignore/add/remove/force

# Controls the spaces before a trailing or embedded comment
sp_before_tr_emb_cmt = ignore # ignore/add/remove/force

Expand Down Expand Up @@ -1107,6 +1141,9 @@ nl_brace_while = ignore # ignore/add/remove/force
# Add or remove newline between 'switch' and '{'
nl_switch_brace = ignore # ignore/add/remove/force

# Add or remove newline between 'synchronized' and '{'
nl_synchronized_brace = ignore # ignore/add/remove/force

# Add a newline between ')' and '{' if the ')' is on a different line than the if/for/etc.
# Overrides nl_for_brace, nl_if_brace, nl_switch_brace, nl_while_switch, and nl_catch_brace.
nl_multi_line_cond = false # false/true
Expand Down Expand Up @@ -1247,7 +1284,7 @@ nl_brace_struct_var = ignore # ignore/add/remove/force
# Whether to alter newlines in '#define' macros
nl_define_macro = false # false/true

# Whether to not put blanks after '#ifxx', '#elxx', or before '#endif'
# Whether to not put blanks after '#ifxx', '#elxx', or before '#endif'. Does not affect the whole-file #ifdef.
nl_squeeze_ifdef = false # false/true

# Add or remove blank line before 'if'
Expand All @@ -1274,6 +1311,12 @@ nl_before_switch = ignore # ignore/add/remove/force
# Add or remove blank line after 'switch' statement
nl_after_switch = ignore # ignore/add/remove/force

# Add or remove blank line before 'synchronized'
nl_before_synchronized = ignore # ignore/add/remove/force

# Add or remove blank line after 'synchronized' statement
nl_after_synchronized = ignore # ignore/add/remove/force

# Add or remove blank line before 'do'
nl_before_do = ignore # ignore/add/remove/force

Expand Down Expand Up @@ -1395,7 +1438,7 @@ nl_before_cpp_comment = 0 # number
# Whether to force a newline after a multi-line comment.
nl_after_multiline_comment = false # false/true

# Whether to force a newline after a label (outside of a switch, as for goto)
# Whether to force a newline after a label's colon.
nl_after_label_colon = false # false/true

# The number of newlines after '}' or ';' of a struct/enum/union definition
Expand Down
4 changes: 4 additions & 0 deletions src/indent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,9 @@ static int token_indent(c_token_t type)
case CT_ELSEIF:
return(8);

case CT_SYNCHRONIZED:
return(13);

default:
return(0);
}
Expand Down Expand Up @@ -1032,6 +1035,7 @@ void indent_text(void)
(pc->parent_type == CT_WHILE) ||
(pc->parent_type == CT_USING_STMT) ||
(pc->parent_type == CT_SWITCH) ||
(pc->parent_type == CT_SYNCHRONIZED) ||
(pc->parent_type == CT_FOR))
{
if (parent_token_indent != 0)
Expand Down
4 changes: 3 additions & 1 deletion src/keywords.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,8 @@ static const chunk_tag_t keywords[] =
{ "struct", CT_STRUCT, LANG_C | LANG_CPP | LANG_CS | LANG_D | LANG_VALA },
{ "super", CT_SUPER, LANG_D | LANG_JAVA | LANG_ECMA },
{ "switch", CT_SWITCH, LANG_ALL }, // PAWN
{ "synchronized", CT_QUALIFIER, LANG_D | LANG_JAVA | LANG_ECMA },
{ "synchronized", CT_QUALIFIER, LANG_D | LANG_ECMA },
{ "synchronized", CT_SYNCHRONIZED, LANG_JAVA },
{ "tagof", CT_TAGOF, LANG_PAWN }, // PAWN
{ "template", CT_TEMPLATE, LANG_CPP | LANG_D },
{ "this", CT_THIS, LANG_CPP | LANG_CS | LANG_D | LANG_JAVA | LANG_VALA | LANG_ECMA },
Expand Down Expand Up @@ -518,6 +519,7 @@ pattern_class get_token_pattern_class(c_token_t tok)
case CT_SWITCH:
case CT_FOR:
case CT_WHILE:
case CT_SYNCHRONIZED:
case CT_USING_STMT:
case CT_LOCK:
case CT_D_WITH:
Expand Down
Loading

0 comments on commit 55581c4

Please sign in to comment.