Java Code Examples for com.intellij.codeInsight.lookup.LookupElementBuilder#withAutoCompletionPolicy()

The following examples show how to use com.intellij.codeInsight.lookup.LookupElementBuilder#withAutoCompletionPolicy() . These examples are extracted from open source projects. 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
@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
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 3
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;
}