Search in sources :

Example 11 with TailType

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

the class SmartCompletionDecorator method handleInsert.

@Override
public void handleInsert(InsertionContext context) {
    if (getObject() instanceof PsiVariable && context.getCompletionChar() == Lookup.REPLACE_SELECT_CHAR) {
        context.commitDocument();
        replaceMethodCallIfNeeded(context);
    }
    context.commitDocument();
    myPosition = getPosition(context, this);
    TailType tailType = computeTailType(context);
    super.handleInsert(context);
    if (tailType == TailType.COMMA) {
        AutoPopupController.getInstance(context.getProject()).autoPopupParameterInfo(context.getEditor(), null);
    }
}
Also used : TailType(com.intellij.codeInsight.TailType)

Example 12 with TailType

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

the class JavaKeywordCompletion method addStatementKeywords.

private static void addStatementKeywords(Consumer<LookupElement> variant, PsiElement position, @Nullable PsiElement prevLeaf) {
    variant.consume(new OverrideableSpace(createKeyword(position, PsiKeyword.SWITCH), TailTypes.SWITCH_LPARENTH));
    variant.consume(new OverrideableSpace(createKeyword(position, PsiKeyword.WHILE), TailTypes.WHILE_LPARENTH));
    variant.consume(new OverrideableSpace(createKeyword(position, PsiKeyword.DO), TailTypes.DO_LBRACE));
    variant.consume(new OverrideableSpace(createKeyword(position, PsiKeyword.FOR), TailTypes.FOR_LPARENTH));
    variant.consume(new OverrideableSpace(createKeyword(position, PsiKeyword.IF), TailTypes.IF_LPARENTH));
    variant.consume(new OverrideableSpace(createKeyword(position, PsiKeyword.TRY), TailTypes.TRY_LBRACE));
    variant.consume(new OverrideableSpace(createKeyword(position, PsiKeyword.THROW), TailType.INSERT_SPACE));
    variant.consume(new OverrideableSpace(createKeyword(position, PsiKeyword.NEW), TailType.INSERT_SPACE));
    variant.consume(new OverrideableSpace(createKeyword(position, PsiKeyword.SYNCHRONIZED), TailTypes.SYNCHRONIZED_LPARENTH));
    if (PsiUtil.getLanguageLevel(position).isAtLeast(LanguageLevel.JDK_1_4)) {
        variant.consume(new OverrideableSpace(createKeyword(position, PsiKeyword.ASSERT), TailType.INSERT_SPACE));
    }
    TailType returnTail = getReturnTail(position);
    LookupElement ret = createKeyword(position, PsiKeyword.RETURN);
    if (returnTail != TailType.NONE) {
        ret = new OverrideableSpace(ret, returnTail);
    }
    variant.consume(ret);
    if (psiElement().withText(";").withSuperParent(2, PsiIfStatement.class).accepts(prevLeaf) || psiElement().withText("}").withSuperParent(3, PsiIfStatement.class).accepts(prevLeaf)) {
        variant.consume(new OverrideableSpace(createKeyword(position, PsiKeyword.ELSE), TailType.HUMBLE_SPACE_BEFORE_WORD));
    }
    if (psiElement().withText("}").withParent(psiElement(PsiCodeBlock.class).withParent(or(psiElement(PsiTryStatement.class), psiElement(PsiCatchSection.class)))).accepts(prevLeaf)) {
        variant.consume(new OverrideableSpace(createKeyword(position, PsiKeyword.CATCH), TailTypes.CATCH_LPARENTH));
        variant.consume(new OverrideableSpace(createKeyword(position, PsiKeyword.FINALLY), TailTypes.FINALLY_LBRACE));
    }
}
Also used : TailType(com.intellij.codeInsight.TailType)

Example 13 with TailType

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

the class JavaKeywordCompletion method addExpressionKeywords.

private static void addExpressionKeywords(CompletionParameters parameters, Consumer<LookupElement> result, PsiElement position, @Nullable PsiElement prevLeaf, boolean statementPosition) {
    if (psiElement(JavaTokenType.DOUBLE_COLON).accepts(prevLeaf)) {
        PsiMethodReferenceExpression parent = PsiTreeUtil.getParentOfType(parameters.getPosition(), PsiMethodReferenceExpression.class);
        TailType tail = parent != null && !LambdaHighlightingUtil.insertSemicolon(parent.getParent()) ? TailType.SEMICOLON : TailType.NONE;
        result.consume(new OverrideableSpace(createKeyword(position, PsiKeyword.NEW), tail));
        return;
    }
    if (isExpressionPosition(position)) {
        if (PsiTreeUtil.getParentOfType(position, PsiAnnotation.class) == null) {
            if (!statementPosition) {
                result.consume(TailTypeDecorator.withTail(createKeyword(position, PsiKeyword.NEW), TailType.INSERT_SPACE));
            }
            result.consume(createKeyword(position, PsiKeyword.NULL));
        }
        if (mayExpectBoolean(parameters)) {
            result.consume(createKeyword(position, PsiKeyword.TRUE));
            result.consume(createKeyword(position, PsiKeyword.FALSE));
        }
    }
}
Also used : TailType(com.intellij.codeInsight.TailType)

Example 14 with TailType

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

the class TypeArgumentCompletionProvider method fillAllArgs.

private void fillAllArgs(CompletionResultSet resultSet, PsiElement context, ExpectedTypeInfo info, List<PsiType> expectedArgs, PsiTypeParameterListOwner paramOwner) {
    List<PsiTypeLookupItem> typeItems = ContainerUtil.map(expectedArgs, arg -> PsiTypeLookupItem.createLookupItem(arg, context));
    TailType globalTail = mySmart ? info.getTailType() : TailType.NONE;
    TypeArgsLookupElement element = new TypeArgsLookupElement(typeItems, globalTail, hasParameters(paramOwner, context));
    element.registerSingleClass(mySession);
    resultSet.addElement(element);
}
Also used : PsiTypeLookupItem(com.intellij.codeInsight.lookup.PsiTypeLookupItem) TailType(com.intellij.codeInsight.TailType) CharTailType(com.intellij.codeInsight.CharTailType)

Example 15 with TailType

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

the class XmlTagInsertHandler method handleInsert.

@Override
public void handleInsert(InsertionContext context, LookupElement item) {
    Project project = context.getProject();
    Editor editor = context.getEditor();
    // Need to insert " " to prevent creating tags like <tagThis is my text
    InjectedLanguageUtil.getTopLevelEditor(editor).getDocument().putUserData(ENFORCING_TAG, Boolean.TRUE);
    final int offset = editor.getCaretModel().getOffset();
    editor.getDocument().insertString(offset, " ");
    PsiDocumentManager.getInstance(project).commitDocument(editor.getDocument());
    PsiElement current = context.getFile().findElementAt(context.getStartOffset());
    editor.getDocument().deleteString(offset, offset + 1);
    InjectedLanguageUtil.getTopLevelEditor(editor).getDocument().putUserData(ENFORCING_TAG, null);
    final XmlTag tag = PsiTreeUtil.getContextOfType(current, XmlTag.class, true);
    if (tag == null)
        return;
    if (context.getCompletionChar() != Lookup.COMPLETE_STATEMENT_SELECT_CHAR) {
        context.setAddCompletionChar(false);
    }
    final XmlElementDescriptor descriptor = tag.getDescriptor();
    if (XmlUtil.getTokenOfType(tag, XmlTokenType.XML_TAG_END) == null && XmlUtil.getTokenOfType(tag, XmlTokenType.XML_EMPTY_ELEMENT_END) == null) {
        if (descriptor != null) {
            insertIncompleteTag(context.getCompletionChar(), editor, tag);
        }
    } else if (context.getCompletionChar() == Lookup.REPLACE_SELECT_CHAR) {
        PsiDocumentManager.getInstance(project).commitAllDocuments();
        int caretOffset = editor.getCaretModel().getOffset();
        PsiElement otherTag = PsiTreeUtil.getParentOfType(context.getFile().findElementAt(caretOffset), XmlTag.class);
        PsiElement endTagStart = XmlUtil.getTokenOfType(otherTag, XmlTokenType.XML_END_TAG_START);
        if (endTagStart != null) {
            PsiElement sibling = endTagStart.getNextSibling();
            assert sibling != null;
            ASTNode node = sibling.getNode();
            assert node != null;
            if (node.getElementType() == XmlTokenType.XML_NAME) {
                int sOffset = sibling.getTextRange().getStartOffset();
                int eOffset = sibling.getTextRange().getEndOffset();
                editor.getDocument().deleteString(sOffset, eOffset);
                editor.getDocument().insertString(sOffset, ((XmlTag) otherTag).getName());
            }
        }
        editor.getCaretModel().moveToOffset(caretOffset + 1);
        editor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE);
        editor.getSelectionModel().removeSelection();
    }
    if (context.getCompletionChar() == ' ' && TemplateManager.getInstance(project).getActiveTemplate(editor) != null) {
        return;
    }
    final TailType tailType = LookupItem.handleCompletionChar(editor, item, context.getCompletionChar());
    tailType.processTail(editor, editor.getCaretModel().getOffset());
}
Also used : Project(com.intellij.openapi.project.Project) ASTNode(com.intellij.lang.ASTNode) Editor(com.intellij.openapi.editor.Editor) PsiElement(com.intellij.psi.PsiElement) XmlTag(com.intellij.psi.xml.XmlTag) 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