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

fix: support annotations for runtime package model #4210

Merged
merged 2 commits into from
Oct 7, 2021

Conversation

SirYwell
Copy link
Collaborator

@SirYwell SirYwell commented Oct 6, 2021

Previously, packages where only visited from type references. This means the package of the type given to the scan method isn't necessarily visited, and its annotations aren't visited either.

This fixes it. The test case assumes that the package has the @Deprecated annotation declared in the package-info.java:

@Deprecated
package spoon.test.pkg;

When debugging, I saw that packages (java.util, java.lang) are visited multiple times, as they are always visited whenever a type (new) or type reference (before) is visited. As the values of a package don't change at runtime (well, at least within a module), this doesn't seem necessary. Should we skip that by making sure that packages are only visited once here:

public void visitPackage(Package aPackage) {
final CtPackage ctPackage = factory.Package().getOrCreate(aPackage.getName());
enter(new PackageRuntimeBuilderContext(ctPackage));
super.visitPackage(aPackage);
exit();
contexts.peek().addPackage(ctPackage);
}
? I'm not really sure if this would cause any issues.

@SirYwell SirYwell changed the title wip: fix: scan packages and extract their annotations review: fix: scan packages and extract their annotations Oct 6, 2021
@monperrus
Copy link
Collaborator

LGTM! Could you add the contract in the test? Thanks.

@SirYwell
Copy link
Collaborator Author

SirYwell commented Oct 7, 2021

Could you add the contract in the test?

Oh yeah I forgot that.

@monperrus monperrus changed the title review: fix: scan packages and extract their annotations fix: support annotations for runtime package model Oct 7, 2021
@monperrus monperrus merged commit bd36786 into INRIA:master Oct 7, 2021
@monperrus
Copy link
Collaborator

Thanks a lot @SirYwell

@SirYwell SirYwell deleted the fix/reflective-packages branch February 16, 2023 17:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants