void (@NotNull PsiScopeProcessor processor) { DelegatingScopeProcessor filterProcessor = new DelegatingScopeProcessor(processor) { private PsiElement myResolveContext; private final Set<String> myVarNames = new HashSet<>(); @Override public boolean execute(@NotNull PsiElement element, @NotNull ResolveState state) { return !shouldProcess(element) || super.execute(element, state); } private boolean shouldProcess(@NotNull PsiElement element) { if (element instanceof PsiVariable) return ensureNonShadowedVariable((PsiVariable)element); if (element instanceof PsiClass) return !seemsScrambled((PsiClass)element); if (element instanceof PsiPackage) return isQualified(); if (element instanceof PsiMethod) return shouldProcessMethod((PsiMethod)element); return false; } private boolean ensureNonShadowedVariable(@NotNull PsiVariable element) { boolean added = myVarNames.add(element.getName()); return !PsiUtil.isJvmLocalVariable(element) || added; } private boolean shouldProcessMethod(@NotNull PsiMethod method) { PsiReferenceExpressionImpl ref = PsiReferenceExpressionImpl.this; return !method.isConstructor() && hasValidQualifier(method, ref, myResolveContext); } @Override public void handleEvent(@NotNull Event event, Object associated) { if (event == JavaScopeProcessorEvent.SET_CURRENT_FILE_CONTEXT) { myResolveContext = (PsiElement)associated; } super.handleEvent(event, associated); } }; PsiScopesUtil.resolveAndWalk(filterProcessor, this, null, true); }