RFR: 8285150: Improve tab completion for annotations

Chen Liang liach at openjdk.org
Fri Dec 20 08:17:35 UTC 2024


On Fri, 20 Dec 2024 06:24:13 GMT, Jan Lahoda <jlahoda at openjdk.org> wrote:

> When using types code like:
> 
> @Deprecated(
> 
> 
> and presses `<tab>`, there should be a sensible completion, but currently there is nothing. This PR proposes to add code completion for annotation attributes.

src/jdk.jshell/share/classes/jdk/jshell/SourceCodeAnalysisImpl.java line 993:

> 991:         if (tp.getParentPath().getLeaf().getKind() == Kind.NEW_ARRAY &&
> 992:             ((NewArrayTree) tp.getParentPath().getLeaf()).getInitializers().contains(tp.getLeaf())) {
> 993:             return isAnnotationAttributeValue(tp.getParentPath());

I recall JLS requires annotation arrays to be one-dimensional only, but this check seems to allow multi-dimensional arrays with annotation elements.

src/jdk.jshell/share/classes/jdk/jshell/SourceCodeAnalysisImpl.java line 1027:

> 1025:     }
> 1026: 
> 1027:     private boolean isAnnotationAttributeValueType(AnalyzeTask at, TypeMirror type) {

This name is misleading - it is checking if a static final field type is suitable for an annotation attribute.  This is more restrictive than general annotation element return types, which also allows annotation interfaces and one-dimensional arrays of primitives, enums, strings, and annotation interfaces.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/22840#discussion_r1893609453
PR Review Comment: https://git.openjdk.org/jdk/pull/22840#discussion_r1893612456


More information about the kulla-dev mailing list