Search in sources :

Example 6 with RefElement

use of com.intellij.codeInspection.reference.RefElement in project intellij-community by JetBrains.

the class InspectionTreeCellRenderer method getMainForegroundAttributes.

private static SimpleTextAttributes getMainForegroundAttributes(InspectionTreeNode node) {
    SimpleTextAttributes foreground = SimpleTextAttributes.REGULAR_ATTRIBUTES;
    if (node instanceof RefElementNode) {
        RefEntity refElement = ((RefElementNode) node).getElement();
        if (refElement instanceof RefElement) {
            refElement = ((RefElement) refElement).getContainingEntry();
            if (((RefElement) refElement).isEntry() && ((RefElement) refElement).isPermanentEntry()) {
                foreground = new SimpleTextAttributes(SimpleTextAttributes.STYLE_PLAIN, JBColor.blue);
            }
        }
    }
    final FileStatus nodeStatus = node.getNodeStatus();
    if (nodeStatus != FileStatus.NOT_CHANGED) {
        foreground = new SimpleTextAttributes(foreground.getBgColor(), nodeStatus.getColor(), foreground.getWaveColor(), foreground.getStyle());
    }
    return foreground;
}
Also used : RefElement(com.intellij.codeInspection.reference.RefElement) FileStatus(com.intellij.openapi.vcs.FileStatus) RefEntity(com.intellij.codeInspection.reference.RefEntity) SimpleTextAttributes(com.intellij.ui.SimpleTextAttributes)

Example 7 with RefElement

use of com.intellij.codeInspection.reference.RefElement in project intellij-community by JetBrains.

the class LocalDescriptorsUtil method addProblemDescriptors.

static void addProblemDescriptors(@NotNull List<ProblemDescriptor> descriptors, boolean filterSuppressed, @NotNull GlobalInspectionContext context, @Nullable LocalInspectionTool tool, @NotNull TripleFunction<LocalInspectionTool, PsiElement, GlobalInspectionContext, RefElement> getProblemElementFunction, @NotNull InspectionToolPresentation dpi) {
    if (descriptors.isEmpty())
        return;
    Map<RefElement, List<ProblemDescriptor>> problems = new HashMap<>();
    final RefManagerImpl refManager = (RefManagerImpl) context.getRefManager();
    for (ProblemDescriptor descriptor : descriptors) {
        final PsiElement element = descriptor.getPsiElement();
        if (element == null)
            continue;
        if (filterSuppressed) {
            String alternativeId;
            String id;
            if (refManager.isDeclarationsFound() && (context.isSuppressed(element, id = tool.getID()) || (alternativeId = tool.getAlternativeID()) != null && !alternativeId.equals(id) && context.isSuppressed(element, alternativeId))) {
                continue;
            }
            if (SuppressionUtil.inspectionResultSuppressed(element, tool))
                continue;
        }
        RefElement refElement = getProblemElementFunction.fun(tool, element, context);
        List<ProblemDescriptor> elementProblems = problems.get(refElement);
        if (elementProblems == null) {
            elementProblems = new ArrayList<>();
            problems.put(refElement, elementProblems);
        }
        elementProblems.add(descriptor);
    }
    for (Map.Entry<RefElement, List<ProblemDescriptor>> entry : problems.entrySet()) {
        final List<ProblemDescriptor> problemDescriptors = entry.getValue();
        RefElement refElement = entry.getKey();
        CommonProblemDescriptor[] descriptions = problemDescriptors.toArray(new CommonProblemDescriptor[problemDescriptors.size()]);
        dpi.addProblemElement(refElement, filterSuppressed, descriptions);
    }
}
Also used : HashMap(java.util.HashMap) RefManagerImpl(com.intellij.codeInspection.reference.RefManagerImpl) RefElement(com.intellij.codeInspection.reference.RefElement) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) PsiElement(com.intellij.psi.PsiElement)

Example 8 with RefElement

use of com.intellij.codeInspection.reference.RefElement in project intellij-community by JetBrains.

the class QuickFixAction method getReadOnlyFiles.

private static Set<VirtualFile> getReadOnlyFiles(@NotNull RefEntity[] refElements) {
    Set<VirtualFile> readOnlyFiles = new THashSet<>();
    for (RefEntity refElement : refElements) {
        PsiElement psiElement = refElement instanceof RefElement ? ((RefElement) refElement).getElement() : null;
        if (psiElement == null || psiElement.getContainingFile() == null)
            continue;
        readOnlyFiles.add(psiElement.getContainingFile().getVirtualFile());
    }
    return readOnlyFiles;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) RefElement(com.intellij.codeInspection.reference.RefElement) RefEntity(com.intellij.codeInspection.reference.RefEntity) THashSet(gnu.trove.THashSet) PsiElement(com.intellij.psi.PsiElement)

Example 9 with RefElement

use of com.intellij.codeInspection.reference.RefElement in project intellij-community by JetBrains.

the class InspectionEngine method runInspectionOnFile.

@NotNull
public static List<ProblemDescriptor> runInspectionOnFile(@NotNull final PsiFile file, @NotNull InspectionToolWrapper toolWrapper, @NotNull final GlobalInspectionContext inspectionContext) {
    final InspectionManager inspectionManager = InspectionManager.getInstance(file.getProject());
    toolWrapper.initialize(inspectionContext);
    RefManagerImpl refManager = (RefManagerImpl) inspectionContext.getRefManager();
    refManager.inspectionReadActionStarted();
    try {
        if (toolWrapper instanceof LocalInspectionToolWrapper) {
            return inspect(Collections.singletonList((LocalInspectionToolWrapper) toolWrapper), file, inspectionManager, new EmptyProgressIndicator());
        }
        if (toolWrapper instanceof GlobalInspectionToolWrapper) {
            final GlobalInspectionTool globalTool = ((GlobalInspectionToolWrapper) toolWrapper).getTool();
            final List<ProblemDescriptor> descriptors = new ArrayList<>();
            if (globalTool instanceof GlobalSimpleInspectionTool) {
                GlobalSimpleInspectionTool simpleTool = (GlobalSimpleInspectionTool) globalTool;
                ProblemsHolder problemsHolder = new ProblemsHolder(inspectionManager, file, false);
                ProblemDescriptionsProcessor collectProcessor = new ProblemDescriptionsProcessor() {

                    @Nullable
                    @Override
                    public CommonProblemDescriptor[] getDescriptions(@NotNull RefEntity refEntity) {
                        return descriptors.toArray(new CommonProblemDescriptor[descriptors.size()]);
                    }

                    @Override
                    public void ignoreElement(@NotNull RefEntity refEntity) {
                        throw new RuntimeException();
                    }

                    @Override
                    public void addProblemElement(@Nullable RefEntity refEntity, @NotNull CommonProblemDescriptor... commonProblemDescriptors) {
                        if (!(refEntity instanceof RefElement))
                            return;
                        PsiElement element = ((RefElement) refEntity).getElement();
                        convertToProblemDescriptors(element, commonProblemDescriptors, descriptors);
                    }

                    @Override
                    public RefEntity getElement(@NotNull CommonProblemDescriptor descriptor) {
                        throw new RuntimeException();
                    }
                };
                simpleTool.checkFile(file, inspectionManager, problemsHolder, inspectionContext, collectProcessor);
                return descriptors;
            }
            RefElement fileRef = refManager.getReference(file);
            final AnalysisScope scope = new AnalysisScope(file);
            assert fileRef != null;
            fileRef.accept(new RefVisitor() {

                @Override
                public void visitElement(@NotNull RefEntity elem) {
                    CommonProblemDescriptor[] elemDescriptors = globalTool.checkElement(elem, scope, inspectionManager, inspectionContext);
                    if (elemDescriptors != null) {
                        convertToProblemDescriptors(file, elemDescriptors, descriptors);
                    }
                    for (RefEntity child : elem.getChildren()) {
                        child.accept(this);
                    }
                }
            });
            return descriptors;
        }
    } finally {
        refManager.inspectionReadActionFinished();
        toolWrapper.cleanup(file.getProject());
        inspectionContext.cleanup();
    }
    return Collections.emptyList();
}
Also used : GlobalInspectionToolWrapper(com.intellij.codeInspection.ex.GlobalInspectionToolWrapper) EmptyProgressIndicator(com.intellij.openapi.progress.EmptyProgressIndicator) RefManagerImpl(com.intellij.codeInspection.reference.RefManagerImpl) NotNull(org.jetbrains.annotations.NotNull) RefElement(com.intellij.codeInspection.reference.RefElement) AnalysisScope(com.intellij.analysis.AnalysisScope) RefVisitor(com.intellij.codeInspection.reference.RefVisitor) RefEntity(com.intellij.codeInspection.reference.RefEntity) LocalInspectionToolWrapper(com.intellij.codeInspection.ex.LocalInspectionToolWrapper) Nullable(org.jetbrains.annotations.Nullable) NotNull(org.jetbrains.annotations.NotNull)

Example 10 with RefElement

use of com.intellij.codeInspection.reference.RefElement in project intellij-community by JetBrains.

the class GlobalInspectionContextUtil method retrieveRefElement.

public static RefElement retrieveRefElement(@NotNull PsiElement element, @NotNull GlobalInspectionContext globalContext) {
    PsiFile elementFile = element.getContainingFile();
    RefElement refElement = globalContext.getRefManager().getReference(elementFile);
    if (refElement == null) {
        PsiElement context = InjectedLanguageManager.getInstance(elementFile.getProject()).getInjectionHost(elementFile);
        if (context != null)
            refElement = globalContext.getRefManager().getReference(context.getContainingFile());
    }
    return refElement;
}
Also used : RefElement(com.intellij.codeInspection.reference.RefElement) PsiFile(com.intellij.psi.PsiFile) PsiElement(com.intellij.psi.PsiElement)

Aggregations

RefElement (com.intellij.codeInspection.reference.RefElement)25 RefEntity (com.intellij.codeInspection.reference.RefEntity)16 PsiElement (com.intellij.psi.PsiElement)11 NotNull (org.jetbrains.annotations.NotNull)7 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 Nullable (org.jetbrains.annotations.Nullable)4 EntryPoint (com.intellij.codeInspection.reference.EntryPoint)3 PsiFile (com.intellij.psi.PsiFile)3 Element (org.jdom.Element)3 UnusedDeclarationInspectionBase (com.intellij.codeInspection.deadCode.UnusedDeclarationInspectionBase)2 GlobalInspectionToolWrapper (com.intellij.codeInspection.ex.GlobalInspectionToolWrapper)2 LocalInspectionToolWrapper (com.intellij.codeInspection.ex.LocalInspectionToolWrapper)2 RefClass (com.intellij.codeInspection.reference.RefClass)2 RefJavaUtil (com.intellij.codeInspection.reference.RefJavaUtil)2 RefManagerImpl (com.intellij.codeInspection.reference.RefManagerImpl)2 Project (com.intellij.openapi.project.Project)2 Navigatable (com.intellij.pom.Navigatable)2 SearchScope (com.intellij.psi.search.SearchScope)2 HashSet (com.intellij.util.containers.HashSet)2 THashSet (gnu.trove.THashSet)2