Skip to content

Commit

Permalink
Only visit types with parent ATs when inheriting
Browse files Browse the repository at this point in the history
When inheriting method ATs, classes may need to be processed that are
not found in the source AT set as they inherit their ATs from their
parent.
The previous iteration would accomplish this by simply visiting the
entire source root.

The commit introduces a simplistic heuristic, filtering out any types
from processing that do not have a parent with an AT defined.
While this is not exact, e.g. a class will still be processed if its
parent type has a field changed via AT, the accesstransformer library
used does not expose the types of ATs defined on a class, making this a
best effort approximation.
  • Loading branch information
lynxplay committed Dec 18, 2024
1 parent b4c3dcf commit 64a53bb
Showing 1 changed file with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,25 @@ public void visitElement(@NotNull PsiElement element) {
if (element instanceof PsiClass psiClass) {
if (psiClass.getQualifiedName() != null) {
String className = ClassUtil.getJVMClassName(psiClass);
if (!inheritMethodATs && !ats.containsClassTarget(className)) {
boolean shouldBeSkipped = !ats.containsClassTarget(className);

// Classes may need changing that are not in the source at set.
// Check if any of this classe's parents are in the source at set first to potentially inherit their ATs.
if (shouldBeSkipped && this.inheritMethodATs) {
for (
PsiClass parentType = psiClass.getSuperClass();
parentType != null;
parentType = parentType.getSuperClass()
) {
if (this.ats.containsClassTarget(ClassUtil.getJVMClassName(parentType))) {
// Process class as we inherit method ATs and we found *some* AT.
// Heuristic isn't perfect, but the alternative would be scanning *all* method targets for the parent owning type.
shouldBeSkipped = false;
break;
}
}
}
if (shouldBeSkipped) {
// Skip this class and its children, but not the inner classes
for (PsiClass innerClass : psiClass.getInnerClasses()) {
visitElement(innerClass);
Expand Down

0 comments on commit 64a53bb

Please sign in to comment.