Bug 532928 - Show proper occurance marker label in Generic Editor

Instead of the current "Line N" show "Occurrences of 'word'" which is
way more informative.
Also enable save actions to speed up development.

Change-Id: I8dde587bcedcb8294c4dea5dcf621b9731b3bafa
Signed-off-by: Alexander Kurtakov <akurtako@redhat.com>
diff --git a/org.eclipse.ui.genericeditor/.settings/org.eclipse.jdt.ui.prefs b/org.eclipse.ui.genericeditor/.settings/org.eclipse.jdt.ui.prefs
new file mode 100644
index 0000000..1cbfac2
--- /dev/null
+++ b/org.eclipse.ui.genericeditor/.settings/org.eclipse.jdt.ui.prefs
@@ -0,0 +1,59 @@
+eclipse.preferences.version=1
+editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true
+sp_cleanup.add_default_serial_version_id=true
+sp_cleanup.add_generated_serial_version_id=false
+sp_cleanup.add_missing_annotations=true
+sp_cleanup.add_missing_deprecated_annotations=true
+sp_cleanup.add_missing_methods=false
+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.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.convert_functional_interfaces=false
+sp_cleanup.convert_to_enhanced_for_loop=false
+sp_cleanup.correct_indentation=false
+sp_cleanup.format_source_code=true
+sp_cleanup.format_source_code_changes_only=false
+sp_cleanup.insert_inferred_type_arguments=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.never_use_blocks=false
+sp_cleanup.never_use_parentheses_in_expressions=true
+sp_cleanup.on_save_use_additional_actions=true
+sp_cleanup.organize_imports=true
+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.remove_private_constructors=true
+sp_cleanup.remove_redundant_type_arguments=false
+sp_cleanup.remove_trailing_whitespaces=false
+sp_cleanup.remove_trailing_whitespaces_all=true
+sp_cleanup.remove_trailing_whitespaces_ignore_empty=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_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.sort_members=false
+sp_cleanup.sort_members_all=false
+sp_cleanup.use_anonymous_class_creation=false
+sp_cleanup.use_blocks=false
+sp_cleanup.use_blocks_only_for_return_and_throw=false
+sp_cleanup.use_lambda=true
+sp_cleanup.use_parentheses_in_expressions=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
diff --git a/org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/DefaultWordHighlightStrategy.java b/org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/DefaultWordHighlightStrategy.java
index 4f4ce28..e5822ac 100644
--- a/org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/DefaultWordHighlightStrategy.java
+++ b/org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/DefaultWordHighlightStrategy.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2017 Red Hat Inc. and others.
+ * Copyright (c) 2017, 2018 Red Hat Inc. and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -35,21 +35,24 @@
 import org.eclipse.jface.text.source.IAnnotationModel;
 import org.eclipse.jface.text.source.IAnnotationModelExtension;
 import org.eclipse.jface.text.source.ISourceViewer;
+import org.eclipse.osgi.util.NLS;
 import org.eclipse.swt.custom.CaretEvent;
 import org.eclipse.swt.custom.CaretListener;
 
 /**
-*
-* This Reconciler Strategy is a default stategy which will be present if
-* no other highlightReconcilers are registered for a given content-type. It splits
-* the text into 'words' (which are defined as anything in-between
-* non-alphanumeric characters) and searches the document highlighting all like words.
-*
-* E.g. if your file contains "t^he dog in the bog" and you leave your caret at
-* ^ you will get both instances of 'the' highlighted.
-*
-*/
-public class DefaultWordHighlightStrategy implements IReconcilingStrategy, IReconcilingStrategyExtension, CaretListener, IPreferenceChangeListener {
+ *
+ * This Reconciler Strategy is a default stategy which will be present if no
+ * other highlightReconcilers are registered for a given content-type. It splits
+ * the text into 'words' (which are defined as anything in-between
+ * non-alphanumeric characters) and searches the document highlighting all like
+ * words.
+ *
+ * E.g. if your file contains "t^he dog in the bog" and you leave your caret at
+ * ^ you will get both instances of 'the' highlighted.
+ *
+ */
+public class DefaultWordHighlightStrategy
+		implements IReconcilingStrategy, IReconcilingStrategyExtension, CaretListener, IPreferenceChangeListener {
 
 	private static final String ANNOTATION_TYPE = "org.eclipse.ui.genericeditor.text"; //$NON-NLS-1$
 
@@ -59,7 +62,8 @@
 
 	private static final String WORD_REGEXP = "\\w+"; //$NON-NLS-1$
 	private static final Pattern WORD_PATTERN = Pattern.compile(WORD_REGEXP, Pattern.UNICODE_CHARACTER_CLASS);
-	private static final Pattern CURRENT_WORD_START_PATTERN = Pattern.compile(WORD_REGEXP + "$", Pattern.UNICODE_CHARACTER_CLASS); //$NON-NLS-1$
+	private static final Pattern CURRENT_WORD_START_PATTERN = Pattern.compile(WORD_REGEXP + "$", //$NON-NLS-1$
+			Pattern.UNICODE_CHARACTER_CLASS);
 
 	private Annotation[] fOccurrenceAnnotations = null;
 
@@ -70,24 +74,26 @@
 		}
 
 		String text = document.get();
-		offset = ((ITextViewerExtension5)sourceViewer).widgetOffset2ModelOffset(offset);
+		offset = ((ITextViewerExtension5) sourceViewer).widgetOffset2ModelOffset(offset);
 
 		String word = findCurrentWord(text, offset);
-		if(word == null) {
+		if (word == null) {
 			removeOccurrenceAnnotations();
 			return;
 		}
 
 		Matcher m = WORD_PATTERN.matcher(text);
 		Map<Annotation, Position> annotationMap = new HashMap<>();
-		while(m.find()) {
-			if(m.group().equals(word)) {
-				annotationMap.put(new Annotation(ANNOTATION_TYPE, false, null),
+		while (m.find()) {
+			if (m.group().equals(word)) {
+				annotationMap.put(
+						new Annotation(ANNOTATION_TYPE, false,
+								NLS.bind(Messages.DefaultWordHighlightStrategy_OccurrencesOf, word)),
 						new Position(m.start(), m.end() - m.start()));
 			}
 		}
 
-		if(annotationMap.size() < 2) {
+		if (annotationMap.size() < 2) {
 			removeOccurrenceAnnotations();
 			return;
 		}
@@ -111,11 +117,11 @@
 	private static String findCurrentWord(String text, int offset) {
 		String wordStart = null;
 		String wordEnd = null;
-		
+
 		String substring = text.substring(0, offset);
 		Matcher m = CURRENT_WORD_START_PATTERN.matcher(substring);
 		if (m.find()) {
-			wordStart=m.group();
+			wordStart = m.group();
 		}
 		substring = text.substring(offset);
 		m = WORD_PATTERN.matcher(substring);
diff --git a/org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/Messages.java b/org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/Messages.java
new file mode 100644
index 0000000..b7d9031
--- /dev/null
+++ b/org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/Messages.java
@@ -0,0 +1,25 @@
+/*******************************************************************************
+ * Copyright (c) 2018 Red Hat Inc. and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *   Alexander Kurtakov (Red Hat Inc.) - initial version
+ *******************************************************************************/
+package org.eclipse.ui.internal.genericeditor;
+
+import org.eclipse.osgi.util.NLS;
+
+public class Messages extends NLS {
+	private static final String BUNDLE_NAME = "org.eclipse.ui.internal.genericeditor.messages"; //$NON-NLS-1$
+	public static String DefaultWordHighlightStrategy_OccurrencesOf;
+	static {
+		// initialize resource bundle
+		NLS.initializeMessages(BUNDLE_NAME, Messages.class);
+	}
+
+	private Messages() {
+	}
+}
diff --git a/org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/messages.properties b/org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/messages.properties
new file mode 100644
index 0000000..620d32c
--- /dev/null
+++ b/org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/messages.properties
@@ -0,0 +1,11 @@
+###############################################################################
+# Copyright (c) 2018 Red Hat Inc. and others.
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Eclipse Public License v1.0
+# which accompanies this distribution, and is available at
+# http://www.eclipse.org/legal/epl-v10.html
+#
+# Contributors:
+#     Alexander Kurtakov (Red Hat Inc.) - initial API and implementation
+###############################################################################
+DefaultWordHighlightStrategy_OccurrencesOf=Occurrence of ''{0}''