Skip to content

Commit

Permalink
Adjust visibility and accessability checks.
Browse files Browse the repository at this point in the history
  • Loading branch information
raphw committed Aug 15, 2024
1 parent 3c868d0 commit 0e49cc3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -610,23 +610,21 @@ public int getActualModifiers(boolean manifest, Visibility visibility) {
* {@inheritDoc}
*/
public boolean isVisibleTo(TypeDescription typeDescription) {
return (isVirtual() || getDeclaringType().asErasure().isVisibleTo(typeDescription))
&& (isPublic()
|| typeDescription.equals(getDeclaringType().asErasure())
|| isProtected() && getDeclaringType().asErasure().isAssignableFrom(typeDescription)
|| !isPrivate() && typeDescription.isSamePackage(getDeclaringType().asErasure())
|| isPrivate() && typeDescription.isNestMateOf(getDeclaringType().asErasure()));
return getDeclaringType().asErasure().equals(typeDescription)
|| isPublic() && getDeclaringType().isPublic()
|| (isPublic() || isProtected()) && getDeclaringType().asErasure().isAssignableFrom(typeDescription)
|| !isPrivate() && getDeclaringType().asErasure().isSamePackage(typeDescription)
|| isPrivate() && getDeclaringType().asErasure().isNestMateOf(typeDescription);
}

/**
* {@inheritDoc}
*/
public boolean isAccessibleTo(TypeDescription typeDescription) {
return (isVirtual() || getDeclaringType().asErasure().isVisibleTo(typeDescription))
&& (isPublic()
|| typeDescription.equals(getDeclaringType().asErasure())
|| !isPrivate() && typeDescription.isSamePackage(getDeclaringType().asErasure()))
|| isPrivate() && typeDescription.isNestMateOf(getDeclaringType().asErasure());
return getDeclaringType().asErasure().equals(typeDescription)
|| isPublic() && getDeclaringType().isPublic()
|| !isPrivate() && getDeclaringType().asErasure().isSamePackage(typeDescription)
|| isPrivate() && getDeclaringType().asErasure().isNestMateOf(typeDescription);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ public void testMethodIsVisibleTo() throws Exception {
assertThat(describe(PublicType.class.getDeclaredMethod("privateMethod"))
.isVisibleTo(TypeDescription.ForLoadedType.of(MethodDescriptionTestHelper.class)), is(false));
assertThat(describe(PackagePrivateType.class.getDeclaredMethod("publicMethod"))
.isVisibleTo(TypeDescription.ForLoadedType.of(Object.class)), is(true));
.isVisibleTo(TypeDescription.ForLoadedType.of(Object.class)), is(false));
assertThat(describe(PackagePrivateType.class.getDeclaredMethod("protectedMethod"))
.isVisibleTo(TypeDescription.ForLoadedType.of(Object.class)), is(false));
assertThat(describe(PackagePrivateType.class.getDeclaredMethod("packagePrivateMethod"))
Expand Down Expand Up @@ -535,7 +535,7 @@ public void testMethodIsAccessibleTo() throws Exception {
assertThat(describe(PublicType.class.getDeclaredMethod("privateMethod"))
.isAccessibleTo(TypeDescription.ForLoadedType.of(MethodDescriptionTestHelper.class)), is(false));
assertThat(describe(PackagePrivateType.class.getDeclaredMethod("publicMethod"))
.isAccessibleTo(TypeDescription.ForLoadedType.of(Object.class)), is(true));
.isAccessibleTo(TypeDescription.ForLoadedType.of(Object.class)), is(false));
assertThat(describe(PackagePrivateType.class.getDeclaredMethod("protectedMethod"))
.isAccessibleTo(TypeDescription.ForLoadedType.of(Object.class)), is(false));
assertThat(describe(PackagePrivateType.class.getDeclaredMethod("packagePrivateMethod"))
Expand Down

0 comments on commit 0e49cc3

Please sign in to comment.