Skip to content

Fix Wildcard Import Annotation Resolution#192

Merged
rcosta358 merged 2 commits intomainfrom
fix-wildcard-imports
Mar 28, 2026
Merged

Fix Wildcard Import Annotation Resolution#192
rcosta358 merged 2 commits intomainfrom
fix-wildcard-imports

Conversation

@rcosta358
Copy link
Copy Markdown
Collaborator

@rcosta358 rcosta358 commented Mar 26, 2026

This PR fixes an error when importing the LiquidJava annotations using a wildcard import:

import liquidjava.specification.*;

@ExternalRefinementsFor("java.net.Socket")
@StateSet({"unconnected", "bound", "connected", "closed"})
public class SocketRefinements {
    // ...
}

spoon.support.SpoonClassNotFoundException: cannot load class: com.example.socket.StateSet

Root Cause

The problem was that annotation comparison checks were using ann.getActualAnnotation().annotationType().getCanonicalName(), which caused Spoon to load the annotation classes with the prefix of the analyzed package instead of the correct one liquidjava.specification.

Fix

Replace those checks with getAnnotationType().getQualifiedName().

@rcosta358 rcosta358 self-assigned this Mar 26, 2026
@rcosta358 rcosta358 added the bug Something isn't working label Mar 26, 2026
Copy link
Copy Markdown
Collaborator

@CatarinaGamboa CatarinaGamboa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

.getCanonicalName().contentEquals("liquidjava.specification.StateRefinement"))
.collect(Collectors.toList());
private static List<CtAnnotation<? extends Annotation>> getStateAnnotations(CtElement element) {
return element.getAnnotations().stream().filter(ann -> ann.getAnnotationType().getQualifiedName()
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@rcosta358 rcosta358 merged commit 0836fc5 into main Mar 28, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants