isFileOfType(): add javadoc, run detectors when asked about PlainTextFileType (IDEA-CR-48346)

GitOrigin-RevId: a70ba89a9b352ca4e968259feb4e57872344286d
This commit is contained in:
Dmitry Jemerov
2019-06-14 14:19:56 +03:00
committed by intellij-monorepo-bot
parent 0dd72b8614
commit 43512b6420
2 changed files with 12 additions and 2 deletions
@@ -32,6 +32,13 @@ public abstract class FileTypeRegistry {
public abstract boolean isFileIgnored(@NotNull VirtualFile file);
/**
* Checks if the given file has the given file type. This is faster than getting the file type
* and comparing it, because for file types that are identified by virtual file, it will only
* check if the given file type matches, and will not run other detectors. However, this can
* lead to inconsistent results if two file types report the same file as matching (which should
* generally be avoided).
*/
public abstract boolean isFileOfType(@NotNull VirtualFile file, @NotNull FileType type);
@Nullable
@@ -996,9 +996,12 @@ public class FileTypeManagerImpl extends FileTypeManagerEx implements Persistent
@Override
public boolean isFileOfType(@NotNull VirtualFile file, @NotNull FileType type) {
if (type instanceof UnknownFileType) {
if (type.equals(PlainTextFileType.INSTANCE) || type.equals(UnknownFileType.INSTANCE)) {
// a file has unknown file type if none of file type detectors matched it
return file.getFileType() instanceof UnknownFileType;
// for plain text file type, we run file type detection based on content
//noinspection SSBasedInspection
return file.getFileType().equals(type);
}
if (file instanceof LightVirtualFile) {