use of com.intellij.ide.fileTemplates.FileTemplate in project intellij-community by JetBrains.
the class JavaTestGenerator method createTestClassFromCodeTemplate.
private static PsiClass createTestClassFromCodeTemplate(final CreateTestDialog d, final FileTemplateDescriptor fileTemplateDescriptor, final PsiDirectory targetDirectory) {
final String templateName = fileTemplateDescriptor.getFileName();
final FileTemplate fileTemplate = FileTemplateManager.getInstance(targetDirectory.getProject()).getCodeTemplate(templateName);
final Properties defaultProperties = FileTemplateManager.getInstance(targetDirectory.getProject()).getDefaultProperties();
Properties properties = new Properties(defaultProperties);
properties.setProperty(FileTemplate.ATTRIBUTE_NAME, d.getClassName());
final PsiClass targetClass = d.getTargetClass();
if (targetClass != null && targetClass.isValid()) {
properties.setProperty(FileTemplate.ATTRIBUTE_CLASS_NAME, targetClass.getQualifiedName());
}
try {
final PsiElement psiElement = FileTemplateUtil.createFromTemplate(fileTemplate, templateName, properties, targetDirectory);
if (psiElement instanceof PsiClass) {
return (PsiClass) psiElement;
}
return null;
} catch (Exception e) {
return null;
}
}
use of com.intellij.ide.fileTemplates.FileTemplate in project intellij-community by JetBrains.
the class JavaSurroundWithTest method testSurroundWithTryCatchProperties.
public void testSurroundWithTryCatchProperties() {
FileTemplate template = FileTemplateManager.getInstance(getProject()).getCodeTemplate(JavaTemplateUtil.TEMPLATE_CATCH_BODY);
String old = template.getText();
template.setText("// ${DS} \n" + "${EXCEPTION}.printStackTrace();");
try {
doTest(new JavaWithTryCatchSurrounder());
} finally {
template.setText(old);
}
}
use of com.intellij.ide.fileTemplates.FileTemplate in project intellij-community by JetBrains.
the class CreateFromTemplateGroup method update.
@Override
public void update(AnActionEvent e) {
super.update(e);
Presentation presentation = e.getPresentation();
Project project = e.getProject();
if (project != null) {
FileTemplate[] allTemplates = FileTemplateManager.getInstance(project).getAllTemplates();
for (FileTemplate template : allTemplates) {
if (canCreateFromTemplate(e, template)) {
presentation.setEnabled(true);
return;
}
}
}
presentation.setEnabled(false);
}
use of com.intellij.ide.fileTemplates.FileTemplate in project intellij-community by JetBrains.
the class FileTemplateManagerImpl method validateRecentNames.
private void validateRecentNames() {
final Collection<FileTemplateBase> allTemplates = getSettings().getDefaultTemplatesManager().getAllTemplates(false);
final List<String> allNames = new ArrayList<>(allTemplates.size());
for (FileTemplate fileTemplate : allTemplates) {
allNames.add(fileTemplate.getName());
}
myState.validateNames(allNames);
}
use of com.intellij.ide.fileTemplates.FileTemplate in project intellij-community by JetBrains.
the class GroovyGeneratePropertyMissingHandler method generateMemberPrototypes.
@NotNull
@Override
protected List<? extends GenerationInfo> generateMemberPrototypes(PsiClass aClass, ClassMember[] members) throws IncorrectOperationException {
final String templName = JavaTemplateUtil.TEMPLATE_FROM_USAGE_METHOD_BODY;
final FileTemplate template = FileTemplateManager.getInstance(aClass.getProject()).getCodeTemplate(templName);
final GrMethod getter = genGetter(aClass, template);
final GrMethod setter = genSetter(aClass, template);
final ArrayList<GroovyGenerationInfo<GrMethod>> result = new ArrayList<>();
if (getter != null)
result.add(new GroovyGenerationInfo<>(getter, true));
if (setter != null)
result.add(new GroovyGenerationInfo<>(setter, true));
return result;
}
Aggregations