void (@NotNull InsertionContext context) { int startOffset = context.getStartOffset(); int endOffset = context.getEditor().getCaretModel().getOffset(); Document document = context.getDocument(); String canonicalText = myModel.getCanonicalText(); document.replaceString(startOffset, endOffset, canonicalText); PsiDocumentManager.getInstance(context.getProject()).commitDocument(document); PsiDeconstructionPattern pattern = PsiTreeUtil.getParentOfType(context.getFile().findElementAt(startOffset), PsiDeconstructionPattern.class); TextRange patternRange = pattern == null ? null : pattern.getTextRange(); if (patternRange == null || patternRange.getStartOffset() != startOffset || patternRange.getLength() != canonicalText.length()) { document.replaceString(startOffset, startOffset+canonicalText.length(), myModel.toString()); return; } pattern = (PsiDeconstructionPattern)JavaCodeStyleManager.getInstance(context.getProject()).shortenClassReferences(pattern); context.setTailOffset(pattern.getTextRange().getEndOffset()); super.handleInsert(context); }