Bug 559496 - [content assist] UI: support subword matching

Change-Id: I9adcba8dfd591d3b6bd1f22424ac8acf9b62ca90
Signed-off-by: Julian Honnen <julian.honnen@vector.com>
diff --git a/org.eclipse.jdt.ui/plugin.properties b/org.eclipse.jdt.ui/plugin.properties
index f8eb47c..88525e7 100644
--- a/org.eclipse.jdt.ui/plugin.properties
+++ b/org.eclipse.jdt.ui/plugin.properties
@@ -120,7 +120,7 @@
 preferenceKeywords.javaeditor=Java java editor quick assist appearance navigation colors light bulb smart caret positioning highlight matching bracket foreground background show selected only save action participant clean up
 preferenceKeywords.javaeditorproperty= Java java editor save action participant clean up
 
-preferenceKeywords.contentassist=Java editor content code assist complete completion insert overwrite single proposal common prefix automatically import fill argument name guess alphabetical hide discouraged reference forbidden auto activation trigger Javadoc camel camelcase category categories separate specific timeout type types word hippie template static members favorites postfix chain asynchronous
+preferenceKeywords.contentassist=Java editor content code assist complete completion insert overwrite single proposal common prefix automatically import fill argument name guess alphabetical hide discouraged reference forbidden auto activation trigger Javadoc camel camelcase category categories separate specific timeout type types word hippie template static members favorites postfix chain asynchronous subword
 preferenceKeywords.hover=pop-up Java editor hover popup sticky annotation roll over key modifier combined variable problem externalized externalize string source
 preferenceKeywords.syntaxcoloring=Java editor colors semantic coloring highlighting Javadoc html links tags multi line single line comment task tag method invocation static field annotation autoboxing unboxing boxing constant deprecated field keywords local variable operators brackets strings type variable inherited method declaration
 preferenceKeywords.templates=Java editor templates snippet macros
diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/CodeAssistConfigurationBlock.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/CodeAssistConfigurationBlock.java
index 71bed2a..2b0b22f 100644
--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/CodeAssistConfigurationBlock.java
+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/CodeAssistConfigurationBlock.java
@@ -82,6 +82,7 @@
 	private static final Key PREF_CODEASSIST_DEPRECATION_CHECK= getJDTCoreKey(JavaCore.CODEASSIST_DEPRECATION_CHECK);
 	private static final Key PREF_CODEASSIST_CAMEL_CASE_MATCH= getJDTCoreKey(JavaCore.CODEASSIST_CAMEL_CASE_MATCH);
 	private static final Key PREF_CODEASSIST_SUBSTRING_MATCH= getJDTCoreKey(JavaCore.CODEASSIST_SUBSTRING_MATCH);
+	private static final Key PREF_CODEASSIST_SUBWORD_MATCH= getJDTCoreKey(JavaCore.CODEASSIST_SUBWORD_MATCH);
 
 	private static Key[] getAllKeys() {
 		return new Key[] {
@@ -102,6 +103,7 @@
 				PREF_CODEASSIST_DEPRECATION_CHECK,
 				PREF_CODEASSIST_CAMEL_CASE_MATCH,
 				PREF_CODEASSIST_SUBSTRING_MATCH,
+				PREF_CODEASSIST_SUBWORD_MATCH,
 				PREF_CODEASSIST_DISABLE_COMPLETION_PROPOSAL_TRIGGER_CHARS
 		};
 	}
@@ -285,6 +287,9 @@
 		label= PreferencesMessages.CodeAssistConfigurationBlock_matchSubstring_label;
 		addCheckBox(composite, label, PREF_CODEASSIST_SUBSTRING_MATCH, enabledDisabled, 0);
 
+		label= PreferencesMessages.CodeAssistConfigurationBlock_matchSubword_label;
+		addCheckBox(composite, label, PREF_CODEASSIST_SUBWORD_MATCH, enabledDisabled, 0);
+
 		label= PreferencesMessages.JavaEditorPreferencePage_showOnlyProposalsVisibleInTheInvocationContext;
 		addCheckBox(composite, label, PREF_CODEASSIST_SHOW_VISIBLE_PROPOSALS, trueFalse, 0);
 
diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/PreferencesMessages.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/PreferencesMessages.java
index 1f2d11a..75185d4 100644
--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/PreferencesMessages.java
+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/PreferencesMessages.java
@@ -829,6 +829,7 @@
 	public static String JavaBasePreferencePage_do_not_hide_dialog_message;
 	public static String CodeAssistConfigurationBlock_matchCamelCase_label;
 	public static String CodeAssistConfigurationBlock_matchSubstring_label;
+	public static String CodeAssistConfigurationBlock_matchSubword_label;
 	public static String ComplianceConfigurationBlock_version16;
 	public static String ComplianceConfigurationBlock_version17;
 	public static String ComplianceConfigurationBlock_version18;
diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/PreferencesMessages.properties b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/PreferencesMessages.properties
index 1a6e2df..b7657e5 100644
--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/PreferencesMessages.properties
+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/PreferencesMessages.properties
@@ -928,6 +928,7 @@
 CodeAssistConfigurationBlock_sortingSection_title=Sorting and Filtering
 CodeAssistConfigurationBlock_matchCamelCase_label=Show ca&mel case matches
 CodeAssistConfigurationBlock_matchSubstring_label=Show su&bstring matches
+CodeAssistConfigurationBlock_matchSubword_label=Show subword mat&ches
 CodeAssistConfigurationBlock_autoactivationSection_title=Auto Activation
 # do not translate the href argument (org.eclipse.jdt.ui.preferences.ProblemSeveritiesPreferencePage)
 TypeFilterPreferencePage_restricted_link=Type references with <a href="org.eclipse.jdt.ui.preferences.ProblemSeveritiesPreferencePage">access restrictions</a>:
diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/AbstractJavaCompletionProposal.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/AbstractJavaCompletionProposal.java
index 16555a6..a3cd88b 100644
--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/AbstractJavaCompletionProposal.java
+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/AbstractJavaCompletionProposal.java
@@ -941,6 +941,8 @@
 			return SearchPattern.R_CAMELCASE_MATCH;
 		} else if (isSubstringMatching() && CharOperation.substringMatch(pattern.toCharArray(), string.toCharArray())) {
 			return SearchPattern.R_SUBSTRING_MATCH;
+		} else if (isSubwordMatching() && CharOperation.subWordMatch(pattern.toCharArray(), string.toCharArray())) {
+			return SearchPattern.R_SUBWORD_MATCH;
 		} else {
 			return -1;
 		}
@@ -1004,6 +1006,11 @@
 		return JavaCore.ENABLED.equals(value);
 	}
 
+	private boolean isSubwordMatching() {
+		String value= JavaCore.getOption(JavaCore.CODEASSIST_SUBWORD_MATCH);
+		return JavaCore.ENABLED.equals(value);
+	}
+
 	protected static boolean insertCompletion() {
 		IPreferenceStore preference= JavaPlugin.getDefault().getPreferenceStore();
 		return preference.getBoolean(PreferenceConstants.CODEASSIST_INSERT_COMPLETION);