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()]);
}
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;
}
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));
}
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);
}
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;
}
Aggregations