SearchScope (@NotNull PsiMember member) { PsiFile file = member.getContainingFile(); PsiElement topElement = file == null ? member : file; Project project = topElement.getProject(); final GlobalSearchScope maximalUseScope = ResolveScopeManager.getInstance(project).getUseScope(topElement); if (isInServerPage(file)) return maximalUseScope; PsiClass aClass = member.getContainingClass(); if (aClass instanceof PsiAnonymousClass && !(aClass instanceof PsiEnumConstantInitializer && member instanceof PsiMethod && member.hasModifierProperty(PsiModifier.PUBLIC) && ((PsiMethod)member).findSuperMethods().length > 0)) { //member from anonymous class can be called from outside the class PsiElement scope = PsiUtil.isLanguageLevel8OrHigher(aClass) ? PsiTreeUtil.getTopmostParentOfType(aClass, PsiStatement.class) : PsiTreeUtil.getParentOfType(aClass, PsiMethodCallExpression.class); if (scope instanceof PsiDeclarationStatement) { PsiElement[] elements = ((PsiDeclarationStatement)scope).getDeclaredElements(); if (elements.length == 1 && elements[0] instanceof PsiLocalVariable && ((PsiLocalVariable)elements[0]).getTypeElement().isInferredType()) { // Inferred type: can be used in the surrounding code block as well scope = scope.getParent(); } } return new LocalSearchScope(scope != null ? scope : aClass); } if (aClass != null) { PsiElement parent = aClass.getParent(); while (parent instanceof PsiClass && !(parent instanceof PsiAnonymousClass)) { parent = parent.getParent(); } // members of local classes or of classes contained in anonymous or local classes have a small scope if (parent instanceof PsiAnonymousClass) return new LocalSearchScope(parent); if (parent instanceof PsiDeclarationStatement) return new LocalSearchScope(parent.getParent()); } PsiModifierList modifierList = (member instanceof PsiRecordComponent && aClass != null) ? aClass.getModifierList() : member.getModifierList(); int accessLevel = modifierList == null ? PsiUtil.ACCESS_LEVEL_PUBLIC : PsiUtil.getAccessLevel(modifierList); if (accessLevel == PsiUtil.ACCESS_LEVEL_PUBLIC || accessLevel == PsiUtil.ACCESS_LEVEL_PROTECTED) { SearchScope classScope = getClassUseScopeIfApplicable(member, aClass, accessLevel); return (classScope != null) ? classScope : maximalUseScope; } if (accessLevel == PsiUtil.ACCESS_LEVEL_PRIVATE) { PsiClass topClass = PsiUtil.getTopLevelClass(member); return topClass != null ? new LocalSearchScope(topClass) : file == null ? maximalUseScope : new LocalSearchScope(file); } if (file instanceof PsiJavaFile) { PsiPackage aPackage = JavaPsiFacade.getInstance(project).findPackage(((PsiJavaFile)file).getPackageName()); final SearchScope classScope = getClassUseScopeIfApplicable(member, aClass, accessLevel); if (classScope != null) return classScope; if (aPackage != null) { SearchScope scope = PackageScope.packageScope(aPackage, false); return scope.intersectWith(maximalUseScope); } } return maximalUseScope; }