Skip to content

Commit a6f666c

Browse files
committed
Allow new classes to be added
1 parent f728dfa commit a6f666c

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

gradle/plugins/japicmp/src/main/kotlin/junitbuild/japicmp/AcceptedViolationSuppressor.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package junitbuild.japicmp
22

3+
import japicmp.model.JApiBehavior
34
import japicmp.model.JApiClass
5+
import japicmp.model.JApiCompatibility
6+
import japicmp.model.JApiField
47
import japicmp.model.JApiImplementedInterface
58
import me.champeau.gradle.japicmp.report.Severity.accepted
69
import me.champeau.gradle.japicmp.report.Violation
@@ -20,11 +23,21 @@ class AcceptedViolationSuppressor(params: Map<String, String>) : ViolationTransf
2023
private fun Violation.isRedundant(): Boolean =
2124
// The changes about the interface's methods will be reported already
2225
member is JApiImplementedInterface
26+
// Allow new classes to be added
27+
|| member.isInNewClass()
2328
// A member of the class breaks binary or source compatibility and will be reported
2429
|| (member is JApiClass && member.compatibilityChanges.none { !it.isBinaryCompatible || !it.isSourceCompatible } && !member.isBreakingSuperClassChange())
2530

2631
private fun Violation.isAccepted(): Boolean =
2732
acceptedIncompatibilities.contains(member.fullyQualifiedName)
2833
|| acceptedIncompatibilities.contains(member.fullyQualifiedClassName)
2934

35+
private fun JApiCompatibility.isInNewClass(): Boolean {
36+
return when (this) {
37+
is JApiClass -> oldClass.isEmpty
38+
is JApiBehavior -> getjApiClass().isInNewClass()
39+
is JApiField -> getjApiClass().isInNewClass()
40+
else -> false
41+
}
42+
}
3043
}

0 commit comments

Comments
 (0)