Feature Envy, a common code smell characterized by excessive reliance on external classes, undermines software maintainability by violating principles of cohesion and coupling. Traditional detection methods, which rely on heuristic thresholds and machine learning approaches, face limitations in generalizability and semantic understanding. In contrast, large language models (LLMs) offer promising capabilities for code analysis through deep semantic modeling. This study explores the performance of LLMs in Feature Envy detection, proposing a context-aware and reasoning-driven detection framework. The framework extracts relevant information from the target method and its containing class, incorporating reasoning-structured prompt designs to enhance detection accuracy. We examine three research questions: (1) the impact of prompt design on detection performance, particularly reasoning-based prompts (e.g., Chain-of-Thought and Tree-of-Thought), (2) the comparative effectiveness of state-of-the-art LLMs, and (3) model adaptability across four severity levels of Feature Envy. Experimental results reveal that reasoning-based prompts outperform non-reasoning prompts in 75% of scenarios, with significant improvements in F1-score, MCC, and Recall. Among evaluated models, DeepSeek-V3 achieves the highest overall performance, while GPT-4 excels in precision-critical tasks. Severity-level analysis shows DeepSeek-V3 and CodeLlama-7b excel in detecting high-severity instances, whereas GPT-4 demonstrates proficiency in identifying non-smell cases. These findings underscore the potential of LLMs in code smell detection and provide valuable insights for LLM-driven tools in technical debt management.

错误:搜索内容不能为空,请输入英文关键词
错误:关键词超出字数限制,请精简
高级检索

Leveraging Large Language Models for Feature Envy Detection: A Context-Aware and Reasoning-Driven Approach

  • Jiamin Guo,
  • Yangyang Zhao,
  • Zhifei Chen,
  • Liming Nie

摘要

Feature Envy, a common code smell characterized by excessive reliance on external classes, undermines software maintainability by violating principles of cohesion and coupling. Traditional detection methods, which rely on heuristic thresholds and machine learning approaches, face limitations in generalizability and semantic understanding. In contrast, large language models (LLMs) offer promising capabilities for code analysis through deep semantic modeling. This study explores the performance of LLMs in Feature Envy detection, proposing a context-aware and reasoning-driven detection framework. The framework extracts relevant information from the target method and its containing class, incorporating reasoning-structured prompt designs to enhance detection accuracy. We examine three research questions: (1) the impact of prompt design on detection performance, particularly reasoning-based prompts (e.g., Chain-of-Thought and Tree-of-Thought), (2) the comparative effectiveness of state-of-the-art LLMs, and (3) model adaptability across four severity levels of Feature Envy. Experimental results reveal that reasoning-based prompts outperform non-reasoning prompts in 75% of scenarios, with significant improvements in F1-score, MCC, and Recall. Among evaluated models, DeepSeek-V3 achieves the highest overall performance, while GPT-4 excels in precision-critical tasks. Severity-level analysis shows DeepSeek-V3 and CodeLlama-7b excel in detecting high-severity instances, whereas GPT-4 demonstrates proficiency in identifying non-smell cases. These findings underscore the potential of LLMs in code smell detection and provide valuable insights for LLM-driven tools in technical debt management.