CompletionVariant[] (final PsiElement position, final PsiFile file) { final List<CompletionVariant> variants = new ArrayList<>(); PsiElement scope = position; if(scope == null){ scope = file; } while (scope != null) { boolean breakFlag = false; if (isScopeAcceptable(scope)){ for (final CompletionVariant variant : myCompletionVariants) { if (variant.isVariantApplicable(position, scope) && !variants.contains(variant)) { variants.add(variant); if (variant.isScopeFinal(scope)) { breakFlag = true; } } } } if(breakFlag) break; scope = scope.getContext(); if (scope instanceof PsiDirectory) break; } return variants.toArray(new CompletionVariant[0]); }