@@ -66,9 +66,9 @@ class SimilarBlock extends Copy, @similarity {
6666 }
6767}
6868
69- Method sourceMethod ( ) { method_location ( result , _) and numlines ( result , _, _, _) }
69+ private Method sourceMethod ( ) { method_location ( result , _) and numlines ( result , _, _, _) }
7070
71- int numberOfSourceMethods ( Class c ) {
71+ private int numberOfSourceMethods ( Class c ) {
7272 result = count ( Method m | m = sourceMethod ( ) and m .getDeclaringType ( ) = c )
7373}
7474
@@ -97,6 +97,7 @@ private predicate duplicateStatement(Method m1, Method m2, Stmt s1, Stmt s2) {
9797 )
9898}
9999
100+ /** Holds if `duplicate` number of statements are duplicated in the methods. */
100101predicate duplicateStatements ( Method m1 , Method m2 , int duplicate , int total ) {
101102 duplicate = strictcount ( Stmt s | duplicateStatement ( m1 , m2 , s , _) ) and
102103 total = strictcount ( statementInMethod ( m1 ) )
@@ -109,7 +110,7 @@ predicate duplicateMethod(Method m, Method other) {
109110 exists ( int total | duplicateStatements ( m , other , total , total ) )
110111}
111112
112- predicate similarLines ( File f , int line ) {
113+ private predicate similarLines ( File f , int line ) {
113114 exists ( SimilarBlock b | b .sourceFile ( ) = f and line in [ b .sourceStartLine ( ) .. b .sourceEndLine ( ) ] )
114115}
115116
@@ -148,7 +149,7 @@ private predicate similarLinesCovered(File f, int coveredLines, File otherFile)
148149 )
149150}
150151
151- predicate duplicateLines ( File f , int line ) {
152+ private predicate duplicateLines ( File f , int line ) {
152153 exists ( DuplicateBlock b |
153154 b .sourceFile ( ) = f and line in [ b .sourceStartLine ( ) .. b .sourceEndLine ( ) ]
154155 )
@@ -189,6 +190,7 @@ private predicate duplicateLinesCovered(File f, int coveredLines, File otherFile
189190 )
190191}
191192
193+ /** Holds if the two files are not duplicated but have more than 80% similar lines. */
192194predicate similarFiles ( File f , File other , int percent ) {
193195 exists ( int covered , int total |
194196 similarLinesCovered ( f , covered , other ) and
@@ -199,6 +201,7 @@ predicate similarFiles(File f, File other, int percent) {
199201 not duplicateFiles ( f , other , _)
200202}
201203
204+ /** Holds if the two files have more than 70% duplicated lines. */
202205predicate duplicateFiles ( File f , File other , int percent ) {
203206 exists ( int covered , int total |
204207 duplicateLinesCovered ( f , covered , other ) and
@@ -209,7 +212,7 @@ predicate duplicateFiles(File f, File other, int percent) {
209212}
210213
211214pragma [ noopt]
212- predicate duplicateAnonymousClass ( AnonymousClass c , AnonymousClass other ) {
215+ private predicate duplicateAnonymousClass ( AnonymousClass c , AnonymousClass other ) {
213216 exists ( int numDup |
214217 numDup =
215218 strictcount ( Method m1 |
@@ -248,6 +251,7 @@ private predicate mostlyDuplicateClassBase(Class c, Class other, int numDup, int
248251 not other instanceof AnonymousClass
249252}
250253
254+ /** Holds if the methods in the two classes are more than 80% duplicated. */
251255predicate mostlyDuplicateClass ( Class c , Class other , string message ) {
252256 exists ( int numDup , int total |
253257 mostlyDuplicateClassBase ( c , other , numDup , total ) and
@@ -272,19 +276,28 @@ predicate mostlyDuplicateClass(Class c, Class other, string message) {
272276 )
273277}
274278
279+ /** Holds if the two files are similar or duplated. */
275280predicate fileLevelDuplication ( File f , File other ) {
276281 similarFiles ( f , other , _) or duplicateFiles ( f , other , _)
277282}
278283
284+ /**
285+ * Holds if the two classes are duplicated anonymous classes or more than 80% of
286+ * their methods are duplicated.
287+ */
279288predicate classLevelDuplication ( Class c , Class other ) {
280289 duplicateAnonymousClass ( c , other ) or mostlyDuplicateClass ( c , other , _)
281290}
282291
283- Element whitelistedDuplicateElement ( ) {
292+ private Element whitelistedDuplicateElement ( ) {
284293 result instanceof UsingNamespaceDirective or
285294 result instanceof UsingStaticDirective
286295}
287296
297+ /**
298+ * Holds if the `line` in the `file` contains an element, such as a `using`
299+ * directive, that is not considered for code duplication.
300+ */
288301predicate whitelistedLineForDuplication ( File file , int line ) {
289302 exists ( Location loc | loc = whitelistedDuplicateElement ( ) .getLocation ( ) |
290303 line = loc .getStartLine ( ) and file = loc .getFile ( )
0 commit comments