本文整理汇总了Java中com.intellij.ide.fileTemplates.FileTemplate类的典型用法代码示例。如果您正苦于以下问题:Java FileTemplate类的具体用法?Java FileTemplate怎么用?Java FileTemplate使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
FileTemplate类属于com.intellij.ide.fileTemplates包,在下文中一共展示了FileTemplate类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getAvailableTemplates
import com.intellij.ide.fileTemplates.FileTemplate; //导入依赖的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.FileTemplate; //导入依赖的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.FileTemplate; //导入依赖的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.FileTemplate; //导入依赖的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.FileTemplate; //导入依赖的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.FileTemplate; //导入依赖的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: buildDialog
import com.intellij.ide.fileTemplates.FileTemplate; //导入依赖的package包/类
@Override
protected void buildDialog(Project project, PsiDirectory directory, CreateFileFromTemplateDialog.Builder builder) {
builder
.setTitle(GroovyBundle.message("newclass.dlg.title"))
.addKind("Class", JetgroovyIcons.Groovy.Class, GroovyTemplates.GROOVY_CLASS)
.addKind("Interface", JetgroovyIcons.Groovy.Interface, GroovyTemplates.GROOVY_INTERFACE);
if (GroovyConfigUtils.getInstance().isVersionAtLeast(directory, GroovyConfigUtils.GROOVY2_3, true)) {
builder.addKind("Trait", JetgroovyIcons.Groovy.Trait, GroovyTemplates.GROOVY_TRAIT);
}
builder
.addKind("Enum", JetgroovyIcons.Groovy.Enum, GroovyTemplates.GROOVY_ENUM)
.addKind("Annotation", JetgroovyIcons.Groovy.AnnotationType, GroovyTemplates.GROOVY_ANNOTATION);
for (FileTemplate template : FileTemplateManager.getInstance(project).getAllTemplates()) {
FileType fileType = FileTypeManagerEx.getInstanceEx().getFileTypeByExtension(template.getExtension());
if (fileType.equals(GroovyFileType.GROOVY_FILE_TYPE) && JavaDirectoryService.getInstance().getPackage(directory) != null) {
builder.addKind(template.getName(), JetgroovyIcons.Groovy.Class, template.getName());
}
}
}
示例8: getDefaultTemplatePriority
import com.intellij.ide.fileTemplates.FileTemplate; //导入依赖的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;
}
示例9: getTreeCellRendererComponent
import com.intellij.ide.fileTemplates.FileTemplate; //导入依赖的package包/类
@Override
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) {
super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, false);
if (value instanceof FileTemplateNode) {
final FileTemplateNode node = (FileTemplateNode)value;
setText((String) node.getUserObject());
setIcon(node.getIcon());
setFont(getFont().deriveFont(AllFileTemplatesConfigurable.isInternalTemplate(node.getTemplateName(), getTitle()) ? Font.BOLD : Font.PLAIN));
final FileTemplate template = getTemplate(node);
if (template != null && !template.isDefault()) {
if (!sel) {
setForeground(MODIFIED_FOREGROUND);
}
}
}
return this;
}
示例10: createUsageUI
import com.intellij.ide.fileTemplates.FileTemplate; //导入依赖的package包/类
private void createUsageUI(JPanel container, Project project) {
if (getPackageTemplateWrapper().getMode() != PackageTemplateWrapper.ViewMode.USAGE) {
return;
}
FileTemplate fileTemplate = FileTemplateHelper.getTemplate(
getFile().getTemplateName(),
project,
getPackageTemplateWrapper().getPackageTemplate().getFileTemplateSource()
);
if (fileTemplate == null) {
return;
}
panelVariables = new CreateFromTemplatePanel(
AttributesHelper.getUnsetAttributes(fileTemplate, getPackageTemplateWrapper()),
false,
null
);
container.add(panelVariables.getComponent(), new CC().spanX().pad(0, UIHelper.PADDING, 0, 0).wrap());
}
示例11: genMethod
import com.intellij.ide.fileTemplates.FileTemplate; //导入依赖的package包/类
@Nullable
private static GrMethod genMethod(PsiClass aClass, FileTemplate template) {
Properties properties = FileTemplateManager.getInstance(aClass.getProject()).getDefaultProperties();
properties.setProperty(FileTemplate.ATTRIBUTE_RETURN_TYPE, "java.lang.Object");
properties.setProperty(FileTemplate.ATTRIBUTE_DEFAULT_RETURN_VALUE, "null");
properties.setProperty(FileTemplate.ATTRIBUTE_CALL_SUPER, "");
properties.setProperty(FileTemplate.ATTRIBUTE_CLASS_NAME, aClass.getQualifiedName());
properties.setProperty(FileTemplate.ATTRIBUTE_SIMPLE_CLASS_NAME, aClass.getName());
properties.setProperty(FileTemplate.ATTRIBUTE_METHOD_NAME, "methodMissing");
String bodyText;
try {
bodyText = StringUtil.replace(template.getText(properties), ";", "");
}
catch (IOException e) {
return null;
}
return GroovyPsiElementFactory.getInstance(aClass.getProject())
.createMethodFromText("def methodMissing(String name, def args) {\n" + bodyText + "\n}");
}
示例12: createFileFromTemplate
import com.intellij.ide.fileTemplates.FileTemplate; //导入依赖的package包/类
@Nullable
public static VirtualFile createFileFromTemplate(final String templateName, final VirtualFile parent, final String fileName) {
parent.refresh(false, false);
final FileTemplate template = FileTemplateManager.getDefaultInstance().getJ2eeTemplate(templateName);
try {
final String text = template.getText(FileTemplateManager.getDefaultInstance().getDefaultProperties());
VirtualFile file = parent.findChild(fileName);
if (file == null) {
file = parent.createChildData(AppEngineSupportProvider.class, fileName);
}
VfsUtil.saveText(file, text);
return file;
}
catch (IOException e) {
LOG.error(e);
return null;
}
}
示例13: createFileFromTemplate
import com.intellij.ide.fileTemplates.FileTemplate; //导入依赖的package包/类
@Override
protected PsiFile createFileFromTemplate(String s, FileTemplate template, PsiDirectory directory) {
if (directory.findSubdirectory(s) != null || directory.findFile(s) != null) {
/* toDo: Выдавать сообщение, что файл или директория с таким именем не существует */
return null;
}
PsiDirectory createdSect = createdSect = directory.createSubdirectory(s);
CustomFileTemplate createdFile = new CustomFileTemplate("someName", "php");
if (template.getName().equals("bxSimpleSection")) {
/* .section.php */
createdFile.setText(BxCore.loadTemplate("bxSimpleSectionConfig"));
super.createFileFromTemplate(".section", createdFile, createdSect);
/* index.php */
createdFile.setText(BxCore.loadTemplate("bxSimpleSectionIndex"));
return super.createFileFromTemplate("index", createdFile, createdSect);
}
return null;
}
示例14: checkFileHeader
import com.intellij.ide.fileTemplates.FileTemplate; //导入依赖的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);
}
示例15: createTestClassFromCodeTemplate
import com.intellij.ide.fileTemplates.FileTemplate; //导入依赖的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;
}
}