本文整理汇总了Java中com.intellij.ide.fileTemplates.FileTemplateManager类的典型用法代码示例。如果您正苦于以下问题:Java FileTemplateManager类的具体用法?Java FileTemplateManager怎么用?Java FileTemplateManager使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
FileTemplateManager类属于com.intellij.ide.fileTemplates包,在下文中一共展示了FileTemplateManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getAvailableTemplates
import com.intellij.ide.fileTemplates.FileTemplateManager; //导入依赖的package包/类
private List<Trinity> getAvailableTemplates() {
List<Trinity> templates = new ArrayList<Trinity>();
FileTemplate classTemplate = FileTemplateManager.getInstance(this.myProject).getInternalTemplate("PHP Class");
for (FileTemplate template : FileTemplateManager.getInstance(this.myProject).getAllTemplates()) {
if (template.getExtension().equals("class.php")) {
templates.add(new Trinity(template.getName(), PhpIcons.CLASS, template));
}
}
if (templates.size() < 1) {
templates.add(new Trinity(classTemplate.getName(), PhpIcons.CLASS, classTemplate));
}
return templates;
}
示例2: createTestsForNewSubtask
import com.intellij.ide.fileTemplates.FileTemplateManager; //导入依赖的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);
}
});
}
示例3: configureModule
import com.intellij.ide.fileTemplates.FileTemplateManager; //导入依赖的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());
}
});
}
示例4: createFromTemplate
import com.intellij.ide.fileTemplates.FileTemplateManager; //导入依赖的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);
}
}
示例5: updateTestHelper
import com.intellij.ide.fileTemplates.FileTemplateManager; //导入依赖的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");
}
}));
}
示例6: createLog4JTest
import com.intellij.ide.fileTemplates.FileTemplateManager; //导入依赖的package包/类
private VirtualFile createLog4JTest(final Project project, final MavenId projectId, final VirtualFile appDirectory)
{
return new WriteCommandAction<VirtualFile>(project, "Create Log4J Test File", PsiFile.EMPTY_ARRAY)
{
@Override
protected void run(@NotNull Result<VirtualFile> result) throws Throwable
{
try
{
VirtualFile configFile = appDirectory.findOrCreateChildData(this, "log4j2-test.xml");
final FileTemplateManager manager = FileTemplateManager.getInstance(project);
final FileTemplate template = manager.getInternalTemplate(MuleFileTemplateDescriptorManager.LOG4J2_TEST);
final Properties defaultProperties = manager.getDefaultProperties();
final String text = template.getText(defaultProperties);
VfsUtil.saveText(configFile, text);
result.setResult(configFile);
}
catch (IOException e)
{
showError(project, e);
}
}
}.execute().getResultObject();
}
示例7: createFromTemplate
import com.intellij.ide.fileTemplates.FileTemplateManager; //导入依赖的package包/类
public static PsiFile createFromTemplate(final PsiDirectory directory, final String name,
String fileName, String templateName,
@NonNls String... parameters) throws IncorrectOperationException {
final FileTemplate template = FileTemplateManager.getInstance(directory.getProject()).getInternalTemplate(templateName);
String text;
try {
text = template.getText();
} catch (Exception e) {
throw new RuntimeException("Unable to load template for " +
FileTemplateManager.getInstance().internalTemplateToSubject(templateName), e);
}
final PsiFileFactory factory = PsiFileFactory.getInstance(directory.getProject());
final PsiFile file = factory.createFileFromText(fileName, WeexFileType.INSTANCE, text);
CodeStyleManager.getInstance(directory.getProject()).reformat(file);
return (PsiFile) directory.add(file);
}
示例8: getProjectTemplatePriority
import com.intellij.ide.fileTemplates.FileTemplateManager; //导入依赖的package包/类
private static FileTemplate getProjectTemplatePriority(String name, FileTemplateManager projectManager, FileTemplateManager defaultManager) {
FileTemplate result;
// Project
result = getProjectTemplateOnly(name, projectManager, defaultManager);
if (result != null) {
return result;
}
// Default
result = getDefaultTemplateOnly(name, projectManager, defaultManager);
if (result != null) {
return result;
}
return null;
}
示例9: getDefaultTemplatePriority
import com.intellij.ide.fileTemplates.FileTemplateManager; //导入依赖的package包/类
private static FileTemplate getDefaultTemplatePriority(String name, FileTemplateManager projectManager, FileTemplateManager defaultManager) {
FileTemplate result;
// Default
result = getDefaultTemplateOnly(name, projectManager, defaultManager);
if (result != null) {
return result;
}
// Project
result = getProjectTemplateOnly(name, projectManager, defaultManager);
if (result != null) {
return result;
}
return null;
}
示例10: applyFix
import com.intellij.ide.fileTemplates.FileTemplateManager; //导入依赖的package包/类
@Override
public void applyFix(@NotNull final Project project, @NotNull final ProblemDescriptor descriptor) {
final FileTemplateConfigurable configurable = new FileTemplateConfigurable(project);
ApplicationManager.getApplication().invokeLater(new Runnable() {
@Override
public void run() {
configurable.setTemplate(myTemplateToEdit, null);
boolean ok = ShowSettingsUtil.getInstance().editConfigurable(project, configurable);
if (ok) {
WriteCommandAction.runWriteCommandAction(project, new Runnable() {
@Override
public void run() {
FileTemplateManager.getInstance(project).saveAllTemplates();
myReplaceTemplateFix.applyFix(project, descriptor);
}
});
}
}
});
}
示例11: checkFileHeader
import com.intellij.ide.fileTemplates.FileTemplateManager; //导入依赖的package包/类
static ProblemDescriptor checkFileHeader(@NotNull PsiFile file, @NotNull InspectionManager manager, boolean onTheFly) {
TIntObjectHashMap<String> offsetToProperty = new TIntObjectHashMap<String>();
FileTemplate defaultTemplate = FileTemplateManager.getInstance(file.getProject()).getDefaultTemplate(FileTemplateManager.FILE_HEADER_TEMPLATE_NAME);
Pattern pattern = getTemplatePattern(defaultTemplate, file.getProject(), offsetToProperty);
Matcher matcher = pattern.matcher(file.getViewProvider().getContents());
if (!matcher.matches()) {
return null;
}
PsiComment element = PsiTreeUtil.findElementOfClassAtRange(file, matcher.start(1), matcher.end(1), PsiComment.class);
if (element == null) {
return null;
}
LocalQuickFix[] fixes = createQuickFix(matcher, offsetToProperty, file.getProject());
String description = InspectionsBundle.message("default.file.template.description");
return manager.createProblemDescriptor(element, description, onTheFly, fixes, ProblemHighlightType.GENERIC_ERROR_OR_WARNING);
}
示例12: createTestClassFromCodeTemplate
import com.intellij.ide.fileTemplates.FileTemplateManager; //导入依赖的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;
}
}
示例13: testRemoveTemplate
import com.intellij.ide.fileTemplates.FileTemplateManager; //导入依赖的package包/类
public void testRemoveTemplate() throws Exception {
FileTemplate[] before = myTemplateManager.getAllTemplates();
try {
FileTemplate template = myTemplateManager.getTemplate(TEST_TEMPLATE_TXT);
myTemplateManager.removeTemplate(template);
assertNull(myTemplateManager.getTemplate(TEST_TEMPLATE_TXT));
myTemplateManager.setCurrentScheme(myTemplateManager.getProjectScheme());
assertNull(myTemplateManager.getTemplate(TEST_TEMPLATE_TXT));
myTemplateManager.setCurrentScheme(FileTemplatesScheme.DEFAULT);
assertNull(myTemplateManager.getTemplate(TEST_TEMPLATE_TXT));
}
finally {
myTemplateManager.setTemplates(FileTemplateManager.DEFAULT_TEMPLATES_CATEGORY, Arrays.asList(before));
myTemplateManager.setCurrentScheme(myTemplateManager.getProjectScheme());
myTemplateManager.setTemplates(FileTemplateManager.DEFAULT_TEMPLATES_CATEGORY, Arrays.asList(before));
}
}
示例14: getFileText
import com.intellij.ide.fileTemplates.FileTemplateManager; //导入依赖的package包/类
@Override
protected String getFileText() {
if (!isDirectory) {
String templateName = myReference.getNewFileTemplateName();
if (templateName != null) {
Project project = myReference.getElement().getProject();
FileTemplateManager fileTemplateManager = FileTemplateManager.getInstance(project);
FileTemplate template = fileTemplateManager.getTemplate(templateName);
if (template == null) template = fileTemplateManager.findInternalTemplate(templateName);
if (template != null) {
try {
return template.getText(fileTemplateManager.getDefaultProperties());
} catch (IOException ex) {
throw new RuntimeException(ex);
}
}
}
}
return super.getFileText();
}
示例15: update
import com.intellij.ide.fileTemplates.FileTemplateManager; //导入依赖的package包/类
@Override
public void update(AnActionEvent e){
super.update(e);
Presentation presentation = e.getPresentation();
Project project = CommonDataKeys.PROJECT.getData(e.getDataContext());
if (project != null) {
FileTemplate[] allTemplates = FileTemplateManager.getInstance(project).getAllTemplates();
for (FileTemplate template : allTemplates) {
if (canCreateFromTemplate(e, template)) {
presentation.setEnabled(true);
return;
}
}
}
presentation.setEnabled(false);
}