Search in sources :

Example 16 with FileViewProvider

use of com.intellij.psi.FileViewProvider 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)

Example 17 with FileViewProvider

use of com.intellij.psi.FileViewProvider in project intellij-community by JetBrains.

the class GotoCustomRegionAction method getCustomFoldingDescriptors.

@NotNull
private static Collection<FoldingDescriptor> getCustomFoldingDescriptors(@NotNull Editor editor, @NotNull Project project) {
    Set<FoldingDescriptor> foldingDescriptors = new HashSet<>();
    final Document document = editor.getDocument();
    PsiDocumentManager documentManager = PsiDocumentManager.getInstance(project);
    PsiFile file = documentManager != null ? documentManager.getPsiFile(document) : null;
    if (file != null) {
        final FileViewProvider viewProvider = file.getViewProvider();
        for (final Language language : viewProvider.getLanguages()) {
            final PsiFile psi = viewProvider.getPsi(language);
            final FoldingBuilder foldingBuilder = LanguageFolding.INSTANCE.forLanguage(language);
            if (psi != null) {
                for (FoldingDescriptor descriptor : LanguageFolding.buildFoldingDescriptors(foldingBuilder, psi, document, false)) {
                    CustomFoldingBuilder customFoldingBuilder = getCustomFoldingBuilder(foldingBuilder, descriptor);
                    if (customFoldingBuilder != null) {
                        if (customFoldingBuilder.isCustomRegionStart(descriptor.getElement())) {
                            foldingDescriptors.add(descriptor);
                        }
                    }
                }
            }
        }
    }
    return foldingDescriptors;
}
Also used : FileViewProvider(com.intellij.psi.FileViewProvider) Language(com.intellij.lang.Language) PsiFile(com.intellij.psi.PsiFile) Document(com.intellij.openapi.editor.Document) HashSet(com.intellij.util.containers.HashSet) PsiDocumentManager(com.intellij.psi.PsiDocumentManager) NotNull(org.jetbrains.annotations.NotNull)

Example 18 with FileViewProvider

use of com.intellij.psi.FileViewProvider in project intellij-community by JetBrains.

the class TemplateLanguageErrorQuickFixProvider method registerErrorQuickFix.

@Override
public void registerErrorQuickFix(@NotNull final PsiErrorElement errorElement, @NotNull final HighlightInfo highlightInfo) {
    final PsiFile psiFile = errorElement.getContainingFile();
    final FileViewProvider provider = psiFile.getViewProvider();
    if (!(provider instanceof TemplateLanguageFileViewProvider))
        return;
    if (psiFile.getLanguage() != ((TemplateLanguageFileViewProvider) provider).getTemplateDataLanguage())
        return;
    QuickFixAction.registerQuickFixAction(highlightInfo, createChangeTemplateDataLanguageFix(errorElement));
}
Also used : FileViewProvider(com.intellij.psi.FileViewProvider) PsiFile(com.intellij.psi.PsiFile)

Example 19 with FileViewProvider

use of com.intellij.psi.FileViewProvider in project intellij-community by JetBrains.

the class InjectedPsiCachedValueProvider method compute.

@Override
public CachedValueProvider.Result<MultiHostRegistrarImpl> compute(PsiElement element) {
    PsiFile hostPsiFile = element.getContainingFile();
    if (hostPsiFile == null)
        return null;
    FileViewProvider viewProvider = hostPsiFile.getViewProvider();
    final DocumentEx hostDocument = (DocumentEx) viewProvider.getDocument();
    if (hostDocument == null)
        return null;
    PsiManager psiManager = viewProvider.getManager();
    final Project project = psiManager.getProject();
    InjectedLanguageManagerImpl injectedManager = InjectedLanguageManagerImpl.getInstanceImpl(project);
    final MultiHostRegistrarImpl result = doCompute(element, injectedManager, project, hostPsiFile);
    return CachedValueProvider.Result.create(result, PsiModificationTracker.MODIFICATION_COUNT, hostDocument);
}
Also used : DocumentEx(com.intellij.openapi.editor.ex.DocumentEx) Project(com.intellij.openapi.project.Project) FileViewProvider(com.intellij.psi.FileViewProvider) PsiManager(com.intellij.psi.PsiManager) PsiFile(com.intellij.psi.PsiFile)

Example 20 with FileViewProvider

use of com.intellij.psi.FileViewProvider in project intellij-community by JetBrains.

the class ExternalAnnotatorBatchInspection method checkFile.

/**
   * To be invoked during batch run
   */
@NotNull
default default ProblemDescriptor[] checkFile(@NotNull PsiFile file, @NotNull GlobalInspectionContext context, @NotNull InspectionManager manager) {
    final String shortName = getShortName();
    final FileViewProvider viewProvider = file.getViewProvider();
    final Set<Language> relevantLanguages = viewProvider.getLanguages();
    for (Language language : relevantLanguages) {
        PsiFile psiRoot = viewProvider.getPsi(language);
        final List<ExternalAnnotator> externalAnnotators = ExternalLanguageAnnotators.allForFile(language, psiRoot);
        for (ExternalAnnotator annotator : externalAnnotators) {
            if (shortName.equals(annotator.getPairedBatchInspectionShortName())) {
                return ExternalAnnotatorInspectionVisitor.checkFileWithExternalAnnotator(file, manager, false, annotator);
            }
        }
    }
    return ProblemDescriptor.EMPTY_ARRAY;
}
Also used : ExternalAnnotator(com.intellij.lang.annotation.ExternalAnnotator) FileViewProvider(com.intellij.psi.FileViewProvider) Language(com.intellij.lang.Language) PsiFile(com.intellij.psi.PsiFile) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

FileViewProvider (com.intellij.psi.FileViewProvider)41 PsiFile (com.intellij.psi.PsiFile)22 Language (com.intellij.lang.Language)21 PsiElement (com.intellij.psi.PsiElement)15 NotNull (org.jetbrains.annotations.NotNull)12 TextRange (com.intellij.openapi.util.TextRange)6 VirtualFile (com.intellij.openapi.vfs.VirtualFile)5 TemplateLanguageFileViewProvider (com.intellij.psi.templateLanguages.TemplateLanguageFileViewProvider)5 Project (com.intellij.openapi.project.Project)4 ASTNode (com.intellij.lang.ASTNode)3 Document (com.intellij.openapi.editor.Document)3 Pair (com.intellij.openapi.util.Pair)3 Nullable (org.jetbrains.annotations.Nullable)3 HighlightingLevelManager (com.intellij.codeInsight.daemon.impl.analysis.HighlightingLevelManager)2 FileASTNode (com.intellij.lang.FileASTNode)2 ExternalAnnotator (com.intellij.lang.annotation.ExternalAnnotator)2 XMLLanguage (com.intellij.lang.xml.XMLLanguage)2 FileType (com.intellij.openapi.fileTypes.FileType)2 SingleRootFileViewProvider (com.intellij.psi.SingleRootFileViewProvider)2 IStubFileElementType (com.intellij.psi.tree.IStubFileElementType)2