private static List<RangeMarker> add(DocumentEx document, int... offsets) {
   List<RangeMarker> result = new ArrayList<RangeMarker>();
   for (int i = 0; i < offsets.length; i += 2) {
     int start = offsets[i];
     int end = offsets[i + 1];
     RangeMarker m = document.createRangeMarker(start, end);
     result.add(m);
   }
   return result;
 }
 public static List<CustomLiveTemplate> listApplicableCustomTemplates(
     @NotNull Editor editor, @NotNull PsiFile file, boolean selectionOnly) {
   List<CustomLiveTemplate> result = new ArrayList<CustomLiveTemplate>();
   for (CustomLiveTemplate template : CustomLiveTemplate.EP_NAME.getExtensions()) {
     if ((!selectionOnly || template.supportsWrapping())
         && isApplicable(template, editor, file, selectionOnly)) {
       result.add(template);
     }
   }
   return result;
 }
  private static List<TemplateImpl> filterApplicableCandidates(
      PsiFile file, int caretOffset, List<TemplateImpl> candidates) {
    if (candidates.isEmpty()) {
      return candidates;
    }

    PsiFile copy =
        insertDummyIdentifierIfNeeded(
            file, caretOffset, caretOffset, CompletionUtil.DUMMY_IDENTIFIER_TRIMMED);

    List<TemplateImpl> result = new ArrayList<TemplateImpl>();
    for (TemplateImpl candidate : candidates) {
      if (isApplicable(copy, caretOffset - candidate.getKey().length(), candidate)) {
        result.add(candidate);
      }
    }
    return result;
  }