Skip to content

Commit

Permalink
Fix inner class AT validation always reporting missing targets (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
Matyrobbrt authored Jun 26, 2024
1 parent 7e2e887 commit 5816c51
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,12 @@ public void beforeRun(TransformContext context) {
@Override
public boolean afterRun(TransformContext context) {
if (!pendingATs.isEmpty()) {
pendingATs.forEach((target, transformation) -> logger.error("Access transformer %s, targeting %s did not apply as its target doesn't exist", transformation, target));
pendingATs.forEach((target, transformation) -> {
// ClassTarget for inner classes have a corresponding InnerClassTarget which is more obvious for users
// so we don't log the ClassTarget as that will cause duplication
if (target instanceof Target.ClassTarget && target.className().contains("$")) return;
logger.error("Access transformer %s, targeting %s did not apply as its target doesn't exist", transformation, target);
});
errored = true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ public void visitElement(@NotNull PsiElement element) {
}

apply(pendingATs.remove(new Target.ClassTarget(className)), psiClass, psiClass);
// We also remove any possible inner class ATs declared for that class as all class targets targeting inner classes
// generate a InnerClassTarget AT
if (psiClass.getParent() instanceof PsiClass parent) {
pendingATs.remove(new Target.InnerClassTarget(ClassUtil.getJVMClassName(parent), className));
}

var fieldWildcard = pendingATs.remove(new Target.WildcardFieldTarget(className));
if (fieldWildcard != null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
public com.example.RootClass$InnerClass1
protected-f com.example.RootClass$InnerClass1$InnerClassNested

# Inner class ATs with missing targets should only generate one log entry
public com.example.RootClass$InnerDoesntExist
1 change: 1 addition & 0 deletions tests/data/accesstransformer/inner_classes/expected.log
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Access transformer PUBLIC LEAVE {atpath}:5, targeting com.example.RootClass INNERCLASS InnerDoesntExist did not apply as its target doesn't exist

0 comments on commit 5816c51

Please sign in to comment.