Java Code Examples for com.intellij.codeInsight.lookup.LookupElementBuilder#withPresentableText()
The following examples show how to use
com.intellij.codeInsight.lookup.LookupElementBuilder#withPresentableText() .
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: CamelJavaBeanReferenceSmartCompletion.java From camel-idea-plugin with Apache License 2.0 | 6 votes |
@NotNull private LookupElement buildLookupElement(PsiMethod method, String presentableMethod) { LookupElementBuilder builder = LookupElementBuilder.create(method); builder = builder.withPresentableText(presentableMethod); builder = builder.withTypeText(method.getContainingClass().getName(), true); builder = builder.withIcon(AllIcons.Nodes.Method); if (getCamelIdeaUtils().isAnnotatedWithHandler(method)) { //@Handle methods are marked with builder = builder.withBoldness(true); } if (method.isDeprecated()) { // mark as deprecated builder = builder.withStrikeoutness(true); } return builder.withAutoCompletionPolicy(AutoCompletionPolicy.GIVE_CHANCE_TO_OVERWRITE); }
Example 2
Source File: CamelSmartCompletionEndpointValue.java From camel-idea-plugin with Apache License 2.0 | 6 votes |
private static void addEnumSuggestions(Editor editor, String val, String suffix, List<LookupElement> answer, String deprecated, String enums, String defaultValue, boolean xmlMode) { String[] parts = enums.split(","); for (String part : parts) { String lookup = val + part; LookupElementBuilder builder = LookupElementBuilder.create(lookup); builder = addInsertHandler(editor, suffix, builder, xmlMode); // only show the option in the UI builder = builder.withPresentableText(part); builder = builder.withBoldness(true); if ("true".equals(deprecated)) { // mark as deprecated builder = builder.withStrikeoutness(true); } boolean isDefaultValue = defaultValue != null && part.equals(defaultValue); if (isDefaultValue) { builder = builder.withTailText(" (default value)"); // add default value first in the list answer.add(0, builder.withAutoCompletionPolicy(AutoCompletionPolicy.GIVE_CHANCE_TO_OVERWRITE)); } else { answer.add(builder.withAutoCompletionPolicy(AutoCompletionPolicy.GIVE_CHANCE_TO_OVERWRITE)); } } }
Example 3
Source File: CamelSmartCompletionEndpointOptions.java From camel-idea-plugin with Apache License 2.0 | 6 votes |
public static List<LookupElement> addSmartCompletionSuggestionsContextPath(String val, final ComponentModel component, final Map<String, String> existing, final boolean xmlMode, final PsiElement psiElement) { final List<LookupElement> answer = new ArrayList<>(); // show the syntax as the only choice for now LookupElementBuilder builder = LookupElementBuilder.create(val); builder = builder.withIcon(getCamelPreferenceService().getCamelIcon()); builder = builder.withBoldness(true); builder = builder.withPresentableText(component.getSyntax()); final LookupElement element = builder.withAutoCompletionPolicy(AutoCompletionPolicy.NEVER_AUTOCOMPLETE); answer.add(element); val = removeUnknownEnum(val, psiElement); final List<LookupElement> old = addSmartCompletionContextPathEnumSuggestions(val, component, existing); if (!old.isEmpty()) { answer.addAll(old); } return answer; }
Example 4
Source File: LatteCompletionContributor.java From intellij-latte with MIT License | 6 votes |
private LookupElementBuilder createBuilderForMacro(LatteTagSettings tag, boolean isEndTag) { String name = (isEndTag ? "/" : "") + tag.getMacroName(); LookupElementBuilder builder = LookupElementBuilder.create(name); builder = builder.withInsertHandler(MacroInsertHandler.getInstance()); if (!isEndTag) { String appendText = tag.getType() == LatteTagSettings.Type.PAIR ? (" … {/" + tag.getMacroName() + "}") : ""; String arguments = tag.getArgumentsInfo(); if (arguments.length() > 0) { builder = builder.withTailText(" " + arguments + "}" + appendText); } else { builder = builder.withTailText("}" + appendText); } } else { builder = builder.withTailText("}"); } if (tag.isDeprecated()) { builder = builder.withStrikeoutness(true); } builder = builder.withPresentableText("{" + name); return builder.withIcon(LatteIcons.MACRO); }
Example 5
Source File: CSharpLookupElementBuilder.java From consulo-csharp with Apache License 2.0 | 6 votes |
@RequiredReadAction private static <E extends DotNetGenericParameterListOwner & DotNetQualifiedElement> LookupElementBuilder buildTypeLikeElement(@Nonnull E element, @Nonnull DotNetGenericExtractor extractor) { String genericText = CSharpElementPresentationUtil.formatGenericParameters(element, extractor); String name = CSharpNamedElement.getEscapedName(element); LookupElementBuilder builder = LookupElementBuilder.create(element, name + (extractor == DotNetGenericExtractor.EMPTY ? "" : genericText)); builder = builder.withPresentableText(name); // always show only name builder = builder.withIcon(IconDescriptorUpdaters.getIcon(element, Iconable.ICON_FLAG_VISIBILITY)); builder = builder.withTypeText(element.getPresentableParentQName()); builder = builder.withTailText(genericText, true); if(extractor == DotNetGenericExtractor.EMPTY) { builder = withGenericInsertHandler(element, builder); } return builder; }
Example 6
Source File: CamelSmartCompletionEndpointValue.java From camel-idea-plugin with Apache License 2.0 | 5 votes |
private static void addBooleanSuggestions(Editor editor, String val, String suffix, List<LookupElement> answer, String deprecated, String defaultValue, boolean xmlMode) { // for boolean types then give a choice between true|false String lookup = val + "true"; LookupElementBuilder builder = LookupElementBuilder.create(lookup); builder = addInsertHandler(editor, suffix, builder, xmlMode); // only show the option in the UI builder = builder.withPresentableText("true"); if ("true".equals(deprecated)) { // mark as deprecated builder = builder.withStrikeoutness(true); } boolean isDefaultValue = defaultValue != null && "true".equals(defaultValue); if (isDefaultValue) { builder = builder.withTailText(" (default value)"); // add default value first in the list answer.add(0, builder.withAutoCompletionPolicy(AutoCompletionPolicy.GIVE_CHANCE_TO_OVERWRITE)); } else { answer.add(builder.withAutoCompletionPolicy(AutoCompletionPolicy.GIVE_CHANCE_TO_OVERWRITE)); } lookup = val + "false"; builder = LookupElementBuilder.create(lookup); builder = addInsertHandler(editor, suffix, builder, xmlMode); // only show the option in the UI builder = builder.withPresentableText("false"); if ("true".equals(deprecated)) { // mark as deprecated builder = builder.withStrikeoutness(true); } isDefaultValue = defaultValue != null && "false".equals(defaultValue); if (isDefaultValue) { builder = builder.withTailText(" (default value)"); // add default value first in the list answer.add(0, builder.withAutoCompletionPolicy(AutoCompletionPolicy.GIVE_CHANCE_TO_OVERWRITE)); } else { answer.add(builder.withAutoCompletionPolicy(AutoCompletionPolicy.GIVE_CHANCE_TO_OVERWRITE)); } }
Example 7
Source File: CamelSmartCompletionEndpointValue.java From camel-idea-plugin with Apache License 2.0 | 5 votes |
private static void addDefaultValueSuggestions(Editor editor, String val, String suffix, List<LookupElement> answer, String deprecated, String defaultValue, boolean xmlMode) { String lookup = val + defaultValue; LookupElementBuilder builder = LookupElementBuilder.create(lookup); builder = addInsertHandler(editor, suffix, builder, xmlMode); // only show the option in the UI builder = builder.withPresentableText(defaultValue); if ("true".equals(deprecated)) { // mark as deprecated builder = builder.withStrikeoutness(true); } builder = builder.withTailText(" (default value)"); // there is only one value in the list and its the default value, so never auto complete it but show as suggestion answer.add(0, builder.withAutoCompletionPolicy(AutoCompletionPolicy.NEVER_AUTOCOMPLETE)); }
Example 8
Source File: HaxeLookupElementFactory.java From intellij-haxe with Apache License 2.0 | 5 votes |
@Nullable public static LookupElementBuilder create(@NotNull HaxeModel model, @Nullable String alias) { PsiElement basePsi = model.getBasePsi(); HaxeNamedComponent namedComponent = getNamedComponent(basePsi); if (namedComponent == null) return null; String name = StringUtil.defaultIfEmpty(alias, model.getName()); String presentableText = null; String tailText = getParentPath(model); Icon icon = null; ItemPresentation presentation = namedComponent.getPresentation(); if (presentation != null) { icon = presentation.getIcon(false); presentableText = presentation.getPresentableText(); } LookupElementBuilder lookupElement = LookupElementBuilder.create(basePsi, name); if (presentableText != null) { if (alias != null && presentableText.startsWith(model.getName())) { presentableText = presentableText.replace(model.getName(), alias); } lookupElement = lookupElement.withPresentableText(presentableText); } if (icon != null) lookupElement = lookupElement.withIcon(icon); if (tailText != null) { if (alias != null) { tailText = HaxeBundle.message("haxe.lookup.alias", tailText + "." + model.getName()); } tailText = " " + tailText; lookupElement = lookupElement.withTailText(tailText, true); } return lookupElement; }
Example 9
Source File: CamelSmartCompletionEndpointOptions.java From camel-idea-plugin with Apache License 2.0 | 4 votes |
public static List<LookupElement> addSmartCompletionSuggestionsQueryParameters(final String[] query, final ComponentModel component, final Map<String, String> existing, final boolean xmlMode, final PsiElement element, final Editor editor) { final List<LookupElement> answer = new ArrayList<>(); String queryAtPosition = query[2]; if (xmlMode) { queryAtPosition = queryAtPosition.replace("&", "&"); } final List<EndpointOptionModel> options = component.getEndpointOptions(); // sort the options A..Z which is easier to users to understand options.sort((o1, o2) -> o1 .getName() .compareToIgnoreCase(o2.getName())); queryAtPosition = removeUnknownOption(queryAtPosition, existing, element); for (final EndpointOptionModel option : options) { if ("parameter".equals(option.getKind())) { final String name = option.getName(); // if we are consumer only, then any option that has producer in the label should be skipped (as its only for producer) final boolean consumerOnly = getCamelIdeaUtils().isConsumerEndpoint(element); if (consumerOnly && option .getLabel() .contains("producer")) { continue; } // if we are producer only, then any option that has consume in the label should be skipped (as its only for consumer) final boolean producerOnly = getCamelIdeaUtils().isProducerEndpoint(element); if (producerOnly && option.getLabel().contains("consumer")) { continue; } // only add if not already used (or if the option is multi valued then it can have many) final String old = existing != null ? existing.get(name) : ""; if ("true".equals(option.getMultiValue()) || existing == null || old == null || old.isEmpty()) { // no tail for prefix, otherwise use = to setup for value final String key = option .getPrefix() .isEmpty() ? name : option.getPrefix(); // the lookup should prepare for the new option String lookup; final String concatQuery = query[0]; if (!concatQuery.contains("?")) { // none existing options so we need to start with a ? mark lookup = queryAtPosition + "?" + key; } else { if (!queryAtPosition.endsWith("&") && !queryAtPosition.endsWith("?")) { lookup = queryAtPosition + "&" + key; } else { // there is already either an ending ? or & lookup = queryAtPosition + key; } } if (xmlMode) { lookup = lookup.replace("&", "&"); } LookupElementBuilder builder = LookupElementBuilder.create(lookup); final String suffix = query[1]; builder = addInsertHandler(editor, builder, suffix); // only show the option in the UI builder = builder.withPresentableText(name); // we don't want to highlight the advanced options which should be more seldom in use final boolean advanced = option .getGroup() .contains("advanced"); builder = builder.withBoldness(!advanced); if (!option.getJavaType().isEmpty()) { builder = builder.withTypeText(option.getJavaType(), true); } if ("true".equals(option.getDeprecated())) { // mark as deprecated builder = builder.withStrikeoutness(true); } // add icons for various options if ("true".equals(option.getRequired())) { builder = builder.withIcon(AllIcons.Toolwindows.ToolWindowFavorites); } else if ("true".equals(option.getSecret())) { builder = builder.withIcon(AllIcons.Nodes.SecurityRole); } else if ("true".equals(option.getMultiValue())) { builder = builder.withIcon(AllIcons.General.ArrowRight); } else if (!option.getEnums().isEmpty()) { builder = builder.withIcon(AllIcons.Nodes.Enum); } else if ("object".equals(option.getType())) { builder = builder.withIcon(AllIcons.Nodes.Class); } answer.add(builder.withAutoCompletionPolicy(AutoCompletionPolicy.GIVE_CHANCE_TO_OVERWRITE)); } } } return answer; }
Example 10
Source File: CamelSmartCompletionEndpointOptions.java From camel-idea-plugin with Apache License 2.0 | 4 votes |
private static List<LookupElement> addSmartCompletionContextPathEnumSuggestions(final String val, final ComponentModel component, final Map<String, String> existing) { final List<LookupElement> answer = new ArrayList<>(); double priority = 100.0d; // lets help the suggestion list if we are editing the context-path and only have 1 enum type option // and the option has not been in use yet, then we can populate the list with the enum values. final long enums = component .getEndpointOptions() .stream() .filter(o -> "path".equals(o.getKind()) && !o .getEnums() .isEmpty()) .count(); if (enums == 1) { for (final EndpointOptionModel option : component.getEndpointOptions()) { // only add support for enum in the context-path smart completion if ("path".equals(option.getKind()) && !option .getEnums() .isEmpty()) { final String name = option.getName(); // only add if not already used final String old = existing != null ? existing.get(name) : ""; if (existing == null || old == null || old.isEmpty()) { // add all enum as choices for (final String choice : option .getEnums() .split(",")) { final String key = choice; final String lookup = val + key; LookupElementBuilder builder = LookupElementBuilder.create(lookup); // only show the option in the UI builder = builder.withPresentableText(choice); // lets use the option name as the type so its visible builder = builder.withTypeText(name, true); builder = builder.withIcon(AllIcons.Nodes.Enum); if ("true".equals(option.getDeprecated())) { // mark as deprecated builder = builder.withStrikeoutness(true); } // its an enum so always auto complete the choices LookupElement element = builder.withAutoCompletionPolicy(AutoCompletionPolicy.ALWAYS_AUTOCOMPLETE); // they should be in the exact order element = PrioritizedLookupElement.withPriority(element, priority); priority -= 1.0d; answer.add(element); } } } } } return answer; }
Example 11
Source File: UnitySpecificMethodCompletion.java From consulo-unity3d with Apache License 2.0 | 4 votes |
@Nonnull @RequiredReadAction private static LookupElementBuilder buildLookupItem(UnityFunctionManager.FunctionInfo functionInfo, CSharpTypeDeclaration scope) { StringBuilder builder = new StringBuilder(); builder.append("void "); builder.append(functionInfo.getName()); builder.append("("); boolean first = true; for(Map.Entry<String, String> entry : functionInfo.getParameters().entrySet()) { if(first) { first = false; } else { builder.append(", "); } DotNetTypeRef typeRef = UnityFunctionManager.createTypeRef(scope, entry.getValue()); builder.append(CSharpTypeRefPresentationUtil.buildShortText(typeRef, scope)); builder.append(" "); builder.append(entry.getKey()); } builder.append(")"); String presentationText = builder.toString(); builder.append("{\n"); builder.append("}"); LookupElementBuilder lookupElementBuilder = LookupElementBuilder.create(builder.toString()); lookupElementBuilder = lookupElementBuilder.withPresentableText(presentationText); lookupElementBuilder = lookupElementBuilder.withLookupString(functionInfo.getName()); lookupElementBuilder = lookupElementBuilder.withTailText("{...}", true); IconDescriptor iconDescriptor = new IconDescriptor(new IconDescriptor(AllIcons.Nodes.Method).toIcon()); iconDescriptor.setRightIcon(Unity3dIcons.EventMethod); lookupElementBuilder = lookupElementBuilder.withIcon(iconDescriptor.toIcon()); lookupElementBuilder = lookupElementBuilder.withInsertHandler(new InsertHandler<LookupElement>() { @Override @RequiredUIAccess public void handleInsert(InsertionContext context, LookupElement item) { CaretModel caretModel = context.getEditor().getCaretModel(); PsiElement elementAt = context.getFile().findElementAt(caretModel.getOffset() - 1); if(elementAt == null) { return; } DotNetVirtualImplementOwner virtualImplementOwner = PsiTreeUtil.getParentOfType(elementAt, DotNetVirtualImplementOwner.class); if(virtualImplementOwner == null) { return; } if(virtualImplementOwner instanceof CSharpMethodDeclaration) { PsiElement codeBlock = ((CSharpMethodDeclaration) virtualImplementOwner).getCodeBlock().getElement(); if(codeBlock instanceof CSharpBlockStatementImpl) { DotNetStatement[] statements = ((CSharpBlockStatementImpl) codeBlock).getStatements(); if(statements.length > 0) { caretModel.moveToOffset(statements[0].getTextOffset() + statements[0].getTextLength()); } else { caretModel.moveToOffset(((CSharpBlockStatementImpl) codeBlock).getLeftBrace().getTextOffset() + 1); } } } context.commitDocument(); CodeStyleManager.getInstance(context.getProject()).reformat(virtualImplementOwner); } }); return lookupElementBuilder; }
Example 12
Source File: CSharpNoVariantsDelegator.java From consulo-csharp with Apache License 2.0 | 4 votes |
@RequiredReadAction private static void consumeType(final CompletionParameters completionParameters, CSharpReferenceExpression referenceExpression, Consumer<LookupElement> consumer, boolean insideUsingList, DotNetTypeDeclaration someType) { final String parentQName = someType.getPresentableParentQName(); if(StringUtil.isEmpty(parentQName)) { return; } String presentationText = MsilHelper.cutGenericMarker(someType.getName()); int genericCount; DotNetGenericParameter[] genericParameters = someType.getGenericParameters(); if((genericCount = genericParameters.length) > 0) { presentationText += "<" + StringUtil.join(genericParameters, parameter -> parameter.getName(), ", "); presentationText += ">"; } String lookupString = insideUsingList ? someType.getPresentableQName() : someType.getName(); if(lookupString == null) { return; } lookupString = MsilHelper.cutGenericMarker(lookupString); DotNetQualifiedElement targetElementForLookup = someType; CSharpMethodDeclaration methodDeclaration = someType.getUserData(CSharpResolveUtil.DELEGATE_METHOD_TYPE); if(methodDeclaration != null) { targetElementForLookup = methodDeclaration; } LookupElementBuilder builder = LookupElementBuilder.create(targetElementForLookup, lookupString); builder = builder.withPresentableText(presentationText); builder = builder.withIcon(IconDescriptorUpdaters.getIcon(targetElementForLookup, Iconable.ICON_FLAG_VISIBILITY)); builder = builder.withTypeText(parentQName, true); final InsertHandler<LookupElement> ltGtInsertHandler = genericCount == 0 ? null : LtGtInsertHandler.getInstance(genericCount > 0); if(insideUsingList) { builder = builder.withInsertHandler(ltGtInsertHandler); } else { builder = builder.withInsertHandler(new InsertHandler<LookupElement>() { @Override @RequiredWriteAction public void handleInsert(InsertionContext context, LookupElement item) { if(ltGtInsertHandler != null) { ltGtInsertHandler.handleInsert(context, item); } context.commitDocument(); new AddUsingAction(completionParameters.getEditor(), context.getFile(), Collections.<NamespaceReference>singleton(new NamespaceReference(parentQName, null))).execute(); } }); } if(DotNetAttributeUtil.hasAttribute(someType, DotNetTypes.System.ObsoleteAttribute)) { builder = builder.withStrikeoutness(true); } CSharpTypeLikeLookupElement element = CSharpTypeLikeLookupElement.create(builder, DotNetGenericExtractor.EMPTY, referenceExpression); element.putUserData(CSharpNoVariantsDelegator.NOT_IMPORTED, Boolean.TRUE); consumer.consume(element); }