Skip to content

Commit

Permalink
Inherit internal status from member owner
Browse files Browse the repository at this point in the history
  • Loading branch information
Su5eD committed May 2, 2024
1 parent dce2a83 commit af4b559
Showing 1 changed file with 8 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@ public static ClassInfoComparisonResults compare(boolean checkBinary, @Nullable
List<String> internalAnnotations, InternalAnnotationCheckMode internalAnnotationCheckMode, ClassInfoCache baseCache, ClassInfo baseClassInfo,
ClassInfoCache concreteCache, @Nullable ClassInfo concreteClassInfo) {
ClassInfoComparisonResults results = new ClassInfoComparisonResults(baseClassInfo);
boolean classInternal = isInternalApi(baseClassInfo, baseCache, internalAnnotations, internalAnnotationCheckMode);
String name = baseClassInfo.getName();
int idx = name.lastIndexOf('/');
String packageInfoName = name.substring(0, idx + 1) + "package-info";
ClassInfo packageInfo = baseCache.getMainClassInfo(packageInfoName);
boolean classInternal = isInternalApi(baseClassInfo, internalAnnotations, internalAnnotationCheckMode, packageInfo);

if (classInternal && internalAnnotationCheckMode == InternalAnnotationCheckMode.SKIP)
return results;
Expand Down Expand Up @@ -117,7 +121,7 @@ public static ClassInfoComparisonResults compare(boolean checkBinary, @Nullable

boolean isStatic = (baseInfo.access & Opcodes.ACC_STATIC) != 0;
MethodInfo inputInfo = getMethodInfo(concreteClassInfo, concreteParents, isStatic, baseInfo.name, baseInfo.desc);
boolean methodInternal = isInternalApi(baseInfo, baseCache, internalAnnotations, internalAnnotationCheckMode);
boolean methodInternal = classInternal || isInternalApi(baseInfo, internalAnnotations, internalAnnotationCheckMode, packageInfo);
if (methodInternal && internalAnnotationCheckMode == InternalAnnotationCheckMode.SKIP)
continue;

Expand Down Expand Up @@ -165,7 +169,7 @@ public static ClassInfoComparisonResults compare(boolean checkBinary, @Nullable
for (FieldInfo baseInfo : baseClassInfo.getFields().values()) {
boolean isStatic = (baseInfo.access & Opcodes.ACC_STATIC) != 0;
FieldInfo inputInfo = getFieldInfo(concreteClassInfo, concreteParents, isStatic, baseInfo.name);
boolean fieldInternal = isInternalApi(baseInfo, baseCache, internalAnnotations, internalAnnotationCheckMode);
boolean fieldInternal = classInternal || isInternalApi(baseInfo, internalAnnotations, internalAnnotationCheckMode, packageInfo);
if (fieldInternal && internalAnnotationCheckMode == InternalAnnotationCheckMode.SKIP)
continue;

Expand Down Expand Up @@ -222,15 +226,10 @@ public static boolean isMadeFinal(boolean checkBinary, int baseAccess, int input
return isVisible(checkBinary, baseAccess) && (baseAccess & Opcodes.ACC_FINAL) == 0 && (inputAccess & Opcodes.ACC_FINAL) != 0;
}

public static boolean isInternalApi(MemberInfo memberInfo, ClassInfoCache cache, List<String> internalAnnotations, InternalAnnotationCheckMode checkMode) {
public static boolean isInternalApi(MemberInfo memberInfo, List<String> internalAnnotations, InternalAnnotationCheckMode checkMode, @Nullable ClassInfo packageInfo) {
if (checkMode == InternalAnnotationCheckMode.ERROR)
return false; // Even if internal, we want to handle internal members like normal for ERROR check mode

String name = memberInfo.getName();
int idx = name.lastIndexOf('/');
String packageInfoName = name.substring(0, idx + 1) + "package-info";
ClassInfo packageInfo = cache.getMainClassInfo(packageInfoName);

for (String internalAnnotation : internalAnnotations) {
if (memberInfo.hasAnnotation(internalAnnotation) || packageInfo != null && packageInfo.hasAnnotation(internalAnnotation))
return true;
Expand Down

0 comments on commit af4b559

Please sign in to comment.