Search in sources :

Example 21 with RefElement

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

the class QuickFixAction method removeElements.

public static void removeElements(@NotNull RefEntity[] refElements, @NotNull Project project, @NotNull InspectionToolWrapper toolWrapper) {
    refreshViews(project, refElements, toolWrapper);
    final ArrayList<RefElement> deletedRefs = new ArrayList<>(1);
    for (RefEntity refElement : refElements) {
        if (!(refElement instanceof RefElement))
            continue;
        refElement.getRefManager().removeRefElement((RefElement) refElement, deletedRefs);
    }
}
Also used : RefElement(com.intellij.codeInspection.reference.RefElement) RefEntity(com.intellij.codeInspection.reference.RefEntity)

Example 22 with RefElement

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

the class QuickFixAction method refreshViews.

protected static void refreshViews(@NotNull Project project, @NotNull RefEntity[] refElements, @NotNull InspectionToolWrapper toolWrapper) {
    final Set<PsiElement> ignoredElements = new HashSet<>();
    for (RefEntity element : refElements) {
        final PsiElement psiElement = element instanceof RefElement ? ((RefElement) element).getElement() : null;
        if (psiElement != null && psiElement.isValid()) {
            ignoredElements.add(psiElement);
        }
    }
    refreshViews(project, ignoredElements, toolWrapper);
}
Also used : RefElement(com.intellij.codeInspection.reference.RefElement) RefEntity(com.intellij.codeInspection.reference.RefEntity) PsiElement(com.intellij.psi.PsiElement) THashSet(gnu.trove.THashSet)

Example 23 with RefElement

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

the class OfflineInspectionRVContentProvider method getFilteredContent.

@Nullable
@SuppressWarnings({ "UnusedAssignment" })
private Map<String, Set<OfflineProblemDescriptor>> getFilteredContent(@NotNull GlobalInspectionContextImpl context, @NotNull InspectionToolWrapper toolWrapper) {
    Map<String, Set<OfflineProblemDescriptor>> content = myContent.get(toolWrapper.getShortName());
    if (content == null)
        return null;
    if (context.getUIOptions().FILTER_RESOLVED_ITEMS) {
        final Map<String, Set<OfflineProblemDescriptor>> current = new HashMap<>(content);
        //GC it
        content = null;
        InspectionToolPresentation presentation = context.getPresentation(toolWrapper);
        for (RefEntity refEntity : presentation.getIgnoredRefElements()) {
            if (refEntity instanceof RefElement) {
                excludeProblem(refEntity.getExternalName(), current);
            }
        }
        return current;
    }
    return content;
}
Also used : RefElement(com.intellij.codeInspection.reference.RefElement) HashSet(com.intellij.util.containers.HashSet) THashMap(gnu.trove.THashMap) RefEntity(com.intellij.codeInspection.reference.RefEntity) Nullable(org.jetbrains.annotations.Nullable)

Example 24 with RefElement

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

the class EmptyDirectoryInspection method runInspection.

@Override
public void runInspection(@NotNull final AnalysisScope scope, @NotNull final InspectionManager manager, @NotNull final GlobalInspectionContext context, @NotNull final ProblemDescriptionsProcessor processor) {
    final Project project = context.getProject();
    final ProjectFileIndex index = ProjectRootManager.getInstance(project).getFileIndex();
    final SearchScope searchScope = scope.toSearchScope();
    if (!(searchScope instanceof GlobalSearchScope)) {
        return;
    }
    final GlobalSearchScope globalSearchScope = (GlobalSearchScope) searchScope;
    final PsiManager psiManager = PsiManager.getInstance(project);
    index.iterateContent(fileOrDir -> {
        if (!fileOrDir.isDirectory()) {
            return true;
        }
        if (!globalSearchScope.contains(fileOrDir)) {
            return true;
        }
        if (onlyReportDirectoriesUnderSourceRoots && !index.isInSourceContent(fileOrDir)) {
            return true;
        }
        final VirtualFile[] children = fileOrDir.getChildren();
        if (children.length != 0) {
            return true;
        }
        final PsiDirectory directory = ReadAction.compute(() -> psiManager.findDirectory(fileOrDir));
        final RefElement refDirectory = context.getRefManager().getReference(directory);
        if (refDirectory == null || context.shouldCheck(refDirectory, this)) {
            return true;
        }
        final String relativePath = getPathRelativeToModule(fileOrDir, project);
        if (relativePath == null) {
            return true;
        }
        processor.addProblemElement(refDirectory, manager.createProblemDescriptor(InspectionGadgetsBundle.message("empty.directories.problem.descriptor", relativePath), new EmptyPackageFix(fileOrDir.getUrl(), fileOrDir.getName())));
        return true;
    });
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) RefElement(com.intellij.codeInspection.reference.RefElement) Project(com.intellij.openapi.project.Project) ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) PsiDirectory(com.intellij.psi.PsiDirectory) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) SearchScope(com.intellij.psi.search.SearchScope) PsiManager(com.intellij.psi.PsiManager)

Example 25 with RefElement

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

the class InitializationDependencyUtils method tabulateInitializationDependencyClasses.

@SuppressWarnings({ "MethodWithMultipleLoops" })
static void tabulateInitializationDependencyClasses(RefElement element, Set<RefClass> dependencies) {
    final Collection<RefElement> references = element.getOutReferences();
    final RefJavaUtil refUtil = RefJavaUtil.getInstance();
    for (RefElement reference : references) {
        final RefClass refClass = refUtil.getTopLevelClass(reference);
        if (refClass != null) {
            dependencies.add(refClass);
        }
    }
    final List<RefEntity> children = element.getChildren();
    for (RefEntity child : children) {
        if (child instanceof RefElement) {
            tabulateInitializationDependencyClasses((RefElement) child, dependencies);
        }
    }
}
Also used : RefElement(com.intellij.codeInspection.reference.RefElement) RefClass(com.intellij.codeInspection.reference.RefClass) RefEntity(com.intellij.codeInspection.reference.RefEntity) RefJavaUtil(com.intellij.codeInspection.reference.RefJavaUtil)

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