boolean (@NotNull PsiScopeProcessor processor, @NotNull ResolveState state, PsiElement lastParent, @NotNull PsiElement place) { GlobalSearchScope scope = place.getResolveScope(); processor.handleEvent(PsiScopeProcessor.Event.SET_DECLARATION_HOLDER, this); ElementClassHint classHint = processor.getHint(ElementClassHint.KEY); final Condition<String> nameCondition = processor.getHint(JavaCompletionHints.NAME_FILTER); NameHint providedNameHint = processor.getHint(NameHint.KEY); final String providedName = providedNameHint == null ? null : providedNameHint.getName(state); if (classHint == null || classHint.shouldProcess(ElementClassHint.DeclarationKind.CLASS)) { if (providedName != null) { PsiClass[] classes = findClassByShortName(providedName, scope); if (classes.length == 0 && PsiUtil.isInsideJavadocComment(place)) { //extend scope for javadoc references when no classes are found in the resolve scope: //always replacing the scope works bad for the case when multiple classes with the same FQName exist, //because the index returns them in unpredictable order, //so class not accessible from `place` may be used instead of another accessible class classes = findClassByShortName(providedName, allScope()); } if (!processClasses(processor, state, classes, Conditions.alwaysTrue())) return false; } else { PsiClass[] classes = getClasses(scope); if (classes.length == 0 && PsiUtil.isInsideJavadocComment(place)) { classes = getClasses(allScope()); } if (!processClasses(processor, state, classes, nameCondition != null ? nameCondition : Conditions.alwaysTrue())) return false; } } if (classHint == null || classHint.shouldProcess(ElementClassHint.DeclarationKind.PACKAGE)) { if (providedName != null) { PsiPackage aPackage = findSubPackageByName(providedName); if (aPackage != null) { if (!processor.execute(aPackage, state)) return false; } } else { PsiPackage[] packs = getSubPackages(scope); for (PsiPackage pack : packs) { final String packageName = pack.getName(); if (packageName == null) continue; if (!PsiNameHelper.getInstance(getProject()).isIdentifier(packageName, PsiUtil.getLanguageLevel(this))) { continue; } if (!processor.execute(pack, state)) { return false; } } } } return true; }