@@ -16,23 +16,37 @@ class UtBotFieldsModificatorsSearcher {
16
16
* Finds field modificators.
17
17
*
18
18
* @param analysisMode represents which type of modificators (e.g. setters) are considered.
19
- * @param packageName describes a location of package-private methods that need to be considered.
19
+ * @param basePackageName describes a location of package-private methods that need to be considered.
20
20
*/
21
- fun findModificators (analysisMode : AnalysisMode , packageName : String? = null): Map <FieldId , Set <StatementId >> {
21
+ fun findModificators (analysisMode : AnalysisMode , basePackageName : String? = null): Map <FieldId , Set <StatementId >> {
22
22
val modificators = findModificators(analysisMode)
23
- if (packageName == null ) {
23
+
24
+ if (basePackageName == null ) {
24
25
return modificators
25
26
}
26
27
27
28
val filteredModifications = mutableMapOf<FieldId , Set <StatementId >>()
28
29
for ((fieldId, statements) in modificators) {
29
- val filteredStmts = statements.filter { it.classId.packageName.startsWith(packageName ) }.toSet()
30
- filteredModifications[fieldId] = filteredStmts
30
+ val filteredStmts = statements.filter { stmt -> fieldId.isAccessibleBy(stmt, basePackageName !! ) }
31
+ filteredModifications[fieldId] = filteredStmts.toSet()
31
32
}
32
33
33
34
return filteredModifications
34
35
}
35
36
37
+ private fun FieldId.isAccessibleBy (statementId : StatementId , basePackageName : String ): Boolean {
38
+ val classPackageName = statementId.classId.packageName
39
+ if (basePackageName == " " ) {
40
+ return classPackageName == " "
41
+ } else {
42
+ if (this .isPublic) return true
43
+ if (this .isProtected) return classPackageName.startsWith(basePackageName)
44
+ if (this .isPackagePrivate) return classPackageName == basePackageName
45
+ // for private fields no filtering based on package names is required
46
+ return true
47
+ }
48
+ }
49
+
36
50
private fun findModificators (analysisMode : AnalysisMode ): Map <FieldId , Set <StatementId >> {
37
51
statementsStorage.updateCaches()
38
52
return findModificatorsInCache(analysisMode)
0 commit comments