Search in sources :

Example 6 with LookupElementBuilder

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

the class GrMethodOverrideCompletionProvider method addSuperMethods.

private static void addSuperMethods(final GrTypeDefinition psiClass, CompletionResultSet completionResultSet, boolean toImplement) {
    final Collection<CandidateInfo> candidates = GroovyOverrideImplementExploreUtil.getMethodsToOverrideImplement(psiClass, toImplement);
    for (CandidateInfo candidateInfo : candidates) {
        final PsiMethod method = (PsiMethod) candidateInfo.getElement();
        if (method.isConstructor())
            continue;
        RowIcon icon = new RowIcon(2);
        icon.setIcon(method.getIcon(0), 0);
        icon.setIcon(toImplement ? AllIcons.Gutter.ImplementingMethod : AllIcons.Gutter.OverridingMethod, 1);
        PsiSubstitutor substitutor = candidateInfo.getSubstitutor();
        String parameters = PsiFormatUtil.formatMethod(method, substitutor, PsiFormatUtilBase.SHOW_PARAMETERS, PsiFormatUtilBase.SHOW_NAME);
        String visibility = VisibilityUtil.getVisibilityModifier(method.getModifierList());
        String modifiers = (visibility == PsiModifier.PACKAGE_LOCAL ? "" : visibility + " ");
        PsiType type = substitutor.substitute(method.getReturnType());
        String parentClassName = psiClass == null ? "" : psiClass.getName();
        String signature = modifiers + (type == null ? "" : type.getPresentableText() + " ") + method.getName();
        LookupElementBuilder lookupElement = LookupElementBuilder.create(method, signature).appendTailText(parameters, false).appendTailText("{...}", true).withTypeText(parentClassName).withIcon(icon).withInsertHandler(new GroovyMethodOverrideHandler(psiClass));
        completionResultSet.addElement(lookupElement);
    }
}
Also used : CandidateInfo(com.intellij.psi.infos.CandidateInfo) LookupElementBuilder(com.intellij.codeInsight.lookup.LookupElementBuilder) RowIcon(com.intellij.ui.RowIcon) GroovyMethodOverrideHandler(org.jetbrains.plugins.groovy.lang.completion.handlers.GroovyMethodOverrideHandler)

Example 7 with LookupElementBuilder

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

the class ResourceBundleReference method getVariants.

@Override
@NotNull
public Object[] getVariants() {
    final ProjectFileIndex projectFileIndex = ProjectFileIndex.SERVICE.getInstance(getElement().getProject());
    final PropertiesReferenceManager referenceManager = PropertiesReferenceManager.getInstance(getElement().getProject());
    final Set<String> bundleNames = new HashSet<>();
    final List<LookupElement> variants = new SmartList<>();
    PropertiesFileProcessor processor = new PropertiesFileProcessor() {

        @Override
        public boolean process(String baseName, PropertiesFile propertiesFile) {
            if (!bundleNames.add(baseName))
                return true;
            final LookupElementBuilder builder = LookupElementBuilder.create(baseName).withIcon(AllIcons.Nodes.ResourceBundle);
            boolean isInContent = projectFileIndex.isInContent(propertiesFile.getVirtualFile());
            variants.add(isInContent ? PrioritizedLookupElement.withPriority(builder, Double.MAX_VALUE) : builder);
            return true;
        }
    };
    referenceManager.processPropertiesFiles(myElement.getResolveScope(), processor, this);
    return variants.toArray(new LookupElement[variants.size()]);
}
Also used : ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex) LookupElementBuilder(com.intellij.codeInsight.lookup.LookupElementBuilder) PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile) SmartList(com.intellij.util.SmartList) LookupElement(com.intellij.codeInsight.lookup.LookupElement) PrioritizedLookupElement(com.intellij.codeInsight.completion.PrioritizedLookupElement) HashSet(java.util.HashSet) NotNull(org.jetbrains.annotations.NotNull)

Example 8 with LookupElementBuilder

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

the class MapArgumentCompletionProvider method addCompletions.

@Override
protected void addCompletions(@NotNull CompletionParameters parameters, ProcessingContext context, @NotNull CompletionResultSet result) {
    PsiElement mapOrArgumentList = findMapOrArgumentList(parameters);
    if (mapOrArgumentList == null) {
        return;
    }
    if (isMapKeyCompletion(parameters)) {
        result.stopHere();
    }
    final Map<String, NamedArgumentDescriptor> map = ContainerUtil.newHashMap(calculateNamedArguments(mapOrArgumentList));
    for (GrNamedArgument argument : getSiblingNamedArguments(mapOrArgumentList)) {
        map.remove(argument.getLabelName());
    }
    for (Map.Entry<String, NamedArgumentDescriptor> entry : map.entrySet()) {
        LookupElementBuilder lookup = LookupElementBuilder.create(entry.getValue(), entry.getKey()).withInsertHandler(NamedArgumentInsertHandler.INSTANCE).withTailText(":");
        if (entry.getValue().getPriority() == NamedArgumentDescriptor.Priority.UNLIKELY) {
            lookup = lookup.withItemTextForeground(GroovySyntaxHighlighter.MAP_KEY.getDefaultAttributes().getForegroundColor());
        } else {
            lookup = lookup.withIcon(JetgroovyIcons.Groovy.DynamicProperty);
        }
        LookupElement customized = entry.getValue().customizeLookupElement(lookup);
        result.addElement(customized == null ? lookup : customized);
    }
}
Also used : NamedArgumentDescriptor(org.jetbrains.plugins.groovy.extensions.NamedArgumentDescriptor) GrNamedArgument(org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrNamedArgument) LookupElementBuilder(com.intellij.codeInsight.lookup.LookupElementBuilder) LookupElement(com.intellij.codeInsight.lookup.LookupElement) HashMap(java.util.HashMap) GrListOrMap(org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.GrListOrMap) Map(java.util.Map) PsiElement(com.intellij.psi.PsiElement)

Example 9 with LookupElementBuilder

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

the class ChooseTypeExpression method calculateLookupItems.

@Override
public LookupElement[] calculateLookupItems(ExpressionContext context) {
    List<LookupElement> result = ContainerUtil.newArrayList();
    for (SmartTypePointer item : myItems) {
        PsiType type = TypesUtil.unboxPrimitiveTypeWrapper(item.getType());
        if (type == null)
            continue;
        PsiTypeLookupItem lookupItem = PsiTypeLookupItem.createLookupItem(type, null, PsiTypeLookupItem.isDiamond(type), IMPORT_FIXER);
        result.add(lookupItem);
    }
    if (myForGroovy) {
        LookupElementBuilder def = LookupElementBuilder.create(GrModifier.DEF).bold();
        if (mySelectDef) {
            result.add(0, def);
        } else {
            result.add(def);
        }
    }
    return result.toArray(new LookupElement[result.size()]);
}
Also used : PsiTypeLookupItem(com.intellij.codeInsight.lookup.PsiTypeLookupItem) LookupElementBuilder(com.intellij.codeInsight.lookup.LookupElementBuilder) LookupElement(com.intellij.codeInsight.lookup.LookupElement)

Example 10 with LookupElementBuilder

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

the class XmlCompletionContributor method addEntityRefCompletions.

private static void addEntityRefCompletions(PsiElement context, CompletionResultSet resultSet) {
    XmlFile containingFile = null;
    XmlFile descriptorFile = null;
    final XmlTag tag = PsiTreeUtil.getParentOfType(context, XmlTag.class);
    if (tag != null) {
        containingFile = (XmlFile) tag.getContainingFile();
        descriptorFile = findDescriptorFile(tag, containingFile);
    }
    if (HtmlUtil.isHtml5Context(tag)) {
        descriptorFile = XmlUtil.findXmlFile(containingFile, Html5SchemaProvider.getCharsDtdLocation());
    } else if (tag == null) {
        final XmlDocument document = PsiTreeUtil.getParentOfType(context, XmlDocument.class);
        if (document != null) {
            containingFile = (XmlFile) document.getContainingFile();
            final FileType ft = containingFile.getFileType();
            if (HtmlUtil.isHtml5Document(document)) {
                descriptorFile = XmlUtil.findXmlFile(containingFile, Html5SchemaProvider.getCharsDtdLocation());
            } else if (ft != StdFileTypes.XML) {
                final String namespace = ft == StdFileTypes.XHTML || ft == StdFileTypes.JSPX ? XmlUtil.XHTML_URI : XmlUtil.HTML_URI;
                final XmlNSDescriptor nsDescriptor = document.getDefaultNSDescriptor(namespace, true);
                if (nsDescriptor != null) {
                    descriptorFile = nsDescriptor.getDescriptorFile();
                }
            }
        }
    }
    if (descriptorFile != null && containingFile != null) {
        final boolean acceptSystemEntities = containingFile.getFileType() == StdFileTypes.XML;
        final PsiElementProcessor processor = new PsiElementProcessor() {

            @Override
            public boolean execute(@NotNull final PsiElement element) {
                if (element instanceof XmlEntityDecl) {
                    final XmlEntityDecl xmlEntityDecl = (XmlEntityDecl) element;
                    if (xmlEntityDecl.isInternalReference() || acceptSystemEntities) {
                        final LookupElementBuilder _item = buildEntityLookupItem(xmlEntityDecl);
                        if (_item != null) {
                            resultSet.addElement(_item);
                            resultSet.stopHere();
                        }
                    }
                }
                return true;
            }
        };
        XmlUtil.processXmlElements(descriptorFile, processor, true);
        if (descriptorFile != containingFile && acceptSystemEntities) {
            final XmlProlog element = containingFile.getDocument().getProlog();
            if (element != null)
                XmlUtil.processXmlElements(element, processor, true);
        }
    }
}
Also used : NotNull(org.jetbrains.annotations.NotNull) PsiElementProcessor(com.intellij.psi.search.PsiElementProcessor) XmlNSDescriptor(com.intellij.xml.XmlNSDescriptor) FileType(com.intellij.openapi.fileTypes.FileType) LookupElementBuilder(com.intellij.codeInsight.lookup.LookupElementBuilder) PsiElement(com.intellij.psi.PsiElement)

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