use of com.intellij.ide.fileTemplates.FileTemplate in project intellij-community by JetBrains.
the class GroovyOverrideImplementUtil method generateMethodPrototype.
public static GrMethod generateMethodPrototype(GrTypeDefinition aClass, PsiMethod method, PsiSubstitutor substitutor) {
final Project project = aClass.getProject();
final boolean isAbstract = method.hasModifierProperty(PsiModifier.ABSTRACT);
String templName = isAbstract ? JavaTemplateUtil.TEMPLATE_IMPLEMENTED_METHOD_BODY : JavaTemplateUtil.TEMPLATE_OVERRIDDEN_METHOD_BODY;
final FileTemplate template = FileTemplateManager.getInstance(method.getProject()).getCodeTemplate(templName);
final GrMethod result = (GrMethod) GenerateMembersUtil.substituteGenericMethod(method, substitutor, aClass);
setupModifierList(result);
setupOverridingMethodBody(project, method, result, template, substitutor);
setupReturnType(result, method);
setupAnnotations(aClass, method, result);
GroovyChangeContextUtil.encodeContextInfo(result);
return result;
}
use of com.intellij.ide.fileTemplates.FileTemplate in project intellij-community by JetBrains.
the class CCNewSubtaskAction method createTaskDescriptionFile.
private static void createTaskDescriptionFile(Project project, VirtualFile taskDir, int index) {
String taskDescriptionFileName = StudyUtils.getTaskDescriptionFileName(CCSettings.getInstance().useHtmlAsDefaultTaskFormat());
FileTemplate taskTextTemplate = FileTemplateManager.getInstance(project).getInternalTemplate(taskDescriptionFileName);
PsiDirectory taskPsiDir = PsiManager.getInstance(project).findDirectory(taskDir);
if (taskTextTemplate != null && taskPsiDir != null) {
String nextTaskTextName = FileUtil.getNameWithoutExtension(taskDescriptionFileName) + EduNames.SUBTASK_MARKER + index + "." + FileUtilRt.getExtension(taskDescriptionFileName);
try {
FileTemplateUtil.createFromTemplate(taskTextTemplate, nextTaskTextName, null, taskPsiDir);
} catch (Exception e) {
LOG.error(e);
}
}
}
use of com.intellij.ide.fileTemplates.FileTemplate in project intellij-community by JetBrains.
the class CreatePackageAction method createInitPy.
private static void createInitPy(PsiDirectory directory) {
final FileTemplateManager fileTemplateManager = FileTemplateManager.getInstance(directory.getProject());
final FileTemplate template = fileTemplateManager.getInternalTemplate("Python Script");
if (directory.findFile(PyNames.INIT_DOT_PY) != null) {
return;
}
if (template != null) {
try {
FileTemplateUtil.createFromTemplate(template, PyNames.INIT_DOT_PY, fileTemplateManager.getDefaultProperties(), directory);
} catch (Exception e) {
LOG.error(e);
}
} else {
final PsiFile file = PsiFileFactory.getInstance(directory.getProject()).createFileFromText(PyNames.INIT_DOT_PY, "");
directory.add(file);
}
}
use of com.intellij.ide.fileTemplates.FileTemplate in project intellij-community by JetBrains.
the class JavaI18nizeQuickFixDialog method getI18nizedText.
public String getI18nizedText() {
String propertyKey = StringUtil.escapeStringCharacters(getKey());
I18nizedTextGenerator textGenerator = myResourceBundleManager.getI18nizedTextGenerator();
if (textGenerator != null) {
return generateText(textGenerator, propertyKey, getPropertiesFile(), myLiteralExpression);
}
String templateName = getTemplateName();
LOG.assertTrue(templateName != null);
FileTemplate template = FileTemplateManager.getInstance(myProject).getCodeTemplate(templateName);
Map<String, String> attributes = new THashMap<>();
attributes.put(PROPERTY_KEY_OPTION_KEY, propertyKey);
attributes.put(RESOURCE_BUNDLE_OPTION_KEY, getResourceBundleText());
attributes.put(PROPERTY_VALUE_ATTR, StringUtil.escapeStringCharacters(myDefaultPropertyValue));
addAdditionalAttributes(attributes);
String text = null;
try {
text = template.getText(attributes);
} catch (IOException e) {
LOG.error(e);
}
return text;
}
use of com.intellij.ide.fileTemplates.FileTemplate in project intellij-community by JetBrains.
the class JavaI18nizeQuickFixDialog method suggestAvailableResourceBundleExpressions.
private void suggestAvailableResourceBundleExpressions() {
String templateName = getTemplateName();
if (templateName == null)
return;
if (myShowJavaCodeInfo) {
FileTemplate template = FileTemplateManager.getInstance(myProject).getCodeTemplate(templateName);
boolean showResourceBundleSuggester = template.getText().contains("${" + RESOURCE_BUNDLE_OPTION_KEY + "}");
myJavaCodeInfoPanel.setVisible(showResourceBundleSuggester);
}
Set<String> result = JavaI18nUtil.suggestExpressionOfType(myResourceBundleType, myLiteralExpression);
if (result.isEmpty()) {
result.add(getResourceBundleText());
}
myRBEditorTextField.setHistory(ArrayUtil.toStringArray(result));
SwingUtilities.invokeLater(() -> myRBEditorTextField.setSelectedIndex(0));
}
Aggregations