LookupElement (PsiType type, final PsiElement place, CompletionParameters parameters, @Nullable PsiType diamond) { if (!JavaCompletionUtil.hasAccessibleConstructor(type, place)) return null; final PsiClass psiClass = com.intellij.psi.util.PsiUtil.resolveClassInType(type); if (psiClass == null) return null; if (!checkForInnerClass(psiClass, place)) return null; boolean isDiamond = false; if (diamond != null && psiClass.hasTypeParameters() && !((PsiClassType)type).isRaw() && !psiClass.hasModifierProperty(PsiModifier.ABSTRACT)) { final String canonicalText = TypeConversionUtil.erasure(type).getCanonicalText(); final GroovyPsiElementFactory elementFactory = GroovyPsiElementFactory.getInstance(place.getProject()); final String text = diamond.getCanonicalText() + " v = new " + canonicalText + "<>()"; final GrStatement statement = elementFactory.createStatementFromText(text, parameters.getOriginalFile()); final GrVariable declaredVar = ((GrVariableDeclaration)statement).getVariables()[0]; final GrNewExpression initializer = (GrNewExpression)declaredVar.getInitializerGroovy(); assert initializer != null; final boolean hasDefaultConstructorOrNoGenericsOne = PsiDiamondTypeImpl.hasDefaultConstructor(psiClass) || !PsiDiamondTypeImpl.haveConstructorsGenericsParameters(psiClass); final PsiType initializerType = initializer.getType(); if (hasDefaultConstructorOrNoGenericsOne && initializerType instanceof PsiClassType && ((PsiClassType)initializerType).getParameters().length > 0) { type = initializerType; isDiamond = true; } } final PsiTypeLookupItem item = PsiTypeLookupItem.createLookupItem(GenericsUtil.eliminateWildcards(type), place, isDiamond, ChooseTypeExpression.IMPORT_FIXER).setShowPackage(); Object object = item.getObject(); if (object instanceof PsiClass && ((PsiClass)object).hasModifierProperty(PsiModifier.ABSTRACT)) { item.setIndicateAnonymous(true); } item.setInsertHandler(new AfterNewClassInsertHandler((PsiClassType)type, true)); return item; }