private void assertCompletionContains( String completionText, PsiElement context, String[] expectedItems, String[] disallowedItems) { SmaliCodeFragmentFactory codeFragmentFactory = new SmaliCodeFragmentFactory(); JavaCodeFragment fragment = codeFragmentFactory.createCodeFragment( new TextWithImportsImpl(CodeFragmentKind.EXPRESSION, completionText), context, getProject()); Editor editor = createEditor(fragment.getVirtualFile()); editor.getCaretModel().moveToOffset(completionText.length()); new CodeCompletionHandlerBase(CompletionType.BASIC).invokeCompletion(getProject(), editor); List<LookupElement> elements = LookupManager.getInstance(getProject()).getActiveLookup().getItems(); HashSet expectedSet = Sets.newHashSet(expectedItems); HashSet disallowedSet = Sets.newHashSet(disallowedItems); for (LookupElement element : elements) { expectedSet.remove(element.toString()); Assert.assertFalse(disallowedSet.contains(element.toString())); } Assert.assertTrue(expectedSet.size() == 0); }
@NotNull @Override public String toString() { return maybeAddParentheses(myQualifier.toString()) + "." + getDelegate(); }