Author: pkluegl
Date: Mon Jan 16 15:08:01 2012
New Revision: 1232018

URL: http://svn.apache.org/viewvc?rev=1232018&view=rev
Log:
UIMA-2334
refactored string match and added toLowerCase()

Modified:
    
uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/core/codeassist/TextMarkerCompletionEngine.java

Modified: 
uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/core/codeassist/TextMarkerCompletionEngine.java
URL: 
http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/core/codeassist/TextMarkerCompletionEngine.java?rev=1232018&r1=1232017&r2=1232018&view=diff
==============================================================================
--- 
uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/core/codeassist/TextMarkerCompletionEngine.java
 (original)
+++ 
uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/core/codeassist/TextMarkerCompletionEngine.java
 Mon Jan 16 15:08:01 2012
@@ -174,7 +174,7 @@ public class TextMarkerCompletionEngine 
           TextMarkerModuleDeclaration parsed, String startPart, int type, 
String complString) {
     Collection<String> importedEngines = 
parsed.descriptorInfo.getImportedEngines();
     for (String string : importedEngines) {
-      if (string.startsWith(complString) || 
removeLowerCase(string).startsWith(complString)) {
+      if (match(complString, string)) {
         addProposal(complString, string, CompletionProposal.PACKAGE_REF);
       }
     }
@@ -182,7 +182,7 @@ public class TextMarkerCompletionEngine 
     for (String each : importedScripts) {
       String[] split = each.split("\\.");
       String string = split[split.length - 1];
-      if (string.startsWith(complString) || 
removeLowerCase(string).startsWith(complString)) {
+      if (match(complString, string)) {
         addProposal(complString, string, CompletionProposal.PACKAGE_REF);
       }
     }
@@ -198,7 +198,7 @@ public class TextMarkerCompletionEngine 
     }
     for (IMethod m : blocks) {
       String string = m.getElementName();
-      if (string.startsWith(complString) || 
removeLowerCase(string).startsWith(complString)) {
+      if (match(complString, string)) {
         addProposal(complString, string, CompletionProposal.PACKAGE_REF);
       }
     }
@@ -219,7 +219,7 @@ public class TextMarkerCompletionEngine 
         }
       }
       for (String string : scripts) {
-        if (string.startsWith(complString) || 
removeLowerCase(string).startsWith(complString)) {
+        if (match(complString, string)) {
           addProposal(complString, string, CompletionProposal.PACKAGE_REF);
         }
       }
@@ -234,7 +234,7 @@ public class TextMarkerCompletionEngine 
         }
       }
       for (String string : engines) {
-        if (string.startsWith(complString) || 
removeLowerCase(string).startsWith(complString)) {
+        if (match(complString, string)) {
           addProposal(complString, string, CompletionProposal.PACKAGE_REF);
         }
       }
@@ -249,7 +249,7 @@ public class TextMarkerCompletionEngine 
         }
       }
       for (String string : tss) {
-        if (string.startsWith(complString) || 
removeLowerCase(string).startsWith(complString)) {
+        if (match(complString, string)) {
           addProposal(complString, string, CompletionProposal.PACKAGE_REF);
         }
       }
@@ -327,7 +327,7 @@ public class TextMarkerCompletionEngine 
   private void doCompletionOnDeclaration(ISourceModule cu, String startPart) {
     String[] keywords = 
TextMarkerKeywordsManager.getKeywords(ITextMarkerKeywords.DECLARATION);
     for (String string : keywords) {
-      if (string.startsWith(startPart) || 
removeLowerCase(string).startsWith(startPart)) {
+      if (match(startPart, string)) {
         addProposal(startPart, string, CompletionProposal.KEYWORD);
       }
     }
@@ -400,7 +400,7 @@ public class TextMarkerCompletionEngine 
           String startPart, int type, String complString) {
     String[] keywords = 
TextMarkerKeywordsManager.getKeywords(ITextMarkerKeywords.ACTION);
     for (String string : keywords) {
-      if (string.startsWith(complString) || 
removeLowerCase(string).startsWith(complString)) {
+      if (match(complString, string)) {
         addProposal(complString, string, 
CompletionProposal.METHOD_NAME_REFERENCE);
       }
     }
@@ -413,7 +413,7 @@ public class TextMarkerCompletionEngine 
     }
     String[] keywords = 
TextMarkerKeywordsManager.getKeywords(ITextMarkerKeywords.CONDITION);
     for (String string : keywords) {
-      if (string.startsWith(complString) || 
removeLowerCase(string).startsWith(complString)) {
+      if (match(complString, string)) {
         addProposal(complString, string, 
CompletionProposal.METHOD_NAME_REFERENCE);
       }
     }
@@ -430,7 +430,7 @@ public class TextMarkerCompletionEngine 
     } catch (Exception e) {
     }
     for (String string : types) {
-      if (string.startsWith(complString) || 
removeLowerCase(string).startsWith(complString)) {
+      if (match(complString, string)) {
         addProposal(complString, string, CompletionProposal.TYPE_REF);
       }
     }
@@ -465,6 +465,11 @@ public class TextMarkerCompletionEngine 
     }
   }
 
+  private boolean match(String complString, String string) {
+    return string.toLowerCase().startsWith(complString.toLowerCase())
+            || removeLowerCase(string).startsWith(complString);
+  }
+
   private void collectFields(SourceMethod sm, List<IField> fields) throws 
ModelException {
     IModelElement[] children = sm.getChildren();
     for (IModelElement me : children) {
@@ -546,9 +551,10 @@ public class TextMarkerCompletionEngine 
     char[] fieldName = field.getElementName().toCharArray();
     char[] complFragment = complString.toCharArray();
 
-    if (CharOperation.camelCaseMatch(complString.toCharArray(), fieldName)) {
+    if (CharOperation.camelCaseMatch(complString.toCharArray(), fieldName)
+            || match(complString, field.getElementName())) {
 
-      int relevance = RelevanceConstants.R_DEFAULT;
+      int relevance = RelevanceConstants.R_DEFAULT +1;
       relevance += computeRelevanceForCaseMatching(complFragment, fieldName);
 
       // accept result
@@ -581,9 +587,9 @@ public class TextMarkerCompletionEngine 
     if (complString.length() > 0) {
       pattern = complString.toCharArray();
     }
-    if (CharOperation.camelCaseMatch(pattern, fieldName)) {
+    if (CharOperation.camelCaseMatch(pattern, fieldName) || match(complString, 
string)) {
 
-      int relevance = RelevanceConstants.R_DEFAULT;
+      int relevance = RelevanceConstants.R_DEFAULT +1;
       relevance += computeRelevanceForCaseMatching(complFragment, fieldName);
 
       // accept result


Reply via email to