本文整理汇总了Java中com.intellij.ide.fileTemplates.FileTemplateUtil类的典型用法代码示例。如果您正苦于以下问题:Java FileTemplateUtil类的具体用法?Java FileTemplateUtil怎么用?Java FileTemplateUtil使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
FileTemplateUtil类属于com.intellij.ide.fileTemplates包,在下文中一共展示了FileTemplateUtil类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createTestsForNewSubtask
import com.intellij.ide.fileTemplates.FileTemplateUtil; //导入依赖的package包/类
@Override
public void createTestsForNewSubtask(@NotNull Project project, @NotNull TaskWithSubtasks task) {
VirtualFile taskDir = task.getTaskDir(project);
if (taskDir == null) {
return;
}
int nextSubtaskIndex = task.getLastSubtaskIndex() + 1;
String nextSubtaskTestsFileName = getSubtaskTestsFileName(nextSubtaskIndex);
ApplicationManager.getApplication().runWriteAction(() -> {
try {
PsiDirectory taskPsiDir = PsiManager.getInstance(project).findDirectory(taskDir);
FileTemplate testsTemplate = FileTemplateManager.getInstance(project).getInternalTemplate(TESTS_PY);
if (taskPsiDir == null || testsTemplate == null) {
return;
}
FileTemplateUtil.createFromTemplate(testsTemplate, nextSubtaskTestsFileName, null, taskPsiDir);
}
catch (Exception e) {
LOG.error(e);
}
});
}
示例2: configureModule
import com.intellij.ide.fileTemplates.FileTemplateUtil; //导入依赖的package包/类
@Override
public void configureModule(@NotNull Module module) {
final Project project = module.getProject();
StartupManager.getInstance(project).runWhenProjectIsInitialized(() -> {
final VirtualFile baseDir = project.getBaseDir();
final String testHelper = EduNames.TEST_HELPER;
if (baseDir.findChild(testHelper) != null) return;
final FileTemplate template = FileTemplateManager.getInstance(project).getInternalTemplate("test_helper");
final PsiDirectory projectDir = PsiManager.getInstance(project).findDirectory(baseDir);
if (projectDir == null) return;
try {
FileTemplateUtil.createFromTemplate(template, testHelper, null, projectDir);
}
catch (Exception exception) {
LOG.error("Can't copy test_helper.py " + exception.getMessage());
}
});
}
示例3: createFromTemplate
import com.intellij.ide.fileTemplates.FileTemplateUtil; //导入依赖的package包/类
public static void createFromTemplate(@NotNull Project project,
@NotNull PsiDirectory taskDirectory,
@NotNull String name,
@Nullable IdeView view,
boolean open) {
FileTemplate template = FileTemplateManager.getInstance(project).getInternalTemplate(name);
if (template == null) {
LOG.info("Template " + name + " wasn't found");
return;
}
try {
final PsiElement file = FileTemplateUtil.createFromTemplate(template, name, null, taskDirectory);
if (view != null && open) {
EditorHelper.openInEditor(file, false);
view.selectElement(file);
}
}
catch (Exception e) {
LOG.error(e);
}
}
示例4: updateTestHelper
import com.intellij.ide.fileTemplates.FileTemplateUtil; //导入依赖的package包/类
private void updateTestHelper() {
StartupManager.getInstance(myProject).runWhenProjectIsInitialized(() -> ApplicationManager.getApplication().runWriteAction(() -> {
final VirtualFile baseDir = myProject.getBaseDir();
if (baseDir == null) {
return;
}
final VirtualFile testHelper = baseDir.findChild(EduNames.TEST_HELPER);
if (testHelper != null) {
StudyUtils.deleteFile(testHelper);
}
final FileTemplate template =
FileTemplateManager.getInstance(myProject).getInternalTemplate(FileUtil.getNameWithoutExtension(EduNames.TEST_HELPER));
try {
final PsiDirectory projectDir = PsiManager.getInstance(myProject).findDirectory(baseDir);
if (projectDir != null) {
FileTemplateUtil.createFromTemplate(template, EduNames.TEST_HELPER, null, projectDir);
}
}
catch (Exception e) {
LOG.warn("Failed to create new test helper");
}
}));
}
示例5: getSelector
import com.intellij.ide.fileTemplates.FileTemplateUtil; //导入依赖的package包/类
@NotNull
private ComboBox getSelector() {
ArrayList<TemplateForSearch> listTemplateForSearch = FileTemplateHelper.getTemplates(
project,
cbAddInternal.isSelected(),
cbAddJ2EE.isSelected(),
ptWrapper.getPackageTemplate().getFileTemplateSource()
);
ComboBox comboBox = new ComboBox(listTemplateForSearch.toArray());
comboBox.setRenderer(new ListCellRendererWrapper<TemplateForSearch>() {
@Override
public void customize(JList list, TemplateForSearch template, int index, boolean selected, boolean hasFocus) {
if (template != null) {
setIcon(FileTemplateUtil.getIcon(template.getTemplate()));
setText(template.getTemplate().getName());
}
}
});
new ComboboxSpeedSearch(comboBox);
return comboBox;
}
示例6: createTestClassFromCodeTemplate
import com.intellij.ide.fileTemplates.FileTemplateUtil; //导入依赖的package包/类
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;
}
}
示例7: doCreate
import com.intellij.ide.fileTemplates.FileTemplateUtil; //导入依赖的package包/类
private void doCreate(@Nullable String fileName) {
try {
String newName = fileName;
PsiDirectory directory = myDirectory;
if (fileName != null) {
final String finalFileName = fileName;
CreateFileAction.MkDirs mkDirs = ApplicationManager.getApplication().runWriteAction(new Computable<CreateFileAction.MkDirs>() {
@Override
public CreateFileAction.MkDirs compute() {
return new CreateFileAction.MkDirs(finalFileName, myDirectory);
}
});
newName = mkDirs.newName;
directory = mkDirs.directory;
}
myCreatedElement = FileTemplateUtil.createFromTemplate(myTemplate, newName, myAttrPanel.getProperties(myDefaultProperties), directory);
}
catch (Exception e) {
showErrorDialog(e);
}
}
示例8: getListCellRendererComponent
import com.intellij.ide.fileTemplates.FileTemplateUtil; //导入依赖的package包/类
@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
Icon icon = null;
if (value instanceof FileTemplate) {
FileTemplate template = (FileTemplate) value;
icon = FileTemplateUtil.getIcon(template);
final boolean internalTemplate = AllFileTemplatesConfigurable.isInternalTemplate(template.getName(), getTitle());
if (internalTemplate) {
setFont(getFont().deriveFont(Font.BOLD));
setText(template.getName());
}
else {
setFont(getFont().deriveFont(Font.PLAIN));
setText(template.getName());
}
if (!template.isDefault()) {
if (!isSelected) {
setForeground(MODIFIED_FOREGROUND);
}
}
}
setIcon(icon);
return this;
}
示例9: commitModule
import com.intellij.ide.fileTemplates.FileTemplateUtil; //导入依赖的package包/类
@Nullable
@Override
public Module commitModule(@NotNull final Project project, @Nullable ModifiableModuleModel model) {
Module module = super.commitModule(project, model);
if (module != null) {
final VirtualFile baseDir = project.getBaseDir();
studyProjectGenerator.generateProject(project, baseDir);
final FileTemplate template = FileTemplateManager.getInstance(project).getInternalTemplate("test_helper.py");
StartupManager.getInstance(project).runWhenProjectIsInitialized(new Runnable() {
@Override
public void run() {
final PsiDirectory projectDir = PsiManager.getInstance(project).findDirectory(baseDir);
if (projectDir != null) {
try {
FileTemplateUtil.createFromTemplate(template, "test_helper.py", null, projectDir);
}
catch (Exception e) {
LOG.error("Failed to create test_helper", e);
}
}
}
});
}
return module;
}
示例10: createInitPy
import com.intellij.ide.fileTemplates.FileTemplateUtil; //导入依赖的package包/类
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);
}
}
示例11: createFromTemplateAndOpen
import com.intellij.ide.fileTemplates.FileTemplateUtil; //导入依赖的package包/类
private static void createFromTemplateAndOpen(@NotNull final PsiDirectory taskDirectory,
@Nullable final FileTemplate template,
@Nullable IdeView view) {
if (template == null) {
return;
}
try {
final PsiElement file = FileTemplateUtil.createFromTemplate(template, template.getName(), null, taskDirectory);
if (view != null) {
EditorHelper.openInEditor(file, false);
view.selectElement(file);
}
}
catch (Exception e) {
LOG.error(e);
}
}
示例12: getAllFileTemplatesVariables
import com.intellij.ide.fileTemplates.FileTemplateUtil; //导入依赖的package包/类
public Set<String> getAllFileTemplatesVariables() {
Set<String> result = new TreeSet<String>();
List<FileTemplate> allTemplates = new ArrayList<FileTemplate>();
FileTemplateManager fileTemplateManager = FileTemplateManager.getInstance();
FileTemplate[] templates = fileTemplateManager.getAllTemplates();
FileTemplate[] patterns = fileTemplateManager.getAllPatterns();
FileTemplate[] codeTemplates = fileTemplateManager.getAllCodeTemplates();
FileTemplate[] j2eeTemplates = fileTemplateManager.getAllJ2eeTemplates();
allTemplates.addAll(Arrays.asList(templates));
allTemplates.addAll(Arrays.asList(codeTemplates));
allTemplates.addAll(Arrays.asList(j2eeTemplates));
allTemplates.addAll(Arrays.asList(patterns));
for (FileTemplate template : allTemplates) {
try {
String[] variables = FileTemplateUtil.calculateAttributes(template.getText(), new Properties(), true, myProject);
result.addAll(Arrays.asList(variables));
} catch (ParseException e) {
logger.warn("Parsing exception", e);
}
}
return result;
}
示例13: getListCellRendererComponent
import com.intellij.ide.fileTemplates.FileTemplateUtil; //导入依赖的package包/类
@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
Icon icon = null;
if (value instanceof FileTemplate) {
FileTemplate template = (FileTemplate) value;
icon = FileTemplateUtil.getIcon(template);
final boolean internalTemplate = AllFileTemplatesConfigurable.isInternalTemplate(template.getName(), getTitle());
if (internalTemplate) {
setFont(getFont().deriveFont(Font.BOLD));
setText(FileTemplateManagerImpl.getInstanceImpl().localizeInternalTemplateName(template));
}
else {
setFont(getFont().deriveFont(Font.PLAIN));
setText(template.getName());
}
if (!template.isDefault()) {
if (!isSelected) {
setForeground(MODIFIED_FOREGROUND);
}
}
}
setIcon(icon);
return this;
}
示例14: createFile
import com.intellij.ide.fileTemplates.FileTemplateUtil; //导入依赖的package包/类
@Override
@RequiredReadAction
protected PsiFile createFile(String name, String templateName, final PsiDirectory dir)
{
FileTemplate template = FileTemplateManager.getInstance(dir.getProject()).getInternalTemplate(templateName);
try
{
Map<String, Object> map = new HashMap<>();
map.put("psiDirectory", dir);
return (PsiFile) FileTemplateUtil.createFromTemplate(template, name, map, dir, getClass().getClassLoader());
}
catch(Exception e)
{
e.printStackTrace();
return null;
}
}
示例15: doCreate
import com.intellij.ide.fileTemplates.FileTemplateUtil; //导入依赖的package包/类
private void doCreate(@Nullable String fileName) {
try {
String newName = fileName;
PsiDirectory directory = myDirectory;
if (fileName != null) {
final String finalFileName = fileName;
CreateFileAction.MkDirs mkDirs = WriteAction.compute(() -> new CreateFileAction.MkDirs(finalFileName, myDirectory));
newName = mkDirs.newName;
directory = mkDirs.directory;
}
myCreatedElement = FileTemplateUtil.createFromTemplate(myTemplate, newName, myAttrPanel.getVariables(myDefaultProperties), directory);
}
catch (Exception e) {
showErrorDialog(e);
}
}