The problem you are talking about is well known in the research clone community and one of the main problems why many people use cloning in practice. SonarQube implements a fairly simple and naive algorithm that detects code duplication based on sequences of tokens and therefore does not understand what a method is (besides a number of other problems). So the answer to your question is no .
One solution would be to look for a clone detection algorithm that detects code duplication based on abstract syntax trees (AST). But, as far as I know, there is no such tool for free.
An alternative solution would be to use ConQAT . ConQAT also uses a token-based clone detection approach, but has quite complex post-processing steps. One of them is the so-called "AST-alignment", where duplicated code fragments are aligned with the syntactic units (for example, methods) in the source code after detection. This should be exactly what you are looking for.
Nils gode
source share