Skip to content

Commit 64a53bb

Browse files
committed
Only visit types with parent ATs when inheriting
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.
1 parent b4c3dcf commit 64a53bb

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

accesstransformers/src/main/java/net/neoforged/jst/accesstransformers/ApplyATsVisitor.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,25 @@ public void visitElement(@NotNull PsiElement element) {
6868
if (element instanceof PsiClass psiClass) {
6969
if (psiClass.getQualifiedName() != null) {
7070
String className = ClassUtil.getJVMClassName(psiClass);
71-
if (!inheritMethodATs && !ats.containsClassTarget(className)) {
71+
boolean shouldBeSkipped = !ats.containsClassTarget(className);
72+
73+
// Classes may need changing that are not in the source at set.
74+
// Check if any of this classe's parents are in the source at set first to potentially inherit their ATs.
75+
if (shouldBeSkipped && this.inheritMethodATs) {
76+
for (
77+
PsiClass parentType = psiClass.getSuperClass();
78+
parentType != null;
79+
parentType = parentType.getSuperClass()
80+
) {
81+
if (this.ats.containsClassTarget(ClassUtil.getJVMClassName(parentType))) {
82+
// Process class as we inherit method ATs and we found *some* AT.
83+
// Heuristic isn't perfect, but the alternative would be scanning *all* method targets for the parent owning type.
84+
shouldBeSkipped = false;
85+
break;
86+
}
87+
}
88+
}
89+
if (shouldBeSkipped) {
7290
// Skip this class and its children, but not the inner classes
7391
for (PsiClass innerClass : psiClass.getInnerClasses()) {
7492
visitElement(innerClass);

0 commit comments

Comments
 (0)