本文整理汇总了Java中com.intellij.codeInsight.template.TemplateManager.createTemplate方法的典型用法代码示例。如果您正苦于以下问题:Java TemplateManager.createTemplate方法的具体用法?Java TemplateManager.createTemplate怎么用?Java TemplateManager.createTemplate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.intellij.codeInsight.template.TemplateManager
的用法示例。
在下文中一共展示了TemplateManager.createTemplate方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: invoke
import com.intellij.codeInsight.template.TemplateManager; //导入方法依赖的package包/类
@Override
public void invoke(@NotNull final Project project, final Editor editor, final PsiFile file) throws IncorrectOperationException {
if (!FileModificationService.getInstance().prepareFileForWrite(file)) return;
final XmlTag rootTag = myTargetFile.getDocument().getRootTag();
OpenFileDescriptor descriptor = new OpenFileDescriptor(
project,
myTargetFile.getVirtualFile(),
rootTag.getValue().getTextRange().getEndOffset()
);
Editor targetEditor = FileEditorManager.getInstance(project).openTextEditor(descriptor, true);
TemplateManager manager = TemplateManager.getInstance(project);
final Template template = manager.createTemplate("", "");
addTextTo(template, rootTag);
manager.startTemplate(targetEditor, template);
}
示例2: invoke
import com.intellij.codeInsight.template.TemplateManager; //导入方法依赖的package包/类
public void invoke(@NotNull final Project project, final Editor editor, final PsiFile file) throws IncorrectOperationException {
if (!FileModificationService.getInstance().prepareFileForWrite(file)) return;
final XmlTag rootTag = myTargetFile.getDocument().getRootTag();
OpenFileDescriptor descriptor = new OpenFileDescriptor(
project,
myTargetFile.getVirtualFile(),
rootTag.getValue().getTextRange().getEndOffset()
);
Editor targetEditor = FileEditorManager.getInstance(project).openTextEditor(descriptor, true);
TemplateManager manager = TemplateManager.getInstance(project);
final Template template = manager.createTemplate("", "");
addTextTo(template, rootTag);
manager.startTemplate(targetEditor, template);
}
示例3: invoke
import com.intellij.codeInsight.template.TemplateManager; //导入方法依赖的package包/类
@Override
public void invoke(@NotNull final Project project, final Editor editor, final PsiFile file) throws IncorrectOperationException {
if (!FileModificationService.getInstance().prepareFileForWrite(file)) return;
final XmlTag rootTag = myTargetFile.getDocument().getRootTag();
OpenFileDescriptor descriptor = new OpenFileDescriptor(
project,
myTargetFile.getVirtualFile(),
rootTag.getValue().getTextRange().getEndOffset()
);
Editor targetEditor = FileEditorManager.getInstance(project).openTextEditor(descriptor, true);
TemplateManager manager = TemplateManager.getInstance(project);
final Template template = manager.createTemplate("", "");
addTextTo(template, rootTag);
manager.startTemplate(targetEditor, template);
}
示例4: applyFix
import com.intellij.codeInsight.template.TemplateManager; //导入方法依赖的package包/类
@Override
public void applyFix(@NotNull final Project project, @NotNull final ProblemDescriptor descriptor)
{
final PsiElement element = descriptor.getPsiElement();
final Editor editor = BaseCreateFix.getEditor(project, element.getContainingFile());
if(editor == null)
{
return;
}
final String shortenedType = JSResolveUtil.getShortenedType(this.type, element);
final TemplateManager templateManager = TemplateManager.getInstance(project);
Template template = templateManager.createTemplate("", "", shortenedType + "($SELECTION$)");
template.setToReformat(true);
final int offset = element.getTextOffset();
editor.getSelectionModel().setSelection(offset, offset + element.getTextLength());
editor.getCaretModel().moveToOffset(offset);
templateManager.startTemplate(editor, element.getText(), template);
}
示例5: applyFix
import com.intellij.codeInsight.template.TemplateManager; //导入方法依赖的package包/类
@Override
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor problemDescriptor) {
Method method = (Method)methodReference.resolve();
if (method != null) {
Parameter[] parameters = method.getParameters();
int paramParameterIndex = ClassUtils.getParamIndex(method, "params");
int conditionParameterIndex = ClassUtils.getParamIndex(method, new String[]{ "condition", "expression", "sql"});
if (paramParameterIndex > -1
&& conditionParameterIndex > -1
&& conditionParameterIndex == paramParameterIndex - 1
&& methodReference.getParameters().length > conditionParameterIndex) {
String condition = methodReference.getParameters()[conditionParameterIndex].getText();
String[] conditionParams = DatabaseUtils.extractParamsFromCondition(condition);
ArrayCreationExpression array = null;
if (methodReference.getParameters().length > paramParameterIndex) {
PsiElement paramParameter = methodReference.getParameters()[paramParameterIndex];
if (paramParameter instanceof ArrayCreationExpression)
array = (ArrayCreationExpression)paramParameter;
paramParameter.delete();
}
TemplateManager templateManager = TemplateManager.getInstance(project);
Editor editor = FileEditorManager.getInstance(project).getSelectedTextEditor();
if (editor == null || methodReference.getParameterList() == null) return;
editor.getCaretModel().moveToOffset(methodReference.getParameterList().getLastChild().getTextRange().getEndOffset());
PsiDocumentManager.getInstance(project).doPostponedOperationsAndUnblockDocument(editor.getDocument());
Template template = templateManager.createTemplate("", "");
template.setToReformat(true);
buildParamArray(template, conditionParams, array, conditionParameterIndex);
PsiDocumentManager.getInstance(project).doPostponedOperationsAndUnblockDocument(editor.getDocument());
templateManager.startTemplate(editor, template);
}
}
}
示例6: applyFix
import com.intellij.codeInsight.template.TemplateManager; //导入方法依赖的package包/类
@Override
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor problemDescriptor) {
List<PhpDocPropertyTag> propertyTags = this.comment.getPropertyTags();
Editor editor = FileEditorManager.getInstance(project).getSelectedTextEditor();
if (editor == null)
return;
Document document = editor.getDocument();
PsiDocumentManager.getInstance(project).doPostponedOperationsAndUnblockDocument(document);
TemplateManager templateManager = TemplateManager.getInstance(project);
Template template = templateManager.createTemplate("", "");
template.setToReformat(true);
for (VirtualProperty missingProperty: this.missingProperties)
{
String propertyText = "* @property "+ (missingProperty.getType() != null ? missingProperty.getType() : "") + " $" +missingProperty.getName();
if ( missingProperty.getComment() != null) {
propertyText += " " + missingProperty.getComment();
}
template.addTextSegment("\n" + propertyText);
}
template.addTextSegment("\n");
int offset = comment.getLastChild().getTextOffset();
if (propertyTags.size() > 0) {
PhpDocPropertyTag phpDocPropertyTag = propertyTags.get(comment.getPropertyTags().size() - 1);
offset = phpDocPropertyTag.getTextOffset() + phpDocPropertyTag.getTextLength();
}
editor.getCaretModel().moveToOffset(offset);
PsiDocumentManager.getInstance(project).doPostponedOperationsAndUnblockDocument(document);
templateManager.startTemplate(editor, template);
}
示例7: createJsonTemplate
import com.intellij.codeInsight.template.TemplateManager; //导入方法依赖的package包/类
@NotNull
private Template createJsonTemplate(@NotNull String name, @NotNull String group, @NotNull String text) {
final TemplateManager templateManager = TemplateManager.getInstance(getProject());
final Template template = templateManager.createTemplate(name, group, text);
final TemplateContextType context = ContainerUtil.findInstance(TemplateContextType.EP_NAME.getExtensions(), JsonContextType.class);
assertNotNull(context);
((TemplateImpl)template).getTemplateContext().setEnabled(context, true);
CodeInsightTestUtil.addTemplate(template, myTestRootDisposable);
return template;
}
示例8: expand
import com.intellij.codeInsight.template.TemplateManager; //导入方法依赖的package包/类
@Override
public void expand(@NotNull PsiElement context, @NotNull Editor editor) {
PsiExpression expr = JavaPostfixTemplatesUtils.getTopmostExpression(context);
if (expr == null) return;
Project project = context.getProject();
Document document = editor.getDocument();
document.deleteString(expr.getTextRange().getStartOffset(), expr.getTextRange().getEndOffset());
TemplateManager manager = TemplateManager.getInstance(project);
Template template = manager.createTemplate("", "");
template.setToReformat(true);
template.addTextSegment("for (");
MacroCallNode type = new MacroCallNode(new IterableComponentTypeMacro());
String variable = "variable";
type.addParameter(new VariableNode(variable, null));
MacroCallNode name = new MacroCallNode(new SuggestVariableNameMacro());
template.addVariable("type", type, type, false);
template.addTextSegment(" ");
template.addVariable("name", name, name, true);
template.addTextSegment(" : ");
template.addVariable(variable, new TextExpression(expr.getText()), false);
template.addTextSegment(") {\n");
template.addEndVariable();
template.addTextSegment("\n}");
manager.startTemplate(editor, template);
}
示例9: expand
import com.intellij.codeInsight.template.TemplateManager; //导入方法依赖的package包/类
@Override
public void expand(@NotNull PsiElement context, @NotNull Editor editor) {
PsiExpression expr = JavaPostfixTemplatesUtils.getTopmostExpression(context);
if (expr == null) {
PostfixTemplatesUtils.showErrorHint(context.getProject(), editor);
return;
}
Pair<String, String> bounds = calculateBounds(expr);
if (bounds == null) {
PostfixTemplatesUtils.showErrorHint(context.getProject(), editor);
return;
}
Project project = context.getProject();
Document document = editor.getDocument();
document.deleteString(expr.getTextRange().getStartOffset(), expr.getTextRange().getEndOffset());
TemplateManager manager = TemplateManager.getInstance(project);
Template template = manager.createTemplate("", "");
template.setToReformat(true);
template.addTextSegment("for (" + suggestIndexType(expr) + " ");
MacroCallNode index = new MacroCallNode(new SuggestVariableNameMacro());
String indexVariable = "index";
template.addVariable(indexVariable, index, index, true);
template.addTextSegment(" = " + bounds.first + "; ");
template.addVariableSegment(indexVariable);
template.addTextSegment(getComparativeSign(expr));
template.addTextSegment(bounds.second);
template.addTextSegment("; ");
template.addVariableSegment(indexVariable);
template.addTextSegment(getOperator());
template.addTextSegment(") {\n");
template.addEndVariable();
template.addTextSegment("\n}");
manager.startTemplate(editor, template);
}
示例10: createTemplate
import com.intellij.codeInsight.template.TemplateManager; //导入方法依赖的package包/类
public Template createTemplate(TemplateManager manager, String templateString) {
Template template = manager.createTemplate("", "", templateString);
template.setToReformat(shouldReformat());
return template;
}
示例11: applyFix
import com.intellij.codeInsight.template.TemplateManager; //导入方法依赖的package包/类
@Override
public void applyFix(@NotNull final Project project, @NotNull final ProblemDescriptor descriptor)
{
PsiElement anchor = descriptor.getPsiElement();
PsiFile containingFile = anchor.getContainingFile();
if(!CodeInsightUtilBase.getInstance().prepareFileForWrite(containingFile))
{
return;
}
if(anchor.getParent() instanceof JSFunction)
{
anchor = ((JSFunction) anchor.getParent()).getParameterList();
}
OpenFileDescriptor openDescriptor = new OpenFileDescriptor(project, containingFile.getVirtualFile(), anchor.getTextRange().getEndOffset());
openDescriptor.navigate(true);
Editor textEditor = FileEditorManager.getInstance(project).getSelectedTextEditor();
TemplateManager templateManager = TemplateManager.getInstance(project);
Template t = templateManager.createTemplate("", "");
t.addTextSegment(":");
boolean hasDetectedTypeFromUsage = false;
final PsiElement anchorParent = anchor.getParent();
if(anchorParent instanceof JSVariable)
{
final JSExpression expression = ((JSVariable) anchorParent).getInitializer();
if(expression != null)
{
BaseCreateFix.guessExprTypeAndAddSuchVariable(expression, t, "a", containingFile, Collections.singleton(JavaScriptFeature.CLASS));
hasDetectedTypeFromUsage = true;
}
}
if(!hasDetectedTypeFromUsage)
{
String defaultValue = "uint";
if(ApplicationManager.getApplication().isUnitTestMode())
{
t.addTextSegment(defaultValue);
}
else
{
t.addVariable("a", new MacroCallNode(MacroFactory.createMacro("complete")), new BaseCreateFix.MyExpression(defaultValue), true);
}
}
templateManager.startTemplate(textEditor, t);
}
示例12: createTemplate
import com.intellij.codeInsight.template.TemplateManager; //导入方法依赖的package包/类
/**
* Create a new instance of a code template for the current postfix template.
*
* @param project The current project
* @param manager The template manager
* @param templateString The template string
*/
protected Template createTemplate(Project project, TemplateManager manager, String templateString) {
Template template = manager.createTemplate("", "", templateString);
template.setToReformat(shouldReformat());
template.setValue(Template.Property.USE_STATIC_IMPORT_IF_POSSIBLE, false);
return template;
}
开发者ID:cesards,项目名称:HakunaMatataIntelliJPlugin,代码行数:14,代码来源:AbstractRichStringBasedPostfixTemplate.java