LookupUtils { public static String calcLookupPrefix(String lookup, String content) { for (int i = lookup.length() - 1; i >= 0; i--) { int i2 = i; for (int j = content.length() - 1; j >= 0 && i2 >= 0; j--) { if (lookup.charAt(i2) == content.charAt(j)) { if (i2 == 0) { return (j == 0 || content.charAt(j - 1) == ' ' || content.charAt(j - 1) == '\t' || content.charAt(j - 1) == '\n') ? lookup.substring(0, i + 1) : ""; } } else if (content.charAt(j) == ' ' || content.charAt(j) == '\n' || content.charAt(j) == '\t') { continue; } else { break; } i2--; } } return ""; }  static void scheduleAutoPopup(final Editor editor, final InsertionContext context); static void scheduleAutoPopup2(final Editor editor, final Project project); static String calcLookupPrefix(String lookup, String content); static String adoptPrefix(String lookupString, String text, int endOffset, String prefix); static int calcPrefixSize(String lookupString, String text, int endOffset, String prefix);  }
@Test public void test1() { assertEquals("create", LookupUtils.calcLookupPrefix("create package", "create")); assertEquals("", LookupUtils.calcLookupPrefix("create package", "craate")); assertEquals("", LookupUtils.calcLookupPrefix("create package", "bobauiwcreate")); assertEquals("create", LookupUtils.calcLookupPrefix("create package", "ywuw iwquq bobauiw create")); assertEquals("create pa", LookupUtils.calcLookupPrefix("create package", "create pa")); assertEquals("create ", LookupUtils.calcLookupPrefix("create package", "create ")); assertEquals("create package", LookupUtils.calcLookupPrefix("create package", "create package")); assertEquals("create package", LookupUtils.calcLookupPrefix("create package", "create package ")); assertEquals("create ", LookupUtils.calcLookupPrefix("create package body", "create table eee (\n" + "hjh BLOB\n" + ");\n" + "\n" + "create ")); }
@Test public void test2() { assertEquals("create pa", LookupUtils.calcLookupPrefix("create package", "create \n\npa")); }