Search in sources :

Example 1 with Native2AsciiCharset

use of com.intellij.lang.properties.charset.Native2AsciiCharset in project intellij-community by JetBrains.

the class LossyEncodingInspection method checkFile.

@Override
@Nullable
public ProblemDescriptor[] checkFile(@NotNull PsiFile file, @NotNull InspectionManager manager, boolean isOnTheFly) {
    if (InjectedLanguageManager.getInstance(file.getProject()).isInjectedFragment(file))
        return null;
    if (!file.isPhysical())
        return null;
    FileViewProvider viewProvider = file.getViewProvider();
    if (viewProvider.getBaseLanguage() != file.getLanguage())
        return null;
    VirtualFile virtualFile = file.getVirtualFile();
    if (virtualFile == null)
        return null;
    if (!virtualFile.isInLocalFileSystem())
        return null;
    CharSequence text = viewProvider.getContents();
    Charset charset = LoadTextUtil.extractCharsetFromFileContent(file.getProject(), virtualFile, text);
    // no sense in checking transparently decoded file: all characters there are already safely encoded
    if (charset instanceof Native2AsciiCharset)
        return null;
    List<ProblemDescriptor> descriptors = new SmartList<>();
    boolean ok = checkFileLoadedInWrongEncoding(file, manager, isOnTheFly, virtualFile, charset, descriptors);
    if (ok) {
        checkIfCharactersWillBeLostAfterSave(file, manager, isOnTheFly, text, charset, descriptors);
    }
    return descriptors.toArray(new ProblemDescriptor[descriptors.size()]);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileViewProvider(com.intellij.psi.FileViewProvider) Charset(java.nio.charset.Charset) Native2AsciiCharset(com.intellij.lang.properties.charset.Native2AsciiCharset) SmartList(com.intellij.util.SmartList) Native2AsciiCharset(com.intellij.lang.properties.charset.Native2AsciiCharset) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

Native2AsciiCharset (com.intellij.lang.properties.charset.Native2AsciiCharset)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 FileViewProvider (com.intellij.psi.FileViewProvider)1 SmartList (com.intellij.util.SmartList)1 Charset (java.nio.charset.Charset)1 Nullable (org.jetbrains.annotations.Nullable)1