Java Code Examples for com.intellij.openapi.fileTypes.LanguageFileType#getDefaultExtension()
The following examples show how to use
com.intellij.openapi.fileTypes.LanguageFileType#getDefaultExtension() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ScratchFileActions.java From consulo with Apache License 2.0 | 6 votes |
static PsiFile doCreateNewScratch(@Nonnull Project project, @Nonnull ScratchFileCreationHelper.Context context) { FeatureUsageTracker.getInstance().triggerFeatureUsed("scratch"); Language language = Objects.requireNonNull(context.language); if (context.fileExtension == null) { LanguageFileType fileType = language.getAssociatedFileType(); context.fileExtension = fileType == null ? "" : fileType.getDefaultExtension(); } ScratchFileCreationHelper.EXTENSION.forLanguage(language).beforeCreate(project, context); VirtualFile dir = context.ideView != null ? PsiUtilCore.getVirtualFile(ArrayUtil.getFirstElement(context.ideView.getDirectories())) : null; RootType rootType = dir == null ? null : ScratchFileService.findRootType(dir); String relativePath = rootType != ScratchRootType.getInstance() ? "" : FileUtil.getRelativePath(ScratchFileService.getInstance().getRootPath(rootType), dir.getPath(), '/'); String fileName = (StringUtil.isEmpty(relativePath) ? "" : relativePath + "/") + PathUtil.makeFileName(ObjectUtils.notNull(context.filePrefix, "scratch") + (context.fileCounter != null ? context.fileCounter.create() : ""), context.fileExtension); VirtualFile file = ScratchRootType.getInstance().createScratchFile(project, fileName, language, context.text, context.createOption); if (file == null) return null; PsiNavigationSupport.getInstance().createNavigatable(project, file, context.caretOffset).navigate(true); PsiFile psiFile = PsiManager.getInstance(project).findFile(file); if (context.ideView != null && psiFile != null) { context.ideView.selectElement(psiFile); } return psiFile; }
Example 2
Source File: Trees.java From antlr4-intellij-adaptor with BSD 2-Clause "Simplified" License | 5 votes |
public static PsiFile createFile(Project project, Language language, String text) { LanguageFileType ftype = language.getAssociatedFileType(); if ( ftype==null ) return null; String ext = ftype.getDefaultExtension(); String fileName = "___fubar___."+ext; // random name but must have correct extension PsiFileFactoryImpl factory = (PsiFileFactoryImpl)PsiFileFactory.getInstance(project); return factory.createFileFromText(fileName, language, text, false, false); }
Example 3
Source File: PsiParserFacadeImpl.java From consulo with Apache License 2.0 | 4 votes |
protected PsiFile createDummyFile(String text, final LanguageFileType fileType) { String ext = fileType.getDefaultExtension(); @NonNls String fileName = "_Dummy_." + ext; return PsiFileFactory.getInstance(myManager.getProject()).createFileFromText(fileType, fileName, text, 0, text.length()); }