use of com.intellij.ide.fileTemplates.FileTemplate in project intellij-community by JetBrains.
the class CreateFromTemplateActionBase method actionPerformed.
@Override
public final void actionPerformed(AnActionEvent e) {
DataContext dataContext = e.getDataContext();
IdeView view = LangDataKeys.IDE_VIEW.getData(dataContext);
if (view == null)
return;
PsiDirectory dir = getTargetDirectory(dataContext, view);
if (dir == null)
return;
Project project = dir.getProject();
FileTemplate selectedTemplate = getTemplate(project, dir);
if (selectedTemplate != null) {
AnAction action = getReplacedAction(selectedTemplate);
if (action != null) {
action.actionPerformed(e);
} else {
FileTemplateManager.getInstance(project).addRecentName(selectedTemplate.getName());
AttributesDefaults defaults = getAttributesDefaults(dataContext);
Properties properties = defaults != null ? defaults.getDefaultProperties() : null;
CreateFromTemplateDialog dialog = new CreateFromTemplateDialog(project, dir, selectedTemplate, defaults, properties);
PsiElement createdElement = dialog.create();
if (createdElement != null) {
elementCreated(dialog, createdElement);
view.selectElement(createdElement);
if (selectedTemplate.isLiveTemplateEnabled() && createdElement instanceof PsiFile) {
Map<String, String> defaultValues = getLiveTemplateDefaults(dataContext, ((PsiFile) createdElement));
startLiveTemplate((PsiFile) createdElement, notNull(defaultValues, Collections.emptyMap()));
}
}
}
}
}
use of com.intellij.ide.fileTemplates.FileTemplate in project intellij-community by JetBrains.
the class JavaTestFramework method createSetUpPatternMethod.
public PsiMethod createSetUpPatternMethod(JVMElementFactory factory) {
final FileTemplate template = FileTemplateManager.getDefaultInstance().getCodeTemplate(getSetUpMethodFileTemplateDescriptor().getFileName());
final String templateText = StringUtil.replace(StringUtil.replace(template.getText(), "${BODY}\n", ""), "${NAME}", "setUp");
return factory.createMethodFromText(templateText, null);
}
use of com.intellij.ide.fileTemplates.FileTemplate in project intellij-community by JetBrains.
the class ConfigFileFactoryImpl method getText.
private static String getText(final String templateName, @Nullable Project project) throws IOException {
final FileTemplateManager templateManager = project == null ? FileTemplateManager.getDefaultInstance() : FileTemplateManager.getInstance(project);
final FileTemplate template = templateManager.getJ2eeTemplate(templateName);
if (template == null) {
return "";
}
return template.getText(templateManager.getDefaultProperties());
}
use of com.intellij.ide.fileTemplates.FileTemplate in project intellij-community by JetBrains.
the class CreateFromUsageUtils method setupMethodBody.
public static void setupMethodBody(final PsiMethod method, final PsiClass aClass) throws IncorrectOperationException {
FileTemplate template = FileTemplateManager.getInstance(method.getProject()).getCodeTemplate(JavaTemplateUtil.TEMPLATE_FROM_USAGE_METHOD_BODY);
setupMethodBody(method, aClass, template);
}
use of com.intellij.ide.fileTemplates.FileTemplate in project intellij-community by JetBrains.
the class LightFileTemplatesTest method testSaveReformatCode.
public void testSaveReformatCode() throws Exception {
FileTemplate template = myTemplateManager.getTemplate(TEST_TEMPLATE_TXT);
assertTrue(template.isReformatCode());
template.setReformatCode(false);
FileTemplateSettings settings = ServiceManager.getService(ExportableFileTemplateSettings.class);
Element state = settings.getState();
assertNotNull(state);
Element element = state.getChildren().get(0).getChildren().get(0);
assertEquals("<template name=\"testTemplate.txt\" reformat=\"false\" live-template-enabled=\"false\" enabled=\"true\" />", JDOMUtil.writeElement(element));
}
Aggregations