@Override
  public void processVariants(@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) {
        if (element instanceof PsiField) {
          PsiClass parentClass = PsiTreeUtil.getParentOfType(PsiReferenceExpressionImpl.this, PsiClass.class);
          if (!PsiResolveHelper.getInstance(getProject())
            .isAccessible((PsiField)element, PsiReferenceExpressionImpl.this, parentClass)) {
            return true;
          }
        }
        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);
  }
@Override
  public void processVariants(@NotNull PsiScopeProcessor processor)