PsiNamedElement (@Nullable PsiElement element, @NotNull LocalInspectionTool tool, @NotNull GlobalInspectionContext context) { if (element == null) return null; PsiNamedElement containerFromTool = tool.getProblemElement(element); if (containerFromTool != null && !(containerFromTool instanceof PsiFile)) { return containerFromTool; } PsiNamedElement container = context.getRefManager().getContainerElement(element); return container != null ? container : containerFromTool; }