-
Notifications
You must be signed in to change notification settings - Fork 329
Update jdk-javac-plugin to contain nested annotations #1432
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
Changes from 11 commits
ad3a0f3
4358508
d66e0e4
c2fb5ff
4c9211b
582aade
e7e19be
b21c4d2
0d0f0de
4958718
d83bc26
981ec0c
d5cc811
8606f18
1ae87d2
42b3f41
e8b97f0
997a76b
000f06c
e879332
ad29bce
06c4233
e49e75c
c558007
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,150 @@ | ||||||
| package com.uber.nullaway.javacplugin; | ||||||
|
|
||||||
| import com.google.common.collect.ImmutableList; | ||||||
| import com.sun.tools.javac.code.Type; | ||||||
| import com.sun.tools.javac.code.Types; | ||||||
| import com.uber.nullaway.javacplugin.NestedAnnotationInfo.Annotation; | ||||||
| import com.uber.nullaway.javacplugin.NestedAnnotationInfo.TypePathEntry; | ||||||
| import java.util.ArrayDeque; | ||||||
| import java.util.HashSet; | ||||||
| import java.util.List; | ||||||
| import java.util.Set; | ||||||
| import javax.lang.model.element.AnnotationMirror; | ||||||
| import javax.lang.model.element.TypeElement; | ||||||
| import javax.lang.model.type.TypeMirror; | ||||||
| import org.jspecify.annotations.NullMarked; | ||||||
| import org.jspecify.annotations.Nullable; | ||||||
|
|
||||||
| @NullMarked | ||||||
| public class CreateNestedAnnotationInfoVisitor | ||||||
msridhar marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
| extends Types.DefaultTypeVisitor<Set<NestedAnnotationInfo>, @Nullable Void> { | ||||||
|
||||||
| extends Types.DefaultTypeVisitor<Set<NestedAnnotationInfo>, @Nullable Void> { | |
| extends Types.DefaultTypeVisitor<@Nullable Void, @Nullable Void> { |
Then, return null from every visitXXX method, but add a getter method getNestedAnnotationInfoSet() so that the client can retrieve the set at the end.
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's not store this in a local variable here, since it will do a copy of path for every type variable, whether it is annotated or not. Instead, just call getTypePath() at lines 45 and 47
haewiful marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same suggestions I gave for visitClassType
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems this logic is repeated again and again. Can we extract it to a method (the simplified version) and then call that method everywhere?
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same logic again
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| package com.uber.nullaway.javacplugin; | ||
|
|
||
| import com.google.common.collect.ImmutableList; | ||
| import org.jspecify.annotations.NullMarked; | ||
|
|
||
| /** | ||
| * Class to hold information about a nested nullability annotation within a type, including the type | ||
| * of nullability annotation and the type path to reach it. | ||
| * | ||
| * @param annotation the nullability annotation | ||
| * @param typePath the type path to reach the annotation. If empty, the annotation applies to the | ||
| * outermost type. Otherwise, each entry indicates one step in how to navigate to the nested | ||
| * type. | ||
| */ | ||
| @NullMarked | ||
| public record NestedAnnotationInfo(Annotation annotation, ImmutableList<TypePathEntry> typePath) { | ||
msridhar marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| /** | ||
| * Class for a single entry in a type path, indicating how to navigate the "next step" in the type | ||
| * to eventually reach some target type. | ||
| * | ||
| * @param kind the kind of this type path entry | ||
| * @param index the index associated with the kind. For TYPE_ARGUMENT, this is the type argument | ||
| * index. For WILDCARD_BOUND, this is 0 for the upper bound ({@code ? extends Foo}) and 1 for | ||
| * the lower bound ({@code ? super Foo}). For ARRAY_ELEMENT, this is unused and set to -1. | ||
| */ | ||
| public record TypePathEntry(Kind kind, int index) { | ||
|
|
||
| /** Possible nested type kinds for an entry */ | ||
| public enum Kind { | ||
| ARRAY_ELEMENT, | ||
| TYPE_ARGUMENT, | ||
| WILDCARD_BOUND | ||
| } | ||
| } | ||
|
|
||
| /** Possible annotations for nullability */ | ||
| public enum Annotation { | ||
| NULLABLE, | ||
| NONNULL | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.