Detecting design patterns in source code is essential for understanding and maintaining software architectures, yet remains difficult due to variability in real-world implementations. This paper introduces a neuro-symbolic framework for design pattern detection that combines interpretable structural analysis with learned semantic representations. The approach integrates two complementary signals, i.e., topological conformance via abstract syntax tree analysis under a four-pillar heuristic, and semantic similarity to canonical pattern prototypes in a discriminative latent space. This latent space is obtained by fine-tuning CodeBERT with supervised contrastive learning, yielding cohesive and separable pattern clusters. To mitigate data scarcity and lexical bias, we generate and validate a synthetic dataset using large language models and apply identifier anonymization at the abstract syntax tree level. Evaluation on an unseen synthetic test set and on a manually validated Gold Standard benchmark demonstrates improved robustness over purely structural methods, with strong performance across standard metrics. Overall, combining structural constraints with optimised semantic representations offers a robust and scalable solution for design pattern detection in software architecture analysis.
Intelligent Detection of Design Patterns in Existing Source Code
Passaro, Lucia;Soldani, Jacopo
2026-01-01
Abstract
Detecting design patterns in source code is essential for understanding and maintaining software architectures, yet remains difficult due to variability in real-world implementations. This paper introduces a neuro-symbolic framework for design pattern detection that combines interpretable structural analysis with learned semantic representations. The approach integrates two complementary signals, i.e., topological conformance via abstract syntax tree analysis under a four-pillar heuristic, and semantic similarity to canonical pattern prototypes in a discriminative latent space. This latent space is obtained by fine-tuning CodeBERT with supervised contrastive learning, yielding cohesive and separable pattern clusters. To mitigate data scarcity and lexical bias, we generate and validate a synthetic dataset using large language models and apply identifier anonymization at the abstract syntax tree level. Evaluation on an unseen synthetic test set and on a manually validated Gold Standard benchmark demonstrates improved robustness over purely structural methods, with strong performance across standard metrics. Overall, combining structural constraints with optimised semantic representations offers a robust and scalable solution for design pattern detection in software architecture analysis.I documenti in IRIS sono protetti da copyright e tutti i diritti sono riservati, salvo diversa indicazione.


