diff --git a/java.editor/src/org/netbeans/modules/editor/java/Utilities.java b/java.editor/src/org/netbeans/modules/editor/java/Utilities.java --- a/java.editor/src/org/netbeans/modules/editor/java/Utilities.java +++ b/java.editor/src/org/netbeans/modules/editor/java/Utilities.java @@ -166,6 +166,43 @@ return false; if (prefix == null || prefix.length() == 0) return true; + + // sub word completion + { + // example: + // 'out' produces '.*?[o|O].*?[u|U].*?[t|T].*?' + // org.openide.util.Utilities.acoh -> actionsForPath + // java.lang.System.out -> setOut + // argex -> IllegalArgumentException + // java.util.Collections.que -> asLifoQueue + // java.lang.System.sin -> setIn, getSecurityManager, setSecurityManager + + // check whether user input matches the regex + StringBuilder sb = new StringBuilder(3+8*prefix.length()); + sb.append(".*?"); + for (int i = 0; i < prefix.length(); i++) { + char charAt = prefix.charAt(i); + if (Character.isLowerCase(charAt)) { + sb.append("["); + sb.append(charAt); + sb.append("|"); + sb.append(Character.toUpperCase(charAt)); + sb.append("]"); + } else { + //keep uppercase characters as beacons + // for example: java.lang.System.sIn -> setIn + sb.append(charAt); + } + sb.append(".*?"); + } + + System.out.println(sb); + // FIXME regex matches are expensive + if (Pattern.compile(sb.toString()).matcher(theString).matches()) { + return true; + }; + } + return isCaseSensitive() ? theString.startsWith(prefix) : theString.toLowerCase(Locale.ENGLISH).startsWith(prefix.toLowerCase(Locale.ENGLISH)); }