Using Codecharts for formally modelling and automating detection of patterns with application to Security Patterns