|
|
|
@ -54,7 +54,8 @@ public class VisibilityTransformer @Inject constructor(private val profile: Prof |
|
|
|
|
references: Multimap<DisjointSet.Partition<MemberRef>, String>, |
|
|
|
|
disjointSet: DisjointSet<MemberRef>, |
|
|
|
|
member: MemberRef, |
|
|
|
|
access: Int |
|
|
|
|
access: Int, |
|
|
|
|
classAccess: Int |
|
|
|
|
): Int { |
|
|
|
|
val method = Type.getType(member.desc).sort == Type.METHOD |
|
|
|
|
if (method) { |
|
|
|
@ -72,6 +73,7 @@ public class VisibilityTransformer @Inject constructor(private val profile: Prof |
|
|
|
|
val overridable = method && member.name != "<init>" |
|
|
|
|
val hasOverride = overridable && partition.count { classPath[it.owner]!!.methods.contains(MemberDesc(it)) } > 1 |
|
|
|
|
val abstract = method && access and Opcodes.ACC_ABSTRACT != 0 |
|
|
|
|
val finalClass = classAccess and Opcodes.ACC_FINAL != 0 |
|
|
|
|
val partitionReferences = references[partition] |
|
|
|
|
val partitionOwners = partition.mapTo(mutableSetOf(), MemberRef::owner) |
|
|
|
|
|
|
|
|
@ -82,7 +84,13 @@ public class VisibilityTransformer @Inject constructor(private val profile: Prof |
|
|
|
|
|
|
|
|
|
// pick the weakest access level based on references in our own code |
|
|
|
|
val visibility = when { |
|
|
|
|
partitionReferences.all { it == member.owner } && !hasOverride && !abstract -> Opcodes.ACC_PRIVATE |
|
|
|
|
!hasOverride && !abstract && partitionReferences.all { it == member.owner } -> { |
|
|
|
|
if (finalClass) { |
|
|
|
|
Opcodes.ACC_PRIVATE |
|
|
|
|
} else { |
|
|
|
|
Opcodes.ACC_PROTECTED |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
partitionReferences.all { partitionOwners.contains(it) } -> Opcodes.ACC_PROTECTED |
|
|
|
|
else -> Opcodes.ACC_PUBLIC |
|
|
|
|
} |
|
|
|
@ -118,7 +126,8 @@ public class VisibilityTransformer @Inject constructor(private val profile: Prof |
|
|
|
|
fieldReferences, |
|
|
|
|
inheritedFieldSets, |
|
|
|
|
MemberRef(clazz, field), |
|
|
|
|
access |
|
|
|
|
access, |
|
|
|
|
clazz.access |
|
|
|
|
) |
|
|
|
|
field.access = (access and VISIBILITY_FLAGS.inv()) or visibility |
|
|
|
|
|
|
|
|
@ -135,7 +144,8 @@ public class VisibilityTransformer @Inject constructor(private val profile: Prof |
|
|
|
|
methodReferences, |
|
|
|
|
inheritedMethodSets, |
|
|
|
|
MemberRef(clazz, method), |
|
|
|
|
access |
|
|
|
|
access, |
|
|
|
|
clazz.access |
|
|
|
|
) |
|
|
|
|
method.access = (access and VISIBILITY_FLAGS.inv()) or visibility |
|
|
|
|
|
|
|
|
|