本文整理汇总了Java中com.intellij.ide.fileTemplates.FileTemplateManager.getInstance方法的典型用法代码示例。如果您正苦于以下问题:Java FileTemplateManager.getInstance方法的具体用法?Java FileTemplateManager.getInstance怎么用?Java FileTemplateManager.getInstance使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.intellij.ide.fileTemplates.FileTemplateManager
的用法示例。
在下文中一共展示了FileTemplateManager.getInstance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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();
}
示例2: createInitPy
import com.intellij.ide.fileTemplates.FileTemplateManager; //导入方法依赖的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);
}
}
示例3: getAllFileTemplatesVariables
import com.intellij.ide.fileTemplates.FileTemplateManager; //导入方法依赖的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;
}
示例4: getFileText
import com.intellij.ide.fileTemplates.FileTemplateManager; //导入方法依赖的package包/类
@Override
protected String getFileText() {
if (!isDirectory && myNewFileTemplateName != null) {
Project project = getStartElement().getProject();
FileTemplateManager fileTemplateManager = FileTemplateManager.getInstance(project);
FileTemplate template = findTemplate(fileTemplateManager);
if (template != null) {
try {
return template.getText(fileTemplateManager.getDefaultProperties());
} catch (IOException ex) {
throw new RuntimeException(ex);
}
}
}
return super.getFileText();
}
示例5: getText
import com.intellij.ide.fileTemplates.FileTemplateManager; //导入方法依赖的package包/类
private static String getText(final String templateName, @Nullable Project project) throws IOException {
final FileTemplateManager templateManager = project == null ? FileTemplateManager.getDefaultInstance() : FileTemplateManager.getInstance(project);
final FileTemplate template = templateManager.getJ2eeTemplate(templateName);
if (template == null) {
return "";
}
return template.getText(templateManager.getDefaultProperties());
}
示例6: testSurviveOnProjectReopen
import com.intellij.ide.fileTemplates.FileTemplateManager; //导入方法依赖的package包/类
public void testSurviveOnProjectReopen() throws Exception {
File foo = PlatformTestCase.createTempDir("foo");
Project reloaded = null;
final Project project = ProjectManager.getInstance().createProject("foo", foo.getPath());;
try {
assertNotNull(project);
FileTemplateManager manager = FileTemplateManager.getInstance(project);
manager.setCurrentScheme(manager.getProjectScheme());
FileTemplate template = manager.getTemplate(TEST_TEMPLATE_TXT);
assertEquals(HI_THERE, template.getText());
String newText = "good bye";
template.setText(newText);
assertEquals(newText, manager.getTemplate(TEST_TEMPLATE_TXT).getText());
PlatformTestUtil.saveProject(project);
closeProject(project);
reloaded = ProjectManager.getInstance().loadAndOpenProject(foo.getPath());
assertNotNull(reloaded);
manager = FileTemplateManager.getInstance(reloaded);
assertEquals(manager.getProjectScheme(), manager.getCurrentScheme());
//manager.setCurrentScheme(FileTemplatesScheme.DEFAULT);
//manager.setCurrentScheme(manager.getProjectScheme()); // enforce reloading
assertEquals(newText, manager.getTemplate(TEST_TEMPLATE_TXT).getText());
}
finally {
closeProject(project);
closeProject(reloaded);
}
}
示例7: actionPerformed
import com.intellij.ide.fileTemplates.FileTemplateManager; //导入方法依赖的package包/类
@Override
public void actionPerformed(AnActionEvent e){
Project project = assertNotNull(e.getData(CommonDataKeys.PROJECT));
String fileText = assertNotNull(e.getData(PlatformDataKeys.FILE_TEXT));
VirtualFile file = assertNotNull(e.getData(CommonDataKeys.VIRTUAL_FILE));
String extension = assertNotNull(file.getExtension());
String nameWithoutExtension = file.getNameWithoutExtension();
PsiFile psiFile = e.getData(CommonDataKeys.PSI_FILE);
for(SaveFileAsTemplateHandler handler: Extensions.getExtensions(SaveFileAsTemplateHandler.EP_NAME)) {
String textFromHandler = handler.getTemplateText(psiFile, fileText, nameWithoutExtension);
if (textFromHandler != null) {
fileText = textFromHandler;
break;
}
}
FileTemplateManager templateManager = FileTemplateManager.getInstance(project);
FileTemplate[] templates = templateManager.getAllTemplates();
FileTemplate template = FileTemplateUtil.createTemplate(nameWithoutExtension, extension, fileText, templates);
FileTemplateConfigurable configurable = new FileTemplateConfigurable(project);
configurable.setProportion(0.6f);
configurable.setTemplate(template, FileTemplateManagerImpl.getInstanceImpl(project).getDefaultTemplateDescription());
SaveFileAsTemplateDialog dialog = new SaveFileAsTemplateDialog(project, configurable);
if (dialog.showAndGet()) {
templateManager.setTemplates(FileTemplateManager.DEFAULT_TEMPLATES_CATEGORY, Arrays.asList(ArrayUtil.append(templates, template)));
}
}
示例8: getOrCreateFile
import com.intellij.ide.fileTemplates.FileTemplateManager; //导入方法依赖的package包/类
@NotNull
public static PyFile getOrCreateFile(String path, Project project) {
final VirtualFile vfile = LocalFileSystem.getInstance().findFileByIoFile(new File(path));
final PsiFile psi;
if (vfile == null) {
final File file = new File(path);
try {
final VirtualFile baseDir = project.getBaseDir();
final FileTemplateManager fileTemplateManager = FileTemplateManager.getInstance(project);
final FileTemplate template = fileTemplateManager.getInternalTemplate("Python Script");
final Properties properties = fileTemplateManager.getDefaultProperties();
properties.setProperty("NAME", FileUtil.getNameWithoutExtension(file.getName()));
final String content = (template != null) ? template.getText(properties) : null;
psi = PyExtractSuperclassHelper.placeFile(project,
StringUtil.notNullize(
file.getParent(),
baseDir != null ? baseDir
.getPath() : "."
),
file.getName(),
content
);
}
catch (IOException e) {
throw new IncorrectOperationException(String.format("Cannot create file '%s'", path));
}
}
else {
psi = PsiManager.getInstance(project).findFile(vfile);
}
if (!(psi instanceof PyFile)) {
throw new IncorrectOperationException(PyBundle.message(
"refactoring.move.module.members.error.cannot.place.elements.into.nonpython.file"));
}
return (PyFile)psi;
}
示例9: testTemplateAttributesExpansionInCreatedDestinationModule
import com.intellij.ide.fileTemplates.FileTemplateManager; //导入方法依赖的package包/类
public void testTemplateAttributesExpansionInCreatedDestinationModule() {
final FileTemplateManager instance = FileTemplateManager.getInstance(myFixture.getProject());
final FileTemplate template = instance.getInternalTemplate("Python Script");
assertNotNull(template);
final String oldTemplateContent = template.getText();
try {
template.setText("NAME = '${NAME}'");
doMoveSymbolTest("C", "b.py");
}
finally {
template.setText(oldTemplateContent);
}
}
示例10: runOrApplyFileTemplate
import com.intellij.ide.fileTemplates.FileTemplateManager; //导入方法依赖的package包/类
private static void runOrApplyFileTemplate(Project project,
VirtualFile file,
String templateName,
Properties properties) throws IOException {
FileTemplateManager manager = FileTemplateManager.getInstance();
FileTemplate fileTemplate = manager.getJ2eeTemplate(templateName);
Properties allProperties = manager.getDefaultProperties(project);
allProperties.putAll(properties);
String text = fileTemplate.getText(allProperties);
Pattern pattern = Pattern.compile("\\$\\{(.*)\\}");
Matcher matcher = pattern.matcher(text);
StringBuffer builder = new StringBuffer();
while (matcher.find()) {
matcher.appendReplacement(builder, "\\$" + matcher.group(1).toUpperCase() + "\\$");
}
matcher.appendTail(builder);
text = builder.toString();
TemplateImpl template = (TemplateImpl) TemplateManager.getInstance(project).createTemplate("", "", text);
for (int i = 0; i < template.getSegmentsCount(); i++) {
if (i == template.getEndSegmentNumber()) continue;
String name = template.getSegmentName(i);
String value = "\"" + properties.getProperty(name, "") + "\"";
template.addVariable(name, value, value, true);
}
VfsUtil.saveText(file, template.getTemplateText());
PsiFile psiFile = PsiManager.getInstance(project).findFile(file);
if (psiFile != null) {
new ReformatCodeProcessor(project, psiFile, null, false).run();
}
}
示例11: getText
import com.intellij.ide.fileTemplates.FileTemplateManager; //导入方法依赖的package包/类
@NotNull
public static String getText(@NotNull final Project project,
@NotNull final String template,
@NotNull final Properties properties) throws IOException {
final FileTemplateManager templateManager = FileTemplateManager.getInstance(project);
final Properties defaultProperties = templateManager.getDefaultProperties();
for(final Map.Entry<Object, Object> entry : defaultProperties.entrySet()) {
if(!properties.containsKey(entry.getKey())) {
properties.put(entry.getKey(), entry.getValue());
}
}
return templateManager.getInternalTemplate(template).getText(properties);
}
示例12: getTemplates
import com.intellij.ide.fileTemplates.FileTemplateManager; //导入方法依赖的package包/类
/**
* Return map of extensions and their preferred template.
* This map is obtained from taking all internal templates and overriding them with existing custom templates.
*/
private static Map<String, FileTemplate> getTemplates(Project project){
final Map<String, FileTemplate> result = new HashMap<String, FileTemplate>();
FileTemplateManager manager = FileTemplateManager.getInstance(project);
addTemplates(result,manager.getInternalTemplates());
addTemplates(result,manager.getAllTemplates());
return result;
}
示例13: getText
import com.intellij.ide.fileTemplates.FileTemplateManager; //导入方法依赖的package包/类
private static String getText(final String templateName) throws IOException {
final FileTemplateManager templateManager = FileTemplateManager.getInstance();
final FileTemplate template = templateManager.getJ2eeTemplate(templateName);
if (template == null) {
return "";
}
return template.getText(templateManager.getDefaultProperties());
}
示例14: setupRootModel
import com.intellij.ide.fileTemplates.FileTemplateManager; //导入方法依赖的package包/类
@Override
public void setupRootModel(ModifiableRootModel model) throws ConfigurationException {
String contentPath = getContentEntryPath();
if (StringUtil.isEmpty(contentPath)) {
return;
}
File contentRootDir = new File(contentPath);
FileUtilRt.createDirectory(contentRootDir);
LocalFileSystem fileSystem = LocalFileSystem.getInstance();
VirtualFile vContentRootDir = fileSystem.refreshAndFindFileByIoFile(contentRootDir);
if (vContentRootDir == null) {
return;
}
model.addContentEntry(vContentRootDir);
VirtualFile configFile = getExternalProjectConfigFile(vContentRootDir);
final String templateConfigName = getTemplateConfigName(myExternalProjectSettings);
if (configFile != null && templateConfigName != null) {
FileTemplateManager manager = FileTemplateManager.getInstance(model.getProject());
FileTemplate template = manager.getInternalTemplate(templateConfigName);
try {
VfsUtil.saveText(configFile, template.getText());
}
catch (IOException e) {
LOG.warn(String.format("Unexpected exception on applying template %s config", myExternalSystemId.getReadableName()), e);
throw new ConfigurationException(
e.getMessage(),
String.format("Can't apply %s template config text", myExternalSystemId.getReadableName())
);
}
}
AbstractExternalSystemSettings settings = ExternalSystemApiUtil.getSettings(model.getProject(), myExternalSystemId);
//noinspection unchecked
myExternalProjectSettings.setExternalProjectPath(getContentEntryPath());
settings.linkProject(myExternalProjectSettings);
}
示例15: openFile
import com.intellij.ide.fileTemplates.FileTemplateManager; //导入方法依赖的package包/类
@Override
protected void openFile(@Nonnull Project project, PsiDirectory directory, PsiFile newFile, String text) {
super.openFile(project, directory, newFile, text);
if (!isDirectory && myNewFileTemplateName != null) {
FileTemplateManager fileTemplateManager = FileTemplateManager.getInstance(project);
FileTemplate template = findTemplate(fileTemplateManager);
if (template != null && template.isLiveTemplateEnabled()) {
CreateFromTemplateActionBase.startLiveTemplate(newFile);
}
}
}