Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Determine internal status using package-info annotations #1

Merged
merged 3 commits into from
May 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading