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

The following examples show how to use com.intellij.codeInsight.lookup.LookupElementBuilder#withStrikeoutness() . 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
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
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
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
public void addCompletions(@NotNull CompletionParameters parameters, ProcessingContext context, @NotNull CompletionResultSet resultSet) {
    if(!Symfony2ProjectComponent.isEnabled(parameters.getPosition())) {
        return;
    }

    if(this.lookupList != null) {
        resultSet.addAllElements(this.lookupList);
    } else if(lookupMap != null) {
        for (Map.Entry<String, String> lookup : lookupMap.entrySet()) {
            LookupElementBuilder lookupElement = LookupElementBuilder.create(lookup.getKey()).withTypeText(lookup.getValue(), true).withIcon(Symfony2Icons.SYMFONY);
            if(lookup.getValue() != null && lookup.getValue().contains("deprecated")) {
                lookupElement = lookupElement.withStrikeoutness(true);
            }

            resultSet.addElement(lookupElement);
        }
    }
}
 
Example 6
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
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
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("&amp;", "&");
    }

    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("&", "&amp;");
                }
                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 9
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 10
@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;
}
 
Example 11
@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);
}