use of com.intellij.openapi.fileTypes.LanguageFileType in project intellij-community by JetBrains.
the class ScratchFileActions method doCreateNewScratch.
static void doCreateNewScratch(@NotNull Project project, boolean buffer, @NotNull Language language, @NotNull String text) {
FeatureUsageTracker.getInstance().triggerFeatureUsed("scratch");
LanguageFileType fileType = language.getAssociatedFileType();
String ext = buffer || fileType == null ? "" : fileType.getDefaultExtension();
String fileName = buffer ? "buffer" + nextBufferIndex() : "scratch";
ScratchFileService.Option option = buffer ? ScratchFileService.Option.create_if_missing : ScratchFileService.Option.create_new_always;
VirtualFile f = ScratchRootType.getInstance().createScratchFile(project, PathUtil.makeFileName(fileName, ext), language, text, option);
if (f != null) {
FileEditorManager.getInstance(project).openFile(f, true);
}
}
use of com.intellij.openapi.fileTypes.LanguageFileType in project intellij-community by JetBrains.
the class TypedHandler method getFileType.
private static FileType getFileType(@NotNull PsiFile file, @NotNull Editor editor) {
FileType fileType = file.getFileType();
Language language = PsiUtilBase.getLanguageInEditor(editor, file.getProject());
if (language != null && language != PlainTextLanguage.INSTANCE) {
LanguageFileType associatedFileType = language.getAssociatedFileType();
if (associatedFileType != null)
fileType = associatedFileType;
}
return fileType;
}
use of com.intellij.openapi.fileTypes.LanguageFileType in project intellij-community by JetBrains.
the class PlatformIdTableBuilding method getTodoIndexer.
@Nullable
public static DataIndexer<TodoIndexEntry, Integer, FileContent> getTodoIndexer(FileType fileType, final VirtualFile virtualFile) {
final DataIndexer<TodoIndexEntry, Integer, FileContent> extIndexer;
if (fileType instanceof SubstitutedFileType && !((SubstitutedFileType) fileType).isSameFileType()) {
SubstitutedFileType sft = (SubstitutedFileType) fileType;
extIndexer = new CompositeTodoIndexer(getTodoIndexer(sft.getOriginalFileType(), virtualFile), getTodoIndexer(sft.getFileType(), virtualFile));
} else {
extIndexer = TodoIndexers.INSTANCE.forFileType(fileType);
}
if (extIndexer != null) {
return extIndexer;
}
if (fileType instanceof LanguageFileType) {
final Language lang = ((LanguageFileType) fileType).getLanguage();
final ParserDefinition parserDef = LanguageParserDefinitions.INSTANCE.forLanguage(lang);
final TokenSet commentTokens = parserDef != null ? parserDef.getCommentTokens() : null;
if (commentTokens != null) {
return new TokenSetTodoIndexer(commentTokens, virtualFile);
}
}
if (fileType instanceof CustomSyntaxTableFileType) {
return new TokenSetTodoIndexer(ABSTRACT_FILE_COMMENT_TOKENS, virtualFile);
}
return null;
}
use of com.intellij.openapi.fileTypes.LanguageFileType in project intellij-community by JetBrains.
the class LanguageUtil method isFileLanguage.
public static boolean isFileLanguage(@NotNull Language language) {
if (language instanceof DependentLanguage || language instanceof InjectableLanguage)
return false;
if (LanguageParserDefinitions.INSTANCE.forLanguage(language) == null)
return false;
LanguageFileType type = language.getAssociatedFileType();
if (type == null || StringUtil.isEmpty(type.getDefaultExtension()))
return false;
String name = language.getDisplayName();
if (StringUtil.isEmpty(name) || name.startsWith("<") || name.startsWith("["))
return false;
return StringUtil.isNotEmpty(type.getDefaultExtension());
}
use of com.intellij.openapi.fileTypes.LanguageFileType in project intellij-community by JetBrains.
the class LangDiffIgnoredRangeProvider method getLanguage.
@Nullable
private static Language getLanguage(@NotNull Project project, @NotNull DiffContent content) {
Language language = content.getUserData(DiffUserDataKeys.LANGUAGE);
if (language != null)
return language;
FileType type = content.getContentType();
if (type instanceof LanguageFileType)
language = ((LanguageFileType) type).getLanguage();
if (language != null && content instanceof DocumentContent) {
VirtualFile highlightFile = ((DocumentContent) content).getHighlightFile();
if (highlightFile != null)
language = LanguageSubstitutors.INSTANCE.substituteLanguage(language, highlightFile, project);
}
return language;
}
Aggregations