private void calculateToLift(LookupElement element) {
   for (String string : CompletionUtil.iterateLookupStrings(element)) {
     for (int len = 1; len < string.length(); len++) {
       String prefix = string.substring(0, len);
       for (LookupElement shorterElement : myElements.get(prefix)) {
         if (myCondition.shouldLift(shorterElement, element)) {
           myToLift.putValue(element, shorterElement);
           myReversedToLift.putValue(shorterElement, element);
         }
       }
     }
   }
 }
  @Override
  public void removeElement(@NotNull LookupElement element, @NotNull ProcessingContext context) {
    for (String s : CompletionUtil.iterateLookupStrings(element)) {
      myElements.remove(s, element);
      if (myElements.get(s).isEmpty()) {
        mySortedStrings.remove(s);
      }
    }

    removeFromMap(element, myToLift, myReversedToLift);
    removeFromMap(element, myReversedToLift, myToLift);

    super.removeElement(element, context);
  }
  @Override
  public void addElement(@NotNull LookupElement added, @NotNull ProcessingContext context) {
    myCount++;

    for (String string : CompletionUtil.iterateLookupStrings(added)) {
      if (string.length() == 0) continue;

      myElements.putValue(string, added);
      mySortedStrings.add(string);
      final NavigableSet<String> after = mySortedStrings.tailSet(string, false);
      for (String s : after) {
        if (!s.startsWith(string)) {
          break;
        }
        for (LookupElement longer : myElements.get(s)) {
          updateLongerItem(added, longer);
        }
      }
    }
    super.addElement(added, context);

    calculateToLift(added);
  }