void (@NotNull InsertionContext context, @NotNull JavaPsiClassReferenceElement item) { PsiFile file = context.getFile(); Editor editor = context.getEditor(); int endOffset = editor.getCaretModel().getOffset(); if (PsiTreeUtil.findElementOfClassAtOffset(file, endOffset - 1, GrImportStatement.class, false) != null || !(file instanceof GroovyFileBase)) { AllClassesGetter.INSERT_FQN.handleInsert(context, item); return; } PsiDocumentManager.getInstance(context.getProject()).commitDocument(editor.getDocument()); PsiElement position = file.findElementAt(endOffset - 1); boolean parens = shouldInsertParentheses(position); final PsiClass psiClass = item.getObject(); if (isInVariable(position) || GroovyCompletionUtil.isInPossibleClosureParameter(position)) { Project project = context.getProject(); String qname = psiClass.getQualifiedName(); String shortName = psiClass.getName(); if (qname == null) return; PsiClass aClass = JavaPsiFacade.getInstance(project).getResolveHelper().resolveReferencedClass(shortName, position); if (aClass == null) { ((GroovyFileBase)file).addImportForClass(psiClass); return; } else if (aClass == CompletionUtil.getOriginalOrSelf(psiClass)) { return; } } AllClassesGetter.TRY_SHORTENING.handleInsert(context, item); if (parens && context.getCompletionChar() != '[') { int identifierEnd = context.getTailOffset(); GroovyPsiElement place = PsiTreeUtil.findElementOfClassAtOffset(context.getFile(), context.getStartOffset(), GroovyPsiElement.class, false); JavaCompletionUtil.insertParentheses(context, item, false, place != null && GroovyCompletionUtil.hasConstructorParameters(psiClass, place)); if (context.getCompletionChar() == '<' || psiClass.hasTypeParameters() && context.getCompletionChar() != '(') { context.setAddCompletionChar(false); JavaCompletionUtil.promptTypeArgs(context, identifierEnd); } } }