void (@NotNull CompletionParameters parameters, @NotNull ProcessingContext context, @NotNull CompletionResultSet result) { final PsiElement position = parameters.getPosition(); final GrTypeCastExpression parenthesizedExpression = ((GrTypeCastExpression)position.getParent().getParent().getParent()); final PsiElement assignment = parenthesizedExpression.getParent(); if (assignment instanceof GrAssignmentExpression && ((GrAssignmentExpression)assignment).getLValue() == parenthesizedExpression) { return; } final boolean overwrite = PlatformPatterns.psiElement() .afterLeaf(PlatformPatterns.psiElement().withText("(").withParent(GrTypeCastExpression.class)) .accepts(parameters.getOriginalPosition()); final Set<TypeConstraint> typeConstraints = getExpectedTypeInfos(parameters); for (TypeConstraint typeConstraint : typeConstraints) { final PsiType type = typeConstraint.getType(); final PsiTypeLookupItem item = PsiTypeLookupItem.createLookupItem(type, position, PsiTypeLookupItem.isDiamond(type), ChooseTypeExpression.IMPORT_FIXER) .setShowPackage(); item.setInsertHandler(new InsertHandler<>() { @Override public void handleInsert(@NotNull InsertionContext context, @NotNull LookupElement item) { FeatureUsageTracker.getInstance().triggerFeatureUsed("editing.completion.smarttype.casting"); final Editor editor = context.getEditor(); final Document document = editor.getDocument(); if (overwrite) { document.deleteString(context.getSelectionEndOffset(), context.getOffsetMap().getOffset(CompletionInitializationContext.IDENTIFIER_END_OFFSET)); } final CommonCodeStyleSettings csSettings = CodeStyle.getLanguageSettings(context.getFile(), GroovyLanguage.INSTANCE); final int oldTail = context.getTailOffset(); context.setTailOffset(GroovyCompletionUtil.addRParenth(editor, oldTail, csSettings.SPACE_WITHIN_CAST_PARENTHESES)); if (csSettings.SPACE_AFTER_TYPE_CAST) { context.setTailOffset(TailType.insertChar(editor, context.getTailOffset(), ' ')); } editor.getCaretModel().moveToOffset(context.getTailOffset()); editor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE); GroovyCompletionUtil.addImportForItem(context.getFile(), context.getStartOffset(), item); } }); result.addElement(item); } }