本文整理汇总了Java中com.intellij.ide.fileTemplates.FileTemplateUtil.createFromTemplate方法的典型用法代码示例。如果您正苦于以下问题:Java FileTemplateUtil.createFromTemplate方法的具体用法?Java FileTemplateUtil.createFromTemplate怎么用?Java FileTemplateUtil.createFromTemplate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.intellij.ide.fileTemplates.FileTemplateUtil
的用法示例。
在下文中一共展示了FileTemplateUtil.createFromTemplate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
}
示例2: 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;
}
}
示例3: 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);
}
}
示例4: 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);
}
}
示例5: 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);
}
}
示例6: 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;
}
}
示例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 = 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);
}
}
示例8: create
import com.intellij.ide.fileTemplates.FileTemplateUtil; //导入方法依赖的package包/类
@Override
@NotNull
protected final PsiElement[] create(String newName, PsiDirectory directory)
{
FileTemplate template = FileTemplateManager.getInstance(directory.getProject()).getInternalTemplate(getTemplateName());
try
{
Map<String, Object> properties = getProperties();
PsiElement element = FileTemplateUtil.createFromTemplate(template, newName, properties, directory);
return new PsiElement[]{element};
}
catch(Exception e)
{
throw new RuntimeException(e);
}
}
示例9: createTestHelper
import com.intellij.ide.fileTemplates.FileTemplateUtil; //导入方法依赖的package包/类
private static void createTestHelper(@NotNull Project project, @NotNull VirtualFile baseDir) {
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());
}
}
示例10: createTestHelper
import com.intellij.ide.fileTemplates.FileTemplateUtil; //导入方法依赖的package包/类
private static void createTestHelper(@NotNull Project project, PsiDirectory projectDir) {
final FileTemplate template =
FileTemplateManager.getInstance(project).getInternalTemplate(FileUtil.getNameWithoutExtension(EduNames.TEST_HELPER));
try {
FileTemplateUtil.createFromTemplate(template, EduNames.TEST_HELPER, null, projectDir);
}
catch (Exception ignored) {
}
}
示例11: addTemplate
import com.intellij.ide.fileTemplates.FileTemplateUtil; //导入方法依赖的package包/类
public static void addTemplate(@NotNull final Project project, @NotNull VirtualFile baseDir, @NotNull @NonNls final String templateName) {
final FileTemplate template = FileTemplateManager.getInstance(project).getInternalTemplate(templateName);
final PsiDirectory projectDir = PsiManager.getInstance(project).findDirectory(baseDir);
if (projectDir == null) return;
try {
// PsiDirectory utilDir = projectDir.findSubdirectory("util");
// if (utilDir == null) {
// utilDir = projectDir.createSubdirectory("util");
// }
FileTemplateUtil.createFromTemplate(template, templateName, null, projectDir);
} catch (Exception exception) {
LOG.error("Failed to create from file template ", exception);
}
}
示例12: createFile
import com.intellij.ide.fileTemplates.FileTemplateUtil; //导入方法依赖的package包/类
public static PsiElement createFile(String className, @NotNull PsiDirectory directory, final String templateName, AnAction actionClass) throws Exception {
final Properties props = new Properties(FileTemplateManager.getInstance().getDefaultProperties(directory.getProject()));
props.setProperty(FileTemplate.ATTRIBUTE_NAME, className);
final FileTemplate template = FileTemplateManager.getInstance().getInternalTemplate(templateName);
return FileTemplateUtil.createFromTemplate(template, className, props, directory, actionClass.getClass().getClassLoader());
}
示例13: generateProject
import com.intellij.ide.fileTemplates.FileTemplateUtil; //导入方法依赖的package包/类
@Override
public void generateProject(@NotNull final Project project, @NotNull final VirtualFile baseDir,
@Nullable Object settings, @NotNull Module module) {
myGenerator.generateProject(project, baseDir);
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, "test_helper.py", null, projectDir);
}
catch (Exception exception) {
LOG.error("Can't copy test_helper.py " + exception.getMessage());
}
}
示例14: doCreate
import com.intellij.ide.fileTemplates.FileTemplateUtil; //导入方法依赖的package包/类
private void doCreate(@Nullable final String fileName) {
try {
myCreatedElement = FileTemplateUtil.createFromTemplate(myTemplate, fileName, myAttrPanel.getProperties(myDefaultProperties),
myDirectory);
}
catch (Exception e) {
showErrorDialog(e);
}
}
示例15: createClass
import com.intellij.ide.fileTemplates.FileTemplateUtil; //导入方法依赖的package包/类
public static PsiElement createClass(String className, String packageName, PsiDirectory directory, String templateName, @org.jetbrains.annotations.Nullable java.lang.ClassLoader classLoader)
throws Exception {
final Properties props = new Properties(FileTemplateManager.getInstance().getDefaultProperties(directory.getProject()));
props.setProperty(FileTemplate.ATTRIBUTE_NAME, className);
props.setProperty(FileTemplate.ATTRIBUTE_PACKAGE_NAME, packageName);
final FileTemplate template = FileTemplateManager.getInstance().getInternalTemplate(templateName);
return FileTemplateUtil.createFromTemplate(template, className, props, directory, classLoader);
}