private static void addElement(@NotNull PsiElement o, @NotNull ResolveState state, boolean forTypes, boolean vendoringEnabled, @NotNull Set<String> processedNames, @NotNull CompletionResultSet set) { LookupElement lookup = createLookupElement(o, state, forTypes, vendoringEnabled); if (lookup != null) { String lookupString = lookup.getLookupString(); if (!processedNames.contains(lookupString)) { set.addElement(lookup); processedNames.add(lookupString); } } }
@Override public void renderElement(@NotNull LookupElement element, @NotNull LookupElementPresentation p) { PsiElement o = element.getPsiElement(); if (!(o instanceof GoNamedElement)) return; GoNamedElement v = (GoNamedElement)o; GoType type = typesDisabled ? null : v.getGoType(null); String text = GoPsiImplUtil.getText(type); Icon icon = v instanceof GoVarDefinition ? GoIcons.VARIABLE : v instanceof GoParamDefinition ? GoIcons.PARAMETER : v instanceof GoFieldDefinition ? GoIcons.FIELD : v instanceof GoReceiver ? GoIcons.RECEIVER : v instanceof GoConstDefinition ? GoIcons.CONSTANT : v instanceof GoAnonymousFieldDefinition ? GoIcons.FIELD : null; p.setIcon(icon); p.setTailText(calcTailTextForFields(v), true); p.setTypeText(text); p.setTypeGrayed(true); p.setItemText(element.getLookupString()); } };
public void testIssue457EqualName() { String name = "foo"; LookupElement lookupElement = lookupElement(name); LookupElementPresentation lookupElementPresentation = new LookupElementPresentation(); lookupElement.renderElement(lookupElementPresentation); assertEquals(name, lookupElementPresentation.getItemText()); }
/** * @see EventDispatcherSubscriberUtil#getEventNameLookupElements */ public void testGetEventNameLookupElementsForEventAnnotations() { Collection<LookupElement> eventNameLookupElements = EventDispatcherSubscriberUtil.getEventNameLookupElements(getProject()); ContainerUtil.find(eventNameLookupElements, lookupElement -> lookupElement.getLookupString().equals("bar.pre_bar") ); ContainerUtil.find(eventNameLookupElements, lookupElement -> lookupElement.getLookupString().equals("bar.post_bar") ); ContainerUtil.find(eventNameLookupElements, lookupElement -> { if(!"bar.post_bar".equals(lookupElement.getLookupString())) { return false; } LookupElementPresentation lookupElementPresentation = new LookupElementPresentation(); lookupElement.renderElement(lookupElementPresentation); return "My\\MyFooEvent".equals(lookupElementPresentation.getTypeText()); }); }
@Override public void handleInsert(@NotNull InsertionContext context, @NotNull LookupElement item) { PsiElement element = item.getPsiElement(); if (element instanceof GoNamedElement) { if (myClass != null && myDelegate != null && myClass.isInstance(element)) { myDelegate.handleInsert(context, item); } autoImport(context, (GoNamedElement)element); } }
StringBuilder sb = new StringBuilder(); LookupElementPresentation presentation = new LookupElementPresentation(); lookupElement.renderElement(presentation); .append(StringUtil.join(lookupElement.getAllLookupStrings(), ", ")) .append("; Text: ") .append(presentation.getItemText())
private void renderObject(@NotNull LookupElement lookupElement) { Logger logger = Logger.getInstance(CallDefinitionClause.class); Object object = lookupElement.getObject(); String userMessage = "CallDefinitionClause render called on LookupElement with null getPsiElement\n" + "## name\n" +
@Override public boolean isValid() { return lookupElement.isValid(); }
public void assertCompletionLookupTailEquals(LanguageFileType languageFileType, String configureByText, String lookupString, String tailText) { myFixture.configureByText(languageFileType, configureByText); myFixture.completeBasic(); for (LookupElement lookupElement : myFixture.getLookupElements()) { if(!lookupElement.getLookupString().equals(lookupString)) { continue; } LookupElementPresentation presentation = new LookupElementPresentation(); lookupElement.renderElement(presentation); if(presentation.getTailText() == null) { fail(String.format("failed to check '%s'", lookupString)); } if(!presentation.getTailText().equals(tailText)) { fail(String.format("failed that on '%s' '%s' is equal '%s'", lookupString, tailText, presentation.getTailText())); } return; } fail(String.format("failed to check '%s' because it's unknown", lookupString)); }
@Override public void handleInsert(InsertionContext context, @NotNull LookupElement item) { PsiElement e = item.getPsiElement(); if (e instanceof GoSignatureOwner) { doInsert(context, item, ((GoSignatureOwner)e).getSignature()); } else if (e instanceof GoNamedElement) { GoType type = ((GoNamedElement)e).getGoType(null); if (type instanceof GoFunctionType) { doInsert(context, item, ((GoFunctionType)type).getSignature()); } } }
public void handleInsert(@NotNull InsertionContext context, @NotNull LookupElement lookupElement) { Object object = lookupElement.getObject(); if (!(object instanceof PhpClass)) { return; } StringBuilder textToInsertBuilder = new StringBuilder(); PhpClass aClass = (PhpClass)object; String fqn = aClass.getNamespaceName(); if(fqn.startsWith("\\")) { fqn = fqn.substring(1); } textToInsertBuilder.append(fqn); context.getDocument().insertString(context.getStartOffset(), textToInsertBuilder); }
@Override public void addElement(final LookupElement element) { if (!element.isValid()) { System.out.println("Invalid lookup element: " + element); return; } CompletionResult matched = CompletionResult.wrap(element, getPrefixMatcher(), mySorter); if (matched != null) { passResult(matched); } }
@Nullable @Override public Result calculateResult(ExpressionContext context) { LookupElement firstElement = ArrayUtil.getFirstElement(calculateLookupItems(context)); return new TextResult(firstElement != null ? firstElement.getLookupString() : ""); }
public LookupElementPresentation getCompletionLookupElement(LanguageFileType languageFileType, String configureByText, String lookupString) { myFixture.configureByText(languageFileType, configureByText); myFixture.completeBasic(); for (LookupElement lookupElement : myFixture.getLookupElements()) { if(!lookupElement.getLookupString().equals(lookupString)) { continue; } LookupElementPresentation presentation = new LookupElementPresentation(); lookupElement.renderElement(presentation); return presentation; } fail(String.format("failed to to find lookup element '%s'", lookupString)); return null; }
@Override public void renderElement(@NotNull LookupElement element, @NotNull LookupElementPresentation p) { PsiElement o = element.getPsiElement(); if (!(o instanceof GoNamedSignatureOwner)) return; GoNamedSignatureOwner f = (GoNamedSignatureOwner)o; Icon icon = f instanceof GoMethodDeclaration || f instanceof GoMethodSpec ? GoIcons.METHOD : GoIcons.FUNCTION; String typeText = ""; GoSignature signature = f.getSignature(); String paramText = ""; if (signature != null) { GoResult result = signature.getResult(); paramText = signature.getParameters().getText(); if (result != null) typeText = result.getText(); } p.setIcon(icon); p.setTypeText(typeText); p.setTypeGrayed(true); p.setTailText(calcTailText(f), true); p.setItemText(element.getLookupString() + paramText); } };
@Override public void renderElement(LookupElement element, LookupElementPresentation presentation) { presentation.setItemText(name); presentation.setItemTextBold(true); PsiElement psiElement = element.getPsiElement(); if (psiElement == null) { renderObject(element); } else { renderPsiElement(psiElement, presentation); } }
public void testIssue457LongerNameIssue503() { String name = "fooo"; LookupElement lookupElement = lookupElement(name); LookupElementPresentation lookupElementPresentation = new LookupElementPresentation(); lookupElement.renderElement(lookupElementPresentation); assertEquals(name, lookupElementPresentation.getItemText()); }
public void handleInsert(@NotNull InsertionContext context, @NotNull LookupElement lookupElement) { if(lookupElement.getObject() instanceof AnnotationValue) { String addText = "=\"\""; if(((AnnotationValue) lookupElement.getObject()).getType() == AnnotationValue.Type.Array) { addText = "={}"; } PhpInsertHandlerUtil.insertStringAtCaret(context.getEditor(), addText); } else { PhpInsertHandlerUtil.insertStringAtCaret(context.getEditor(), "=\"\""); } context.getEditor().getCaretModel().moveCaretRelatively(-1, 0, false, false, true); }
protected void selectLookupItem(@NotNull String selectItem) { LookupElement[] lookupElements = myFixture.getLookupElements(); assertNotNull("Lookup is empty", lookupElements); LookupElement toSelect = null; for (LookupElement lookupElement : lookupElements) { if (selectItem.equals(lookupElement.getLookupString())) { toSelect = lookupElement; break; } } assertNotNull(selectItem + " not found in lookup", toSelect); myFixture.getLookup().setCurrentItem(toSelect); myFixture.type(Lookup.NORMAL_SELECT_CHAR); }
public void assertCompletionLookupTailEquals(LanguageFileType languageFileType, String configureByText, String lookupString, String tailText) { myFixture.configureByText(languageFileType, configureByText); myFixture.completeBasic(); for (LookupElement lookupElement : myFixture.getLookupElements()) { if(!lookupElement.getLookupString().equals(lookupString)) { continue; } LookupElementPresentation presentation = new LookupElementPresentation(); lookupElement.renderElement(presentation); if(presentation.getTailText() == null) { fail(String.format("failed to check '%s'", lookupString)); } if(!presentation.getTailText().equals(tailText)) { fail(String.format("failed that on '%s' '%s' is equal '%s'", lookupString, tailText, presentation.getTailText())); } return; } fail(String.format("failed to check '%s' because it's unknown", lookupString)); }