Search in sources :

Example 1 with HighlightVisitorImpl

use of com.intellij.codeInsight.daemon.impl.analysis.HighlightVisitorImpl in project intellij-community by JetBrains.

the class HighlightVisitorInternalInspection method buildVisitor.

@NotNull
@Override
public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, boolean isOnTheFly) {
    final PsiFile file = holder.getFile();
    if (InjectedLanguageManager.getInstance(file.getProject()).isInjectedFragment(file)) {
        return PsiElementVisitor.EMPTY_VISITOR;
    }
    final VirtualFile virtualFile = PsiUtilCore.getVirtualFile(file);
    if (virtualFile == null || virtualFile.getFileType() != StdFileTypes.JAVA || CompilerConfiguration.getInstance(holder.getProject()).isExcludedFromCompilation(virtualFile)) {
        return PsiElementVisitor.EMPTY_VISITOR;
    }
    return new HighlightVisitorImpl(JavaPsiFacade.getInstance(holder.getProject()).getResolveHelper()) {

        {
            prepareToRunAsInspection(new HighlightInfoHolder(file) {

                @Override
                public boolean add(@Nullable HighlightInfo info) {
                    if (super.add(info)) {
                        if (info != null && info.getSeverity() == HighlightSeverity.ERROR) {
                            final int startOffset = info.getStartOffset();
                            final PsiElement element = file.findElementAt(startOffset);
                            if (element != null) {
                                holder.registerProblem(element, info.getDescription());
                            }
                        }
                        return true;
                    }
                    return false;
                }

                @Override
                public boolean hasErrorResults() {
                    //accept multiple errors per file
                    return false;
                }
            });
        }
    };
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) HighlightVisitorImpl(com.intellij.codeInsight.daemon.impl.analysis.HighlightVisitorImpl) HighlightInfoHolder(com.intellij.codeInsight.daemon.impl.analysis.HighlightInfoHolder) HighlightInfo(com.intellij.codeInsight.daemon.impl.HighlightInfo) PsiFile(com.intellij.psi.PsiFile) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

HighlightInfo (com.intellij.codeInsight.daemon.impl.HighlightInfo)1 HighlightInfoHolder (com.intellij.codeInsight.daemon.impl.analysis.HighlightInfoHolder)1 HighlightVisitorImpl (com.intellij.codeInsight.daemon.impl.analysis.HighlightVisitorImpl)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 PsiElement (com.intellij.psi.PsiElement)1 PsiFile (com.intellij.psi.PsiFile)1 NotNull (org.jetbrains.annotations.NotNull)1