2020
2121package net .sf .eclipsecs .core .transformer .ctransformerclasses ;
2222
23+ import java .util .Collections ;
24+ import java .util .List ;
2325import java .util .StringTokenizer ;
2426
2527import net .sf .eclipsecs .core .transformer .CTransformationClass ;
@@ -45,63 +47,52 @@ public FormatterConfiguration transformRule() {
4547 + "PLUS_ASSIGN, QUESTION, RCURLY, SL, SLIST, SL_ASSIGN, SR, SR_ASSIGN, STAR, STAR_ASSIGN" ;
4648 }
4749 final StringTokenizer token = new StringTokenizer (tokens , ", " );
48- String tok ;
4950
5051 while (token .hasMoreTokens ()) {
51- tok = token .nextToken ();
52- if ("ASSIGN" .equals (tok ) || "BAND_ASSIGN" .equals (tok ) || "BOR_ASSIGN" .equals (tok )
53- || "BSR_ASSIGN" .equals (tok ) || "BXOR_ASSIGN" .equals (tok ) || "DIV_ASSIGN" .equals (tok )
54- || "MINUS_ASSIGN" .equals (tok ) || "MOD_ASSIGN" .equals (tok ) || "PLUS_ASSIGN" .equals (tok )
55- || "SL_ASSIGN" .equals (tok ) || "SR_ASSIGN" .equals (tok ) || "STAR_ASSIGN" .equals (tok )) {
56- userFormatterSetting ("insert_space_after_assignment_operator" , "insert" );
57- userFormatterSetting ("insert_space_before_assignment_operator" , "insert" );
58- } else if (("BAND" .equals (tok ) || "BOR" .equals (tok ) || "BSR" .equals (tok ) || "BXOR" .equals (tok )
59- || "DIV" .equals (tok ) || "EQUAL" .equals (tok ) || "GE" .equals (tok ) || "GT" .equals (tok )
60- || "LAND" .equals (tok ) || "LE" .equals (tok ) || "LOR" .equals (tok ) || "LT" .equals (tok )
61- || "MINUS" .equals (tok ) || "MOD" .equals (tok ) || "NOT_EQUAL" .equals (tok )
62- || "PLUS" .equals (tok ) || "SL" .equals (tok ) || "SR" .equals (tok )
63- || "STAR" .equals (tok ))) {
64- userFormatterSetting ("insert_space_after_binary_operator" , "insert" );
65- userFormatterSetting ("insert_space_before_binary_operator" , "insert" );
66- } else if ("COLON" .equals (tok )) {
67- userFormatterSetting ("insert_space_before_colon_in_for" , "insert" );
68- userFormatterSetting ("insert_space_after_colon_in_for" , "insert" );
69- userFormatterSetting ("insert_space_before_colon_in_conditional" , "insert" );
70- userFormatterSetting ("insert_space_after_colon_in_conditional" , "insert" );
71- } else if ("QUESTION" .equals (tok )) {
72- userFormatterSetting ("insert_space_after_question_in_conditional" , "insert" );
73- userFormatterSetting ("insert_space_before_question_in_conditional" , "insert" );
74- } else if ("LCURLY" .equals (tok )) {
75- userFormatterSetting ("insert_space_before_opening_brace_in_type_declaration" , "insert" );
76- userFormatterSetting ("insert_space_after_opening_brace_in_array_initializer" , "insert" );
77- userFormatterSetting ("insert_space_before_opening_brace_in_annotation_type_declaration" ,
78- "insert" );
79- userFormatterSetting ("insert_space_before_opening_brace_in_block" , "insert" );
80- userFormatterSetting ("insert_space_before_opening_brace_in_method_declaration" , "insert" );
81- userFormatterSetting ("insert_space_before_opening_brace_in_enum_declaration" , "insert" );
82- userFormatterSetting ("insert_space_before_opening_brace_in_constructor_declaration" ,
83- "insert" );
84- userFormatterSetting ("insert_space_before_opening_brace_in_enum_constant" , "insert" );
85- userFormatterSetting ("insert_space_before_opening_brace_in_switch" , "insert" );
86- userFormatterSetting ("insert_space_before_opening_brace_in_anonymous_type_declaration" ,
87- "insert" );
88- userFormatterSetting ("insert_space_before_opening_brace_in_array_initializer" , "insert" );
89- } else if ("RCURLY" .equals (tok )) {
90- userFormatterSetting ("insert_space_after_closing_brace_in_block" , "insert" );
91- userFormatterSetting ("insert_space_before_closing_brace_in_array_initializer" , "insert" );
92- } else if ("LITERAL_CATCH" .equals (tok )) {
93- userFormatterSetting ("insert_space_before_opening_paren_in_catch" , "insert" );
94- } else if ("LITERAL_FOR" .equals (tok )) {
95- userFormatterSetting ("insert_space_before_opening_paren_in_for" , "insert" );
96- } else if ("LITERAL_IF" .equals (tok )) {
97- userFormatterSetting ("insert_space_before_opening_paren_in_if" , "insert" );
98- } else if ("LITERAL_RETURN" .equals (tok )) {
99- userFormatterSetting ("insert_space_before_parenthesized_expression_in_return" , "insert" );
100- } else if ("LITERAL_SYNCHRONIZED" .equals (tok )) {
101- userFormatterSetting ("insert_space_before_opening_paren_in_synchronized" , "insert" );
102- } else if ("LITERAL_WHILE" .equals (tok )) {
103- userFormatterSetting ("insert_space_before_opening_paren_in_while" , "insert" );
104- }
52+ List <String > settings = switch (token .nextToken ()) {
53+ case "ASSIGN" , "BAND_ASSIGN" , "BOR_ASSIGN" , "BSR_ASSIGN" ,
54+ "BXOR_ASSIGN" , "DIV_ASSIGN" , "MINUS_ASSIGN" , "MOD_ASSIGN" ,
55+ "PLUS_ASSIGN" , "SL_ASSIGN" , "SR_ASSIGN" , "STAR_ASSIGN" -> List .of (
56+ "insert_space_after_assignment_operator" ,
57+ "insert_space_before_assignment_operator" );
58+ case "BAND" , "BOR" , "BSR" , "BXOR" , "DIV" , "EQUAL" ,
59+ "GE" , "GT" , "LAND" , "LE" , "LOR" , "LT" , "MINUS" ,
60+ "MOD" , "NOT_EQUAL" , "PLUS" , "SL" , "SR" , "STAR" -> List .of (
61+ "insert_space_after_binary_operator" ,
62+ "insert_space_before_binary_operator" );
63+ case "COLON" -> List .of (
64+ "insert_space_before_colon_in_for" ,
65+ "insert_space_after_colon_in_for" ,
66+ "insert_space_before_colon_in_conditional" ,
67+ "insert_space_after_colon_in_conditional" );
68+ case "QUESTION" -> List .of (
69+ "insert_space_before_question_in_conditional" ,
70+ "insert_space_after_question_in_conditional" );
71+ case "LCURLY" -> List .of (
72+ "insert_space_before_opening_brace_in_type_declaration" ,
73+ "insert_space_after_opening_brace_in_array_initializer" ,
74+ "insert_space_before_opening_brace_in_annotation_type_declaration" ,
75+ "insert_space_before_opening_brace_in_block" ,
76+ "insert_space_before_opening_brace_in_method_declaration" ,
77+ "insert_space_before_opening_brace_in_enum_declaration" ,
78+ "insert_space_before_opening_brace_in_constructor_declaration" ,
79+ "insert_space_before_opening_brace_in_enum_constant" ,
80+ "insert_space_before_opening_brace_in_switch" ,
81+ "insert_space_before_opening_brace_in_anonymous_type_declaration" ,
82+ "insert_space_before_opening_brace_in_array_initializer" );
83+ case "RCURLY" -> List .of (
84+ "insert_space_after_closing_brace_in_block" ,
85+ "insert_space_before_closing_brace_in_array_initializer" );
86+ case "LITERAL_CATCH" -> List .of ("insert_space_before_opening_paren_in_catch" );
87+ case "LITERAL_FOR" -> List .of ("insert_space_before_opening_paren_in_for" );
88+ case "LITERAL_IF" -> List .of ("insert_space_before_opening_paren_in_if" );
89+ case "LITERAL_RETURN" -> List .of ("insert_space_before_parenthesized_expression_in_return" );
90+ case "LITERAL_SYNCHRONIZED" -> List .of (
91+ "insert_space_before_opening_paren_in_synchronized" );
92+ case "LITERAL_WHILE" -> List .of ("insert_space_before_opening_paren_in_while" );
93+ default -> Collections .emptyList ();
94+ };
95+ settings .forEach (setting -> userFormatterSetting (setting , "insert" ));
10596 }
10697 return getFormatterSetting ();
10798 }
0 commit comments