@@ -340,10 +340,137 @@ copyBriefAndDetails(Javadoc& javadoc)
340
340
{
341
341
javadoc.brief = src.brief ;
342
342
}
343
- if (copyDetails && !src. blocks . empty () )
343
+ if (copyDetails)
344
344
{
345
- blockIt = javadoc.blocks .insert (blockIt, src.blocks .begin (), src.blocks .end ());
346
- blockIt = std::next (blockIt, src.blocks .size ());
345
+ // Copy detail blocks
346
+ if (!src.blocks .empty ())
347
+ {
348
+ blockIt = javadoc.blocks .insert (blockIt, src.blocks .begin (), src.blocks .end ());
349
+ blockIt = std::next (blockIt, src.blocks .size ());
350
+ }
351
+ // Copy returns only if destination is empty
352
+ if (javadoc.returns .empty ())
353
+ {
354
+ javadoc.returns .insert (
355
+ javadoc.returns .end (),
356
+ src.returns .begin (),
357
+ src.returns .end ());
358
+ }
359
+ // Copy only params that don't exist at the destination
360
+ // documentation but that do exist in the destination
361
+ // function parameters declaration.
362
+ if (current_context_->isFunction ())
363
+ {
364
+ auto const & FI = dynamic_cast <FunctionInfo const &>(*current_context_);
365
+ for (auto const & srcParam: src.params )
366
+ {
367
+ if (std::ranges::find_if (javadoc.params ,
368
+ [&srcParam](doc::Param const & destParam)
369
+ {
370
+ return srcParam.name == destParam.name ;
371
+ }) != javadoc.params .end ())
372
+ {
373
+ // param already exists at the destination,
374
+ // so the user attributed a new meaning to it
375
+ continue ;
376
+ }
377
+ if (std::ranges::find_if (FI.Params ,
378
+ [&srcParam](Param const & destParam)
379
+ {
380
+ return srcParam.name == destParam.Name ;
381
+ }) == FI.Params .end ())
382
+ {
383
+ // param does not exist in the destination function
384
+ // so it would be an error there
385
+ continue ;
386
+ }
387
+ // Push the new param
388
+ javadoc.params .push_back (srcParam);
389
+ }
390
+ }
391
+ // Copy only tparams that don't exist at the destination
392
+ // documentation but that do exist in the destination
393
+ // template parameters.
394
+ TemplateInfo const * destTemplate = visit (
395
+ *current_context_,
396
+ [](auto & I) -> TemplateInfo const *
397
+ {
398
+ if constexpr (requires { I.Template ; })
399
+ {
400
+ if (I.Template )
401
+ {
402
+ return &*I.Template ;
403
+ }
404
+ }
405
+ return nullptr ;
406
+ });
407
+ if (destTemplate)
408
+ {
409
+ for (auto const & srcTParam: src.tparams )
410
+ {
411
+ if (std::ranges::find_if (javadoc.tparams ,
412
+ [&srcTParam](doc::TParam const & destTParam)
413
+ {
414
+ return srcTParam.name == destTParam.name ;
415
+ }) != javadoc.tparams .end ())
416
+ {
417
+ // tparam already exists at the destination,
418
+ // so the user attributed a new meaning to it
419
+ continue ;
420
+ }
421
+ if (std::ranges::find_if (destTemplate->Params ,
422
+ [&srcTParam](Polymorphic<TParam> const & destTParam)
423
+ {
424
+ return srcTParam.name == destTParam->Name ;
425
+ }) == destTemplate->Params .end ())
426
+ {
427
+ // TParam does not exist in the destination definition
428
+ // so it would be an error there
429
+ continue ;
430
+ }
431
+ // Push the new param
432
+ javadoc.tparams .push_back (srcTParam);
433
+ }
434
+ }
435
+ // exceptions
436
+ if (javadoc.exceptions .empty ())
437
+ {
438
+ bool const isNoExcept =
439
+ current_context_->isFunction () ?
440
+ dynamic_cast <FunctionInfo const &>(*current_context_).Noexcept .Kind == NoexceptKind::False :
441
+ false ;
442
+ if (!isNoExcept)
443
+ {
444
+ javadoc.exceptions .insert (
445
+ javadoc.exceptions .end (),
446
+ src.exceptions .begin (),
447
+ src.exceptions .end ());
448
+ }
449
+ }
450
+ // sees
451
+ if (javadoc.sees .empty ())
452
+ {
453
+ javadoc.sees .insert (
454
+ javadoc.sees .end (),
455
+ src.sees .begin (),
456
+ src.sees .end ());
457
+ }
458
+ // preconditions
459
+ if (javadoc.preconditions .empty ())
460
+ {
461
+ javadoc.preconditions .insert (
462
+ javadoc.preconditions .end (),
463
+ src.preconditions .begin (),
464
+ src.preconditions .end ());
465
+ }
466
+ // postconditions
467
+ if (javadoc.postconditions .empty ())
468
+ {
469
+ javadoc.postconditions .insert (
470
+ javadoc.postconditions .end (),
471
+ src.postconditions .begin (),
472
+ src.postconditions .end ());
473
+ }
347
474
continue ;
348
475
}
349
476
// Erasing the paragraph could make the iterator == end()
0 commit comments