public static PsiDiamondType getDiamondType(PsiNewExpression expression) {
    if (PsiUtil.isAvailable(JavaFeature.DIAMOND_TYPES, expression)) {
      final PsiJavaCodeReferenceElement classReference = expression.getClassOrAnonymousClassReference();
      if (classReference != null) {
        final PsiReferenceParameterList parameterList = classReference.getParameterList();
        if (parameterList != null) {
          final PsiTypeElement[] parameterElements = parameterList.getTypeParameterElements();
          if (parameterElements.length == 1) {
            final PsiType type = parameterElements[0].getType();
            return type instanceof PsiDiamondType ? (PsiDiamondType)type : null;
          }
        }
      }
    }
    return null;
  }
public static PsiDiamondType getDiamondType(PsiNewExpression expression)