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);
}
}
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));
}
}
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));
}
}
}
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);
}
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());
}
Aggregations