Search in sources :

Example 56 with LookupElementBuilder

use of com.intellij.codeInsight.lookup.LookupElementBuilder in project intellij-community by JetBrains.

the class XmlCompletionContributor method buildEntityLookupItem.

@Nullable
private static LookupElementBuilder buildEntityLookupItem(@NotNull final XmlEntityDecl decl) {
    final String name = decl.getName();
    if (name == null) {
        return null;
    }
    final LookupElementBuilder result = LookupElementBuilder.create(name).withInsertHandler(ENTITY_INSERT_HANDLER);
    final XmlAttributeValue value = decl.getValueElement();
    final ASTNode node = value.getNode();
    if (node != null) {
        final ASTNode[] nodes = node.getChildren(TokenSet.create(XmlTokenType.XML_CHAR_ENTITY_REF));
        if (nodes.length == 1) {
            final String valueText = nodes[0].getText();
            final int i = valueText.indexOf('#');
            if (i > 0) {
                String s = valueText.substring(i + 1);
                s = StringUtil.trimEnd(s, ";");
                try {
                    final int unicodeChar = Integer.valueOf(s).intValue();
                    return result.withTypeText(String.valueOf((char) unicodeChar));
                } catch (NumberFormatException e) {
                    return result;
                }
            }
        }
    }
    return result;
}
Also used : ASTNode(com.intellij.lang.ASTNode) LookupElementBuilder(com.intellij.codeInsight.lookup.LookupElementBuilder) Nullable(org.jetbrains.annotations.Nullable)

Example 57 with LookupElementBuilder

use of com.intellij.codeInsight.lookup.LookupElementBuilder in project Intellij-Plugin by getgauge.

the class ConceptDynamicArgCompletionProvider method addCompletions.

public void addCompletions(@NotNull CompletionParameters parameters, ProcessingContext context, @NotNull CompletionResultSet resultSet) {
    String prefix = getPrefix(parameters);
    resultSet = resultSet.withPrefixMatcher(new PlainPrefixMatcher(prefix));
    Collection<ConceptDynamicArg> args = PsiTreeUtil.collectElementsOfType(parameters.getOriginalFile(), ConceptDynamicArg.class);
    for (ConceptDynamicArg arg : args) {
        LookupElementBuilder item = LookupElementBuilder.create(arg.getText().replaceAll("<|>", ""));
        resultSet.addElement(item);
    }
}
Also used : ConceptDynamicArg(com.thoughtworks.gauge.language.psi.ConceptDynamicArg) PlainPrefixMatcher(com.intellij.codeInsight.completion.PlainPrefixMatcher) LookupElementBuilder(com.intellij.codeInsight.lookup.LookupElementBuilder)

Aggregations

LookupElementBuilder (com.intellij.codeInsight.lookup.LookupElementBuilder)57 LookupElement (com.intellij.codeInsight.lookup.LookupElement)20 NotNull (org.jetbrains.annotations.NotNull)16 PsiElement (com.intellij.psi.PsiElement)13 Nullable (org.jetbrains.annotations.Nullable)9 PsiFile (com.intellij.psi.PsiFile)7 Document (com.intellij.openapi.editor.Document)5 ArrayList (java.util.ArrayList)5 PlainPrefixMatcher (com.intellij.codeInsight.completion.PlainPrefixMatcher)3 PrioritizedLookupElement (com.intellij.codeInsight.completion.PrioritizedLookupElement)3 Editor (com.intellij.openapi.editor.Editor)3 TextRange (com.intellij.openapi.util.TextRange)3 PsiPresentableMetaData (com.intellij.psi.meta.PsiPresentableMetaData)3 XmlFile (com.intellij.psi.xml.XmlFile)3 XmlExtension (com.intellij.xml.XmlExtension)3 com.intellij.codeInsight.completion (com.intellij.codeInsight.completion)2 CompletionResultSet (com.intellij.codeInsight.completion.CompletionResultSet)2 InsertionContext (com.intellij.codeInsight.completion.InsertionContext)2 ParenthesesInsertHandler (com.intellij.codeInsight.completion.util.ParenthesesInsertHandler)2 AutoCompletionPolicy (com.intellij.codeInsight.lookup.AutoCompletionPolicy)2