当前位置: 首页>>代码示例>>Java>>正文


Java CustomTemplateCallback.getContext方法代码示例

本文整理汇总了Java中com.intellij.codeInsight.template.CustomTemplateCallback.getContext方法的典型用法代码示例。如果您正苦于以下问题:Java CustomTemplateCallback.getContext方法的具体用法?Java CustomTemplateCallback.getContext怎么用?Java CustomTemplateCallback.getContext使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.intellij.codeInsight.template.CustomTemplateCallback的用法示例。


在下文中一共展示了CustomTemplateCallback.getContext方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: expand

import com.intellij.codeInsight.template.CustomTemplateCallback; //导入方法依赖的package包/类
@Override
public void expand(@NotNull final String key, @NotNull final CustomTemplateCallback callback) {
  ApplicationManager.getApplication().assertIsDispatchThread();
  FeatureUsageTracker.getInstance().triggerFeatureUsed("editing.completion.postfix");

  Editor editor = callback.getEditor();
  for (PostfixTemplateProvider provider : LanguagePostfixTemplate.LANG_EP.allForLanguage(getLanguage(callback))) {
    PostfixTemplate postfixTemplate = getTemplate(provider, key);
    if (postfixTemplate != null) {
      final PsiFile file = callback.getContext().getContainingFile();
      if (isApplicableTemplate(provider, key, file, editor)) {
        int offset = deleteTemplateKey(file, editor, key);
        try {
          provider.preExpand(file, editor);
          PsiElement context = CustomTemplateCallback.getContext(file, positiveOffset(offset));
          expandTemplate(postfixTemplate, editor, context);
        }
        finally {
          provider.afterExpand(file, editor);
        }
      }
      // don't care about errors in multiCaret mode
      else if (editor.getCaretModel().getAllCarets().size() == 1) {
        LOG.error("Template not found by key: " + key + "; offset = " + callback.getOffset(), 
                  AttachmentFactory.createAttachment(callback.getFile().getVirtualFile()));
      }
      return;
    }
  }

  // don't care about errors in multiCaret mode
  if (editor.getCaretModel().getAllCarets().size() == 1) {
    LOG.error("Template not found by key: " + key + "; offset = " + callback.getOffset(), 
                  AttachmentFactory.createAttachment(callback.getFile().getVirtualFile()));
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:37,代码来源:PostfixLiveTemplate.java

示例2: createIsApplicationTemplateFunction

import com.intellij.codeInsight.template.CustomTemplateCallback; //导入方法依赖的package包/类
private static Condition<PostfixTemplate> createIsApplicationTemplateFunction(@NotNull final PostfixTemplateProvider provider,
                                                                              @NotNull String key,
                                                                              @NotNull PsiFile file,
                                                                              @NotNull Editor editor) {
  int currentOffset = editor.getCaretModel().getOffset();
  final int newOffset = currentOffset - key.length();
  CharSequence fileContent = editor.getDocument().getCharsSequence();
  StringBuilder fileContentWithoutKey = new StringBuilder();
  fileContentWithoutKey.append(fileContent.subSequence(0, newOffset));
  fileContentWithoutKey.append(fileContent.subSequence(currentOffset, fileContent.length()));
  PsiFile copyFile = copyFile(file, fileContentWithoutKey);
  Document copyDocument = copyFile.getViewProvider().getDocument();
  if (copyDocument == null) {
    return Conditions.alwaysFalse();
  }

  copyFile = provider.preCheck(copyFile, editor, newOffset);
  copyDocument = copyFile.getViewProvider().getDocument();
  if (copyDocument == null) {
    return Conditions.alwaysFalse();
  }

  final PsiElement context = CustomTemplateCallback.getContext(copyFile, positiveOffset(newOffset));
  final Document finalCopyDocument = copyDocument;
  return new Condition<PostfixTemplate>() {
    @Override
    public boolean value(PostfixTemplate template) {
      return template != null && template.isEnabled(provider) && template.isApplicable(context, finalCopyDocument, newOffset);
    }
  };
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:32,代码来源:PostfixLiveTemplate.java

示例3: expand

import com.intellij.codeInsight.template.CustomTemplateCallback; //导入方法依赖的package包/类
public static void expand(@NotNull String key, @NotNull CustomTemplateCallback callback,
                          @NotNull ZenCodingGenerator defaultGenerator,
                          @NotNull Collection<? extends ZenCodingFilter> extraFilters,
                          boolean expandPrimitiveAbbreviations, int segmentsLimit) throws EmmetException {
  final ZenCodingNode node = parse(key, callback, defaultGenerator, null);
  if (node == null) {
    return;
  }
  if (node instanceof TemplateNode) {
    if (key.equals(((TemplateNode)node).getTemplateToken().getKey()) && callback.findApplicableTemplates(key).size() > 1) {
      TemplateManagerImpl templateManager = (TemplateManagerImpl)callback.getTemplateManager();
      Map<TemplateImpl, String> template2Argument = templateManager.findMatchingTemplates(callback.getFile(), callback.getEditor(), null, TemplateSettings.getInstance());
      Runnable runnable = templateManager.startNonCustomTemplates(template2Argument, callback.getEditor(), null);
      if (runnable != null) {
        runnable.run();
      }
      return;
    }
  }

  PsiElement context = callback.getContext();
  ZenCodingGenerator generator = ObjectUtils.notNull(findApplicableGenerator(node, context, false), defaultGenerator);
  List<ZenCodingFilter> filters = getFilters(node, context);
  filters.addAll(extraFilters);

  checkTemplateOutputLength(node, callback);
  
  callback.deleteTemplateKey(key);
  expand(node, generator, filters, null, callback, expandPrimitiveAbbreviations, segmentsLimit);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:31,代码来源:ZenCodingTemplate.java

示例4: isApplicable

import com.intellij.codeInsight.template.CustomTemplateCallback; //导入方法依赖的package包/类
@Override
public boolean isApplicable(PsiFile file, int offset, boolean wrapping) {
  if (file == null) {
    return false;
  }
  PsiElement element = CustomTemplateCallback.getContext(file, offset);
  final ZenCodingGenerator applicableGenerator = findApplicableDefaultGenerator(element, wrapping);
  return applicableGenerator != null && applicableGenerator.isEnabled();
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:10,代码来源:ZenCodingTemplate.java

示例5: XmlEmmetParser

import com.intellij.codeInsight.template.CustomTemplateCallback; //导入方法依赖的package包/类
public XmlEmmetParser(List<ZenCodingToken> tokens,
                      CustomTemplateCallback callback,
                      ZenCodingGenerator generator, boolean surroundWithTemplate) {
  super(tokens, callback, generator);
  PsiElement context = callback.getContext();
  XmlTag parentTag = PsiTreeUtil.getParentOfType(context, XmlTag.class);
  if (surroundWithTemplate && parentTag != null && context.getNode().getElementType() == XmlTokenType.XML_START_TAG_START) {
    parentTag = PsiTreeUtil.getParentOfType(parentTag, XmlTag.class);
  }
  isHtml = generator.isHtml(callback);
  if (parentTag != null) {
    hasTagContext = true;
    tagLevel.push(parentTag.getName());
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:16,代码来源:XmlEmmetParser.java

示例6: computeTemplateKey

import com.intellij.codeInsight.template.CustomTemplateCallback; //导入方法依赖的package包/类
@Nullable
@Override
public String computeTemplateKey(@NotNull CustomTemplateCallback callback) {
  Editor editor = callback.getEditor();
  int currentOffset = editor.getCaretModel().getOffset();
  int startOffset = Math.min(editor.getDocument().getLineStartOffset(editor.getDocument().getLineNumber(currentOffset)), currentOffset);
  CharSequence documentText = editor.getDocument().getCharsSequence();
  PsiElement prevVisibleLeaf = callback.getContext();
  while (prevVisibleLeaf != null) {
    TextRange textRange = prevVisibleLeaf.getTextRange();
    final int endOffset = textRange.getEndOffset();
    if (endOffset <= currentOffset) {
      if (endOffset <= startOffset) {
        break;
      }
      IElementType prevType = prevVisibleLeaf.getNode().getElementType();
      if (prevType == XmlTokenType.XML_TAG_END || prevType == XmlTokenType.XML_EMPTY_ELEMENT_END) {
        startOffset = endOffset;
        break;
      }
    }
    prevVisibleLeaf = PsiTreeUtil.prevVisibleLeaf(prevVisibleLeaf);
  }

  if (startOffset < 0 || currentOffset > documentText.length() || currentOffset < startOffset) {
    Logger.getInstance(getClass())
      .error("Error while calculating emmet abbreviation. Offset: " + currentOffset + "; Start: " + startOffset,
             AttachmentFactory.createAttachment(editor.getDocument()));
    return null;
  }
  String key = computeKey(documentText.subSequence(startOffset, currentOffset));
  return !StringUtil.isEmpty(key) && ZenCodingTemplate.checkTemplateKey(key, callback, this) ? key : null;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:34,代码来源:XmlZenCodingGenerator.java

示例7: XmlEmmetParser

import com.intellij.codeInsight.template.CustomTemplateCallback; //导入方法依赖的package包/类
public XmlEmmetParser(List<ZenCodingToken> tokens,
                      CustomTemplateCallback callback,
                      ZenCodingGenerator generator, boolean surroundWithTemplate) {
  super(tokens, callback, generator);
  PsiElement context = callback.getContext();
  XmlTag parentTag = PsiTreeUtil.getParentOfType(context, XmlTag.class);
  if (surroundWithTemplate && parentTag != null && context.getNode().getElementType() == XmlTokenType.XML_START_TAG_START) {
    parentTag = PsiTreeUtil.getParentOfType(parentTag, XmlTag.class);
  }
  if (parentTag != null) {
    hasTagContext = true;
    tagLevel.push(parentTag.getName());
  }
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:15,代码来源:XmlEmmetParser.java

示例8: computeTemplateKey

import com.intellij.codeInsight.template.CustomTemplateCallback; //导入方法依赖的package包/类
@Nullable
public String computeTemplateKey(@NotNull CustomTemplateCallback callback) {
  Editor editor = callback.getEditor();
  PsiElement element = callback.getContext();
  int line = editor.getCaretModel().getLogicalPosition().line;
  int lineStart = editor.getDocument().getLineStartOffset(line);
  int elementStart = -1;
  do {
    PsiElement e = element;
    while ((e instanceof LeafPsiElement && ((LeafPsiElement)e).getElementType() == XmlTokenType.XML_DATA_CHARACTERS) ||
           e instanceof PsiWhiteSpace || e instanceof PsiErrorElement) {
      elementStart = e.getTextRange().getStartOffset();
      e = e.getPrevSibling();
    }
    if (elementStart >= 0) {
      int startOffset = elementStart > lineStart ? elementStart : lineStart;
      String key = computeKey(editor, startOffset);
      if (key != null) {
        while (key.length() > 0 && !ZenCodingTemplate.checkTemplateKey(key, callback, this)) {
          key = key.substring(1);
        }
        if (key.length() > 0) {
          return key;
        }
      }
    }
    element = element.getParent();
  }
  while (element != null && elementStart > lineStart);
  return null;
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:32,代码来源:ZenCodingGenerator.java

示例9: expand

import com.intellij.codeInsight.template.CustomTemplateCallback; //导入方法依赖的package包/类
@Override
public void expand(@Nonnull final String key, @Nonnull final CustomTemplateCallback callback) {
  ApplicationManager.getApplication().assertIsDispatchThread();
  FeatureUsageTracker.getInstance().triggerFeatureUsed("editing.completion.postfix");

  Editor editor = callback.getEditor();
  for (PostfixTemplateProvider provider : LanguagePostfixTemplate.LANG_EP.allForLanguage(getLanguage(callback))) {
    PostfixTemplate postfixTemplate = getTemplate(provider, key);
    if (postfixTemplate != null) {
      final PsiFile file = callback.getContext().getContainingFile();
      if (isApplicableTemplate(provider, key, file, editor)) {
        int offset = deleteTemplateKey(file, editor, key);
        try {
          provider.preExpand(file, editor);
          PsiElement context = CustomTemplateCallback.getContext(file, positiveOffset(offset));
          expandTemplate(postfixTemplate, editor, context);
        }
        finally {
          provider.afterExpand(file, editor);
        }
      }
      // don't care about errors in multiCaret mode
      else if (editor.getCaretModel().getAllCarets().size() == 1) {
        LOG.error("Template not found by key: " + key);
      }
      return;
    }
  }

  // don't care about errors in multiCaret mode
  if (editor.getCaretModel().getAllCarets().size() == 1) {
    LOG.error("Template not found by key: " + key);
  }
}
 
开发者ID:consulo,项目名称:consulo,代码行数:35,代码来源:PostfixLiveTemplate.java

示例10: createIsApplicationTemplateFunction

import com.intellij.codeInsight.template.CustomTemplateCallback; //导入方法依赖的package包/类
private static Condition<PostfixTemplate> createIsApplicationTemplateFunction(@Nonnull final PostfixTemplateProvider provider,
                                                                              @Nonnull String key,
                                                                              @Nonnull PsiFile file,
                                                                              @Nonnull Editor editor) {
  int currentOffset = editor.getCaretModel().getOffset();
  final int newOffset = currentOffset - key.length();
  CharSequence fileContent = editor.getDocument().getCharsSequence();
  StringBuilder fileContentWithoutKey = new StringBuilder();
  fileContentWithoutKey.append(fileContent.subSequence(0, newOffset));
  fileContentWithoutKey.append(fileContent.subSequence(currentOffset, fileContent.length()));
  PsiFile copyFile = copyFile(file, fileContentWithoutKey);
  Document copyDocument = copyFile.getViewProvider().getDocument();
  if (copyDocument == null) {
    //noinspection unchecked
    return Condition.FALSE;
  }

  copyFile = provider.preCheck(copyFile, editor, newOffset);
  copyDocument = copyFile.getViewProvider().getDocument();
  if (copyDocument == null) {
    //noinspection unchecked
    return Condition.FALSE;
  }

  final PsiElement context = CustomTemplateCallback.getContext(copyFile, positiveOffset(newOffset));
  final Document finalCopyDocument = copyDocument;
  return new Condition<PostfixTemplate>() {
    @Override
    public boolean value(PostfixTemplate template) {
      return template != null && template.isEnabled(provider) && template.isApplicable(context, finalCopyDocument, newOffset);
    }
  };
}
 
开发者ID:consulo,项目名称:consulo,代码行数:34,代码来源:PostfixLiveTemplate.java

示例11: hasCompletionItem

import com.intellij.codeInsight.template.CustomTemplateCallback; //导入方法依赖的package包/类
@Override
public boolean hasCompletionItem(@NotNull PsiFile file, int offset) {
  PsiElement element = CustomTemplateCallback.getContext(file, offset);
  final ZenCodingGenerator applicableGenerator = findApplicableDefaultGenerator(element, false);
  return applicableGenerator != null && applicableGenerator.isEnabled() && applicableGenerator.hasCompletionItem();
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:7,代码来源:ZenCodingTemplate.java


注:本文中的com.intellij.codeInsight.template.CustomTemplateCallback.getContext方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。