本文整理汇总了Java中com.intellij.codeInsight.template.CustomTemplateCallback类的典型用法代码示例。如果您正苦于以下问题:Java CustomTemplateCallback类的具体用法?Java CustomTemplateCallback怎么用?Java CustomTemplateCallback使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CustomTemplateCallback类属于com.intellij.codeInsight.template包,在下文中一共展示了CustomTemplateCallback类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addCompletions
import com.intellij.codeInsight.template.CustomTemplateCallback; //导入依赖的package包/类
@Override
protected void addCompletions(@NotNull CompletionParameters parameters, ProcessingContext context, @NotNull CompletionResultSet result) {
Editor editor = parameters.getEditor();
if (!isCompletionEnabled(parameters) || LiveTemplateCompletionContributor.shouldShowAllTemplates() ||
editor.getCaretModel().getCaretCount() != 1) {
/**
* disabled or covered with {@link com.intellij.codeInsight.template.impl.LiveTemplateCompletionContributor}
*/
return;
}
PsiFile originalFile = parameters.getOriginalFile();
PostfixLiveTemplate postfixLiveTemplate = getPostfixLiveTemplate(originalFile, editor);
if (postfixLiveTemplate != null) {
postfixLiveTemplate.addCompletions(parameters, result.withPrefixMatcher(new MyPrefixMatcher(result.getPrefixMatcher().getPrefix())));
String possibleKey = postfixLiveTemplate.computeTemplateKeyWithoutContextChecking(new CustomTemplateCallback(editor, originalFile));
if (possibleKey != null) {
result = result.withPrefixMatcher(possibleKey);
result.restartCompletionOnPrefixChange(
StandardPatterns.string().oneOf(postfixLiveTemplate.getAllTemplateKeys(originalFile, parameters.getOffset())));
}
}
}
示例2: getLookupElements
import com.intellij.codeInsight.template.CustomTemplateCallback; //导入依赖的package包/类
@NotNull
@Override
public Collection<? extends CustomLiveTemplateLookupElement> getLookupElements(@NotNull PsiFile file,
@NotNull Editor editor,
int offset) {
Collection<CustomLiveTemplateLookupElement> result = ContainerUtil.newHashSet();
CustomTemplateCallback callback = new CustomTemplateCallback(editor, file);
for (PostfixTemplateProvider provider : LanguagePostfixTemplate.LANG_EP.allForLanguage(getLanguage(callback))) {
String key = computeTemplateKeyWithoutContextChecking(callback);
if (key != null && editor.getCaretModel().getCaretCount() == 1) {
Condition<PostfixTemplate> isApplicationTemplateFunction = createIsApplicationTemplateFunction(provider, key, file, editor);
for (PostfixTemplate postfixTemplate : provider.getTemplates()) {
if (isApplicationTemplateFunction.value(postfixTemplate)) {
result.add(new PostfixTemplateLookupElement(this, postfixTemplate, postfixTemplate.getKey(), provider, false));
}
}
}
}
return result;
}
示例3: actionPerformed
import com.intellij.codeInsight.template.CustomTemplateCallback; //导入依赖的package包/类
@Override
public void actionPerformed(AnActionEvent e) {
final Document document = myEditor.getDocument();
final VirtualFile file = FileDocumentManager.getInstance().getFile(document);
if (file != null) {
ReadonlyStatusHandler.getInstance(myFile.getProject()).ensureFilesWritable(file);
}
String selection = myEditor.getSelectionModel().getSelectedText(true);
if (selection != null) {
selection = selection.trim();
PsiDocumentManager.getInstance(myFile.getProject()).commitAllDocuments();
myTemplate.wrap(selection, new CustomTemplateCallback(myEditor, myFile));
}
}
示例4: expand
import com.intellij.codeInsight.template.CustomTemplateCallback; //导入依赖的package包/类
@NotNull
@Override
public List<GenerationNode> expand(int numberInIteration,
int totalIterations, String surroundedText,
CustomTemplateCallback callback,
boolean insertSurroundedTextAtTheEnd, GenerationNode parent) {
List<GenerationNode> result = newArrayList();
result.addAll(myLeftOperand.expand(numberInIteration, totalIterations, surroundedText, callback, insertSurroundedTextAtTheEnd, parent));
GenerationNode grandParent = parent != null ? parent.getParent() : null;
if (grandParent != null) {
myRightOperand.expand(numberInIteration, totalIterations, surroundedText, callback, insertSurroundedTextAtTheEnd, grandParent);
}
else {
result.addAll(myRightOperand.expand(numberInIteration, totalIterations, surroundedText, callback, insertSurroundedTextAtTheEnd, parent));
}
return result;
}
示例5: expand
import com.intellij.codeInsight.template.CustomTemplateCallback; //导入依赖的package包/类
@NotNull
@Override
public List<GenerationNode> expand(int numberInIteration,
int totalIterations, String surroundedText,
CustomTemplateCallback callback,
boolean insertSurroundedTextAtTheEnd, GenerationNode parent) {
TemplateToken templateToken = myTemplateToken;
String templateKey = templateToken.getKey();
if (myGenerator != null && StringUtil.containsChar(templateKey, '$') && callback.findApplicableTemplate(templateKey) == null) {
String newTemplateKey = ZenCodingUtil.replaceMarkers(templateKey, numberInIteration, totalIterations, surroundedText);
TemplateToken newTemplateToken = new TemplateToken(newTemplateKey, templateToken.getAttributes());
TemplateImpl template = myGenerator.createTemplateByKey(newTemplateKey);
if (template != null) {
template.setDeactivated(true);
newTemplateToken.setTemplate(template, callback);
templateToken = newTemplateToken;
}
}
GenerationNode node = new GenerationNode(templateToken, numberInIteration, totalIterations,
surroundedText, insertSurroundedTextAtTheEnd, parent);
return Collections.singletonList(node);
}
示例6: expand
import com.intellij.codeInsight.template.CustomTemplateCallback; //导入依赖的package包/类
@NotNull
@Override
public List<GenerationNode> expand(int numberInIteration,
int totalIterations, String surroundedText,
CustomTemplateCallback callback,
boolean insertSurroundedTextAtTheEnd, GenerationNode parent) {
final TemplateToken templateToken = new TemplateToken("");
final boolean containsSurroundedTextMarker = ZenCodingUtil.containsSurroundedTextMarker(myText);
final String text = ZenCodingUtil.replaceMarkers(myText.replace("${nl}", "\n"), numberInIteration, totalIterations, surroundedText);
final TemplateImpl template = new TemplateImpl("", text, "");
templateToken.setTemplate(template, callback);
final GenerationNode node = new GenerationNode(templateToken, numberInIteration, totalIterations,
containsSurroundedTextMarker ? null : surroundedText,
insertSurroundedTextAtTheEnd, parent);
return Collections.singletonList(node);
}
示例7: expand
import com.intellij.codeInsight.template.CustomTemplateCallback; //导入依赖的package包/类
@NotNull
@Override
public List<GenerationNode> expand(int numberInIteration,
int totalIterations, String surroundedText,
CustomTemplateCallback callback,
boolean insertSurroundedTextAtTheEnd, GenerationNode parent) {
if (surroundedText == null) {
return myOperand.expand(numberInIteration, totalIterations, null, callback, insertSurroundedTextAtTheEnd, parent);
}
String[] lines = LineTokenizer.tokenize(surroundedText, false);
List<GenerationNode> result = new ArrayList<GenerationNode>();
for (int i = 0; i < lines.length; i++) {
result.addAll(myOperand.expand(i, lines.length, lines[i].trim(), callback, insertSurroundedTextAtTheEnd, parent));
}
return result;
}
示例8: parse
import com.intellij.codeInsight.template.CustomTemplateCallback; //导入依赖的package包/类
@Nullable
public static ZenCodingNode parse(@NotNull String text,
@NotNull CustomTemplateCallback callback,
@NotNull ZenCodingGenerator generator,
@Nullable String surroundedText) {
List<ZenCodingToken> tokens = new EmmetLexer().lex(text);
if (tokens == null) {
return null;
}
if (!validate(tokens, generator)) {
return null;
}
EmmetParser parser = generator.createParser(tokens, callback, generator, surroundedText != null);
ZenCodingNode node = parser.parse();
if (parser.getIndex() != tokens.size() || node instanceof TextNode) {
return null;
}
return node;
}
示例9: parseXmlFileInTemplate
import com.intellij.codeInsight.template.CustomTemplateCallback; //导入依赖的package包/类
@NotNull
private static XmlFile parseXmlFileInTemplate(@NotNull TemplateImpl template, @NotNull CustomTemplateCallback callback,
@NotNull Map<String, String> attributes) {
XmlTag dummyRootTag = null;
String templateString = template.getString();
final PsiFileFactory psiFileFactory = PsiFileFactory.getInstance(callback.getProject());
if (!containsAttrsVar(template)) {
XmlFile dummyFile = (XmlFile)psiFileFactory.createFileFromText("dummy.html", HTMLLanguage.INSTANCE, templateString, false, true);
dummyRootTag = dummyFile.getRootTag();
if (dummyRootTag != null) {
addMissingAttributes(dummyRootTag, attributes);
}
}
templateString = dummyRootTag != null ? dummyRootTag.getContainingFile().getText() : templateString;
XmlFile xmlFile =
(XmlFile)psiFileFactory.createFileFromText("dummy.xml", StdFileTypes.XML, templateString, LocalTimeCounter.currentTime(), true);
VirtualFile vFile = xmlFile.getVirtualFile();
if (vFile != null) {
vFile.putUserData(UndoConstants.DONT_RECORD_UNDO, Boolean.TRUE);
}
return xmlFile;
}
示例10: actionPerformed
import com.intellij.codeInsight.template.CustomTemplateCallback; //导入依赖的package包/类
@Override
public void actionPerformed(AnActionEvent e) {
final Document document = myEditor.getDocument();
final VirtualFile file = FileDocumentManager.getInstance().getFile(document);
if (file != null) {
ReadonlyStatusHandler.getInstance(myFile.getProject()).ensureFilesWritable(file);
}
String selection = myEditor.getSelectionModel().getSelectedText();
if (selection != null) {
selection = selection.trim();
PsiDocumentManager.getInstance(myFile.getProject()).commitAllDocuments();
myTemplate.wrap(selection, new CustomTemplateCallback(myEditor, myFile, true));
}
}
示例11: expand
import com.intellij.codeInsight.template.CustomTemplateCallback; //导入依赖的package包/类
@NotNull
@Override
public List<GenerationNode> expand(int numberInIteration,
int totalIterations, String surroundedText,
CustomTemplateCallback callback,
boolean insertSurroundedTextAtTheEnd, GenerationNode parent) {
TemplateToken templateToken = myTemplateToken;
String templateKey = templateToken.getKey();
if (myGenerator != null && StringUtil.containsChar(templateKey, '$') && callback.findApplicableTemplate(templateKey) == null) {
String newTemplateKey = ZenCodingUtil.replaceMarkers(templateKey, numberInIteration, totalIterations, surroundedText);
TemplateToken newTemplateToken = new TemplateToken(newTemplateKey,
templateToken.getAttribute2Value());
TemplateImpl template = myGenerator.createTemplateByKey(newTemplateKey);
if (template != null) {
newTemplateToken.setTemplate(template, callback);
templateToken = newTemplateToken;
}
}
GenerationNode node = new GenerationNode(templateToken, numberInIteration, totalIterations,
surroundedText, insertSurroundedTextAtTheEnd, parent);
return Arrays.asList(node);
}
示例12: expand
import com.intellij.codeInsight.template.CustomTemplateCallback; //导入依赖的package包/类
@NotNull
@Override
public List<GenerationNode> expand(int numberInIteration,
int totalIterations, String surroundedText,
CustomTemplateCallback callback,
boolean insertSurroundedTextAtTheEnd, GenerationNode parent) {
if (surroundedText == null) {
return myOperand.expand(numberInIteration, totalIterations, surroundedText, callback, insertSurroundedTextAtTheEnd, parent);
}
String[] lines = LineTokenizer.tokenize(surroundedText, false);
List<GenerationNode> result = new ArrayList<GenerationNode>();
for (int i = 0; i < lines.length; i++) {
result.addAll(myOperand.expand(i, lines.length, lines[i].trim(), callback, insertSurroundedTextAtTheEnd, parent));
}
return result;
}
示例13: parseXmlFileInTemplate
import com.intellij.codeInsight.template.CustomTemplateCallback; //导入依赖的package包/类
@NotNull
private static XmlFile parseXmlFileInTemplate(TemplateImpl template,
CustomTemplateCallback callback,
List<Pair<String, String>> attributes) {
XmlTag dummyRootTag = null;
String templateString = template.getString();
final PsiFileFactory psiFileFactory = PsiFileFactory.getInstance(callback.getProject());
if (!containsAttrsVar(template)) {
XmlFile dummyFile = (XmlFile)psiFileFactory.createFileFromText("dummy.xml", StdFileTypes.XML, templateString);
dummyRootTag = dummyFile.getRootTag();
if (dummyRootTag != null) {
addMissingAttributes(dummyRootTag, attributes);
}
}
templateString = dummyRootTag != null ? dummyRootTag.getContainingFile().getText() : templateString;
XmlFile xmlFile = (XmlFile)psiFileFactory.createFileFromText("dummy.xml", StdFileTypes.XML, templateString, LocalTimeCounter.currentTime(), true);
VirtualFile vFile = xmlFile.getVirtualFile();
if (vFile != null) {
vFile.putUserData(UndoConstants.DONT_RECORD_UNDO, Boolean.TRUE);
}
return xmlFile;
}
示例14: getLookupElements
import com.intellij.codeInsight.template.CustomTemplateCallback; //导入依赖的package包/类
@Nonnull
@Override
public Collection<? extends CustomLiveTemplateLookupElement> getLookupElements(@Nonnull PsiFile file,
@Nonnull Editor editor,
int offset) {
Collection<CustomLiveTemplateLookupElement> result = ContainerUtil.newHashSet();
CustomTemplateCallback callback = new CustomTemplateCallback(editor, file);
for (PostfixTemplateProvider provider : LanguagePostfixTemplate.LANG_EP.allForLanguage(getLanguage(callback))) {
String key = computeTemplateKeyWithoutContextChecking(callback);
if (key != null && editor.getCaretModel().getCaretCount() == 1) {
Condition<PostfixTemplate> isApplicationTemplateFunction = createIsApplicationTemplateFunction(provider, key, file, editor);
for (PostfixTemplate postfixTemplate : provider.getTemplates()) {
if (isApplicationTemplateFunction.value(postfixTemplate)) {
result.add(new PostfixTemplateLookupElement(this, postfixTemplate, postfixTemplate.getKey(), provider, false));
}
}
}
}
return result;
}
示例15: computeTemplateKey
import com.intellij.codeInsight.template.CustomTemplateCallback; //导入依赖的package包/类
@Nullable
@Override
public String computeTemplateKey(@NotNull CustomTemplateCallback callback) {
Editor editor = callback.getEditor();
CharSequence charsSequence = editor.getDocument().getCharsSequence();
int offset = editor.getCaretModel().getOffset();
for (PostfixTemplateProvider provider : LanguagePostfixTemplate.LANG_EP.allForLanguage(getLanguage(callback))) {
String key = computeTemplateKeyWithoutContextChecking(provider, charsSequence, offset);
if (key != null && isApplicableTemplate(provider, key, callback.getFile(), editor)) {
return key;
}
}
return null;
}