use of com.intellij.codeInsight.template.Template in project intellij-plugins by JetBrains.
the class CreateToStringFix method buildFunctionsText.
protected Template buildFunctionsText(TemplateManager templateManager, Set<DartComponent> elementsToProcess) {
final Template template = templateManager.createTemplate(getClass().getName(), DART_TEMPLATE_GROUP);
template.setToReformat(true);
if (CodeStyleSettingsManager.getSettings(myDartClass.getProject()).INSERT_OVERRIDE_ANNOTATION) {
template.addTextSegment("@override\n");
}
template.addTextSegment("String toString() {");
template.addTextSegment(DartTokenTypes.RETURN.toString());
template.addTextSegment(" ");
template.addTextSegment("'");
//noinspection ConstantConditions
template.addTextSegment(myDartClass.getName());
template.addTextSegment("{");
for (Iterator<DartComponent> iterator = elementsToProcess.iterator(); iterator.hasNext(); ) {
DartComponent component = iterator.next();
//noinspection ConstantConditions
template.addTextSegment(component.getName());
template.addTextSegment(": $");
//noinspection ConstantConditions
template.addTextSegment(component.getName());
if (iterator.hasNext()) {
template.addTextSegment(", ");
}
}
template.addTextSegment("}';\n");
template.addTextSegment("}");
template.addEndVariable();
// trailing space is removed when auto-reformatting, but it helps to enter line break if needed
template.addTextSegment(" ");
return template;
}
use of com.intellij.codeInsight.template.Template in project intellij-plugins by JetBrains.
the class AbstractStepDefinitionCreator method closeActiveTemplateBuilders.
protected void closeActiveTemplateBuilders(PsiFile file) {
final Project project = file.getProject();
final VirtualFile vFile = ObjectUtils.assertNotNull(file.getVirtualFile());
final OpenFileDescriptor descriptor = new OpenFileDescriptor(project, vFile);
FileEditorManager.getInstance(project).getAllEditors(vFile);
FileEditorManager.getInstance(project).openTextEditor(descriptor, true);
final Editor editor = FileEditorManager.getInstance(project).getSelectedTextEditor();
assert editor != null;
final TemplateManager templateManager = TemplateManager.getInstance(file.getProject());
final TemplateState templateState = TemplateManagerImpl.getTemplateState(editor);
final Template template = templateManager.getActiveTemplate(editor);
if (templateState != null && template != null) {
templateState.gotoEnd(false);
}
}
use of com.intellij.codeInsight.template.Template in project intellij-plugins by JetBrains.
the class CreateEventMetadataByMxmlAttributeFix method applyFix.
@Override
protected void applyFix(final Project project, final PsiElement psiElement, PsiFile file, Editor editor) {
assert psiElement instanceof XmlAttribute;
final XmlTag tag = (XmlTag) psiElement.getParent();
final XmlElementDescriptor descriptor = tag.getDescriptor();
PsiElement type = descriptor == null ? null : descriptor.getDeclaration();
if (type == null) {
// can not resolve
return;
}
if (!FileModificationService.getInstance().preparePsiElementForWrite(type)) {
return;
}
file = type.getContainingFile();
editor = getEditor(project, file);
if (editor == null) {
return;
}
final boolean addingToMxml = type instanceof XmlFile;
final TemplateManager templateManager = TemplateManager.getInstance(project);
final Template template = templateManager.createTemplate("", "");
template.setToReformat(true);
if (addingToMxml) {
template.addTextSegment("\n");
}
template.addTextSegment("[Event(name=\"" + myEventName + "\", type=\"");
template.addVariable(new MyExpression(FlexCommonTypeNames.FLASH_EVENT_FQN), true);
template.addTextSegment("\")]");
if (!addingToMxml) {
template.addTextSegment("\n");
}
final int offset;
if (addingToMxml) {
XmlTag metadataTag = WriteAction.compute(() -> createOrGetMetadataTag((XmlFile) type));
offset = metadataTag.getValue().getTextRange().getStartOffset();
} else {
offset = type.getTextRange().getStartOffset();
}
navigate(project, editor, offset, file.getVirtualFile());
templateManager.startTemplate(editor, template);
}
use of com.intellij.codeInsight.template.Template in project intellij-plugins by JetBrains.
the class GenerateFlexUnitMethodActionBase method getGenerateHandler.
protected BaseJSGenerateHandler getGenerateHandler() {
return new BaseJSGenerateHandler() {
protected String getTitleKey() {
return null;
}
protected BaseCreateMethodsFix createFix(JSClass clazz) {
return new BaseCreateMethodsFix(clazz) {
public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
evalAnchor(editor, file);
final PsiElement addedElement = doAddOneMethod(project, "public function fake():void{}", anchor);
PsiDocumentManager.getInstance(project).doPostponedOperationsAndUnblockDocument(editor.getDocument());
final TemplateManager manager = TemplateManager.getInstance(project);
final Template template = manager.createTemplate("", "");
template.setToReformat(true);
buildTemplate(template, myJsClass);
final TextRange range = addedElement.getTextRange();
editor.getDocument().replaceString(range.getStartOffset(), range.getEndOffset(), "");
editor.getCaretModel().moveToOffset(range.getStartOffset());
manager.startTemplate(editor, template);
}
};
}
protected boolean canHaveEmptySelectedElements() {
return true;
}
};
}
Aggregations