private static boolean doCompleteIfNeeded(int offset, PsiFile file, PsiElement lastElement) {
    final Ref<Boolean> isRelevantLanguage = new Ref<>();
    final Ref<Boolean> isAnt = new Ref<>();
    String text = lastElement.getText();
    final int len = offset - lastElement.getTextRange().getStartOffset();
    if (len < text.length()) {
      if (len < 0) {
        LOG.error("wrong last element calculated: " + lastElement);
        return false;
      }
      text = text.substring(0, len);
    }
    if (text.endsWith("<") && isLanguageRelevant(lastElement, file, isRelevantLanguage, isAnt) ||
        text.equals(" ") && isLanguageRelevant(lastElement, file, isRelevantLanguage, isAnt) ||
        text.endsWith("${") && isLanguageRelevant(lastElement, file, isRelevantLanguage, isAnt) && isAnt.get().booleanValue() ||
        text.endsWith("@{") && isLanguageRelevant(lastElement, file, isRelevantLanguage, isAnt) && isAnt.get().booleanValue() ||
        text.endsWith("</") && isLanguageRelevant(lastElement, file, isRelevantLanguage, isAnt) ||
        ContainerUtil.exists(XmlAutoPopupEnabler.EP_NAME.getExtensionList(), p -> p.shouldShowPopup(file, offset))) {
      return true;
    }

    return false;
  }
private static boolean doCompleteIfNeeded(int offset, PsiFile file, PsiElement lastElement)