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

Add type as part of target location #972

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

Ao-senXiong
Copy link
Member

No description provided.

@Ao-senXiong
Copy link
Member Author

Ao-senXiong commented Nov 8, 2024

Hi @wmdietl, do you know how to update the elementcache in

private final Map<Element, AnnotatedTypeMirror> elementCache;
.

It is later retrieved at here.

The expected error did not come up because in the elementCache it does not contain annotation added from DefaultQualifier.

@Ao-senXiong
Copy link
Member Author

The root cause should be here as the method getTypeDeclarationBounds

atypeFactory.getTypeDeclarationBounds(type.getUnderlyingType());

which does not consider bound in Defaultqualifier annotation like @DefaultQualifier( value = A.class, locations = {TypeUseLocation.TYPE})

outer.addAnnotation(t, qual);
atypeFactory.elementCache.put(outer.scope, t);
} else {
// should report error;
Copy link
Member Author

Choose a reason for hiding this comment

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

If the annotation supplied is incompatible with the one in DefaultQualifier, should we report error or we should keep the explicit qualifier? That is to say, in the following code, should we keep @B or should we report error?

@DefaultQualifier(
        value = A.class,
        locations = {TypeUseLocation.TYPE})
@B
public class DefaultQualifierTest {
    @B DefaultQualifierTest() {}
}

@@ -1010,6 +1010,24 @@ public Void scan(@FindDistinct AnnotatedTypeMirror t, AnnotationMirror qual) {
// Some defaults only apply to the top level type.
boolean isTopLevelType = t == outer.type;
switch (outer.location) {
case TYPE:
if (outer.scope != null && outer.scope.getKind().isClass() && isTopLevelType) {
Copy link
Member Author

Choose a reason for hiding this comment

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

Also, another question is should we apply the class level default only for toplevel? Or nested classes as well?

@Ao-senXiong Ao-senXiong self-assigned this Dec 17, 2024
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.

1 participant