Skip to content

Commit

Permalink
feat: warnings for duplicates
Browse files Browse the repository at this point in the history
closes #266, #350
  • Loading branch information
alandefreitas committed Jun 24, 2024
1 parent 71ab1e6 commit a691052
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions src/lib/AST/ParseJavadoc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -958,6 +958,18 @@ visitBlockCommandComment(
auto scope = enterScope(returns);
// Scope scope(returns, block_);
visitChildren(C->getParagraph());

auto itr = std::ranges::find_if(
jd_.getBlocks(),
[&](const std::unique_ptr<doc::Block> & b)
{
return b->kind != doc::Kind::returns;
});
if (itr != jd_.getBlocks().end())
{
report::warn("{}: Duplicate @returns statement", C->getBeginLoc().printToString(sm_));
}

jd_.emplace_back(std::move(returns));
return;
}
Expand Down Expand Up @@ -1298,6 +1310,24 @@ visitParamCommandComment(

auto scope = enterScope(param);
visitChildren(C->getParagraph());

auto itr = std::ranges::find_if(
jd_.getBlocks(),
[&](const std::unique_ptr<doc::Block> & b)
{
if (b->kind != doc::Kind::param)
return false;
auto p = dynamic_cast<const doc::Param*>(b.get());
MRDOCS_ASSERT(p != nullptr);
return p->name == param.name;
});
if (itr != jd_.getBlocks().end())
{
report::warn(
"{}: Duplicate @param for argument {}",
C->getBeginLoc().printToString(sm_), param.name);
}

// We want the node even if it is empty
jd_.emplace_back(std::move(param));
}
Expand All @@ -1320,6 +1350,24 @@ visitTParamCommandComment(
}
auto scope = enterScope(tparam);
visitChildren(C->getParagraph());

auto itr = std::ranges::find_if(
jd_.getBlocks(),
[&](const std::unique_ptr<doc::Block> & b)
{
if (b->kind != doc::Kind::tparam)
return false;
auto tp = dynamic_cast<const doc::TParam*>(b.get());
MRDOCS_ASSERT(tp != nullptr);
return tp->name == tparam.name;
});
if (itr != jd_.getBlocks().end())
{
report::warn(
"{}: Duplicate @tparam for argument {}",
C->getBeginLoc().printToString(sm_), tparam.name);
}

// We want the node even if it is empty
jd_.emplace_back(std::move(tparam));
}
Expand Down

0 comments on commit a691052

Please sign in to comment.