Skip to content

Commit

Permalink
Determine internal status using package-info annotations (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
Su5eD authored May 11, 2024
1 parent df7205b commit d40d440
Showing 1 changed file with 12 additions and 4 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, 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, 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, internalAnnotations, internalAnnotationCheckMode);
boolean fieldInternal = classInternal || isInternalApi(baseInfo, internalAnnotations, internalAnnotationCheckMode, packageInfo);
if (fieldInternal && internalAnnotationCheckMode == InternalAnnotationCheckMode.SKIP)
continue;

Expand Down Expand Up @@ -223,11 +227,15 @@ public static boolean isMadeFinal(boolean checkBinary, int baseAccess, int input
}

public static boolean isInternalApi(MemberInfo memberInfo, List<String> internalAnnotations, InternalAnnotationCheckMode checkMode) {
return isInternalApi(memberInfo, internalAnnotations, checkMode, null);
}

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

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

Expand Down

0 comments on commit d40d440

Please sign in to comment.