Example #1
0
 @Nullable
 @Override
 public String computeTemplateKeyWithoutContextChecking(@NotNull CustomTemplateCallback callback) {
   Editor editor = callback.getEditor();
   return computeTemplateKeyWithoutContextChecking(
       editor.getDocument().getCharsSequence(), editor.getCaretModel().getOffset());
 }
Example #2
0
 @Nullable
 @Override
 public String computeTemplateKey(@NotNull CustomTemplateCallback callback) {
   Editor editor = callback.getEditor();
   String key =
       computeTemplateKeyWithoutContextChecking(
           editor.getDocument().getCharsSequence(), editor.getCaretModel().getOffset());
   if (key == null) return null;
   return isApplicableTemplate(
           getTemplateByKey(key), key, callback.getContext().getContainingFile(), editor)
       ? key
       : null;
 }
Example #3
0
  @Override
  public void expand(@NotNull final String key, @NotNull final CustomTemplateCallback callback) {
    ApplicationManager.getApplication().assertIsDispatchThread();

    final PostfixTemplate template = getTemplateByKey(key);
    final Editor editor = callback.getEditor();
    final PsiFile file = callback.getContext().getContainingFile();
    if (isApplicableTemplate(template, key, file, editor)) {
      int currentOffset = editor.getCaretModel().getOffset();
      PsiElement newContext = deleteTemplateKey(file, editor.getDocument(), currentOffset, key);
      newContext =
          addSemicolonIfNeeded(
              editor, editor.getDocument(), newContext, currentOffset - key.length());
      expandTemplate(template, editor, newContext);
    } else {
      LOG.error("Template not found by key: " + key);
    }
  }