From a691052920b24dcd1cf011fc513d300b0a951589 Mon Sep 17 00:00:00 2001 From: alandefreitas Date: Mon, 24 Jun 2024 18:50:28 -0300 Subject: [PATCH] feat: warnings for duplicates closes #266, #350 --- src/lib/AST/ParseJavadoc.cpp | 48 ++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/src/lib/AST/ParseJavadoc.cpp b/src/lib/AST/ParseJavadoc.cpp index 765932738..b6d2166a4 100644 --- a/src/lib/AST/ParseJavadoc.cpp +++ b/src/lib/AST/ParseJavadoc.cpp @@ -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 & 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; } @@ -1298,6 +1310,24 @@ visitParamCommandComment( auto scope = enterScope(param); visitChildren(C->getParagraph()); + + auto itr = std::ranges::find_if( + jd_.getBlocks(), + [&](const std::unique_ptr & b) + { + if (b->kind != doc::Kind::param) + return false; + auto p = dynamic_cast(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)); } @@ -1320,6 +1350,24 @@ visitTParamCommandComment( } auto scope = enterScope(tparam); visitChildren(C->getParagraph()); + + auto itr = std::ranges::find_if( + jd_.getBlocks(), + [&](const std::unique_ptr & b) + { + if (b->kind != doc::Kind::tparam) + return false; + auto tp = dynamic_cast(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)); }