forked from github/codeql
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDuplicateMethod.ql
More file actions
31 lines (29 loc) · 958 Bytes
/
DuplicateMethod.ql
File metadata and controls
31 lines (29 loc) · 958 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/**
* @name Duplicate method
* @description Duplicated methods make code more difficult to understand and introduce a risk of
* changes being made to only one copy.
* @kind problem
* @problem.severity recommendation
* @precision high
* @id java/duplicate-method
* @tags testability
* maintainability
* useless-code
* duplicate-code
* statistical
* non-attributable
*/
import java
import CodeDuplication
predicate relevant(Method m) {
m.getNumberOfLinesOfCode() > 5 and not m.getName().matches("get%") or
m.getNumberOfLinesOfCode() > 10
}
from Method m, Method other
where
duplicateMethod(m, other) and
relevant(m) and
not fileLevelDuplication(m.getCompilationUnit(), other.getCompilationUnit()) and
not classLevelDuplication(m.getDeclaringType(), other.getDeclaringType())
select m, "Method " + m.getName() + " is duplicated in $@.",
other, other.getDeclaringType().getQualifiedName()