boolean (final PsiNewExpression expression, final PsiNewExpression context, @Nullable final PsiType expectedType, boolean skipDiamonds) { if (PsiUtil.getLanguageLevel(context).isAtLeast(LanguageLevel.JDK_1_7)) { final PsiJavaCodeReferenceElement classReference = expression.getClassOrAnonymousClassReference(); if (classReference != null) { final PsiReferenceParameterList parameterList = classReference.getParameterList(); if (parameterList != null) { final PsiTypeElement[] typeElements = parameterList.getTypeParameterElements(); if (typeElements.length > 0) { if (!skipDiamonds && typeElements.length == 1 && typeElements[0].getType() instanceof PsiDiamondType) return false; final PsiDiamondTypeImpl.DiamondInferenceResult inferenceResult = PsiDiamondTypeImpl.resolveInferredTypes(expression, context); if (inferenceResult.getErrorMessage() == null) { PsiAnonymousClass anonymousClass = expression.getAnonymousClass(); if (anonymousClass != null && ContainerUtil.exists(anonymousClass.getMethods(), method -> !method.hasModifierProperty(PsiModifier.PRIVATE) && method.findSuperMethods().length == 0)) { return false; } final List<PsiType> types = inferenceResult.getInferredTypes(); PsiType[] typeArguments = null; if (expectedType instanceof PsiClassType) { typeArguments = ((PsiClassType)expectedType).getParameters(); } if (typeArguments == null) { typeArguments = parameterList.getTypeArguments(); } if (types.size() == typeArguments.length) { final PsiMethod method = expression.resolveMethod(); final PsiElement resolve = classReference.resolve(); if (resolve instanceof PsiClass) { final PsiTypeParameter[] typeParameters = ((PsiClass)resolve).getTypeParameters(); return areTypeArgumentsRedundant(typeArguments, context, true, method, typeParameters); } } } } } } } return false; }