Java Code Examples for com.intellij.codeInsight.lookup.LookupElementBuilder#withTypeText()
The following examples show how to use
com.intellij.codeInsight.lookup.LookupElementBuilder#withTypeText() .
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: DefaultTextCompletionValueDescriptor.java From consulo with Apache License 2.0 | 6 votes |
@Nonnull @Override public LookupElementBuilder createLookupBuilder(@Nonnull T item) { LookupElementBuilder builder = LookupElementBuilder.create(item, getLookupString(item)) .withIcon(getIcon(item)); InsertHandler<LookupElement> handler = createInsertHandler(item); if (handler != null) { builder = builder.withInsertHandler(handler); } String tailText = getTailText(item); if (tailText != null) { builder = builder.withTailText(tailText, true); } String typeText = getTypeText(item); if (typeText != null) { builder = builder.withTypeText(typeText); } return builder; }
Example 2
Source File: JsonParseUtil.java From idea-php-toolbox with MIT License | 6 votes |
@NotNull public static LookupElementBuilder getDecoratedLookupElementBuilder(@NotNull LookupElementBuilder lookupElement, @Nullable JsonRawLookupElement jsonLookup) { if(jsonLookup == null) { return lookupElement; } if(jsonLookup.getTailText() != null) { lookupElement = lookupElement.withTailText(jsonLookup.getTailText(), true); } if(jsonLookup.getTypeText() != null) { lookupElement = lookupElement.withTypeText(jsonLookup.getTypeText(), true); } String iconString = jsonLookup.getIcon(); if(iconString != null) { Icon icon = getLookupIconOnString(iconString); if(icon != null) { lookupElement = lookupElement.withIcon(icon); } } return lookupElement; }
Example 3
Source File: LatteVariableCompletionProvider.java From intellij-latte with MIT License | 6 votes |
private void attachTemplateTypeCompletions(@NotNull CompletionResultSet result, @NotNull Project project, @NotNull LatteFile file) { LattePhpType type = LatteUtil.findFirstLatteTemplateType(file); if (type == null) { return; } Collection<PhpClass> phpClasses = type.getPhpClasses(project); if (phpClasses != null) { for (PhpClass phpClass : phpClasses) { for (Field field : phpClass.getFields()) { if (!field.isConstant() && field.getModifier().isPublic()) { LookupElementBuilder builder = LookupElementBuilder.create(field, "$" + field.getName()); builder = builder.withInsertHandler(PhpVariableInsertHandler.getInstance()); builder = builder.withTypeText(LattePhpType.create(field.getType()).toString()); builder = builder.withIcon(PhpIcons.VARIABLE); if (field.isDeprecated() || field.isInternal()) { builder = builder.withStrikeoutness(true); } result.addElement(builder); } } } } }
Example 4
Source File: ConstraintPropertyReference.java From idea-php-symfony2-plugin with MIT License | 6 votes |
@NotNull @Override public Object[] getVariants() { List<LookupElement> lookupElements = new ArrayList<>(); for(Field field: constraintPhpClass.getFields()) { if(!field.isConstant() && field.getModifier().isPublic()) { LookupElementBuilder lookupElement = LookupElementBuilder.create(field.getName()).withIcon(Symfony2Icons.SYMFONY); String defaultValue = PhpElementsUtil.getStringValue(field.getDefaultValue()); if(defaultValue != null) { lookupElement = lookupElement.withTypeText(defaultValue, true); } lookupElements.add(lookupElement); } } return lookupElements.toArray(); }
Example 5
Source File: FormFieldNameReference.java From idea-php-symfony2-plugin with MIT License | 6 votes |
public static LookupElement[] getFormLookups(Method method) { MethodReference[] formBuilderTypes = FormUtil.getFormBuilderTypes(method); List<LookupElement> lookupElements = new ArrayList<>(); for(MethodReference methodReference: formBuilderTypes) { String fieldName = PsiElementUtils.getMethodParameterAt(methodReference, 0); if(fieldName != null) { LookupElementBuilder lookup = LookupElementBuilder.create(fieldName).withIcon(Symfony2Icons.FORM_TYPE); String fieldType = PsiElementUtils.getMethodParameterAt(methodReference, 1); if(fieldType != null) { lookup = lookup.withTypeText(fieldType, true); } lookupElements.add(lookup); } } return lookupElements.toArray(new LookupElement[lookupElements.size()]); }
Example 6
Source File: ConfigCompletionProvider.java From idea-php-symfony2-plugin with MIT License | 6 votes |
private LookupElementBuilder getNodeAttributeLookupElement(Node node, Map<String, String> nodeVars, boolean isShortcut) { String nodeName = getNodeName(node); LookupElementBuilder lookupElementBuilder = LookupElementBuilder.create(nodeName).withIcon(Symfony2Icons.CONFIG_VALUE); String textContent = node.getTextContent(); if(StringUtils.isNotBlank(textContent)) { lookupElementBuilder = lookupElementBuilder.withTailText("(" + textContent + ")", true); } if(nodeVars.containsKey(nodeName)) { lookupElementBuilder = lookupElementBuilder.withTypeText(StringUtil.shortenTextWithEllipsis(nodeVars.get(nodeName), 100, 0), true); } if(isShortcut) { lookupElementBuilder = lookupElementBuilder.withIcon(Symfony2Icons.CONFIG_VALUE_SHORTCUT); } return lookupElementBuilder; }
Example 7
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 8
Source File: ShaderReference.java From consulo-unity3d with Apache License 2.0 | 6 votes |
@RequiredReadAction public static void consumeProperties(@Nonnull ShaderLabFile file, @Nonnull Consumer<LookupElement> consumer) { for(ShaderProperty shaderProperty : file.getProperties()) { String name = shaderProperty.getName(); if(name == null) { continue; } LookupElementBuilder builder = LookupElementBuilder.create(name); builder = builder.withIcon((Image) AllIcons.Nodes.Property); ShaderPropertyType type = shaderProperty.getType(); if(type != null) { builder = builder.withTypeText(type.getTargetText(), true); } consumer.consume(builder); } }
Example 9
Source File: ControllerActionReferenceProvider.java From idea-php-shopware-plugin with MIT License | 5 votes |
private LookupElementBuilder attachTypeText(LookupElementBuilder builder, Method method) { PhpClass phpClass = method.getContainingClass(); if(phpClass == null) { return builder; } return builder.withTypeText(phpClass.getPresentableFQN(), true); }
Example 10
Source File: ReturnSourceUtil.java From idea-php-toolbox with MIT License | 5 votes |
public static LookupElementBuilder buildLookupElement(@NotNull Method method, @NotNull String contents, @Nullable JsonRawLookupElement jsonRawLookupElement) { LookupElementBuilder lookupElement = LookupElementBuilder.create(contents); PhpClass phpClass = method.getContainingClass(); if(phpClass != null) { lookupElement = lookupElement.withTypeText(phpClass.getPresentableFQN(), true); lookupElement = lookupElement.withIcon(phpClass.getIcon()); } return JsonParseUtil.getDecoratedLookupElementBuilder( lookupElement, jsonRawLookupElement ); }
Example 11
Source File: PhpArrayCallbackGotoCompletion.java From idea-php-toolbox with MIT License | 5 votes |
@Override public void addCompletions(@NotNull CompletionParameters completionParameters, ProcessingContext context, @NotNull CompletionResultSet resultSet) { PsiElement position = completionParameters.getPosition(); PhpClass phpClass = findClassCallback(position); if(phpClass == null) { return; } for (Method method : phpClass.getMethods()) { String name = method.getName(); // __construct if(name.startsWith("__")) { continue; } LookupElementBuilder lookupElement = LookupElementBuilder.create(name).withIcon(method.getIcon()); PhpClass containingClass = method.getContainingClass(); if(containingClass != null) { lookupElement = lookupElement.withTypeText(containingClass.getPresentableFQN(), true); } resultSet.addElement(lookupElement); } }
Example 12
Source File: LatteCompletionContributor.java From intellij-latte with MIT License | 5 votes |
private LookupElementBuilder createBuilderWithHelp(LatteFilterSettings modifier) { LookupElementBuilder builder = LookupElementBuilder.create(modifier.getModifierName()); if (modifier.getModifierDescription().trim().length() > 0) { builder = builder.withTypeText(modifier.getModifierDescription()); } if (modifier.getModifierHelp().trim().length() > 0) { builder = builder.withTailText(modifier.getModifierHelp()); } builder = builder.withInsertHandler(FilterInsertHandler.getInstance()); return builder.withIcon(LatteIcons.MODIFIER); }
Example 13
Source File: LattePhpFunctionCompletionProvider.java From intellij-latte with MIT License | 5 votes |
private LookupElementBuilder createBuilderWithHelp(LatteFunctionSettings settings) { LookupElementBuilder builder = LookupElementBuilder.create(settings.getFunctionName()); builder = builder.withIcon(PhpIcons.FUNCTION_ICON); builder = builder.withInsertHandler(MacroCustomFunctionInsertHandler.getInstance()); if (settings.getFunctionHelp().trim().length() > 0) { builder = builder.withTailText(settings.getFunctionHelp()); } return builder.withTypeText(settings.getFunctionReturnType()); }
Example 14
Source File: CompletionNavigationProvider.java From idea-php-generics-plugin with MIT License | 5 votes |
@NotNull private static LookupElement createParameterArrayTypeLookupElement(@NotNull ParameterArrayType type) { LookupElementBuilder lookupElementBuilder = LookupElementBuilder.create(type.getKey()) .withIcon(PhpIcons.FIELD); String types = StringUtils.join(type.getValues(), '|'); if (type.isOptional()) { types = "(optional) " + types; } return lookupElementBuilder.withTypeText(types); }
Example 15
Source File: JSGraphQLEndpointCompletionContributor.java From js-graphql-intellij-plugin with MIT License | 5 votes |
private LookupElementBuilder withAutoImport(LookupElementBuilder element, JSGraphQLEndpointTypeResult typeResult, boolean autoImport) { if(autoImport && typeResult.fileToImport != null) { element = element.withInsertHandler(new JSGraphQLEndpointAutoImportInsertHandler(typeResult.fileToImport)); element = element.withTypeText(typeResult.fileToImport.getName(), true); } return element; }
Example 16
Source File: JSGraphQLEndpointCompletionContributor.java From js-graphql-intellij-plugin with MIT License | 5 votes |
private boolean completeOverrideFields(JSGraphQLEndpointFieldDefinitionSet fieldDefinitionSet, PsiElement completionElement, CompletionResultSet result) { if(PsiTreeUtil.getParentOfType(completionElement, JSGraphQLEndpointAnnotation.class) != null) { return false; } final JSGraphQLEndpointObjectTypeDefinition typeDefinition = PsiTreeUtil.getParentOfType(fieldDefinitionSet, JSGraphQLEndpointObjectTypeDefinition.class); if (typeDefinition != null) { if (typeDefinition.getImplementsInterfaces() != null) { final Set<String> implementsNames = typeDefinition.getImplementsInterfaces().getNamedTypeList().stream().map(t -> t.getIdentifier().getText()).collect(Collectors.toSet()); final Collection<JSGraphQLEndpointInterfaceTypeDefinition> interfaceTypeDefinitions = JSGraphQLEndpointPsiUtil.getKnownDefinitions( fieldDefinitionSet.getContainingFile(), JSGraphQLEndpointInterfaceTypeDefinition.class, false, null ); final Set<String> currentFieldNames = fieldDefinitionSet.getFieldDefinitionList().stream().map(f -> f.getProperty().getText()).collect(Collectors.toSet()); for (JSGraphQLEndpointInterfaceTypeDefinition interfaceTypeDefinition : interfaceTypeDefinitions) { if (interfaceTypeDefinition.getNamedTypeDef() != null) { if (implementsNames.contains(interfaceTypeDefinition.getNamedTypeDef().getText())) { if (interfaceTypeDefinition.getFieldDefinitionSet() != null) { for (JSGraphQLEndpointFieldDefinition field : interfaceTypeDefinition.getFieldDefinitionSet().getFieldDefinitionList()) { if (!currentFieldNames.contains(field.getProperty().getText())) { LookupElementBuilder element = LookupElementBuilder.create(field.getText().trim()); element = element.withTypeText(" " + interfaceTypeDefinition.getNamedTypeDef().getText(), true); result.addElement(element); } } } } } } return true; } } return false; }
Example 17
Source File: GoToHashOrRefPopup.java From consulo with Apache License 2.0 | 5 votes |
@Nonnull @Override public LookupElementBuilder createLookupBuilder(@Nonnull VcsRef item) { LookupElementBuilder lookupBuilder = super.createLookupBuilder(item); if (myColorManager.isMultipleRoots()) { lookupBuilder = lookupBuilder .withTypeText(getTypeText(item), new ColorIcon(15, VcsLogGraphTable.getRootBackgroundColor(item.getRoot(), myColorManager)), true); } return lookupBuilder; }
Example 18
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 19
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 20
Source File: CSharpExpressionCompletionContributor.java From consulo-csharp with Apache License 2.0 | 4 votes |
@Nonnull @RequiredReadAction private static LookupElement buildForMethodReference(final CSharpMethodDeclaration methodDeclaration, CSharpTypeDeclaration contextType, final CSharpReferenceExpressionEx expression) { LookupElementBuilder builder = LookupElementBuilder.create(methodDeclaration.getName()); builder = builder.withIcon((Image) AllIcons.Nodes.MethodReference); final DotNetTypeRef[] parameterTypes = methodDeclaration.getParameterTypeRefs(); String genericText = DotNetElementPresentationUtil.formatGenericParameters(methodDeclaration); String parameterText = genericText + "(" + StringUtil.join(parameterTypes, new Function<DotNetTypeRef, String>() { @Override @RequiredReadAction public String fun(DotNetTypeRef parameter) { return CSharpTypeRefPresentationUtil.buildShortText(parameter, methodDeclaration); } }, ", ") + ")"; if(CSharpMethodImplUtil.isExtensionWrapper(methodDeclaration)) { builder = builder.withItemTextUnderlined(true); } builder = builder.withTypeText(CSharpTypeRefPresentationUtil.buildShortText(methodDeclaration.getReturnTypeRef(), methodDeclaration), true); builder = builder.withTailText(parameterText, true); if(DotNetAttributeUtil.hasAttribute(methodDeclaration, DotNetTypes.System.ObsoleteAttribute)) { builder = builder.withStrikeoutness(true); } builder = builder.withInsertHandler(new InsertHandler<LookupElement>() { @Override @RequiredWriteAction public void handleInsert(InsertionContext context, LookupElement item) { char completionChar = context.getCompletionChar(); switch(completionChar) { case ',': if(expression != null && expression.getParent() instanceof CSharpCallArgument) { context.setAddCompletionChar(false); TailType.COMMA.processTail(context.getEditor(), context.getTailOffset()); } break; } } }); if(contextType != null && contextType.isEquivalentTo(methodDeclaration.getParent())) { builder = builder.bold(); } CSharpCompletionSorting.force(builder, CSharpCompletionSorting.KindSorter.Type.member); return builder; }