🤖 AI Summary
To address the limited practicality of large language model (LLM)-generated code comments in scenarios with scarce or absent code documentation, this paper proposes a design-document-enhanced, context-aware comment generation method. The core innovation lies in the first integration of structured design documents into LLM prompts—semantically parsing design documentation and explicitly aligning it with target code snippets to model developer intent and architectural constraints. Our approach employs a lightweight document parser and context-fusion mechanism, requiring no model fine-tuning. Extensive experiments across multiple programming languages and real-world projects demonstrate that, compared to code-only baselines, our method significantly improves comment usefulness (+32.7%) and accuracy (+28.4%). Notably, it enhances codebase maintainability and comprehension efficiency—particularly for novice developers—by grounding comments in architectural context and design rationale.
📝 Abstract
Comments are very useful to the flow of code development. With the increasing commonality of code, novice coders have been creating a significant amount of codebases. Due to lack of commenting standards, their comments are often useless, and increase the time taken to further maintain codes. This study intends to find the usefulness of large language models (LLMs) in these cases to generate potentially better comments. This study focuses on the feasibility of design documents as a context for the LLMs to generate more useful comments, as design documents are often used by maintainers to understand code when comments do not suffice.