diff --git a/bundles/org.eclipse.ui.ide/.settings/org.eclipse.jdt.core.prefs b/bundles/org.eclipse.ui.ide/.settings/org.eclipse.jdt.core.prefs
index 809cfe8885a..a60a4260e58 100644
--- a/bundles/org.eclipse.ui.ide/.settings/org.eclipse.jdt.core.prefs
+++ b/bundles/org.eclipse.ui.ide/.settings/org.eclipse.jdt.core.prefs
@@ -123,22 +123,38 @@ org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning
org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning
org.eclipse.jdt.core.compiler.release=enabled
org.eclipse.jdt.core.compiler.source=17
+org.eclipse.jdt.core.formatter.align_assignment_statements_on_columns=false
org.eclipse.jdt.core.formatter.align_fields_grouping_blank_lines=2147483647
+org.eclipse.jdt.core.formatter.align_selector_in_method_invocation_on_expression_first_line=true
org.eclipse.jdt.core.formatter.align_type_members_on_columns=false
+org.eclipse.jdt.core.formatter.align_variable_declarations_on_columns=false
+org.eclipse.jdt.core.formatter.align_with_spaces=false
org.eclipse.jdt.core.formatter.alignment_for_additive_operator=16
+org.eclipse.jdt.core.formatter.alignment_for_annotations_on_enum_constant=49
+org.eclipse.jdt.core.formatter.alignment_for_annotations_on_field=49
+org.eclipse.jdt.core.formatter.alignment_for_annotations_on_local_variable=49
+org.eclipse.jdt.core.formatter.alignment_for_annotations_on_method=49
+org.eclipse.jdt.core.formatter.alignment_for_annotations_on_package=49
+org.eclipse.jdt.core.formatter.alignment_for_annotations_on_parameter=0
+org.eclipse.jdt.core.formatter.alignment_for_annotations_on_type=49
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=16
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_annotation=0
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_enum_constant=16
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_explicit_constructor_call=16
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_method_invocation=16
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_qualified_allocation_expression=16
+org.eclipse.jdt.core.formatter.alignment_for_assertion_message=16
org.eclipse.jdt.core.formatter.alignment_for_assignment=0
org.eclipse.jdt.core.formatter.alignment_for_bitwise_operator=16
org.eclipse.jdt.core.formatter.alignment_for_compact_if=16
+org.eclipse.jdt.core.formatter.alignment_for_compact_loops=16
org.eclipse.jdt.core.formatter.alignment_for_conditional_expression=80
+org.eclipse.jdt.core.formatter.alignment_for_conditional_expression_chain=0
org.eclipse.jdt.core.formatter.alignment_for_enum_constants=16
org.eclipse.jdt.core.formatter.alignment_for_expressions_in_array_initializer=16
org.eclipse.jdt.core.formatter.alignment_for_expressions_in_for_loop_header=0
+org.eclipse.jdt.core.formatter.alignment_for_expressions_in_switch_case_with_arrow=16
+org.eclipse.jdt.core.formatter.alignment_for_expressions_in_switch_case_with_colon=16
org.eclipse.jdt.core.formatter.alignment_for_logical_operator=16
org.eclipse.jdt.core.formatter.alignment_for_method_declaration=0
org.eclipse.jdt.core.formatter.alignment_for_module_statements=16
@@ -147,19 +163,28 @@ org.eclipse.jdt.core.formatter.alignment_for_multiplicative_operator=16
org.eclipse.jdt.core.formatter.alignment_for_parameterized_type_references=0
org.eclipse.jdt.core.formatter.alignment_for_parameters_in_constructor_declaration=16
org.eclipse.jdt.core.formatter.alignment_for_parameters_in_method_declaration=16
+org.eclipse.jdt.core.formatter.alignment_for_permitted_types_in_type_declaration=16
+org.eclipse.jdt.core.formatter.alignment_for_record_components=16
+org.eclipse.jdt.core.formatter.alignment_for_relational_operator=0
org.eclipse.jdt.core.formatter.alignment_for_resources_in_try=80
org.eclipse.jdt.core.formatter.alignment_for_selector_in_method_invocation=16
+org.eclipse.jdt.core.formatter.alignment_for_shift_operator=0
org.eclipse.jdt.core.formatter.alignment_for_string_concatenation=16
org.eclipse.jdt.core.formatter.alignment_for_superclass_in_type_declaration=16
org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_enum_declaration=16
+org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_record_declaration=16
org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_type_declaration=16
+org.eclipse.jdt.core.formatter.alignment_for_switch_case_with_arrow=20
org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_constructor_declaration=16
org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_method_declaration=16
+org.eclipse.jdt.core.formatter.alignment_for_type_annotations=0
org.eclipse.jdt.core.formatter.alignment_for_type_arguments=0
org.eclipse.jdt.core.formatter.alignment_for_type_parameters=0
org.eclipse.jdt.core.formatter.alignment_for_union_type_in_multicatch=16
org.eclipse.jdt.core.formatter.blank_lines_after_imports=1
+org.eclipse.jdt.core.formatter.blank_lines_after_last_class_body_declaration=0
org.eclipse.jdt.core.formatter.blank_lines_after_package=1
+org.eclipse.jdt.core.formatter.blank_lines_before_abstract_method=1
org.eclipse.jdt.core.formatter.blank_lines_before_field=0
org.eclipse.jdt.core.formatter.blank_lines_before_first_class_body_declaration=0
org.eclipse.jdt.core.formatter.blank_lines_before_imports=1
@@ -168,6 +193,7 @@ org.eclipse.jdt.core.formatter.blank_lines_before_method=1
org.eclipse.jdt.core.formatter.blank_lines_before_new_chunk=1
org.eclipse.jdt.core.formatter.blank_lines_before_package=0
org.eclipse.jdt.core.formatter.blank_lines_between_import_groups=1
+org.eclipse.jdt.core.formatter.blank_lines_between_statement_group_in_switch=0
org.eclipse.jdt.core.formatter.blank_lines_between_type_declarations=1
org.eclipse.jdt.core.formatter.brace_position_for_annotation_type_declaration=end_of_line
org.eclipse.jdt.core.formatter.brace_position_for_anonymous_type_declaration=end_of_line
@@ -179,6 +205,8 @@ org.eclipse.jdt.core.formatter.brace_position_for_enum_constant=end_of_line
org.eclipse.jdt.core.formatter.brace_position_for_enum_declaration=end_of_line
org.eclipse.jdt.core.formatter.brace_position_for_lambda_body=end_of_line
org.eclipse.jdt.core.formatter.brace_position_for_method_declaration=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_record_constructor=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_record_declaration=end_of_line
org.eclipse.jdt.core.formatter.brace_position_for_switch=end_of_line
org.eclipse.jdt.core.formatter.brace_position_for_type_declaration=end_of_line
org.eclipse.jdt.core.formatter.comment.align_tags_descriptions_grouped=true
@@ -194,8 +222,11 @@ org.eclipse.jdt.core.formatter.comment.format_line_comments=true
org.eclipse.jdt.core.formatter.comment.format_source_code=true
org.eclipse.jdt.core.formatter.comment.indent_parameter_description=false
org.eclipse.jdt.core.formatter.comment.indent_root_tags=false
+org.eclipse.jdt.core.formatter.comment.indent_tag_description=false
org.eclipse.jdt.core.formatter.comment.insert_new_line_before_root_tags=insert
+org.eclipse.jdt.core.formatter.comment.insert_new_line_between_different_tags=do not insert
org.eclipse.jdt.core.formatter.comment.insert_new_line_for_parameter=do not insert
+org.eclipse.jdt.core.formatter.comment.javadoc_do_not_separate_block_tags=false
org.eclipse.jdt.core.formatter.comment.line_length=80
org.eclipse.jdt.core.formatter.comment.new_lines_at_block_boundaries=true
org.eclipse.jdt.core.formatter.comment.new_lines_at_javadoc_boundaries=true
@@ -210,6 +241,7 @@ org.eclipse.jdt.core.formatter.format_line_comment_starting_on_first_column=fals
org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_annotation_declaration_header=true
org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_constant_header=true
org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_declaration_header=true
+org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_record_header=true
org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_type_header=true
org.eclipse.jdt.core.formatter.indent_breaks_compare_to_cases=true
org.eclipse.jdt.core.formatter.indent_empty_lines=false
@@ -243,6 +275,8 @@ org.eclipse.jdt.core.formatter.insert_new_line_in_empty_method_body=insert
org.eclipse.jdt.core.formatter.insert_new_line_in_empty_type_declaration=insert
org.eclipse.jdt.core.formatter.insert_space_after_additive_operator=insert
org.eclipse.jdt.core.formatter.insert_space_after_and_in_type_parameter=insert
+org.eclipse.jdt.core.formatter.insert_space_after_arrow_in_switch_case=insert
+org.eclipse.jdt.core.formatter.insert_space_after_arrow_in_switch_default=insert
org.eclipse.jdt.core.formatter.insert_space_after_assignment_operator=insert
org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation=do not insert
org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation_type_declaration=do not insert
@@ -272,13 +306,17 @@ org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_invocation_arg
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_field_declarations=insert
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_local_declarations=insert
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_parameterized_type_reference=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_permitted_types=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_record_components=insert
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_superinterfaces=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_switch_case_expressions=insert
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_arguments=insert
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_parameters=insert
org.eclipse.jdt.core.formatter.insert_space_after_ellipsis=insert
org.eclipse.jdt.core.formatter.insert_space_after_lambda_arrow=insert
org.eclipse.jdt.core.formatter.insert_space_after_logical_operator=insert
org.eclipse.jdt.core.formatter.insert_space_after_multiplicative_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_after_not_operator=do not insert
org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_parameterized_type_reference=do not insert
org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_arguments=do not insert
org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_parameters=do not insert
@@ -295,6 +333,7 @@ org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_if=do not ins
org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_declaration=do not insert
org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_invocation=do not insert
org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_parenthesized_expression=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_record_declaration=do not insert
org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_switch=do not insert
org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_synchronized=do not insert
org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_try=do not insert
@@ -311,6 +350,8 @@ org.eclipse.jdt.core.formatter.insert_space_after_string_concatenation=insert
org.eclipse.jdt.core.formatter.insert_space_after_unary_operator=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_additive_operator=insert
org.eclipse.jdt.core.formatter.insert_space_before_and_in_type_parameter=insert
+org.eclipse.jdt.core.formatter.insert_space_before_arrow_in_switch_case=insert
+org.eclipse.jdt.core.formatter.insert_space_before_arrow_in_switch_default=insert
org.eclipse.jdt.core.formatter.insert_space_before_assignment_operator=insert
org.eclipse.jdt.core.formatter.insert_space_before_at_in_annotation_type_declaration=insert
org.eclipse.jdt.core.formatter.insert_space_before_bitwise_operator=insert
@@ -330,6 +371,7 @@ org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_if=do not in
org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_declaration=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_invocation=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_parenthesized_expression=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_record_declaration=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_switch=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_synchronized=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_try=do not insert
@@ -356,7 +398,10 @@ org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_invocation_ar
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_field_declarations=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_local_declarations=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_parameterized_type_reference=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_permitted_types=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_record_components=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_superinterfaces=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_switch_case_expressions=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_arguments=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_parameters=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_ellipsis=do not insert
@@ -374,6 +419,8 @@ org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_constructor_
org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_constant=insert
org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_declaration=insert
org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_method_declaration=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_record_constructor=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_record_declaration=insert
org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_switch=insert
org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_type_declaration=insert
org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_allocation_expression=do not insert
@@ -389,6 +436,7 @@ org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_if=insert
org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_declaration=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_invocation=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_parenthesized_expression=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_record_declaration=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_switch=insert
org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_synchronized=insert
org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_try=insert
@@ -416,14 +464,37 @@ org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_decla
org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_invocation=do not insert
org.eclipse.jdt.core.formatter.join_lines_in_comments=true
org.eclipse.jdt.core.formatter.join_wrapped_lines=true
+org.eclipse.jdt.core.formatter.keep_annotation_declaration_on_one_line=one_line_never
+org.eclipse.jdt.core.formatter.keep_anonymous_type_declaration_on_one_line=one_line_never
+org.eclipse.jdt.core.formatter.keep_code_block_on_one_line=one_line_never
org.eclipse.jdt.core.formatter.keep_else_statement_on_same_line=false
org.eclipse.jdt.core.formatter.keep_empty_array_initializer_on_one_line=false
+org.eclipse.jdt.core.formatter.keep_enum_constant_declaration_on_one_line=one_line_never
+org.eclipse.jdt.core.formatter.keep_enum_declaration_on_one_line=one_line_never
+org.eclipse.jdt.core.formatter.keep_if_then_body_block_on_one_line=one_line_never
org.eclipse.jdt.core.formatter.keep_imple_if_on_one_line=false
+org.eclipse.jdt.core.formatter.keep_lambda_body_block_on_one_line=one_line_never
+org.eclipse.jdt.core.formatter.keep_loop_body_block_on_one_line=one_line_never
+org.eclipse.jdt.core.formatter.keep_method_body_on_one_line=one_line_never
+org.eclipse.jdt.core.formatter.keep_record_constructor_on_one_line=one_line_never
+org.eclipse.jdt.core.formatter.keep_record_declaration_on_one_line=one_line_never
+org.eclipse.jdt.core.formatter.keep_simple_do_while_body_on_same_line=false
+org.eclipse.jdt.core.formatter.keep_simple_for_body_on_same_line=false
+org.eclipse.jdt.core.formatter.keep_simple_getter_setter_on_one_line=false
+org.eclipse.jdt.core.formatter.keep_simple_while_body_on_same_line=false
+org.eclipse.jdt.core.formatter.keep_switch_body_block_on_one_line=one_line_never
+org.eclipse.jdt.core.formatter.keep_switch_case_with_arrow_on_one_line=one_line_never
org.eclipse.jdt.core.formatter.keep_then_statement_on_same_line=false
+org.eclipse.jdt.core.formatter.keep_type_declaration_on_one_line=one_line_never
org.eclipse.jdt.core.formatter.lineSplit=120
org.eclipse.jdt.core.formatter.never_indent_block_comments_on_first_column=false
org.eclipse.jdt.core.formatter.never_indent_line_comments_on_first_column=false
+org.eclipse.jdt.core.formatter.number_of_blank_lines_after_code_block=0
+org.eclipse.jdt.core.formatter.number_of_blank_lines_at_beginning_of_code_block=0
org.eclipse.jdt.core.formatter.number_of_blank_lines_at_beginning_of_method_body=0
+org.eclipse.jdt.core.formatter.number_of_blank_lines_at_end_of_code_block=0
+org.eclipse.jdt.core.formatter.number_of_blank_lines_at_end_of_method_body=0
+org.eclipse.jdt.core.formatter.number_of_blank_lines_before_code_block=0
org.eclipse.jdt.core.formatter.number_of_empty_lines_to_preserve=1
org.eclipse.jdt.core.formatter.parentheses_positions_in_annotation=common_lines
org.eclipse.jdt.core.formatter.parentheses_positions_in_catch_clause=common_lines
@@ -433,21 +504,27 @@ org.eclipse.jdt.core.formatter.parentheses_positions_in_if_while_statement=commo
org.eclipse.jdt.core.formatter.parentheses_positions_in_lambda_declaration=common_lines
org.eclipse.jdt.core.formatter.parentheses_positions_in_method_delcaration=common_lines
org.eclipse.jdt.core.formatter.parentheses_positions_in_method_invocation=common_lines
+org.eclipse.jdt.core.formatter.parentheses_positions_in_record_declaration=common_lines
org.eclipse.jdt.core.formatter.parentheses_positions_in_switch_statement=common_lines
org.eclipse.jdt.core.formatter.parentheses_positions_in_try_clause=common_lines
org.eclipse.jdt.core.formatter.put_empty_statement_on_new_line=true
org.eclipse.jdt.core.formatter.tabulation.char=tab
org.eclipse.jdt.core.formatter.tabulation.size=4
-org.eclipse.jdt.core.formatter.use_on_off_tags=false
+org.eclipse.jdt.core.formatter.text_block_indentation=0
+org.eclipse.jdt.core.formatter.use_on_off_tags=true
org.eclipse.jdt.core.formatter.use_tabs_only_for_leading_indentations=false
org.eclipse.jdt.core.formatter.wrap_before_additive_operator=true
+org.eclipse.jdt.core.formatter.wrap_before_assertion_message_operator=true
org.eclipse.jdt.core.formatter.wrap_before_assignment_operator=false
org.eclipse.jdt.core.formatter.wrap_before_bitwise_operator=true
org.eclipse.jdt.core.formatter.wrap_before_conditional_operator=true
org.eclipse.jdt.core.formatter.wrap_before_logical_operator=true
org.eclipse.jdt.core.formatter.wrap_before_multiplicative_operator=true
org.eclipse.jdt.core.formatter.wrap_before_or_operator_multicatch=true
+org.eclipse.jdt.core.formatter.wrap_before_relational_operator=true
+org.eclipse.jdt.core.formatter.wrap_before_shift_operator=true
org.eclipse.jdt.core.formatter.wrap_before_string_concatenation=true
+org.eclipse.jdt.core.formatter.wrap_before_switch_case_arrow_operator=false
org.eclipse.jdt.core.formatter.wrap_outer_expressions_when_nested=true
org.eclipse.jdt.core.incompatibleJDKLevel=ignore
org.eclipse.jdt.core.incompleteClasspath=error
diff --git a/bundles/org.eclipse.ui.ide/.settings/org.eclipse.jdt.ui.prefs b/bundles/org.eclipse.ui.ide/.settings/org.eclipse.jdt.ui.prefs
index 2cbcc52ea37..365b3aa5a6b 100644
--- a/bundles/org.eclipse.ui.ide/.settings/org.eclipse.jdt.ui.prefs
+++ b/bundles/org.eclipse.ui.ide/.settings/org.eclipse.jdt.ui.prefs
@@ -1,7 +1,7 @@
eclipse.preferences.version=1
editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true
formatter_profile=org.eclipse.jdt.ui.default.eclipse_profile
-formatter_settings_version=14
+formatter_settings_version=23
internal.default.compliance=user
org.eclipse.jdt.ui.ignorelowercasenames=true
org.eclipse.jdt.ui.importorder=java;javax;org;com;;
@@ -9,6 +9,7 @@ org.eclipse.jdt.ui.javadoc=true
org.eclipse.jdt.ui.ondemandthreshold=99
org.eclipse.jdt.ui.staticondemandthreshold=99
org.eclipse.jdt.ui.text.custom_code_templates=/**\n * @return Returns the ${bare_field_name}.\n *//**\n * @param ${param} The ${bare_field_name} to set.\n *//**\n * ${tags}\n *//**\n * @since 3.4\n *\n * ${tags}\n *//**\n * \n *//**\n * ${tags}\n */${filecomment}\n${package_declaration}\n\n${typecomment}\n${type_declaration}// ${todo} Auto-generated catch block\n${exception_var}.printStackTrace();// ${todo} Auto-generated method stub\n${body_statement}${body_statement}\n// ${todo} Auto-generated constructor stubreturn ${field};${field} \= ${param};\n\n\n\n/**\n * ${tags}\n * ${see_to_target}\n */
+sp_cleanup.add_all=false
sp_cleanup.add_default_serial_version_id=true
sp_cleanup.add_generated_serial_version_id=false
sp_cleanup.add_missing_annotations=true
@@ -18,52 +19,136 @@ sp_cleanup.add_missing_nls_tags=false
sp_cleanup.add_missing_override_annotations=true
sp_cleanup.add_missing_override_annotations_interface_methods=true
sp_cleanup.add_serial_version_id=false
+sp_cleanup.also_simplify_lambda=false
sp_cleanup.always_use_blocks=true
sp_cleanup.always_use_parentheses_in_expressions=false
sp_cleanup.always_use_this_for_non_static_field_access=false
sp_cleanup.always_use_this_for_non_static_method_access=false
+sp_cleanup.array_with_curly=false
+sp_cleanup.arrays_fill=false
+sp_cleanup.bitwise_conditional_expression=false
+sp_cleanup.boolean_literal=false
+sp_cleanup.boolean_value_rather_than_comparison=false
+sp_cleanup.break_loop=false
+sp_cleanup.collection_cloning=false
+sp_cleanup.comparing_on_criteria=false
+sp_cleanup.comparison_statement=false
+sp_cleanup.controlflow_merge=false
sp_cleanup.convert_functional_interfaces=false
sp_cleanup.convert_to_enhanced_for_loop=false
+sp_cleanup.convert_to_enhanced_for_loop_if_loop_var_used=false
+sp_cleanup.convert_to_switch_expressions=false
sp_cleanup.correct_indentation=false
-sp_cleanup.format_source_code=true
+sp_cleanup.do_while_rather_than_while=false
+sp_cleanup.double_negation=false
+sp_cleanup.else_if=false
+sp_cleanup.embedded_if=false
+sp_cleanup.evaluate_nullable=false
+sp_cleanup.extract_increment=false
+sp_cleanup.format_source_code=false
sp_cleanup.format_source_code_changes_only=true
+sp_cleanup.hash=false
+sp_cleanup.if_condition=false
sp_cleanup.insert_inferred_type_arguments=false
+sp_cleanup.instanceof=false
+sp_cleanup.instanceof_keyword=false
+sp_cleanup.invert_equals=false
+sp_cleanup.join=false
+sp_cleanup.lazy_logical_operator=false
sp_cleanup.make_local_variable_final=true
sp_cleanup.make_parameters_final=false
sp_cleanup.make_private_fields_final=true
sp_cleanup.make_type_abstract_if_missing_method=false
sp_cleanup.make_variable_declarations_final=false
+sp_cleanup.map_cloning=false
+sp_cleanup.merge_conditional_blocks=false
+sp_cleanup.multi_catch=false
sp_cleanup.never_use_blocks=false
sp_cleanup.never_use_parentheses_in_expressions=true
+sp_cleanup.no_string_creation=false
+sp_cleanup.no_super=false
+sp_cleanup.number_suffix=false
+sp_cleanup.objects_equals=false
sp_cleanup.on_save_use_additional_actions=true
+sp_cleanup.one_if_rather_than_duplicate_blocks_that_fall_through=false
+sp_cleanup.operand_factorization=false
sp_cleanup.organize_imports=true
+sp_cleanup.overridden_assignment=false
+sp_cleanup.overridden_assignment_move_decl=false
+sp_cleanup.plain_replacement=false
+sp_cleanup.precompile_regex=false
+sp_cleanup.primitive_comparison=false
+sp_cleanup.primitive_parsing=false
+sp_cleanup.primitive_rather_than_wrapper=false
+sp_cleanup.primitive_serialization=false
+sp_cleanup.pull_out_if_from_if_else=false
+sp_cleanup.pull_up_assignment=false
+sp_cleanup.push_down_negation=false
sp_cleanup.qualify_static_field_accesses_with_declaring_class=false
sp_cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true
sp_cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=true
sp_cleanup.qualify_static_member_accesses_with_declaring_class=false
sp_cleanup.qualify_static_method_accesses_with_declaring_class=false
+sp_cleanup.reduce_indentation=false
+sp_cleanup.redundant_comparator=false
+sp_cleanup.redundant_falling_through_block_end=false
sp_cleanup.remove_private_constructors=true
+sp_cleanup.remove_redundant_modifiers=false
+sp_cleanup.remove_redundant_semicolons=false
sp_cleanup.remove_redundant_type_arguments=true
sp_cleanup.remove_trailing_whitespaces=true
sp_cleanup.remove_trailing_whitespaces_all=true
sp_cleanup.remove_trailing_whitespaces_ignore_empty=false
+sp_cleanup.remove_unnecessary_array_creation=false
sp_cleanup.remove_unnecessary_casts=true
sp_cleanup.remove_unnecessary_nls_tags=false
sp_cleanup.remove_unused_imports=false
sp_cleanup.remove_unused_local_variables=false
+sp_cleanup.remove_unused_method_parameters=false
sp_cleanup.remove_unused_private_fields=true
sp_cleanup.remove_unused_private_members=false
sp_cleanup.remove_unused_private_methods=true
sp_cleanup.remove_unused_private_types=true
+sp_cleanup.return_expression=false
+sp_cleanup.simplify_lambda_expression_and_method_ref=false
+sp_cleanup.single_used_field=false
sp_cleanup.sort_members=false
sp_cleanup.sort_members_all=false
+sp_cleanup.standard_comparison=false
+sp_cleanup.static_inner_class=false
+sp_cleanup.strictly_equal_or_different=false
+sp_cleanup.stringbuffer_to_stringbuilder=false
+sp_cleanup.stringbuilder=false
+sp_cleanup.stringbuilder_for_local_vars=false
+sp_cleanup.stringconcat_stringbuffer_stringbuilder=false
+sp_cleanup.stringconcat_to_textblock=false
+sp_cleanup.substring=false
+sp_cleanup.switch=false
+sp_cleanup.system_property=false
+sp_cleanup.system_property_boolean=false
+sp_cleanup.system_property_file_encoding=false
+sp_cleanup.system_property_file_separator=false
+sp_cleanup.system_property_line_separator=false
+sp_cleanup.system_property_path_separator=false
+sp_cleanup.ternary_operator=false
+sp_cleanup.try_with_resource=false
+sp_cleanup.unlooped_while=false
+sp_cleanup.unreachable_block=false
sp_cleanup.use_anonymous_class_creation=false
+sp_cleanup.use_autoboxing=false
sp_cleanup.use_blocks=false
sp_cleanup.use_blocks_only_for_return_and_throw=false
+sp_cleanup.use_directly_map_method=false
sp_cleanup.use_lambda=true
sp_cleanup.use_parentheses_in_expressions=false
+sp_cleanup.use_string_is_blank=false
sp_cleanup.use_this_for_non_static_field_access=false
sp_cleanup.use_this_for_non_static_field_access_only_if_necessary=true
sp_cleanup.use_this_for_non_static_method_access=false
sp_cleanup.use_this_for_non_static_method_access_only_if_necessary=true
sp_cleanup.use_type_arguments=false
+sp_cleanup.use_unboxing=false
+sp_cleanup.use_var=false
+sp_cleanup.useless_continue=false
+sp_cleanup.useless_return=false
+sp_cleanup.valueof_rather_than_instantiation=false
diff --git a/bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/FindReplaceDialog.java b/bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/FindReplaceDialog.java
index fae3682279a..6eaac2a3299 100644
--- a/bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/FindReplaceDialog.java
+++ b/bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/FindReplaceDialog.java
@@ -21,12 +21,10 @@
import java.util.HashSet;
import java.util.List;
import java.util.Set;
-import java.util.regex.PatternSyntaxException;
import org.osgi.framework.FrameworkUtil;
import org.eclipse.swt.SWT;
-import org.eclipse.swt.custom.BusyIndicator;
import org.eclipse.swt.custom.ScrolledComposite;
import org.eclipse.swt.events.ControlAdapter;
import org.eclipse.swt.events.ControlEvent;
@@ -62,19 +60,10 @@
import org.eclipse.jface.text.FindReplaceDocumentAdapter;
import org.eclipse.jface.text.FindReplaceDocumentAdapterContentProposalProvider;
import org.eclipse.jface.text.IFindReplaceTarget;
-import org.eclipse.jface.text.IFindReplaceTargetExtension;
-import org.eclipse.jface.text.IFindReplaceTargetExtension3;
-import org.eclipse.jface.text.IFindReplaceTargetExtension4;
-import org.eclipse.jface.text.IRegion;
-import org.eclipse.jface.text.Region;
import org.eclipse.jface.text.TextUtilities;
-import org.eclipse.ui.IEditorPart;
-import org.eclipse.ui.IWorkbenchPage;
-import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.fieldassist.ContentAssistCommandAdapter;
-import org.eclipse.ui.internal.texteditor.NLSUtility;
import org.eclipse.ui.internal.texteditor.SWTUtil;
@@ -85,6 +74,7 @@
class FindReplaceDialog extends Dialog {
private static final int CLOSE_BUTTON_ID = 101;
+ private FindReplacer findReplacer;
/**
* Updates the find replace dialog on activation changes.
@@ -108,18 +98,17 @@ public void shellDeactivated(ShellEvent e) {
fGlobalRadioButton.setSelection(true);
fSelectedRangeRadioButton.setSelection(false);
- fUseSelectedLines= false;
+ findReplacer.setGlobalSearch(false);
- if (fTarget != null && (fTarget instanceof IFindReplaceTargetExtension))
- ((IFindReplaceTargetExtension) fTarget).setScope(null);
-
- fOldScope= null;
+ findReplacer.deactivateScope();
fActiveShell= null;
updateButtonState();
}
}
+ private final FindModifyListener fFindModifyListener = new FindModifyListener();
+
/**
* Modify listener to update the search result in case of incremental search.
* @since 2.0
@@ -129,7 +118,7 @@ private class FindModifyListener implements ModifyListener {
// XXX: Workaround for Combo bug on Linux (see bug 404202 and bug 410603)
private boolean fIgnoreNextEvent;
private void ignoreNextEvent() {
- fIgnoreNextEvent= true;
+ fIgnoreNextEvent = true;
}
@Override
@@ -137,57 +126,26 @@ public void modifyText(ModifyEvent e) {
// XXX: Workaround for Combo bug on Linux (see bug 404202 and bug 410603)
if (fIgnoreNextEvent) {
- fIgnoreNextEvent= false;
+ fIgnoreNextEvent = false;
return;
}
- if (isIncrementalSearch() && !isRegExSearchAvailableAndChecked()) {
- if (fFindField.getText().equals("") && fTarget != null) { //$NON-NLS-1$
- // empty selection at base location
- int offset= fIncrementalBaseLocation.x;
-
- if (isForwardSearch() && !fNeedsInitialFindBeforeReplace || !isForwardSearch() && fNeedsInitialFindBeforeReplace)
- offset= offset + fIncrementalBaseLocation.y;
-
- fNeedsInitialFindBeforeReplace= false;
- findAndSelect(offset, "", isForwardSearch(), isCaseSensitiveSearch(), isWholeWordSearch(), isRegExSearchAvailableAndChecked()); //$NON-NLS-1$
- } else {
- performSearch(false, false, isForwardSearch());
- }
- }
+ findReplacer.updateSearchResultAfterTextWasModified(getFindString());
- updateButtonState(!isIncrementalSearch());
+ updateButtonState(!findReplacer.isIncrementalSearch());
}
}
/** The size of the dialogs search history. */
private static final int HISTORY_SIZE= 15;
- private Point fIncrementalBaseLocation;
- private boolean fWrapInit, fCaseInit, fWholeWordInit, fForwardInit, fGlobalInit, fIncrementalInit;
- /**
- * Tells whether an initial find operation is needed
- * before the replace operation.
- * @since 3.0
- */
- private boolean fNeedsInitialFindBeforeReplace;
- /**
- * Initial value for telling whether the search string is a regular expression.
- * @since 3.0
- */
- boolean fIsRegExInit;
-
private List fFindHistory;
private List fReplaceHistory;
- private IRegion fOldScope;
- private boolean fIsTargetEditable;
- private IFindReplaceTarget fTarget;
private Shell fParentShell;
private Shell fActiveShell;
private final ActivationListener fActivationListener= new ActivationListener();
- private final FindModifyListener fFindModifyListener= new FindModifyListener();
private Label fReplaceLabel, fStatusLabel;
private Button fForwardRadioButton, fGlobalRadioButton, fSelectedRangeRadioButton;
@@ -212,19 +170,9 @@ public void modifyText(ModifyEvent e) {
private IDialogSettings fDialogSettings;
/**
- * Tells whether the target supports regular expressions.
- * true
if the target supports regular expressions
- * @since 3.0
- */
- private boolean fIsTargetSupportingRegEx;
- /**
- * Tells whether fUseSelectedLines radio is checked.
- * @since 3.0
- */
- private boolean fUseSelectedLines;
- /**
- * true
if the find field should receive focus the next time
- * the dialog is activated, false
otherwise.
+ * true
if the find field should receive focus the next time the
+ * dialog is activated, false
otherwise.
+ *
* @since 3.0
*/
private boolean fGiveFocusToFindField= true;
@@ -242,23 +190,16 @@ public void modifyText(ModifyEvent e) {
*/
public FindReplaceDialog(Shell parentShell) {
super(parentShell);
+ findReplacer = new FindReplacer();
fParentShell= null;
- fTarget= null;
fDialogPositionInit= null;
fFindHistory= new ArrayList<>(HISTORY_SIZE);
fReplaceHistory= new ArrayList<>(HISTORY_SIZE);
- fWrapInit= false;
- fCaseInit= false;
- fIsRegExInit= false;
- fWholeWordInit= false;
- fIncrementalInit= false;
- fGlobalInit= true;
- fForwardInit= true;
-
readConfiguration();
+ updateButtonState();
setShellStyle(getShellStyle() ^ SWT.APPLICATION_MODAL | SWT.MODELESS);
setBlockOnOpen(false);
@@ -333,12 +274,15 @@ private Composite createButtonSection(Composite parent) {
fFindNextButton= makeButton(panel, EditorMessages.FindReplace_FindNextButton_label, 102, true, new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
- if (isIncrementalSearch() && !isRegExSearchAvailableAndChecked())
- initIncrementalBaseLocation();
+ if (findReplacer.isIncrementalSearch() && !findReplacer.isRegExSearchAvailableAndChecked())
+ findReplacer.initIncrementalBaseLocation();
- fNeedsInitialFindBeforeReplace= false;
- performSearch(((e.stateMask & SWT.MODIFIER_MASK) == SWT.SHIFT) ^ isForwardSearch());
+ findReplacer.setNeedsInitialFindBeforeReplace(false);
+ boolean somethingFound = findReplacer.performSearch(getFindString());
+ writeSelection();
+ updateButtonState(!somethingFound);
updateFindHistory();
+ evaluateFindReplacerStatus();
}
});
setGridData(fFindNextButton, SWT.FILL, true, SWT.FILL, false);
@@ -347,8 +291,11 @@ public void widgetSelected(SelectionEvent e) {
new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
- performSelectAll();
+ findReplacer.performSelectAll(getFindString(), fActiveShell.getDisplay());
+ writeSelection();
+ updateButtonState();
updateFindAndReplaceHistory();
+ evaluateFindReplacerStatus();
}
});
setGridData(fSelectAllButton, SWT.FILL, true, SWT.FILL, false);
@@ -358,11 +305,12 @@ public void widgetSelected(SelectionEvent e) {
fReplaceFindButton= makeButton(panel, EditorMessages.FindReplace_ReplaceFindButton_label, 103, false, new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
- if (fNeedsInitialFindBeforeReplace)
- performSearch(((e.stateMask & SWT.MODIFIER_MASK) == SWT.SHIFT) ^ isForwardSearch());
- if (performReplaceSelection())
- performSearch(((e.stateMask & SWT.MODIFIER_MASK) == SWT.SHIFT) ^ isForwardSearch());
+ if (findReplacer.performFindFirstThenReplaceInASecondStep(getFindString(), getReplaceString())) {
+ writeSelection();
+ }
+ updateButtonState();
updateFindAndReplaceHistory();
+ evaluateFindReplacerStatus();
}
});
setGridData(fReplaceFindButton, SWT.FILL, false, SWT.FILL, false);
@@ -370,11 +318,12 @@ public void widgetSelected(SelectionEvent e) {
fReplaceSelectionButton= makeButton(panel, EditorMessages.FindReplace_ReplaceSelectionButton_label, 104, false, new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
- if (fNeedsInitialFindBeforeReplace)
- performSearch();
- performReplaceSelection();
+ if (findReplacer.performSelectAndReplace(getFindString(), getReplaceString())) {
+ writeSelection();
+ }
updateButtonState();
updateFindAndReplaceHistory();
+ evaluateFindReplacerStatus();
}
});
setGridData(fReplaceSelectionButton, SWT.FILL, false, SWT.FILL, false);
@@ -382,14 +331,17 @@ public void widgetSelected(SelectionEvent e) {
fReplaceAllButton= makeButton(panel, EditorMessages.FindReplace_ReplaceAllButton_label, 105, false, new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
- performReplaceAll();
+ findReplacer.performReplaceAll(getFindString(), getReplaceString(), fActiveShell.getDisplay());
+ writeSelection();
+ updateButtonState();
updateFindAndReplaceHistory();
+ evaluateFindReplacerStatus();
}
});
setGridData(fReplaceAllButton, SWT.FILL, true, SWT.FILL, false);
// Make the all the buttons the same size as the Remove Selection button.
- fReplaceAllButton.setEnabled(isEditable());
+ fReplaceAllButton.setEnabled(findReplacer.isEditable());
return panel;
}
@@ -535,12 +487,15 @@ private Composite createDirectionGroup(Composite parent) {
SelectionListener selectionListener= new SelectionListener() {
@Override
public void widgetSelected(SelectionEvent e) {
- if (isIncrementalSearch() && !isRegExSearchAvailableAndChecked())
- initIncrementalBaseLocation();
+ if (findReplacer.isIncrementalSearch() && !findReplacer.isRegExSearchAvailableAndChecked())
+ findReplacer.initIncrementalBaseLocation();
+
+ findReplacer.setForwardSearch(fForwardRadioButton.getSelection());
}
@Override
public void widgetDefaultSelected(SelectionEvent e) {
+ // Do nothing
}
};
@@ -556,8 +511,9 @@ public void widgetDefaultSelected(SelectionEvent e) {
backwardRadioButton.addSelectionListener(selectionListener);
storeButtonWithMnemonicInMap(backwardRadioButton);
- backwardRadioButton.setSelection(!fForwardInit);
- fForwardRadioButton.setSelection(fForwardInit);
+ findReplacer.setForwardSearch(true); // search forward by default
+ backwardRadioButton.setSelection(!findReplacer.isForwardSearch());
+ fForwardRadioButton.setSelection(findReplacer.isForwardSearch());
return panel;
}
@@ -586,14 +542,14 @@ private Composite createScopeGroup(Composite parent) {
fGlobalRadioButton= new Button(group, SWT.RADIO | SWT.LEFT);
fGlobalRadioButton.setText(EditorMessages.FindReplace_GlobalRadioButton_label);
setGridData(fGlobalRadioButton, SWT.LEFT, false, SWT.CENTER, false);
- fGlobalRadioButton.setSelection(fGlobalInit);
+ fGlobalRadioButton.setSelection(findReplacer.isGlobalSearch());
fGlobalRadioButton.addSelectionListener(new SelectionListener() {
@Override
public void widgetSelected(SelectionEvent e) {
- if (!fGlobalRadioButton.getSelection() || !fUseSelectedLines)
+ if (!fGlobalRadioButton.getSelection() || findReplacer.isGlobalSearch())
return;
- fUseSelectedLines= false;
- useSelectedLines(false);
+ findReplacer.setGlobalSearch(true);
+ findReplacer.useSelectedLines(false);
}
@Override
@@ -605,15 +561,14 @@ public void widgetDefaultSelected(SelectionEvent e) {
fSelectedRangeRadioButton= new Button(group, SWT.RADIO | SWT.LEFT);
fSelectedRangeRadioButton.setText(EditorMessages.FindReplace_SelectedRangeRadioButton_label);
setGridData(fSelectedRangeRadioButton, SWT.LEFT, false, SWT.CENTER, false);
- fSelectedRangeRadioButton.setSelection(!fGlobalInit);
- fUseSelectedLines= !fGlobalInit;
+ fSelectedRangeRadioButton.setSelection(!findReplacer.isGlobalSearch());
fSelectedRangeRadioButton.addSelectionListener(new SelectionListener() {
@Override
public void widgetSelected(SelectionEvent e) {
- if (!fSelectedRangeRadioButton.getSelection() || fUseSelectedLines)
+ if (!fSelectedRangeRadioButton.getSelection() || !findReplacer.isGlobalSearch())
return;
- fUseSelectedLines= true;
- useSelectedLines(true);
+ findReplacer.setGlobalSearch(false);
+ findReplacer.useSelectedLines(true);
}
@Override
@@ -625,42 +580,6 @@ public void widgetDefaultSelected(SelectionEvent e) {
return panel;
}
- /**
- * Tells the dialog to perform searches only in the scope given by the actually selected lines.
- * @param selectedLines true
if selected lines should be used
- * @since 2.0
- */
- private void useSelectedLines(boolean selectedLines) {
- if (isIncrementalSearch() && !isRegExSearchAvailableAndChecked())
- initIncrementalBaseLocation();
-
- if (fTarget == null || !(fTarget instanceof IFindReplaceTargetExtension))
- return;
-
- IFindReplaceTargetExtension extensionTarget= (IFindReplaceTargetExtension) fTarget;
-
- if (selectedLines) {
-
- IRegion scope;
- if (fOldScope == null) {
- Point lineSelection= extensionTarget.getLineSelection();
- scope= new Region(lineSelection.x, lineSelection.y);
- } else {
- scope= fOldScope;
- fOldScope= null;
- }
-
- int offset= isForwardSearch()
- ? scope.getOffset()
- : scope.getOffset() + scope.getLength();
-
- extensionTarget.setSelection(offset, 0);
- extensionTarget.setScope(scope);
- } else {
- fOldScope= extensionTarget.getScope();
- extensionTarget.setScope(null);
- }
- }
/**
* Creates the panel where the user specifies the text to search
@@ -743,6 +662,7 @@ private Composite createOptionsGroup(Composite parent) {
SelectionListener selectionListener= new SelectionListener() {
@Override
public void widgetSelected(SelectionEvent e) {
+ setupFindReplacer();
storeSettings();
}
@@ -754,34 +674,35 @@ public void widgetDefaultSelected(SelectionEvent e) {
fCaseCheckBox= new Button(group, SWT.CHECK | SWT.LEFT);
fCaseCheckBox.setText(EditorMessages.FindReplace_CaseCheckBox_label);
setGridData(fCaseCheckBox, SWT.LEFT, false, SWT.CENTER, false);
- fCaseCheckBox.setSelection(fCaseInit);
+ fCaseCheckBox.setSelection(findReplacer.isCaseSensitiveSearch());
fCaseCheckBox.addSelectionListener(selectionListener);
storeButtonWithMnemonicInMap(fCaseCheckBox);
fWrapCheckBox= new Button(group, SWT.CHECK | SWT.LEFT);
fWrapCheckBox.setText(EditorMessages.FindReplace_WrapCheckBox_label);
setGridData(fWrapCheckBox, SWT.LEFT, false, SWT.CENTER, false);
- fWrapCheckBox.setSelection(fWrapInit);
+ fWrapCheckBox.setSelection(findReplacer.isWrapSearch());
fWrapCheckBox.addSelectionListener(selectionListener);
storeButtonWithMnemonicInMap(fWrapCheckBox);
fWholeWordCheckBox= new Button(group, SWT.CHECK | SWT.LEFT);
fWholeWordCheckBox.setText(EditorMessages.FindReplace_WholeWordCheckBox_label);
setGridData(fWholeWordCheckBox, SWT.LEFT, false, SWT.CENTER, false);
- fWholeWordCheckBox.setSelection(fWholeWordInit);
+ fWholeWordCheckBox.setSelection(findReplacer.isWholeWordSearchSetting());
fWholeWordCheckBox.addSelectionListener(selectionListener);
storeButtonWithMnemonicInMap(fWholeWordCheckBox);
fIncrementalCheckBox= new Button(group, SWT.CHECK | SWT.LEFT);
fIncrementalCheckBox.setText(EditorMessages.FindReplace_IncrementalCheckBox_label);
setGridData(fIncrementalCheckBox, SWT.LEFT, false, SWT.CENTER, false);
- fIncrementalCheckBox.setSelection(fIncrementalInit);
+ fIncrementalCheckBox.setSelection(findReplacer.isIncrementalSearch());
fIncrementalCheckBox.addSelectionListener(new SelectionListener() {
@Override
public void widgetSelected(SelectionEvent e) {
- if (isIncrementalSearch() && !isRegExSearch())
- initIncrementalBaseLocation();
+ if (findReplacer.isIncrementalSearch() && !findReplacer.isRegexSearch())
+ findReplacer.initIncrementalBaseLocation();
+ setupFindReplacer();
storeSettings();
}
@@ -795,26 +716,27 @@ public void widgetDefaultSelected(SelectionEvent e) {
fIsRegExCheckBox.setText(EditorMessages.FindReplace_RegExCheckbox_label);
setGridData(fIsRegExCheckBox, SWT.LEFT, false, SWT.CENTER, false);
((GridData)fIsRegExCheckBox.getLayoutData()).horizontalSpan= 2;
- fIsRegExCheckBox.setSelection(fIsRegExInit);
+ fIsRegExCheckBox.setSelection(findReplacer.isRegexSearch());
fIsRegExCheckBox.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
boolean newState= fIsRegExCheckBox.getSelection();
fIncrementalCheckBox.setEnabled(!newState);
- updateButtonState();
+ setupFindReplacer();
storeSettings();
+ updateButtonState();
setContentAssistsEnablement(newState);
}
});
storeButtonWithMnemonicInMap(fIsRegExCheckBox);
- fWholeWordCheckBox.setEnabled(!isRegExSearchAvailableAndChecked());
+ fWholeWordCheckBox.setEnabled(!findReplacer.isRegExSearchAvailableAndChecked());
fWholeWordCheckBox.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
updateButtonState();
}
});
- fIncrementalCheckBox.setEnabled(!isRegExSearchAvailableAndChecked());
+ fIncrementalCheckBox.setEnabled(!findReplacer.isRegExSearchAvailableAndChecked());
return panel;
}
@@ -856,142 +778,6 @@ protected void buttonPressed(int buttonID) {
// ------- action invocation ---------------------------------------
- /**
- * Returns the position of the specified search string, or -1
if the string can not
- * be found when searching using the given options.
- *
- * @param findString the string to search for
- * @param startPosition the position at which to start the search
- * @param forwardSearch the direction of the search
- * @param caseSensitive should the search be case sensitive
- * @param wrapSearch should the search wrap to the start/end if arrived at the end/start
- * @param wholeWord does the search string represent a complete word
- * @param regExSearch if true
findString represents a regular expression
- * @param beep if true
beeps when search does not find a match or needs to wrap
- * @return the occurrence of the find string following the options or -1
if nothing
- * found
- * @since 3.0
- */
- private int findIndex(String findString, int startPosition, boolean forwardSearch, boolean caseSensitive, boolean wrapSearch, boolean wholeWord, boolean regExSearch, boolean beep) {
-
- if (forwardSearch) {
- int index= findAndSelect(startPosition, findString, true, caseSensitive, wholeWord, regExSearch);
- if (index == -1) {
-
- if (beep && okToUse(getShell()))
- getShell().getDisplay().beep();
-
- if (wrapSearch) {
- statusMessage(EditorMessages.FindReplace_Status_wrapped_label);
- index= findAndSelect(-1, findString, true, caseSensitive, wholeWord, regExSearch);
- }
- }
- return index;
- }
-
- // backward
- int index= startPosition == 0 ? -1 : findAndSelect(startPosition - 1, findString, false, caseSensitive, wholeWord, regExSearch);
- if (index == -1) {
-
- if (beep && okToUse(getShell()))
- getShell().getDisplay().beep();
-
- if (wrapSearch) {
- statusMessage(EditorMessages.FindReplace_Status_wrapped_label);
- index= findAndSelect(-1, findString, false, caseSensitive, wholeWord, regExSearch);
- }
- }
- return index;
- }
-
- /**
- * Searches for a string starting at the given offset and using the specified search
- * directives. If a string has been found it is selected and its start offset is
- * returned.
- *
- * @param offset the offset at which searching starts
- * @param findString the string which should be found
- * @param forwardSearch the direction of the search
- * @param caseSensitive true
performs a case sensitive search, false
an insensitive search
- * @param wholeWord if true
only occurrences are reported in which the findString stands as a word by itself
- * @param regExSearch if true
findString represents a regular expression
- * @return the position of the specified string, or -1 if the string has not been found
- * @since 3.0
- */
- private int findAndSelect(int offset, String findString, boolean forwardSearch, boolean caseSensitive, boolean wholeWord, boolean regExSearch) {
- if (fTarget instanceof IFindReplaceTargetExtension3)
- return ((IFindReplaceTargetExtension3)fTarget).findAndSelect(offset, findString, forwardSearch, caseSensitive, wholeWord, regExSearch);
- return fTarget.findAndSelect(offset, findString, forwardSearch, caseSensitive, wholeWord);
- }
-
- /**
- * Replaces the selection with replaceString
. If
- * regExReplace
is true
,
- * replaceString
is a regex replace pattern which will get
- * expanded if the underlying target supports it. Returns the region of the
- * inserted text; note that the returned selection covers the expanded
- * pattern in case of regex replace.
- *
- * @param replaceString the replace string (or a regex pattern)
- * @param regExReplace true
if replaceString
- * is a pattern
- * @return the selection after replacing, i.e. the inserted text
- * @since 3.0
- */
- Point replaceSelection(String replaceString, boolean regExReplace) {
- if (fTarget instanceof IFindReplaceTargetExtension3)
- ((IFindReplaceTargetExtension3)fTarget).replaceSelection(replaceString, regExReplace);
- else
- fTarget.replaceSelection(replaceString);
-
- return fTarget.getSelection();
- }
-
- /**
- * Returns whether the specified search string can be found using the given options.
- *
- * @param findString the string to search for
- * @param forwardSearch the direction of the search
- * @param caseSensitive should the search be case sensitive
- * @param wrapSearch should the search wrap to the start/end if arrived at the end/start
- * @param wholeWord does the search string represent a complete word
- * @param incremental is this an incremental search
- * @param regExSearch if true
findString represents a regular expression
- * @param beep if true
beeps when search does not find a match or needs to wrap
- * @return true
if the search string can be found using the given options
- *
- * @since 3.0
- */
- private boolean findNext(String findString, boolean forwardSearch, boolean caseSensitive, boolean wrapSearch, boolean wholeWord, boolean incremental, boolean regExSearch, boolean beep) {
-
- if (fTarget == null)
- return false;
-
- Point r= null;
- if (incremental)
- r= fIncrementalBaseLocation;
- else
- r= fTarget.getSelection();
-
- int findReplacePosition= r.x;
- if (forwardSearch && !fNeedsInitialFindBeforeReplace || !forwardSearch && fNeedsInitialFindBeforeReplace)
- findReplacePosition += r.y;
-
- fNeedsInitialFindBeforeReplace= false;
-
- int index= findIndex(findString, findReplacePosition, forwardSearch, caseSensitive, wrapSearch, wholeWord, regExSearch, beep);
-
- if (index == -1) {
- String msg= NLSUtility.format(EditorMessages.FindReplace_Status_noMatchWithValue_label, findString);
- statusMessage(false, EditorMessages.FindReplace_Status_noMatch_label, msg);
- return false;
- }
-
- if (forwardSearch && index >= findReplacePosition || !forwardSearch && index <= findReplacePosition)
- statusMessage(""); //$NON-NLS-1$
-
- return true;
- }
/**
* Returns the dialog's boundaries.
@@ -1091,13 +877,10 @@ private void handleDialogClose() {
// store current settings in case of re-open
storeSettings();
- if (fTarget != null && fTarget instanceof IFindReplaceTargetExtension)
- ((IFindReplaceTargetExtension) fTarget).endSession();
+ findReplacer.endSession();
// prevent leaks
fActiveShell= null;
- fTarget= null;
-
}
/**
@@ -1105,11 +888,12 @@ private void handleDialogClose() {
* @since 3.0
*/
private void writeSelection() {
- if (fTarget == null)
+ String selection = findReplacer.getCurrentSelection();
+ if (selection == null)
return;
IDialogSettings s= getDialogSettings();
- s.put("selection", fTarget.getSelectionText()); //$NON-NLS-1$
+ s.put("selection", selection); //$NON-NLS-1$
}
/**
@@ -1118,12 +902,6 @@ private void writeSelection() {
*/
private void storeSettings() {
fDialogPositionInit= getDialogBoundaries();
- fWrapInit= isWrapSearch();
- fWholeWordInit= isWholeWordSetting();
- fCaseInit= isCaseSensitiveSearch();
- fIsRegExInit= isRegExSearch();
- fIncrementalInit= isIncrementalSearch();
- fForwardInit= isForwardSearch();
writeConfiguration();
}
@@ -1134,9 +912,9 @@ private void storeSettings() {
* action's target.
*/
private void initFindStringFromSelection() {
- if (fTarget != null && okToUse(fFindField)) {
- String fullSelection= fTarget.getSelectionText();
- boolean isRegEx= isRegExSearchAvailableAndChecked();
+ String fullSelection = findReplacer.getCurrentSelection();
+ if (fullSelection != null && okToUse(fFindField)) {
+ boolean isRegEx = findReplacer.isRegExSearchAvailableAndChecked();
fFindField.removeModifyListener(fFindModifyListener);
if (!fullSelection.isEmpty()) {
String firstLine= getFirstLine(fullSelection);
@@ -1144,10 +922,9 @@ private void initFindStringFromSelection() {
fFindField.setText(pattern);
if (!firstLine.equals(fullSelection)) {
// multiple lines selected
- useSelectedLines(true);
+ findReplacer.useSelectedLines(true);
fGlobalRadioButton.setSelection(false);
fSelectedRangeRadioButton.setSelection(true);
- fUseSelectedLines= true;
}
} else {
if ("".equals(fFindField.getText())) { //$NON-NLS-1$
@@ -1162,114 +939,6 @@ private void initFindStringFromSelection() {
}
}
- /**
- * Initializes the anchor used as starting point for incremental searching.
- * @since 2.0
- */
- private void initIncrementalBaseLocation() {
- if (fTarget != null && isIncrementalSearch() && !isRegExSearchAvailableAndChecked()) {
- fIncrementalBaseLocation= fTarget.getSelection();
- } else {
- fIncrementalBaseLocation= new Point(0, 0);
- }
- }
-
- // ------- history ---------------------------------------
-
- /**
- * Retrieves and returns the option case sensitivity from the appropriate check box.
- * @return true
if case sensitive
- */
- private boolean isCaseSensitiveSearch() {
- if (okToUse(fCaseCheckBox)) {
- return fCaseCheckBox.getSelection();
- }
- return fCaseInit;
- }
-
- /**
- * Retrieves and returns the regEx option from the appropriate check box.
- *
- * @return true
if case sensitive
- * @since 3.0
- */
- private boolean isRegExSearch() {
- if (okToUse(fIsRegExCheckBox)) {
- return fIsRegExCheckBox.getSelection();
- }
- return fIsRegExInit;
- }
-
- /**
- * If the target supports regular expressions search retrieves and returns
- * regEx option from appropriate check box.
- *
- * @return true
if regEx is available and checked
- * @since 3.0
- */
- private boolean isRegExSearchAvailableAndChecked() {
- if (okToUse(fIsRegExCheckBox)) {
- return fIsTargetSupportingRegEx && fIsRegExCheckBox.getSelection();
- }
- return fIsRegExInit;
- }
-
- /**
- * Retrieves and returns the option search direction from the appropriate check box.
- * @return true
if searching forward
- */
- private boolean isForwardSearch() {
- if (okToUse(fForwardRadioButton)) {
- return fForwardRadioButton.getSelection();
- }
- return fForwardInit;
- }
-
- /**
- * Retrieves and returns the option search whole words from the appropriate check box.
- * @return true
if searching for whole words
- */
- private boolean isWholeWordSetting() {
- if (okToUse(fWholeWordCheckBox)) {
- return fWholeWordCheckBox.getSelection();
- }
- return fWholeWordInit;
- }
-
- /**
- * Returns true
if searching should be restricted to entire
- * words, false
if not. This is the case if the respective
- * checkbox is turned on, regex is off, and the checkbox is enabled, i.e.
- * the current find string is an entire word.
- *
- * @return true
if the search is restricted to whole words
- */
- private boolean isWholeWordSearch() {
- return isWholeWordSetting() && !isRegExSearchAvailableAndChecked() && (okToUse(fWholeWordCheckBox) ? fWholeWordCheckBox.isEnabled() : true);
- }
-
- /**
- * Retrieves and returns the option wrap search from the appropriate check box.
- * @return true
if wrapping while searching
- */
- private boolean isWrapSearch() {
- if (okToUse(fWrapCheckBox)) {
- return fWrapCheckBox.getSelection();
- }
- return fWrapInit;
- }
-
- /**
- * Retrieves and returns the option incremental search from the appropriate check box.
- * @return true
if incremental search
- * @since 2.0
- */
- private boolean isIncrementalSearch() {
- if (okToUse(fIncrementalCheckBox)) {
- return fIncrementalCheckBox.getSelection();
- }
- return fIncrementalInit;
- }
/**
* Creates a button.
@@ -1299,331 +968,6 @@ private void storeButtonWithMnemonicInMap(Button button) {
fMnemonicButtonMap.put(Character.valueOf(Character.toLowerCase(mnemonic)), button);
}
- /**
- * Returns the status line manager of the active editor or null
if there is no such editor.
- * @return the status line manager of the active editor
- */
- private IEditorStatusLine getStatusLineManager() {
- IWorkbenchWindow window= PlatformUI.getWorkbench().getActiveWorkbenchWindow();
- if (window == null)
- return null;
-
- IWorkbenchPage page= window.getActivePage();
- if (page == null)
- return null;
-
- IEditorPart editor= page.getActiveEditor();
- if (editor == null)
- return null;
-
- return editor.getAdapter(IEditorStatusLine.class);
- }
-
- /**
- * Sets the given status message in the status line.
- *
- * @param error true
if it is an error
- * @param dialogMessage the message to display in the dialog's status line
- * @param editorMessage the message to display in the editor's status line
- */
- private void statusMessage(boolean error, String dialogMessage, String editorMessage) {
- fStatusLabel.setText(dialogMessage);
-
- if (error)
- fStatusLabel.setForeground(JFaceColors.getErrorText(fStatusLabel.getDisplay()));
- else
- fStatusLabel.setForeground(null);
-
- IEditorStatusLine statusLine= getStatusLineManager();
- if (statusLine != null)
- statusLine.setMessage(error, editorMessage, null);
-
- if (error)
- getShell().getDisplay().beep();
- }
-
- /**
- * Sets the given error message in the status line.
- * @param message the message
- */
- private void statusError(String message) {
- statusMessage(true, message, message);
- }
-
- /**
- * Sets the given message in the status line.
- * @param message the message
- */
- private void statusMessage(String message) {
- statusMessage(false, message, message);
- }
-
- /**
- * Replaces all occurrences of the user's findString with
- * the replace string. Indicate to the user the number of replacements
- * that occur.
- */
- private void performReplaceAll() {
-
- int replaceCount= 0;
- final String replaceString= getReplaceString();
- final String findString= getFindString();
-
- if (findString != null && !findString.isEmpty()) {
-
- class ReplaceAllRunnable implements Runnable {
- public int numberOfOccurrences;
- @Override
- public void run() {
- numberOfOccurrences = replaceAll(findString, replaceString == null ? "" : replaceString, //$NON-NLS-1$
- isCaseSensitiveSearch(), isWholeWordSearch(), isRegExSearchAvailableAndChecked());
- }
- }
-
- try {
- ReplaceAllRunnable runnable= new ReplaceAllRunnable();
- BusyIndicator.showWhile(fActiveShell.getDisplay(), runnable);
- replaceCount= runnable.numberOfOccurrences;
-
- if (replaceCount != 0) {
- if (replaceCount == 1) { // not plural
- statusMessage(EditorMessages.FindReplace_Status_replacement_label);
- } else {
- String msg= EditorMessages.FindReplace_Status_replacements_label;
- msg= NLSUtility.format(msg, String.valueOf(replaceCount));
- statusMessage(msg);
- }
- } else {
- String msg= NLSUtility.format(EditorMessages.FindReplace_Status_noMatchWithValue_label, findString);
- statusMessage(false, EditorMessages.FindReplace_Status_noMatch_label, msg);
- }
- } catch (PatternSyntaxException ex) {
- statusError(ex.getLocalizedMessage());
- } catch (IllegalStateException ex) {
- // we don't keep state in this dialog
- }
- }
- writeSelection();
- updateButtonState();
- }
-
- /**
- * Replaces all occurrences of the user's findString with the replace string.
- * Indicate to the user the number of replacements that occur.
- */
- private void performSelectAll() {
-
- int selectCount = 0;
- final String findString = getFindString();
-
- if (findString != null && !findString.isEmpty()) {
-
- class SelectAllRunnable implements Runnable {
- public int numberOfOccurrences;
-
- @Override
- public void run() {
- numberOfOccurrences = selectAll(findString, isCaseSensitiveSearch(), isWholeWordSearch(),
- isRegExSearchAvailableAndChecked());
- }
- }
-
- try {
- SelectAllRunnable runnable = new SelectAllRunnable();
- BusyIndicator.showWhile(fActiveShell.getDisplay(), runnable);
- selectCount = runnable.numberOfOccurrences;
-
- if (selectCount != 0) {
- if (selectCount == 1) { // not plural
- statusMessage(EditorMessages.FindReplace_Status_selection_label);
- } else {
- String msg = EditorMessages.FindReplace_Status_selections_label;
- msg = NLSUtility.format(msg, String.valueOf(selectCount));
- statusMessage(msg);
- }
- } else {
- String msg = NLSUtility.format(EditorMessages.FindReplace_Status_noMatchWithValue_label,
- findString);
- statusMessage(false, EditorMessages.FindReplace_Status_noMatch_label, msg);
- }
- } catch (PatternSyntaxException ex) {
- statusError(ex.getLocalizedMessage());
- } catch (IllegalStateException ex) {
- // we don't keep state in this dialog
- }
- }
- writeSelection();
- updateButtonState();
- }
-
- /**
- * Validates the state of the find/replace target.
- *
- * @return true
if target can be changed, false
- * otherwise
- * @since 2.1
- */
- private boolean validateTargetState() {
-
- if (fTarget instanceof IFindReplaceTargetExtension2) {
- IFindReplaceTargetExtension2 extension= (IFindReplaceTargetExtension2) fTarget;
- if (!extension.validateTargetState()) {
- statusError(EditorMessages.FindReplaceDialog_read_only);
- updateButtonState();
- return false;
- }
- }
- return isEditable();
- }
-
- /**
- * Replaces the current selection of the target with the user's
- * replace string.
- *
- * @return true
if the operation was successful
- */
- private boolean performReplaceSelection() {
-
- if (!validateTargetState())
- return false;
-
- String replaceString= getReplaceString();
- if (replaceString == null)
- replaceString= ""; //$NON-NLS-1$
-
- boolean replaced;
- try {
- replaceSelection(replaceString, isRegExSearchAvailableAndChecked());
- replaced= true;
- writeSelection();
- } catch (PatternSyntaxException ex) {
- statusError(ex.getLocalizedMessage());
- replaced= false;
- } catch (IllegalStateException ex) {
- replaced= false;
- }
-
- return replaced;
- }
-
- /**
- * Locates the user's findString in the text of the target.
- */
- private void performSearch() {
- performSearch(isForwardSearch());
- }
-
- /**
- * Locates the user's findString in the text of the target.
- *
- * @param forwardSearch true
if searching forwards, false
otherwise
- * @since 3.7
- */
- private void performSearch(boolean forwardSearch) {
- performSearch(isIncrementalSearch() && !isRegExSearchAvailableAndChecked(), true, forwardSearch);
- }
-
- /**
- * Locates the user's findString in the text of the target.
- *
- * @param mustInitIncrementalBaseLocation true
if base location must be initialized
- * @param beep if true
beeps when search does not find a match or needs to wrap
- * @param forwardSearch the search direction
- * @since 3.0
- */
- private void performSearch(boolean mustInitIncrementalBaseLocation, boolean beep, boolean forwardSearch) {
-
- if (mustInitIncrementalBaseLocation)
- initIncrementalBaseLocation();
-
- String findString= getFindString();
- boolean somethingFound= false;
-
- if (findString != null && !findString.isEmpty()) {
-
- try {
- somethingFound= findNext(findString, forwardSearch, isCaseSensitiveSearch(), isWrapSearch(), isWholeWordSearch(), isIncrementalSearch() && !isRegExSearchAvailableAndChecked(), isRegExSearchAvailableAndChecked(), beep);
- } catch (PatternSyntaxException ex) {
- statusError(ex.getLocalizedMessage());
- } catch (IllegalStateException ex) {
- // we don't keep state in this dialog
- }
- }
- writeSelection();
- updateButtonState(!somethingFound);
- }
-
- /**
- * Replaces all occurrences of the user's findString with
- * the replace string. Returns the number of replacements
- * that occur.
- *
- * @param findString the string to search for
- * @param replaceString the replacement string
- * @param caseSensitive should the search be case sensitive
- * @param wholeWord does the search string represent a complete word
- * @param regExSearch if true
findString represents a regular expression
- * @return the number of occurrences
- *
- * @since 3.0
- */
- private int replaceAll(String findString, String replaceString, boolean caseSensitive, boolean wholeWord,
- boolean regExSearch) {
-
- int replaceCount= 0;
- int findReplacePosition= 0;
-
- findReplacePosition= 0;
-
- if (!validateTargetState())
- return replaceCount;
-
- if (fTarget instanceof IFindReplaceTargetExtension)
- ((IFindReplaceTargetExtension) fTarget).setReplaceAllMode(true);
-
- try {
- int index= 0;
- while (index != -1) {
- index = findAndSelect(findReplacePosition, findString, true, caseSensitive, wholeWord, regExSearch);
- if (index != -1) { // substring not contained from current position
- Point selection= replaceSelection(replaceString, regExSearch);
- replaceCount++;
- findReplacePosition = selection.x + selection.y;
- }
- }
- } finally {
- if (fTarget instanceof IFindReplaceTargetExtension)
- ((IFindReplaceTargetExtension) fTarget).setReplaceAllMode(false);
- }
-
- return replaceCount;
- }
-
- private int selectAll(String findString, boolean caseSensitive, boolean wholeWord, boolean regExSearch) {
-
- int replaceCount = 0;
- int position = 0;
-
- if (!validateTargetState())
- return replaceCount;
-
- List selectedRegions = new ArrayList<>();
- int index = 0;
- do {
- index = findAndSelect(position, findString, true, caseSensitive, wholeWord, regExSearch);
- if (index != -1) { // substring not contained from current position
- Point selection = fTarget.getSelection();
- selectedRegions.add(new Region(selection.x, selection.y));
- replaceCount++;
- position = selection.x + selection.y;
- }
- } while (index != -1);
- if (fTarget instanceof IFindReplaceTargetExtension4) {
- ((IFindReplaceTargetExtension4) fTarget).setSelection(selectedRegions.toArray(IRegion[]::new));
- }
-
- return replaceCount;
- }
// ------- UI creation ---------------------------------------
@@ -1682,21 +1026,29 @@ private void updateButtonState() {
private void updateButtonState(boolean disableReplace) {
if (okToUse(getShell()) && okToUse(fFindNextButton)) {
- boolean selection= false;
- if (fTarget != null)
- selection= !fTarget.getSelectionText().isEmpty();
+ boolean hasActiveSelection = false;
+ String selection = findReplacer.getCurrentSelection();
+ if (selection != null)
+ hasActiveSelection = !selection.isEmpty();
- boolean enable= fTarget != null && (fActiveShell == fParentShell || fActiveShell == getShell());
+ boolean enable = findReplacer.isTargetAvailable()
+ && (fActiveShell == fParentShell || fActiveShell == getShell());
String str= getFindString();
boolean findString= str != null && !str.isEmpty();
- fWholeWordCheckBox.setEnabled(isWord(str) && !isRegExSearchAvailableAndChecked());
-
+ fWholeWordCheckBox.setEnabled(isWord(str) && !findReplacer.isRegExSearchAvailableAndChecked());
fFindNextButton.setEnabled(enable && findString);
- fSelectAllButton.setEnabled(enable && findString && fTarget instanceof IFindReplaceTargetExtension4);
- fReplaceSelectionButton.setEnabled(!disableReplace && enable && isEditable() && selection && (!fNeedsInitialFindBeforeReplace || !isRegExSearchAvailableAndChecked()));
- fReplaceFindButton.setEnabled(!disableReplace && enable && isEditable() && findString && selection && (!fNeedsInitialFindBeforeReplace || !isRegExSearchAvailableAndChecked()));
- fReplaceAllButton.setEnabled(enable && isEditable() && findString);
+ fSelectAllButton.setEnabled(enable && findString && findReplacer.supportsMultiSelection());
+ fReplaceSelectionButton
+ .setEnabled(!disableReplace && enable && findReplacer.isEditable() && hasActiveSelection
+ && (!findReplacer.needsInitialFindBeforeReplace()
+ || !findReplacer.isRegExSearchAvailableAndChecked()));
+ fReplaceFindButton
+ .setEnabled(!disableReplace && enable && findReplacer.isEditable() && findString
+ && hasActiveSelection
+ && (!findReplacer.needsInitialFindBeforeReplace()
+ || !findReplacer.isRegExSearchAvailableAndChecked()));
+ fReplaceAllButton.setEnabled(enable && findReplacer.isEditable() && findString);
}
}
@@ -1779,15 +1131,6 @@ private void updateHistory(Combo combo, List history) {
}
}
- /**
- * Returns whether the target is editable.
- * @return true
if target is editable
- */
- private boolean isEditable() {
- boolean isEditable= (fTarget == null ? false : fTarget.isEditable());
- return fIsTargetEditable && isEditable;
- }
-
/**
* Updates this dialog because of a different target.
* @param target the new target
@@ -1796,49 +1139,35 @@ private boolean isEditable() {
* @since 2.0
*/
public void updateTarget(IFindReplaceTarget target, boolean isTargetEditable, boolean initializeFindString) {
+ findReplacer.updateTarget(target, isTargetEditable);
- fIsTargetEditable= isTargetEditable;
- fNeedsInitialFindBeforeReplace= true;
-
- if (target != fTarget) {
- if (fTarget != null && fTarget instanceof IFindReplaceTargetExtension)
- ((IFindReplaceTargetExtension) fTarget).endSession();
-
- fTarget= target;
- if (fTarget != null)
- fIsTargetSupportingRegEx= fTarget instanceof IFindReplaceTargetExtension3;
-
- if (fTarget instanceof IFindReplaceTargetExtension) {
- ((IFindReplaceTargetExtension) fTarget).beginSession();
-
- fGlobalInit= true;
- fGlobalRadioButton.setSelection(fGlobalInit);
- fSelectedRangeRadioButton.setSelection(!fGlobalInit);
- fUseSelectedLines= !fGlobalInit;
- }
- }
+ boolean globalSearch = findReplacer.isGlobalSearch();
+ fGlobalRadioButton.setSelection(globalSearch);
+ boolean useSelectedLines = !globalSearch;
+ fSelectedRangeRadioButton.setSelection(useSelectedLines);
+ findReplacer.useSelectedLines(useSelectedLines);
if (okToUse(fIsRegExCheckBox))
- fIsRegExCheckBox.setEnabled(fIsTargetSupportingRegEx);
+ fIsRegExCheckBox.setEnabled(findReplacer.isTargetSupportingRegEx());
if (okToUse(fWholeWordCheckBox))
- fWholeWordCheckBox.setEnabled(!isRegExSearchAvailableAndChecked());
+ fWholeWordCheckBox.setEnabled(!findReplacer.isRegExSearchAvailableAndChecked());
if (okToUse(fIncrementalCheckBox))
- fIncrementalCheckBox.setEnabled(!isRegExSearchAvailableAndChecked());
+ fIncrementalCheckBox.setEnabled(!findReplacer.isRegExSearchAvailableAndChecked());
if (okToUse(fReplaceLabel)) {
- fReplaceLabel.setEnabled(isEditable());
- fReplaceField.setEnabled(isEditable());
+ fReplaceLabel.setEnabled(findReplacer.isEditable());
+ fReplaceField.setEnabled(findReplacer.isEditable());
if (initializeFindString) {
initFindStringFromSelection();
- fGiveFocusToFindField= true;
+ fGiveFocusToFindField = true;
}
- initIncrementalBaseLocation();
}
+
updateButtonState();
- setContentAssistsEnablement(isRegExSearchAvailableAndChecked());
+ setContentAssistsEnablement(findReplacer.isRegExSearchAvailableAndChecked());
}
/**
@@ -1901,11 +1230,11 @@ protected int getDialogBoundsStrategy() {
private void readConfiguration() {
IDialogSettings s= getDialogSettings();
- fWrapInit= s.get("wrap") == null || s.getBoolean("wrap"); //$NON-NLS-1$ //$NON-NLS-2$
- fCaseInit= s.getBoolean("casesensitive"); //$NON-NLS-1$
- fWholeWordInit= s.getBoolean("wholeword"); //$NON-NLS-1$
- fIncrementalInit= s.getBoolean("incremental"); //$NON-NLS-1$
- fIsRegExInit= s.getBoolean("isRegEx"); //$NON-NLS-1$
+ findReplacer.setWrapSearch(s.get("wrap") == null || s.getBoolean("wrap")); //$NON-NLS-1$ //$NON-NLS-2$
+ findReplacer.setCaseSensitiveSearch(s.getBoolean("casesensitive")); //$NON-NLS-1$
+ findReplacer.setWholeWordSearchSetting(s.getBoolean("wholeword")); //$NON-NLS-1$
+ findReplacer.setIncrementalSearch(s.getBoolean("incremental")); //$NON-NLS-1$
+ findReplacer.setRegexSearch(s.getBoolean("isRegEx")); //$NON-NLS-1$
String[] findHistory= s.getArray("findhistory"); //$NON-NLS-1$
if (findHistory != null) {
@@ -1922,17 +1251,25 @@ private void readConfiguration() {
}
}
+ private void setupFindReplacer() {
+ findReplacer.setWrapSearch(fWrapCheckBox.getSelection());
+ findReplacer.setCaseSensitiveSearch(fCaseCheckBox.getSelection());
+ findReplacer.setWholeWordSearchSetting(fWholeWordCheckBox.getSelection());
+ findReplacer.setIncrementalSearch(fIncrementalCheckBox.getSelection());
+ findReplacer.setRegexSearch(fIsRegExCheckBox.getSelection());
+ }
+
/**
* Stores its current configuration in the dialog store.
*/
private void writeConfiguration() {
IDialogSettings s= getDialogSettings();
- s.put("wrap", fWrapInit); //$NON-NLS-1$
- s.put("casesensitive", fCaseInit); //$NON-NLS-1$
- s.put("wholeword", fWholeWordInit); //$NON-NLS-1$
- s.put("incremental", fIncrementalInit); //$NON-NLS-1$
- s.put("isRegEx", fIsRegExInit); //$NON-NLS-1$
+ s.put("wrap", findReplacer.isWrapSearch()); //$NON-NLS-1$
+ s.put("casesensitive", findReplacer.isCaseSensitiveSearch()); //$NON-NLS-1$
+ s.put("wholeword", findReplacer.isWholeWordSearchSetting()); //$NON-NLS-1$
+ s.put("incremental", findReplacer.isIncrementalSearch()); //$NON-NLS-1$
+ s.put("isRegEx", findReplacer.isRegexSearch()); //$NON-NLS-1$
List history= getFindHistory();
String findString= getFindString();
@@ -1976,4 +1313,26 @@ private void writeHistory(List history, IDialogSettings settings, String
settings.put(sectionName, names);
}
+
+ public void evaluateFindReplacerStatus() {
+ FindReplaceStatus status = findReplacer.getStatus();
+
+ if (status.shouldBeep() && okToUse(getShell()))
+ getShell().getDisplay().beep();
+
+ String dialogMessage = status.getMessage();
+ boolean error = status.isError();
+
+ fStatusLabel.setText(dialogMessage);
+
+ if (error)
+ fStatusLabel.setForeground(JFaceColors.getErrorText(fStatusLabel.getDisplay()));
+ else
+ fStatusLabel.setForeground(null);
+
+ if (error)
+ getShell().getDisplay().beep();
+
+ findReplacer.resetStatus();
+ }
}
diff --git a/bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/FindReplaceStatus.java b/bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/FindReplaceStatus.java
new file mode 100644
index 00000000000..5f4a20489d2
--- /dev/null
+++ b/bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/FindReplaceStatus.java
@@ -0,0 +1,59 @@
+/*******************************************************************************
+ * Copyright (c) 2023 Vector Informatik GmbH and others.
+ *
+ * This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
+ * https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * Vector Informatik GmbH - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.ui.texteditor;
+
+/**
+ * @since 3.17
+ */
+class FindReplaceStatus {
+ private boolean error;
+ private String message;
+ private boolean beep;
+
+ public void resetStatus() {
+ error = false;
+ beep = false;
+ setMessage(""); //$NON-NLS-1$
+ }
+
+ public boolean shouldBeep() {
+ return beep;
+ }
+
+ public void doBeep() {
+ setBeep(true);
+ }
+
+ public void setBeep(boolean beep) {
+ this.beep = beep;
+ }
+
+ public String getMessage() {
+ return message;
+ }
+
+ public void setMessage(String message) {
+ this.message = message;
+ }
+
+ public boolean isError() {
+ return error;
+ }
+
+ public void setError(boolean error) {
+ this.error = error;
+ }
+
+}
\ No newline at end of file
diff --git a/bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/FindReplacer.java b/bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/FindReplacer.java
new file mode 100644
index 00000000000..f5add4c8985
--- /dev/null
+++ b/bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/FindReplacer.java
@@ -0,0 +1,790 @@
+/*******************************************************************************
+ * Copyright (c) 2023 Vector Informatik GmbH and others.
+ *
+ * This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
+ * https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * Vector Informatik GmbH - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.ui.texteditor;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.regex.PatternSyntaxException;
+
+import org.eclipse.swt.custom.BusyIndicator;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.widgets.Display;
+
+import org.eclipse.jface.text.IFindReplaceTarget;
+import org.eclipse.jface.text.IFindReplaceTargetExtension;
+import org.eclipse.jface.text.IFindReplaceTargetExtension3;
+import org.eclipse.jface.text.IFindReplaceTargetExtension4;
+import org.eclipse.jface.text.IRegion;
+import org.eclipse.jface.text.Region;
+
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.internal.texteditor.NLSUtility;
+
+/**
+ * @since 3.17
+ */
+public class FindReplacer {
+ private FindReplaceStatus status = new FindReplaceStatus();
+ private IFindReplaceTarget fTarget;
+ private IRegion fOldScope;
+ private Point fIncrementalBaseLocation;
+
+ /**
+ * Wether the search is incremental. (Search-as-you-type)
+ */
+ boolean fIncrementalSearch;
+
+ /**
+ * Tells whether an initial find operation is needed before the replace
+ * operation.
+ *
+ * @since 3.0
+ */
+ private boolean fNeedsInitialFindBeforeReplace;
+
+ /**
+ * Tells whether the target supports regular expressions. true
if
+ * the target supports regular expressions
+ */
+ private boolean fIsTargetSupportingRegEx;
+ boolean fRegexSearch;
+ boolean fForwardSearch;
+ boolean fWholeWordSearch;
+ boolean fWrapSearch;
+ boolean fCaseSensitiveSearch;
+ boolean fGlobalSearch;
+ private boolean fTargetEditable;
+
+ public Point getIncrementalBaseLocation() {
+ return fIncrementalBaseLocation;
+ }
+
+ public void setIncrementalBaseLocation(Point incrementalBaseLocation) {
+ fIncrementalBaseLocation = incrementalBaseLocation;
+ }
+
+ public boolean isGlobalSearch() {
+ return fGlobalSearch;
+ }
+
+ public void setGlobalSearch(boolean globalSearch) {
+ fGlobalSearch = globalSearch;
+ }
+
+ public boolean needsInitialFindBeforeReplace() {
+ return fNeedsInitialFindBeforeReplace;
+ }
+
+ public void setNeedsInitialFindBeforeReplace(boolean needsInitialFindBeforeReplace) {
+ fNeedsInitialFindBeforeReplace = needsInitialFindBeforeReplace;
+ }
+
+ public boolean isCaseSensitiveSearch() {
+ return fCaseSensitiveSearch;
+ }
+
+ public void setCaseSensitiveSearch(boolean caseSensitiveSearch) {
+ fCaseSensitiveSearch = caseSensitiveSearch;
+ }
+
+ public boolean isWrapSearch() {
+ return fWrapSearch;
+ }
+
+ public void setWrapSearch(boolean wrapSearch) {
+ fWrapSearch = wrapSearch;
+ }
+
+ public boolean isWholeWordSearchSetting() {
+ return fWholeWordSearch;
+ }
+
+ public void setWholeWordSearchSetting(boolean wholeWordSearch) {
+ fWholeWordSearch = wholeWordSearch;
+ }
+
+ public FindReplaceStatus getStatus() {
+ return status;
+ }
+
+ public void setStatus(FindReplaceStatus status) {
+ this.status = status;
+ }
+
+ public void resetStatus() {
+ status.resetStatus();
+ }
+
+ /**
+ * Returns true
if searching should be restricted to entire words,
+ * false
if not. This is the case if the respective checkbox is
+ * turned on, regex is off, and the checkbox is enabled, i.e. the current find
+ * string is an entire word.
+ *
+ * @return true
if the search is restricted to whole words
+ */
+ private boolean isWholeWordSearch() {
+ return isWholeWordSearchSetting() && !isRegExSearchAvailableAndChecked();
+ }
+
+ public boolean isForwardSearch() {
+ return fForwardSearch;
+ }
+
+ public void setForwardSearch(boolean forwardSearch) {
+ fForwardSearch = forwardSearch;
+ }
+
+ public boolean isTargetSupportingRegEx() {
+ return fIsTargetSupportingRegEx;
+ }
+
+ public void setIsTargetSupportingRegEx(boolean isTargetSupportingRegEx) {
+ fIsTargetSupportingRegEx = isTargetSupportingRegEx;
+ }
+
+ public boolean isIncrementalSearch() {
+ return fIncrementalSearch;
+ }
+
+ public void setIncrementalSearch(boolean incrementalSearch) {
+ fIncrementalSearch = incrementalSearch;
+ }
+
+ public boolean isRegexSearch() {
+ return fRegexSearch;
+ }
+
+ public void setRegexSearch(boolean regexSearch) {
+ fRegexSearch = regexSearch;
+ }
+
+
+ public boolean isRegExSearchAvailableAndChecked() {
+ return isRegexSearch() && fIsTargetSupportingRegEx;
+ }
+
+
+ /**
+ * initializes the anchor used as starting point for incremental searching.
+ *
+ * @since 2.0
+ */
+ public void initIncrementalBaseLocation() {
+ if (fTarget != null && isIncrementalSearch() && !isRegExSearchAvailableAndChecked()) {
+ fIncrementalBaseLocation = fTarget.getSelection();
+ } else {
+ fIncrementalBaseLocation = new Point(0, 0);
+ }
+ }
+
+ /**
+ * Tells the dialog to perform searches only in the scope given by the actually
+ * selected lines.
+ *
+ * @param selectedLines true
if selected lines should be used
+ * @since 2.0
+ */
+ public void useSelectedLines(boolean selectedLines) {
+ if (isIncrementalSearch() && !isRegExSearchAvailableAndChecked())
+ initIncrementalBaseLocation();
+
+ if (fTarget == null || !(fTarget instanceof IFindReplaceTargetExtension))
+ return;
+
+ IFindReplaceTargetExtension extensionTarget = (IFindReplaceTargetExtension) fTarget;
+
+ if (selectedLines) {
+
+ IRegion scope;
+ if (fOldScope == null) {
+ Point lineSelection = extensionTarget.getLineSelection();
+ scope = new Region(lineSelection.x, lineSelection.y);
+ } else {
+ scope = fOldScope;
+ fOldScope = null;
+ }
+
+ int offset = isForwardSearch() ? scope.getOffset() : scope.getOffset() + scope.getLength();
+
+ extensionTarget.setSelection(offset, 0);
+ extensionTarget.setScope(scope);
+ } else {
+ fOldScope = extensionTarget.getScope();
+ extensionTarget.setScope(null);
+ }
+ }
+
+ /**
+ * Returns the status line manager of the active editor or null
if
+ * there is no such editor.
+ *
+ * @return the status line manager of the active editor
+ */
+ private IEditorStatusLine getStatusLineManager() {
+ IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
+ if (window == null)
+ return null;
+
+ IWorkbenchPage page = window.getActivePage();
+ if (page == null)
+ return null;
+
+ IEditorPart editor = page.getActiveEditor();
+ if (editor == null)
+ return null;
+
+ return editor.getAdapter(IEditorStatusLine.class);
+ }
+
+
+ /**
+ * Replaces all occurrences of the user's findString with the replace string.
+ * Indicate to the user the number of replacements that occur.
+ *
+ * @param replaceString
+ * @param findString
+ * @param display
+ */
+ public void performReplaceAll(String replaceString, String findString, Display display) {
+
+ int replaceCount = 0;
+
+ if (findString != null && !findString.isEmpty()) {
+
+ class ReplaceAllRunnable implements Runnable {
+ public int numberOfOccurrences;
+
+ @Override
+ public void run() {
+ numberOfOccurrences = replaceAll(findString, replaceString == null ? "" : replaceString, //$NON-NLS-1$
+ isCaseSensitiveSearch(), isWholeWordSearch(), isRegExSearchAvailableAndChecked());
+ }
+ }
+
+ try {
+ ReplaceAllRunnable runnable = new ReplaceAllRunnable();
+ BusyIndicator.showWhile(display, runnable);
+ replaceCount = runnable.numberOfOccurrences;
+
+ if (replaceCount != 0) {
+ if (replaceCount == 1) { // not plural
+ statusMessage(EditorMessages.FindReplace_Status_replacement_label);
+ } else {
+ String msg = EditorMessages.FindReplace_Status_replacements_label;
+ msg = NLSUtility.format(msg, String.valueOf(replaceCount));
+ statusMessage(msg);
+ }
+ } else {
+ String msg = NLSUtility.format(EditorMessages.FindReplace_Status_noMatchWithValue_label,
+ findString);
+ statusMessage(false, EditorMessages.FindReplace_Status_noMatch_label, msg);
+ }
+ } catch (PatternSyntaxException ex) {
+ statusError(ex.getLocalizedMessage());
+ } catch (IllegalStateException ex) {
+ // we don't keep state in this dialog
+ }
+ }
+ }
+
+ /**
+ * Replaces all occurrences of the user's findString with the replace string.
+ * Indicate to the user the number of replacements that occur.
+ */
+ public void performSelectAll(String findString, Display display) {
+
+ int selectCount = 0;
+
+ if (findString != null && !findString.isEmpty()) {
+
+ class SelectAllRunnable implements Runnable {
+ public int numberOfOccurrences;
+
+ @Override
+ public void run() {
+ numberOfOccurrences = selectAll(findString, isCaseSensitiveSearch(), isWholeWordSearch(),
+ isRegExSearchAvailableAndChecked());
+ }
+ }
+
+ try {
+ SelectAllRunnable runnable = new SelectAllRunnable();
+ BusyIndicator.showWhile(display, runnable);
+ selectCount = runnable.numberOfOccurrences;
+
+ if (selectCount != 0) {
+ if (selectCount == 1) { // not plural
+ statusMessage(EditorMessages.FindReplace_Status_selection_label);
+ } else {
+ String msg = EditorMessages.FindReplace_Status_selections_label;
+ msg = NLSUtility.format(msg, String.valueOf(selectCount));
+ statusMessage(msg);
+ }
+ } else {
+ String msg = NLSUtility.format(EditorMessages.FindReplace_Status_noMatchWithValue_label,
+ findString);
+ statusMessage(false, EditorMessages.FindReplace_Status_noMatch_label, msg);
+ }
+ } catch (PatternSyntaxException ex) {
+ statusError(ex.getLocalizedMessage());
+ } catch (IllegalStateException ex) {
+ // we don't keep state in this dialog
+ }
+ }
+ }
+
+ /**
+ * Validates the state of the find/replace target.
+ *
+ * @return true
if target can be changed, false
+ * otherwise
+ * @since 2.1
+ */
+ public boolean validateTargetState() {
+
+ if (fTarget instanceof IFindReplaceTargetExtension2) {
+ IFindReplaceTargetExtension2 extension = (IFindReplaceTargetExtension2) fTarget;
+ if (!extension.validateTargetState()) {
+ statusError(EditorMessages.FindReplaceDialog_read_only);
+ return false;
+ }
+ }
+ return isEditable();
+ }
+
+ /**
+ * Replaces the current selection of the target with the user's replace string.
+ *
+ * @return true
if the operation was successful
+ */
+ public boolean performReplaceSelection(String replaceString) {
+
+ if (!validateTargetState())
+ return false;
+
+ if (replaceString == null)
+ replaceString = ""; //$NON-NLS-1$
+
+ boolean replaced;
+ try {
+ replaceSelection(replaceString, isRegExSearchAvailableAndChecked());
+ replaced = true;
+ } catch (PatternSyntaxException ex) {
+ statusError(ex.getLocalizedMessage());
+ replaced = false;
+ } catch (IllegalStateException ex) {
+ replaced = false;
+ }
+
+ return replaced;
+ }
+
+ /**
+ * Locates the user's findString in the text of the target.
+ *
+ * @since 3.7
+ */
+ public boolean performSearch(String searchString) {
+ return performSearch(isIncrementalSearch() && !isRegExSearchAvailableAndChecked(), searchString);
+ }
+
+ /**
+ * Locates the user's findString in the text of the target.
+ *
+ * @param mustInitIncrementalBaseLocation true
if base location
+ * must be initialized
+ * @param beep if true
beeps when search
+ * does not find a match or needs to wrap
+ * @param forwardSearch the search direction
+ * @since 3.0
+ */
+ public boolean performSearch(boolean mustInitIncrementalBaseLocation, String findString) {
+
+ if (mustInitIncrementalBaseLocation)
+ initIncrementalBaseLocation();
+
+ boolean somethingFound = false;
+
+ if (findString != null && !findString.isEmpty()) {
+
+ try {
+ somethingFound = findNext(findString, isForwardSearch());
+ } catch (PatternSyntaxException ex) {
+ statusError(ex.getLocalizedMessage());
+ } catch (IllegalStateException ex) {
+ // we don't keep state in this dialog
+ }
+ }
+ return somethingFound;
+ }
+
+ /**
+ * Replaces all occurrences of the user's findString with the replace string.
+ * Returns the number of replacements that occur.
+ *
+ * @param findString the string to search for
+ * @param replaceString the replacement string
+ * @param caseSensitive should the search be case sensitive
+ * @param wholeWord does the search string represent a complete word
+ * @param regExSearch if true
findString represents a regular
+ * expression
+ * @return the number of occurrences
+ *
+ * @since 3.0
+ */
+ public int replaceAll(String findString, String replaceString, boolean caseSensitive, boolean wholeWord,
+ boolean regExSearch) {
+
+ int replaceCount = 0;
+ int findReplacePosition = 0;
+
+ findReplacePosition = 0;
+
+ if (!validateTargetState())
+ return replaceCount;
+
+ if (fTarget instanceof IFindReplaceTargetExtension)
+ ((IFindReplaceTargetExtension) fTarget).setReplaceAllMode(true);
+
+ try {
+ int index = 0;
+ while (index != -1) {
+ index = findAndSelect(findReplacePosition, findString);
+ if (index != -1) { // substring not contained from current position
+ Point selection = replaceSelection(replaceString, regExSearch);
+ replaceCount++;
+ findReplacePosition = selection.x + selection.y;
+ }
+ }
+ } finally {
+ if (fTarget instanceof IFindReplaceTargetExtension)
+ ((IFindReplaceTargetExtension) fTarget).setReplaceAllMode(false);
+ }
+
+ return replaceCount;
+ }
+
+ public int selectAll(String findString, boolean caseSensitive, boolean wholeWord, boolean regExSearch) {
+
+ int replaceCount = 0;
+ int position = 0;
+
+ if (!validateTargetState())
+ return replaceCount;
+
+ List selectedRegions = new ArrayList<>();
+ int index = 0;
+ do {
+ index = findAndSelect(position, findString);
+ if (index != -1) { // substring not contained from current position
+ Point selection = fTarget.getSelection();
+ selectedRegions.add(new Region(selection.x, selection.y));
+ replaceCount++;
+ position = selection.x + selection.y;
+ }
+ } while (index != -1);
+ if (fTarget instanceof IFindReplaceTargetExtension4) {
+ ((IFindReplaceTargetExtension4) fTarget).setSelection(selectedRegions.toArray(IRegion[]::new));
+ }
+
+ return replaceCount;
+ }
+
+ /**
+ * Returns the position of the specified search string, or -1
if
+ * the string can not be found when searching using the given options.
+ *
+ * @param findString the string to search for
+ * @param startPosition the position at which to start the search
+ * @param forwardSearch the direction of the search
+ * @param caseSensitive should the search be case sensitive
+ * @param wrapSearch should the search wrap to the start/end if arrived at
+ * the end/start
+ * @param wholeWord does the search string represent a complete word
+ * @param regExSearch if true
findString represents a regular
+ * expression
+ * @param beep if true
beeps when search does not find a
+ * match or needs to wrap
+ * @return the occurrence of the find string following the options or
+ * -1
if nothing found
+ * @since 3.0
+ */
+ public int findIndex(String findString, int startPosition) {
+
+ if (isForwardSearch()) {
+ int index = findAndSelect(startPosition, findString);
+ if (index == -1) {
+
+ status.doBeep();
+
+ if (isWrapSearch()) {
+ statusMessage(EditorMessages.FindReplace_Status_wrapped_label);
+ index = findAndSelect(-1, findString);
+ }
+ }
+ return index;
+ }
+
+ // backward
+ int index = startPosition == 0 ? -1
+ : findAndSelect(startPosition - 1, findString);
+ if (index == -1) {
+
+ status.doBeep();
+
+ if (isWrapSearch()) {
+ statusMessage(EditorMessages.FindReplace_Status_wrapped_label);
+ index = findAndSelect(-1, findString);
+ }
+ }
+ return index;
+ }
+
+ /**
+ * Searches for a string starting at the given offset and using the specified
+ * search directives. If a string has been found it is selected and its start
+ * offset is returned.
+ *
+ * @param offset the offset at which searching starts
+ * @param findString the string which should be found
+ * @param forwardSearch the direction of the search
+ * @param caseSensitive true
performs a case sensitive search,
+ * false
an insensitive search
+ * @param wholeWord if true
only occurrences are reported in
+ * which the findString stands as a word by itself
+ * @param regExSearch if true
findString represents a regular
+ * expression
+ * @return the position of the specified string, or -1 if the string has not
+ * been found
+ * @since 3.0
+ */
+ public int findAndSelect(int offset, String findString) {
+ if (fTarget instanceof IFindReplaceTargetExtension3)
+ return ((IFindReplaceTargetExtension3) fTarget).findAndSelect(offset, findString, isForwardSearch(),
+ isCaseSensitiveSearch(), isWholeWordSearch(), isRegexSearch());
+ return fTarget.findAndSelect(offset, findString, isForwardSearch(), isCaseSensitiveSearch(),
+ isWholeWordSearch());
+ }
+
+ /**
+ * Replaces the selection with replaceString
. If
+ * regExReplace
is true
, replaceString
is
+ * a regex replace pattern which will get expanded if the underlying target
+ * supports it. Returns the region of the inserted text; note that the returned
+ * selection covers the expanded pattern in case of regex replace.
+ *
+ * @param replaceString the replace string (or a regex pattern)
+ * @param regExReplace true
if replaceString
is a
+ * pattern
+ * @return the selection after replacing, i.e. the inserted text
+ * @since 3.0
+ */
+ public Point replaceSelection(String replaceString, boolean regExReplace) {
+ if (fTarget instanceof IFindReplaceTargetExtension3)
+ ((IFindReplaceTargetExtension3) fTarget).replaceSelection(replaceString, regExReplace);
+ else
+ fTarget.replaceSelection(replaceString);
+
+ return fTarget.getSelection();
+ }
+
+ /**
+ * Returns whether the specified search string can be found using the given
+ * options.
+ *
+ * @param findString the string to search for
+ * @param forwardSearch the direction of the search
+ * @param caseSensitive should the search be case sensitive
+ * @param wrapSearch should the search wrap to the start/end if arrived at
+ * the end/start
+ * @param wholeWord does the search string represent a complete word
+ * @param incremental is this an incremental search
+ * @param regExSearch if true
findString represents a regular
+ * expression
+ * @param beep if true
beeps when search does not find a
+ * match or needs to wrap
+ * @return true
if the search string can be found using the given
+ * options
+ *
+ * @since 3.0
+ */
+ public boolean findNext(String findString, boolean forwardSearch) {
+
+ if (fTarget == null)
+ return false;
+
+ Point r = null;
+ if (isIncrementalSearch())
+ r = fIncrementalBaseLocation;
+ else
+ r = fTarget.getSelection();
+
+ int findReplacePosition = r.x;
+ if (forwardSearch && !fNeedsInitialFindBeforeReplace || !forwardSearch && fNeedsInitialFindBeforeReplace)
+ findReplacePosition += r.y;
+
+ fNeedsInitialFindBeforeReplace = false;
+
+ int index = findIndex(findString, findReplacePosition);
+
+ if (index == -1) {
+ String msg = NLSUtility.format(EditorMessages.FindReplace_Status_noMatchWithValue_label, findString);
+ statusMessage(false, EditorMessages.FindReplace_Status_noMatch_label, msg);
+ return false;
+ }
+
+ if (forwardSearch && index >= findReplacePosition || !forwardSearch && index <= findReplacePosition)
+ statusMessage(""); //$NON-NLS-1$
+
+ return true;
+ }
+
+ public boolean performFindFirstThenReplaceInASecondStep(String findString, String replaceString) {
+ if (fNeedsInitialFindBeforeReplace) {
+ performSearch(findString);
+ }
+ if (performReplaceSelection(replaceString)) {
+ performSearch(findString);
+ return true;
+ }
+ return false;
+ }
+
+ public boolean performSelectAndReplace(String findString, String replaceString) {
+ if (fNeedsInitialFindBeforeReplace)
+ performSearch(findString);
+ return performReplaceSelection(replaceString);
+ }
+
+ public void updateTarget(IFindReplaceTarget target, boolean isTargetEditable) {
+ fTargetEditable = isTargetEditable;
+ fNeedsInitialFindBeforeReplace = true;
+
+ if (target != fTarget) {
+ if (fTarget != null && fTarget instanceof IFindReplaceTargetExtension)
+ ((IFindReplaceTargetExtension) fTarget).endSession();
+
+ fTarget = target;
+ if (fTarget != null)
+ fIsTargetSupportingRegEx = fTarget instanceof IFindReplaceTargetExtension3;
+
+ if (fTarget instanceof IFindReplaceTargetExtension) {
+ ((IFindReplaceTargetExtension) fTarget).beginSession();
+
+ setGlobalSearch(true);
+ }
+ }
+
+ initIncrementalBaseLocation();
+ }
+
+ public void endSession() {
+ if (fTarget != null && fTarget instanceof IFindReplaceTargetExtension)
+ ((IFindReplaceTargetExtension) fTarget).endSession();
+
+ fTarget = null;
+ }
+
+
+ public void deactivateScope() {
+ if (fTarget != null && (fTarget instanceof IFindReplaceTargetExtension))
+ ((IFindReplaceTargetExtension) fTarget).setScope(null);
+
+ fOldScope = null;
+ }
+
+ public String getCurrentSelection() {
+ if (fTarget == null) {
+ return null;
+ }
+
+ return fTarget.getSelectionText();
+ }
+
+ /**
+ * Returns whether the target is editable.
+ *
+ * @return true
if target is editable
+ */
+ public boolean isEditable() {
+ boolean isEditable = (fTarget == null ? false : fTarget.isEditable());
+ return fTargetEditable && isEditable;
+ }
+
+ public boolean supportsMultiSelection() {
+ return fTarget instanceof IFindReplaceTargetExtension4;
+ }
+
+ public boolean isTargetAvailable() {
+ return fTarget != null;
+ }
+
+ /**
+ * Sets the given status message in the status line.
+ *
+ * @param error true
if it is an error
+ * @param dialogMessage the message to display in the dialog's status line
+ * @param editorMessage the message to display in the editor's status line
+ */
+ private void statusMessage(boolean error, String dialogMessage, String editorMessage) {
+ status.setError(error);
+ status.setMessage(dialogMessage);
+
+ IEditorStatusLine statusLine = getStatusLineManager();
+ if (statusLine != null)
+ statusLine.setMessage(error, editorMessage, null);
+ }
+
+ /**
+ * Sets the given error message in the status line.
+ *
+ * @param message the message
+ */
+ private void statusError(String message) {
+ statusMessage(true, message, message);
+ }
+
+ /**
+ * Sets the given message in the status line.
+ *
+ * @param message the message
+ */
+ private void statusMessage(String message) {
+ statusMessage(false, message, message);
+ }
+
+ public void updateSearchResultAfterTextWasModified(String searchString) {
+ if (isIncrementalSearch() && !isRegExSearchAvailableAndChecked()) {
+ if (searchString.equals("") && fTarget != null) { //$NON-NLS-1$
+ // empty selection at base location
+ int offset = fIncrementalBaseLocation.x;
+
+ if (isForwardSearch() && !fNeedsInitialFindBeforeReplace
+ || !isForwardSearch() && fNeedsInitialFindBeforeReplace)
+ offset = offset + fIncrementalBaseLocation.y;
+
+ fNeedsInitialFindBeforeReplace = false;
+ findAndSelect(offset, ""); //$NON-NLS-1$
+ } else {
+ performSearch(false, searchString);
+ }
+ }
+ }
+
+}