Search in sources :

Example 1 with InjectedFileViewProvider

use of com.intellij.psi.impl.source.tree.injected.InjectedFileViewProvider in project Perl5-IDEA by Camelcade.

the class PerlUseWarningsInspection method buildVisitor.

@NotNull
@Override
public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, boolean isOnTheFly) {
    return new PerlVisitor() {

        @Override
        public void visitFile(PsiFile file) {
            if (file.getViewProvider() instanceof InjectedFileViewProvider || !file.isWritable() || !file.isPhysical() || file.getVirtualFile() instanceof LightVirtualFile) {
                return;
            }
            FileType fileType = file.getFileType();
            if (!(fileType instanceof PerlFileType) || !((PerlFileType) fileType).checkWarningsPragma()) {
                return;
            }
            for (PerlUseStatement useStatement : PsiTreeUtil.findChildrenOfType(file, PerlUseStatement.class)) {
                if (useStatement.getPackageProcessor() instanceof PerlWarningsProvider) {
                    return;
                }
            }
            holder.registerProblem(file, PerlBundle.message("perl.inspection.use.warnings"), ProblemHighlightType.GENERIC_ERROR_OR_WARNING, new PerlUsePackageQuickFix("warnings FATAL => 'all'"), new PerlUsePackageQuickFix("warnings"));
        }
    };
}
Also used : InjectedFileViewProvider(com.intellij.psi.impl.source.tree.injected.InjectedFileViewProvider) PerlFileType(com.perl5.lang.perl.fileTypes.PerlFileType) PerlUsePackageQuickFix(com.perl5.lang.perl.idea.quickfixes.PerlUsePackageQuickFix) FileType(com.intellij.openapi.fileTypes.FileType) PerlFileType(com.perl5.lang.perl.fileTypes.PerlFileType) LightVirtualFile(com.intellij.testFramework.LightVirtualFile) PsiFile(com.intellij.psi.PsiFile) PerlVisitor(com.perl5.lang.perl.psi.PerlVisitor) PerlWarningsProvider(com.perl5.lang.perl.extensions.packageprocessor.PerlWarningsProvider) PerlUseStatement(com.perl5.lang.perl.psi.PerlUseStatement) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with InjectedFileViewProvider

use of com.intellij.psi.impl.source.tree.injected.InjectedFileViewProvider in project intellij-community by JetBrains.

the class LineMarkersPass method queryLineMarkersForInjected.

private static void queryLineMarkersForInjected(@NotNull PsiElement element, @NotNull final PsiFile containingFile, @NotNull Set<PsiFile> visitedInjectedFiles, @NotNull final PairConsumer<PsiElement, LineMarkerInfo> consumer) {
    if (containingFile.getViewProvider() instanceof InjectedFileViewProvider)
        return;
    final InjectedLanguageManager manager = InjectedLanguageManager.getInstance(containingFile.getProject());
    InjectedLanguageUtil.enumerate(element, containingFile, false, (injectedPsi, places) -> {
        // there may be several concatenated literals making the one injected file
        if (!visitedInjectedFiles.add(injectedPsi))
            return;
        final Project project = injectedPsi.getProject();
        Document document = PsiDocumentManager.getInstance(project).getCachedDocument(injectedPsi);
        if (!(document instanceof DocumentWindow))
            return;
        List<PsiElement> injElements = CollectHighlightsUtil.getElementsInRange(injectedPsi, 0, injectedPsi.getTextLength());
        final List<LineMarkerProvider> providers = getMarkerProviders(injectedPsi.getLanguage(), project);
        queryProviders(injElements, injectedPsi, providers, (injectedElement, injectedMarker) -> {
            GutterIconRenderer gutterRenderer = injectedMarker.createGutterRenderer();
            TextRange injectedRange = new TextRange(injectedMarker.startOffset, injectedMarker.endOffset);
            List<TextRange> editables = manager.intersectWithAllEditableFragments(injectedPsi, injectedRange);
            for (TextRange editable : editables) {
                TextRange hostRange = manager.injectedToHost(injectedPsi, editable);
                Icon icon = gutterRenderer == null ? null : gutterRenderer.getIcon();
                GutterIconNavigationHandler<PsiElement> navigationHandler = injectedMarker.getNavigationHandler();
                LineMarkerInfo<PsiElement> converted = new LineMarkerInfo<>(injectedElement, hostRange, icon, injectedMarker.updatePass, e -> injectedMarker.getLineMarkerTooltip(), navigationHandler, GutterIconRenderer.Alignment.RIGHT);
                consumer.consume(injectedElement, converted);
            }
        });
    });
}
Also used : TextRange(com.intellij.openapi.util.TextRange) Document(com.intellij.openapi.editor.Document) InjectedLanguageManager(com.intellij.lang.injection.InjectedLanguageManager) DocumentWindow(com.intellij.injected.editor.DocumentWindow) InjectedFileViewProvider(com.intellij.psi.impl.source.tree.injected.InjectedFileViewProvider) Project(com.intellij.openapi.project.Project) GutterIconRenderer(com.intellij.openapi.editor.markup.GutterIconRenderer) PsiElement(com.intellij.psi.PsiElement)

Example 3 with InjectedFileViewProvider

use of com.intellij.psi.impl.source.tree.injected.InjectedFileViewProvider in project Perl5-IDEA by Camelcade.

the class PerlUseStrictInspection method buildVisitor.

@NotNull
@Override
public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, boolean isOnTheFly) {
    return new PerlVisitor() {

        @Override
        public void visitFile(PsiFile file) {
            if (file.getViewProvider() instanceof InjectedFileViewProvider || !file.isWritable() || !file.isPhysical() || file.getVirtualFile() instanceof LightVirtualFile) {
                return;
            }
            FileType fileType = file.getFileType();
            if (!(fileType instanceof PerlFileType) || !((PerlFileType) fileType).checkStrictPragma()) {
                return;
            }
            for (PerlUseStatement useStatement : PsiTreeUtil.findChildrenOfType(file, PerlUseStatement.class)) {
                if (useStatement.getPackageProcessor() instanceof PerlStrictProvider) {
                    return;
                }
            }
            holder.registerProblem(file, PerlBundle.message("perl.inspection.use.strict"), ProblemHighlightType.GENERIC_ERROR_OR_WARNING, new PerlUsePackageQuickFix("strict"));
        }
    };
}
Also used : InjectedFileViewProvider(com.intellij.psi.impl.source.tree.injected.InjectedFileViewProvider) PerlFileType(com.perl5.lang.perl.fileTypes.PerlFileType) PerlStrictProvider(com.perl5.lang.perl.extensions.packageprocessor.PerlStrictProvider) PerlUsePackageQuickFix(com.perl5.lang.perl.idea.quickfixes.PerlUsePackageQuickFix) FileType(com.intellij.openapi.fileTypes.FileType) PerlFileType(com.perl5.lang.perl.fileTypes.PerlFileType) LightVirtualFile(com.intellij.testFramework.LightVirtualFile) PsiFile(com.intellij.psi.PsiFile) PerlVisitor(com.perl5.lang.perl.psi.PerlVisitor) PerlUseStatement(com.perl5.lang.perl.psi.PerlUseStatement) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

InjectedFileViewProvider (com.intellij.psi.impl.source.tree.injected.InjectedFileViewProvider)3 FileType (com.intellij.openapi.fileTypes.FileType)2 PsiFile (com.intellij.psi.PsiFile)2 LightVirtualFile (com.intellij.testFramework.LightVirtualFile)2 PerlFileType (com.perl5.lang.perl.fileTypes.PerlFileType)2 PerlUsePackageQuickFix (com.perl5.lang.perl.idea.quickfixes.PerlUsePackageQuickFix)2 PerlUseStatement (com.perl5.lang.perl.psi.PerlUseStatement)2 PerlVisitor (com.perl5.lang.perl.psi.PerlVisitor)2 NotNull (org.jetbrains.annotations.NotNull)2 DocumentWindow (com.intellij.injected.editor.DocumentWindow)1 InjectedLanguageManager (com.intellij.lang.injection.InjectedLanguageManager)1 Document (com.intellij.openapi.editor.Document)1 GutterIconRenderer (com.intellij.openapi.editor.markup.GutterIconRenderer)1 Project (com.intellij.openapi.project.Project)1 TextRange (com.intellij.openapi.util.TextRange)1 PsiElement (com.intellij.psi.PsiElement)1 PerlStrictProvider (com.perl5.lang.perl.extensions.packageprocessor.PerlStrictProvider)1 PerlWarningsProvider (com.perl5.lang.perl.extensions.packageprocessor.PerlWarningsProvider)1