Search in sources :

Example 6 with TailType

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

the class SmartCompletionDecorator method computeTailType.

@Override
protected TailType computeTailType(InsertionContext context) {
    if (context.getCompletionChar() == Lookup.COMPLETE_STATEMENT_SELECT_CHAR) {
        return TailType.NONE;
    }
    if (LookupItem.getDefaultTailType(context.getCompletionChar()) != null) {
        return null;
    }
    LookupElement delegate = getDelegate();
    LookupItem item = as(LookupItem.CLASS_CONDITION_KEY);
    Object object = delegate.getObject();
    if (!CodeInsightSettings.getInstance().AUTOINSERT_PAIR_BRACKET && (object instanceof PsiMethod || object instanceof PsiClass)) {
        return TailType.NONE;
    }
    final PsiExpression enclosing = PsiTreeUtil.getContextOfType(myPosition, PsiExpression.class, true);
    if (enclosing != null) {
        final PsiType type = JavaCompletionUtil.getLookupElementType(delegate);
        final TailType itemType = item != null ? item.getTailType() : TailType.NONE;
        if (type != null && type.isValid()) {
            Set<TailType> voidTyped = new HashSet<>();
            Set<TailType> sameTyped = new HashSet<>();
            Set<TailType> assignableTyped = new HashSet<>();
            for (ExpectedTypeInfo info : myExpectedTypeInfos) {
                final PsiType infoType = info.getType();
                final PsiType originalInfoType = JavaCompletionUtil.originalize(infoType);
                if (PsiType.VOID.equals(infoType)) {
                    voidTyped.add(info.getTailType());
                } else if (infoType.equals(type) || originalInfoType.equals(type)) {
                    sameTyped.add(info.getTailType());
                } else if ((info.getKind() == ExpectedTypeInfo.TYPE_OR_SUBTYPE && (infoType.isAssignableFrom(type) || originalInfoType.isAssignableFrom(type))) || (info.getKind() == ExpectedTypeInfo.TYPE_OR_SUPERTYPE && (type.isAssignableFrom(infoType) || type.isAssignableFrom(originalInfoType)))) {
                    assignableTyped.add(info.getTailType());
                }
            }
            if (!sameTyped.isEmpty()) {
                return sameTyped.size() == 1 ? sameTyped.iterator().next() : itemType;
            }
            if (!assignableTyped.isEmpty()) {
                return assignableTyped.size() == 1 ? assignableTyped.iterator().next() : itemType;
            }
            if (!voidTyped.isEmpty()) {
                return voidTyped.size() == 1 ? voidTyped.iterator().next() : itemType;
            }
        } else {
            if (myExpectedTypeInfos.size() == 1) {
                return myExpectedTypeInfos.iterator().next().getTailType();
            }
        }
        return itemType;
    }
    return null;
}
Also used : ExpectedTypeInfo(com.intellij.codeInsight.ExpectedTypeInfo) LookupItem(com.intellij.codeInsight.lookup.LookupItem) LookupElement(com.intellij.codeInsight.lookup.LookupElement) TailType(com.intellij.codeInsight.TailType) THashSet(gnu.trove.THashSet) HashSet(java.util.HashSet)

Example 7 with TailType

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

the class CompletionData method objectToLookupItem.

public static LookupElement objectToLookupItem(@NotNull final Object object) {
    if (object instanceof LookupElement)
        return (LookupElement) object;
    String s = null;
    TailType tailType = TailType.NONE;
    if (object instanceof PsiElement) {
        s = PsiUtilCore.getName((PsiElement) object);
    } else if (object instanceof PsiMetaData) {
        s = ((PsiMetaData) object).getName();
    } else if (object instanceof String) {
        s = (String) object;
    } else if (object instanceof Template) {
        s = ((Template) object).getKey();
    } else if (object instanceof PresentableLookupValue) {
        s = ((PresentableLookupValue) object).getPresentation();
    }
    if (s == null) {
        throw new AssertionError("Null string for object: " + object + " of class " + object.getClass());
    }
    LookupItem item = new LookupItem(object, s);
    if (object instanceof LookupValueWithUIHint && ((LookupValueWithUIHint) object).isBold()) {
        item.setBold();
    }
    item.setAttribute(LookupItem.TAIL_TYPE_ATTR, tailType);
    return item;
}
Also used : PsiMetaData(com.intellij.psi.meta.PsiMetaData) LookupValueWithUIHint(com.intellij.codeInsight.lookup.LookupValueWithUIHint) LookupItem(com.intellij.codeInsight.lookup.LookupItem) LookupElement(com.intellij.codeInsight.lookup.LookupElement) PresentableLookupValue(com.intellij.codeInsight.lookup.PresentableLookupValue) TailType(com.intellij.codeInsight.TailType) Template(com.intellij.codeInsight.template.Template)

Example 8 with TailType

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

the class LookupItem method handleInsert.

@Override
public void handleInsert(final InsertionContext context) {
    final InsertHandler<? extends LookupElement> handler = getInsertHandler();
    if (handler != null) {
        //noinspection unchecked
        ((InsertHandler) handler).handleInsert(context, this);
    }
    if (getTailType() != TailType.UNKNOWN && myInsertHandler == null) {
        context.setAddCompletionChar(false);
        final TailType type = handleCompletionChar(context.getEditor(), this, context.getCompletionChar());
        type.processTail(context.getEditor(), context.getTailOffset());
    }
}
Also used : InsertHandler(com.intellij.codeInsight.completion.InsertHandler) CharTailType(com.intellij.codeInsight.CharTailType) TailType(com.intellij.codeInsight.TailType)

Example 9 with TailType

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

the class LookupItem method handleCompletionChar.

@NotNull
public static TailType handleCompletionChar(@NotNull final Editor editor, @NotNull final LookupElement lookupElement, final char completionChar) {
    final TailType type = getDefaultTailType(completionChar);
    if (type != null) {
        return type;
    }
    if (lookupElement instanceof LookupItem) {
        final LookupItem<?> item = (LookupItem) lookupElement;
        final TailType attr = item.getAttribute(TAIL_TYPE_ATTR);
        if (attr != null) {
            return attr;
        }
    }
    return TailType.NONE;
}
Also used : CharTailType(com.intellij.codeInsight.CharTailType) TailType(com.intellij.codeInsight.TailType) NotNull(org.jetbrains.annotations.NotNull)

Example 10 with TailType

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

the class DefaultInsertHandler method handleInsert.

@Override
public void handleInsert(final InsertionContext context, LookupElement lookupElement) {
    context.commitDocument();
    TailType tailType = getTailType(context.getCompletionChar(), (LookupItem) lookupElement);
    final Editor editor = context.getEditor();
    editor.getCaretModel().moveToOffset(context.getSelectionEndOffset());
    tailType.processTail(editor, context.getSelectionEndOffset());
    editor.getSelectionModel().removeSelection();
    if (tailType == TailType.DOT || context.getCompletionChar() == '.') {
        AutoPopupController.getInstance(context.getProject()).autoPopupMemberLookup(editor, null);
    }
}
Also used : Editor(com.intellij.openapi.editor.Editor) CharTailType(com.intellij.codeInsight.CharTailType) TailType(com.intellij.codeInsight.TailType)

Aggregations

TailType (com.intellij.codeInsight.TailType)15 CharTailType (com.intellij.codeInsight.CharTailType)4 Editor (com.intellij.openapi.editor.Editor)3 LookupElement (com.intellij.codeInsight.lookup.LookupElement)2 LookupItem (com.intellij.codeInsight.lookup.LookupItem)2 Template (com.intellij.codeInsight.template.Template)2 PsiElement (com.intellij.psi.PsiElement)2 PsiMetaData (com.intellij.psi.meta.PsiMetaData)2 NotNull (org.jetbrains.annotations.NotNull)2 ExpectedTypeInfo (com.intellij.codeInsight.ExpectedTypeInfo)1 InsertHandler (com.intellij.codeInsight.completion.InsertHandler)1 JavaMethodCallElement (com.intellij.codeInsight.completion.JavaMethodCallElement)1 ParenthesesInsertHandler (com.intellij.codeInsight.completion.util.ParenthesesInsertHandler)1 LookupValueWithUIHint (com.intellij.codeInsight.lookup.LookupValueWithUIHint)1 PresentableLookupValue (com.intellij.codeInsight.lookup.PresentableLookupValue)1 PsiTypeLookupItem (com.intellij.codeInsight.lookup.PsiTypeLookupItem)1 CfmlAttributeDescription (com.intellij.coldFusion.model.info.CfmlAttributeDescription)1 CfmlComponent (com.intellij.coldFusion.model.psi.CfmlComponent)1 CfmlTag (com.intellij.coldFusion.model.psi.CfmlTag)1 CfmlAttributeImpl (com.intellij.coldFusion.model.psi.impl.CfmlAttributeImpl)1