com.intellij.codeInsight.lookup.LookupElementPresentation Java Examples
The following examples show how to use
com.intellij.codeInsight.lookup.LookupElementPresentation.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LiveTemplateLookupElement.java From consulo with Apache License 2.0 | 6 votes |
@Override public void renderElement(LookupElementPresentation presentation) { super.renderElement(presentation); char shortcut = getTemplateShortcut(); presentation.setItemText(getItemText()); if (sudden) { presentation.setItemTextBold(true); if (!presentation.isReal() || !((RealLookupElementPresentation)presentation).isLookupSelectionTouched()) { if (shortcut == TemplateSettings.DEFAULT_CHAR) { shortcut = TemplateSettings.getInstance().getDefaultShortcutChar(); } presentation.setTypeText(" [" + KeyEvent.getKeyText(shortcut) + "] "); } if (StringUtil.isNotEmpty(myDescription)) { presentation.setTailText(" (" + myDescription + ")", true); } } else { presentation.setTypeText(myDescription); } }
Example #2
Source File: EventDispatcherSubscriberUtilTest.java From idea-php-symfony2-plugin with MIT License | 6 votes |
/** * @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()); }); }
Example #3
Source File: JsonParseUtil.java From idea-php-toolbox with MIT License | 6 votes |
public static void decorateLookupElement(@NotNull LookupElementPresentation lookupElement, @NotNull JsonRawLookupElement jsonLookup) { if(jsonLookup.getTailText() != null) { lookupElement.setTailText(jsonLookup.getTailText(), true); } if(jsonLookup.getTypeText() != null) { lookupElement.setTypeText(jsonLookup.getTypeText()); lookupElement.setTypeGrayed(true); } String iconString = jsonLookup.getIcon(); if(iconString != null) { Icon icon = getLookupIconOnString(iconString); if(icon != null) { lookupElement.setIcon(icon); } } }
Example #4
Source File: DrupalLightCodeInsightFixtureTestCase.java From idea-php-drupal-symfony2-bridge with MIT License | 6 votes |
public void assertCompletionLookupContainsPresentableItem(LanguageFileType languageFileType, String configureByText, LookupElementPresentationAssert.Assert presentationAssert) { myFixture.configureByText(languageFileType, configureByText); myFixture.completeBasic(); LookupElement[] lookupElements = myFixture.getLookupElements(); if(lookupElements == null) { fail("failed to find lookup presentable on empty collection"); } for (LookupElement lookupElement : lookupElements) { LookupElementPresentation presentation = new LookupElementPresentation(); lookupElement.renderElement(presentation); if(presentationAssert.match(presentation)) { return; } } fail("failed to find lookup presentable"); }
Example #5
Source File: JsonParseUtil.java From idea-php-toolbox with MIT License | 6 votes |
public static void decorateLookupElement(@NotNull LookupElementPresentation lookupElement, @NotNull JsonRawLookupElement jsonLookup) { if(jsonLookup.getTailText() != null) { lookupElement.setTailText(jsonLookup.getTailText(), true); } if(jsonLookup.getTypeText() != null) { lookupElement.setTypeText(jsonLookup.getTypeText()); lookupElement.setTypeGrayed(true); } String iconString = jsonLookup.getIcon(); if(iconString != null) { Icon icon = getLookupIconOnString(iconString); if(icon != null) { lookupElement.setIcon(icon); } } }
Example #6
Source File: SymfonyLightCodeInsightFixtureTestCase.java From idea-php-symfony2-plugin with MIT License | 6 votes |
public void assertCompletionLookupContainsPresentableItem(LanguageFileType languageFileType, String configureByText, LookupElementPresentationAssert.Assert presentationAssert) { myFixture.configureByText(languageFileType, configureByText); myFixture.completeBasic(); LookupElement[] lookupElements = myFixture.getLookupElements(); if(lookupElements == null) { fail("failed to find lookup presentable on empty collection"); } for (LookupElement lookupElement : lookupElements) { LookupElementPresentation presentation = new LookupElementPresentation(); lookupElement.renderElement(presentation); if(presentationAssert.match(presentation)) { return; } } fail("failed to find lookup presentable"); }
Example #7
Source File: DoctrineEntityLookupElement.java From idea-php-symfony2-plugin with MIT License | 6 votes |
public void renderElement(LookupElementPresentation presentation) { if(this.useClassNameAsLookupString) { presentation.setItemText(className.getPresentableFQN()); presentation.setTypeText(getLookupString()); } else { presentation.setItemText(getLookupString()); presentation.setTypeText(className.getPresentableFQN()); } presentation.setTypeGrayed(true); if(isWeak) { // @TODO: remove weak presentation.setIcon(getWeakIcon()); } else { presentation.setIcon(getIcon()); } }
Example #8
Source File: LookupCellRenderer.java From consulo with Apache License 2.0 | 6 votes |
@Nullable Font getFontAbleToDisplay(LookupElementPresentation p) { String sampleString = p.getItemText() + p.getTailText() + p.getTypeText(); // assume a single font can display all lookup item chars Set<Font> fonts = ContainerUtil.newHashSet(); FontPreferences fontPreferences = myLookup.getFontPreferences(); for (int i = 0; i < sampleString.length(); i++) { fonts.add(ComplementaryFontsRegistry.getFontAbleToDisplay(sampleString.charAt(i), Font.PLAIN, fontPreferences, null).getFont()); } eachFont: for (Font font : fonts) { if (font.equals(myNormalFont)) continue; for (int i = 0; i < sampleString.length(); i++) { if (!font.canDisplay(sampleString.charAt(i))) { continue eachFont; } } return font; } return null; }
Example #9
Source File: FormClassConstantsLookupElement.java From idea-php-symfony2-plugin with MIT License | 6 votes |
@Override public void renderElement(LookupElementPresentation presentation) { // provides parent and string alias name List<String> tailsText = new ArrayList<>(); String getName = PhpElementsUtil.getMethodReturnAsString(phpClass, "getName"); if(getName != null) { tailsText.add(getName); } // @TODO: getParent should String getParent = PhpElementsUtil.getMethodReturnAsString(phpClass, "getParent"); if(getParent != null && !getParent.equals("form")) { tailsText.add(getParent); } if(tailsText.size() > 0) { presentation.setTailText("(" + StringUtils.join(tailsText, ",") + ")", true); } presentation.setIcon(Symfony2Icons.FORM_TYPE); super.renderElement(presentation); }
Example #10
Source File: RouteLookupElement.java From idea-php-symfony2-plugin with MIT License | 6 votes |
/** * "(GET|POST, var1, var2)" */ private void formatTail(@NotNull LookupElementPresentation presentation) { List<String> tails = new ArrayList<>(); Collection<String> methods = route.getMethods(); if(methods.size() > 0) { tails.add(StringUtils.join(ContainerUtil.map(methods, String::toUpperCase), "|")); } Set<String> variables = this.route.getVariables(); if(variables.size() > 0) { tails.addAll(variables); } if(tails.size() > 0) { presentation.setTailText("(" + StringUtils.join(tails, ", ") + ")", true); } }
Example #11
Source File: ShopwareLightCodeInsightFixtureTestCase.java From idea-php-shopware-plugin with MIT License | 6 votes |
public void assertCompletionLookupContainsPresentableItem(LanguageFileType languageFileType, String configureByText, LookupElementPresentationAssert.Assert presentationAssert) { myFixture.configureByText(languageFileType, configureByText); myFixture.completeBasic(); LookupElement[] lookupElements = myFixture.getLookupElements(); if(lookupElements == null) { fail("failed to find lookup presentable on empty collection"); } for (LookupElement lookupElement : lookupElements) { LookupElementPresentation presentation = new LookupElementPresentation(); lookupElement.renderElement(presentation); if(presentationAssert.match(presentation)) { return; } } fail("failed to find lookup presentable"); }
Example #12
Source File: AnnotationLightCodeInsightFixtureTestCase.java From idea-php-annotation-plugin with MIT License | 6 votes |
protected void assertCompletionContainsDeprecationPresentation(LanguageFileType languageFileType, String configureByText, String lookupString, boolean deprecated) { myFixture.configureByText(languageFileType, configureByText); myFixture.completeBasic(); final LookupElement[] lookupElements = myFixture.completeBasic(); for (LookupElement lookupElement : lookupElements) { final String myLookupString = lookupElement.getLookupString(); if (myLookupString.equals(lookupString)) { LookupElementPresentation presentation = new LookupElementPresentation(); lookupElement.renderElement(presentation); assertEquals(deprecated, presentation.isStrikeout()); return; } } fail("Unable to assert element presentation"); }
Example #13
Source File: ParameterLookupElement.java From idea-php-symfony2-plugin with MIT License | 6 votes |
public void renderElement(LookupElementPresentation presentation) { presentation.setItemText(containerParameter.getName()); String value = containerParameter.getValue(); if(value != null && StringUtils.isNotBlank(value)) { presentation.setTypeText(value); } presentation.setTypeGrayed(true); presentation.setIcon(Symfony2Icons.PARAMETER); if(this.containerParameter.isWeak()) { presentation.setIcon(Symfony2Icons.PARAMETER_OPACITY); } }
Example #14
Source File: LookupPreview.java From consulo with Apache License 2.0 | 6 votes |
private String getSuffixText(@Nullable LookupElement item) { if (item != null) { String itemText = StringUtil.notNullize(LookupElementPresentation.renderElement(item).getItemText()); String prefix = myLookup.itemPattern(item); if (prefix.isEmpty()) { return itemText; } FList<TextRange> fragments = LookupCellRenderer.getMatchingFragments(prefix, itemText); if (fragments != null && !fragments.isEmpty()) { List<TextRange> list = ContainerUtil.newArrayList(fragments); return itemText.substring(list.get(list.size() - 1).getEndOffset(), itemText.length()); } } return ""; }
Example #15
Source File: HaxeLookupElement.java From intellij-haxe with Apache License 2.0 | 5 votes |
@Override public void renderElement(LookupElementPresentation presentation) { final ItemPresentation myComponentNamePresentation = myComponentName.getPresentation(); if (myComponentNamePresentation == null) { presentation.setItemText(getLookupString()); return; } String presentableText = myComponentNamePresentation.getPresentableText(); // Check for members: methods and fields HaxeBaseMemberModel model = HaxeBaseMemberModel.fromPsi(myComponentName); if (model != null) { // TODO: Specialization support required presentableText = model.getPresentableText(context); // Check deprecated modifiers if (model instanceof HaxeMemberModel && ((HaxeMemberModel)model).getModifiers().hasModifier(HaxePsiModifier.DEPRECATED)) { presentation.setStrikeout(true); } // Check for non-inherited members to highlight them as intellij-java does // @TODO: Self members should be displayed first! if (leftReference != null) { if (model.getDeclaringClass().getPsi() == leftReference.getHaxeClass()) { presentation.setItemTextBold(true); } } } presentation.setItemText(presentableText); presentation.setIcon(myComponentNamePresentation.getIcon(true)); final String pkg = myComponentNamePresentation.getLocationString(); if (StringUtil.isNotEmpty(pkg)) { presentation.setTailText(" " + pkg, true); } }
Example #16
Source File: JsonProviderTest.java From idea-php-toolbox with MIT License | 5 votes |
public void testClassProvider() { assertCompletionContains(PhpFileType.INSTANCE, "<?php date('<caret>')", "foo", "bar"); LookupElementPresentation elementFoo = getCompletionLookupElement(PhpFileType.INSTANCE, "<?php date('fo<caret>o')", "foo"); assertNotNull(elementFoo.getIcon()); assertEquals("Day of month (01..31)", elementFoo.getTypeText()); LookupElementPresentation elementBar = getCompletionLookupElement(PhpFileType.INSTANCE, "<?php date('ba<caret>r')", "bar"); assertNotNull(elementBar.getIcon()); assertEquals("(TypeText)", elementBar.getTypeText()); }
Example #17
Source File: ArrayReturnSourceContributorTest.java From idea-php-toolbox with MIT License | 5 votes |
/** * @see ArrayReturnSourceContributor */ public void testArrayStringReturn() { assertCompletionContains(PhpFileType.INSTANCE, "<?php date_2('<caret>')", "foo_array", "foo_array_1"); assertNavigationMatch(PhpFileType.INSTANCE, "<?php date_2('foo_array_1<caret>')", PlatformPatterns.psiElement(Method.class)); assertCompletionLookupTailEquals(PhpFileType.INSTANCE, "<?php date_2('<caret>')", "foo_array_1", "DefaultTail"); LookupElementPresentation element = getCompletionLookupElement(PhpFileType.INSTANCE, "<?php date('<caret>')", "foo_return"); assertEquals(element.getIcon(), PhpIcons.METHOD); }
Example #18
Source File: StringReturnSourceContributorTest.java From idea-php-toolbox with MIT License | 5 votes |
/** * @see de.espend.idea.php.toolbox.provider.source.contributor.StringReturnSourceContributor */ public void testStringReturn() { assertCompletionContains(PhpFileType.INSTANCE, "<?php date('<caret>')", "foo_item", "foo_return"); assertNavigationMatch(PhpFileType.INSTANCE, "<?php date('foo_return<caret>')", PlatformPatterns.psiElement(Method.class)); assertCompletionLookupTailEquals(PhpFileType.INSTANCE, "<?php date('<caret>')", "foo_return", "DefaultTail"); LookupElementPresentation element = getCompletionLookupElement(PhpFileType.INSTANCE, "<?php date('<caret>')", "foo_return"); assertEquals(element.getIcon(), PhpIcons.METHOD); }
Example #19
Source File: TabNineCompletionContributor.java From tabnine-intellij with MIT License | 5 votes |
@Override public void renderElement(LookupElementPresentation presentation) { if (this.detail != null) { presentation.setTypeText(this.detail); } presentation.setItemTextBold(true); presentation.setStrikeout(this.deprecated); presentation.setItemText(this.newPrefix); }
Example #20
Source File: LookupCellRenderer.java From consulo with Apache License 2.0 | 5 votes |
private void setTailTextLabel(boolean isSelected, LookupElementPresentation presentation, Color foreground, int allowedWidth, boolean nonFocusedSelection, FontMetrics fontMetrics) { int style = getStyle(false, presentation.isStrikeout(), false); for (LookupElementPresentation.TextFragment fragment : presentation.getTailFragments()) { if (allowedWidth < 0) { return; } String trimmed = trimLabelText(fragment.text, allowedWidth, fontMetrics); int fragmentStyle = fragment.isItalic() ? style | SimpleTextAttributes.STYLE_ITALIC : style; myTailComponent.append(trimmed, new SimpleTextAttributes(fragmentStyle, getTailTextColor(isSelected, fragment, foreground, nonFocusedSelection))); allowedWidth -= RealLookupElementPresentation.getStringWidth(trimmed, fontMetrics); } }
Example #21
Source File: PhpTwigMethodLookupElement.java From idea-php-symfony2-plugin with MIT License | 5 votes |
@Override public void renderElement(LookupElementPresentation presentation) { super.renderElement(presentation); PhpNamedElement phpNamedElement = this.getNamedElement(); // reset method to show full name again, which was stripped inside getLookupString if(phpNamedElement instanceof Method && TwigTypeResolveUtil.isPropertyShortcutMethod((Method) phpNamedElement)) { presentation.setItemText(phpNamedElement.getName()); } }
Example #22
Source File: TwigExtensionLookupElement.java From idea-php-symfony2-plugin with MIT License | 5 votes |
@Override public void renderElement(LookupElementPresentation presentation) { presentation.setIcon(TwigExtensionParser.getIcon(this.twigExtension.getTwigExtensionType())); buildTailText(presentation); presentation.setItemText(name); presentation.setTypeText(StringUtils.camelize(this.twigExtension.getType().toLowerCase())); presentation.setTypeGrayed(true); }
Example #23
Source File: ExistFileLookupElement.java From yiistorm with MIT License | 5 votes |
public void renderElement(LookupElementPresentation presentation) { presentation.setItemText(title); ImageIcon icon = new ImageIcon(this.getClass().getResource("/com/yiistorm/images/yii.png")); presentation.setIcon(icon); presentation.setTypeText(createTitle); presentation.setTypeGrayed(false); }
Example #24
Source File: TranslatorLookupElement.java From idea-php-symfony2-plugin with MIT License | 5 votes |
public void renderElement(LookupElementPresentation presentation) { presentation.setItemText(getLookupString()); presentation.setTypeText(domain); presentation.setTypeGrayed(true); if(this.isWeak) { presentation.setIcon(Symfony2Icons.TRANSLATION_WEAK); } else { presentation.setIcon(Symfony2Icons.TRANSLATION); } }
Example #25
Source File: ClassConstantLookupElementAbstract.java From idea-php-symfony2-plugin with MIT License | 5 votes |
@Override public void renderElement(LookupElementPresentation presentation) { presentation.setItemText(phpClass.getName()); presentation.setTypeText(phpClass.getPresentableFQN()); presentation.setTypeGrayed(true); super.renderElement(presentation); }
Example #26
Source File: TwigMatcherTest.java From idea-php-toolbox with MIT License | 5 votes |
public void testDecoratedLookupItems() { LookupElementPresentation element = getCompletionLookupElement(TwigFileType.INSTANCE, "{{ foo_blank('<caret>') }}", "foo_return"); assertNotNull(element); // only test that fails on PhpStorm9; not really an issue // assertNotNull(element.getIcon()); // assertTrue(element.getIcon().toString().contains("class.png")); assertNotNull(element.getTypeText()); assertTrue(element.getTypeText().equals("ReturnClass")); }
Example #27
Source File: IgnoredLookupElement.java From yiistorm with MIT License | 5 votes |
public void renderElement(LookupElementPresentation presentation) { presentation.setItemText(""); //presentation.setIcon(PlatformIcons.); //String base=getPsiElement().getProject().getBasePath(); presentation.setTypeText(""); //ignore autocomplete presentation.setTypeGrayed(false); }
Example #28
Source File: MessageLookupElement.java From yiistorm with MIT License | 5 votes |
public void renderElement(LookupElementPresentation presentation) { presentation.setItemText(title); presentation.setIcon(icon); presentation.setTypeText(langTitle); presentation.setTypeGrayed(false); }
Example #29
Source File: TemplateLookupElement.java From idea-php-shopware-plugin with MIT License | 5 votes |
@Override public void renderElement(LookupElementPresentation presentation) { super.renderElement(presentation); if(this.templateName.endsWith("tpl")) { presentation.setIcon(ShopwarePluginIcons.SHOPWARE_SMARTY); } if(this.templateName.endsWith("js")) { presentation.setIcon(AllIcons.FileTypes.JavaScript); } }
Example #30
Source File: PostfixTemplateLookupElement.java From consulo with Apache License 2.0 | 5 votes |
@Override public void renderElement(LookupElementPresentation presentation) { super.renderElement(presentation); if (sudden) { presentation.setTailText(" " + UIUtil.rightArrow() + " " + myTemplate.getExample()); } else { presentation.setTypeText(myTemplate.getExample()); presentation.setTypeGrayed(true); } }