当前位置: 首页>>代码示例>>Java>>正文


Java FileTemplateUtil.createFromTemplate方法代码示例

本文整理汇总了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);
  }
}
 
开发者ID:medvector,项目名称:educational-plugin,代码行数:22,代码来源:StudyUtils.java

示例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;
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:24,代码来源:JavaTestGenerator.java

示例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);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:22,代码来源:CreateFromTemplateDialog.java

示例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);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:20,代码来源:CreatePackageAction.java

示例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);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:18,代码来源:CCCreateTask.java

示例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;
	}
}
 
开发者ID:consulo,项目名称:consulo-csharp,代码行数:19,代码来源:CSharpCreateFileAction.java

示例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);
  }
}
 
开发者ID:consulo,项目名称:consulo,代码行数:17,代码来源:CreateFromTemplateDialog.java

示例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);
	}
}
 
开发者ID:consulo,项目名称:consulo-google-guice,代码行数:18,代码来源:GeneratePluginClassAction.java

示例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());
  }
}
 
开发者ID:medvector,项目名称:educational-plugin,代码行数:14,代码来源:PyStudyDirectoryProjectGenerator.java

示例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) {
  }
}
 
开发者ID:medvector,项目名称:educational-plugin,代码行数:10,代码来源:PyCCProjectGenerator.java

示例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);
        }

    }
 
开发者ID:medvector,项目名称:educational-plugin,代码行数:16,代码来源:EduIntellijUtils.java

示例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());
}
 
开发者ID:PioBeat,项目名称:GravSupport,代码行数:9,代码来源:FileCreateUtil.java

示例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());
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:15,代码来源:PyStudyDirectoryProjectGenerator.java

示例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);
  }
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:10,代码来源:CreateFromTemplateDialog.java

示例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);
}
 
开发者ID:HaxeFoundation,项目名称:intellij-haxe,代码行数:11,代码来源:HaxeFileTemplateUtil.java


注:本文中的com.intellij.ide.fileTemplates.FileTemplateUtil.createFromTemplate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。