本文整理汇总了Java中com.intellij.codeInsight.template.impl.TemplateImpl类的典型用法代码示例。如果您正苦于以下问题:Java TemplateImpl类的具体用法?Java TemplateImpl怎么用?Java TemplateImpl使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TemplateImpl类属于com.intellij.codeInsight.template.impl包,在下文中一共展示了TemplateImpl类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getType
import com.intellij.codeInsight.template.impl.TemplateImpl; //导入依赖的package包/类
@Override
public PsiType getType() {
final Template template = getTemplate();
String text = template.getTemplateText();
StringBuilder resultingText = new StringBuilder(text);
int segmentsCount = template.getSegmentsCount();
for (int j = segmentsCount - 1; j >= 0; j--) {
if (template.getSegmentName(j).equals(TemplateImpl.END)) {
continue;
}
resultingText.insert(template.getSegmentOffset(j), "xxx");
}
try {
final PsiExpression templateExpression = JavaPsiFacade.getElementFactory(myContext.getProject()).createExpressionFromText(resultingText.toString(), myContext);
return templateExpression.getType();
}
catch (IncorrectOperationException e) { // can happen when text of the template does not form an expression
return null;
}
}
示例2: updateDetails
import com.intellij.codeInsight.template.impl.TemplateImpl; //导入依赖的package包/类
private void updateDetails(final PatternDescriptor descriptor) {
new WriteCommandAction.Simple(myProject) {
@Override
protected void run() throws Throwable {
final Template template = descriptor.getTemplate();
if (template instanceof TemplateImpl) {
String text = ((TemplateImpl)template).getString();
myEditor.getDocument().replaceString(0, myEditor.getDocument().getTextLength(), text);
TemplateEditorUtil.setHighlighter(myEditor, ((TemplateImpl)template).getTemplateContext());
}
else {
myEditor.getDocument().replaceString(0, myEditor.getDocument().getTextLength(), "");
}
}
}.execute();
}
示例3: startLiveTemplate
import com.intellij.codeInsight.template.impl.TemplateImpl; //导入依赖的package包/类
public static void startLiveTemplate(PsiFile file) {
Project project = file.getProject();
final Editor editor = EditorHelper.openInEditor(file);
if (editor == null) return;
final TemplateImpl template = new TemplateImpl("", file.getText(), "");
template.setInline(true);
int count = template.getSegmentsCount();
if (count == 0) return;
Set<String> variables = new HashSet<String>();
for (int i = 0; i < count; i++) {
variables.add(template.getSegmentName(i));
}
variables.removeAll(TemplateImpl.INTERNAL_VARS_SET);
for (String variable : variables) {
template.addVariable(variable, null, "\"" + variable + "\"", true);
}
WriteCommandAction.runWriteCommandAction(project, new Runnable() {
@Override
public void run() {
editor.getDocument().setText(template.getTemplateText());
}
});
TemplateManager.getInstance(project).startTemplate(editor, template);
}
示例4: expand
import com.intellij.codeInsight.template.impl.TemplateImpl; //导入依赖的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);
}
示例5: expandTemplate
import com.intellij.codeInsight.template.impl.TemplateImpl; //导入依赖的package包/类
@NotNull
private static TemplateImpl expandTemplate(@NotNull TemplateImpl template,
Map<String, String> predefinedVarValues,
String surroundedText,
int segmentsLimit) {
LiveTemplateBuilder builder = new LiveTemplateBuilder(EmmetOptions.getInstance().isAddEditPointAtTheEndOfTemplate(), segmentsLimit);
if (predefinedVarValues == null && surroundedText == null) {
return template;
}
int offset = builder.insertTemplate(0, template, predefinedVarValues);
if (surroundedText != null) {
builder.insertText(offset, surroundedText, true);
builder.setIsToReformat(true);
}
return builder.buildTemplate();
}
示例6: expand
import com.intellij.codeInsight.template.impl.TemplateImpl; //导入依赖的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: parseTemplate
import com.intellij.codeInsight.template.impl.TemplateImpl; //导入依赖的package包/类
@Nullable
protected ZenCodingNode parseTemplate() {
ZenCodingToken token = getToken();
if (!(token instanceof IdentifierToken)) {
return null;
}
String templateKey = ((IdentifierToken)token).getText();
advance();
TemplateImpl template = myCallback.findApplicableTemplate(templateKey);
if (template == null && !ZenCodingUtil.isXML11ValidQName(templateKey)) {
return null;
}
final TemplateToken templateToken = new TemplateToken(templateKey);
if (!setTemplate(templateToken, template)) {
return null;
}
return new TemplateNode(templateToken);
}
示例8: parseXmlFileInTemplate
import com.intellij.codeInsight.template.impl.TemplateImpl; //导入依赖的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;
}
示例9: getType
import com.intellij.codeInsight.template.impl.TemplateImpl; //导入依赖的package包/类
@Override
public PsiType getType() {
final Template template = getObject();
String text = template.getTemplateText();
StringBuilder resultingText = new StringBuilder(text);
int segmentsCount = template.getSegmentsCount();
for (int j = segmentsCount - 1; j >= 0; j--) {
if (template.getSegmentName(j).equals(TemplateImpl.END)) {
continue;
}
int segmentOffset = template.getSegmentOffset(j);
resultingText.insert(segmentOffset, PLACEHOLDER);
}
try {
final PsiExpression templateExpression = JavaPsiFacade.getElementFactory(myContext.getProject()).createExpressionFromText(resultingText.toString(), myContext);
return templateExpression.getType();
}
catch (IncorrectOperationException e) { // can happen when text of the template does not form an expression
return null;
}
}
示例10: filterApplicableCandidates
import com.intellij.codeInsight.template.impl.TemplateImpl; //导入依赖的package包/类
public List<TemplateImpl> filterApplicableCandidates(Collection<? extends TemplateImpl> candidates) {
List<TemplateImpl> result = new ArrayList<TemplateImpl>();
for (TemplateImpl candidate : candidates) {
if (TemplateManagerImpl.isApplicable(myFile, myOffset, candidate)) {
result.add(candidate);
}
/*TemplateContext context = candidate.getTemplateContext();
for (TemplateContextType contextType : contextTypes) {
if (context.isEnabled(contextType)) {
result.add(candidate);
break;
}
}*/
}
return result;
}
示例11: expand
import com.intellij.codeInsight.template.impl.TemplateImpl; //导入依赖的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: expandTemplate
import com.intellij.codeInsight.template.impl.TemplateImpl; //导入依赖的package包/类
@NotNull
private static TemplateImpl expandTemplate(@NotNull TemplateImpl template,
Map<String, String> predefinedVarValues,
String surroundedText) {
LiveTemplateBuilder builder = new LiveTemplateBuilder();
if (predefinedVarValues == null && surroundedText == null) {
return template;
}
int offset = builder.insertTemplate(0, template, predefinedVarValues);
if (surroundedText != null) {
builder.insertText(offset, surroundedText, true);
/*if (offset < builder.length()) {
builder.insertVariableSegment(offset, TemplateImpl.END);
}*/
}
return builder.buildTemplate();
}
示例13: parseXmlFileInTemplate
import com.intellij.codeInsight.template.impl.TemplateImpl; //导入依赖的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: testPrologContext
import com.intellij.codeInsight.template.impl.TemplateImpl; //导入依赖的package包/类
@Test
public void testPrologContext() throws Exception {
final TemplateImpl template = TemplateSettings.getInstance().getTemplate("var", "XQuery");
assertTrue(isApplicableFor("<caret>xxx", template));
assertTrue(isApplicableFor("import module namespace x = 'x'; <caret>xxx", template));
assertTrue(isApplicableFor("module namespace x = 'x'; <caret>xxx", template));
assertTrue(isApplicableFor("declare variable $x := 'x';\n" +
"<caret>xxx", template));
assertTrue(isApplicableFor("declare function x(){'x'};\n" +
"<caret>xxx", template));
assertFalse(isApplicableFor("xquery version '1.0';\n<caret>xxx\nmodule namespace x = 'x';", template));
assertFalse(isApplicableFor("declare variable $x := <caret>xxx;", template));
assertFalse(isApplicableFor("declare function x(){<caret>xxx};", template));
assertFalse(isApplicableFor("let $x := <caret>xxx return $x", template));
assertFalse(isApplicableFor("let $x := 'x' return $x\n" +
"<caret>xxx", template));
assertFalse(isApplicableFor("let $x := 'x' return $x(: comment :)" +
"<caret>xxx", template));
assertFalse(isApplicableFor("let $x := 'x' return $x\n" +
"var <caret>xxx", template));
}
示例15: testExpressionContext
import com.intellij.codeInsight.template.impl.TemplateImpl; //导入依赖的package包/类
@Test
public void testExpressionContext() throws Exception {
final TemplateImpl template = TemplateSettings.getInstance().getTemplate("let", "XQuery");
assertTrue(isApplicableFor("<caret>xxx", template));
assertTrue(isApplicableFor("import module namespace x = 'x'; <caret>xxx", template));
assertFalse(isApplicableFor("module namespace x = 'x'; <caret>xxx", template));
assertTrue(isApplicableFor("declare variable $x := 'x';\n" +
"<caret>xxx", template));
assertTrue(isApplicableFor("declare function x(){'x'};\n" +
"<caret>xxx", template));
assertFalse(isApplicableFor("xquery version '1.0';\n<caret>xxx\nmodule namespace x = 'x';", template));
assertTrue(isApplicableFor("declare variable $x := <caret>xxx;", template));
assertTrue(isApplicableFor("declare function x(){<caret>xxx};", template));
assertTrue(isApplicableFor("let $x := <caret>xxx return $x", template));
assertFalse(isApplicableFor("let $x := 'x' return $x\n" +
"<caret>xxx", template));
assertFalse(isApplicableFor("let $x := 'x' return $x(: comment :)" +
"<caret>xxx", template));
assertFalse(isApplicableFor("let $x := 'x' return $x\n" +
"var <caret>xxx", template));
assertTrue(isApplicableFor("let $x := 'x' return $x,<caret>xxx", template));
}