eclipse-jdt / eclipse-jdt/eclipse.jdt.core

Autofill required annotation member values

Open
#3,048 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
237
Forks
195
Avg merge
1d 12h
Merged PRs (30d)
47

Description

For method invocations, when invoking completion at the `|`:

```java
public class Main {
static int a = 1, b = 2;
private static int myFunc(int x, int y) {
return x + y;
}
public static void main(String... args) {
myFun|
}
}
```

it autofills the invocation with guesses for parameters from the enclosing scopes:

```java
public class Main {
static int a = 1, b = 2;
private static int myFunc(int x, int y) {
return x + y;
}
public static void main(String... args) {
myFunc(a, b)|
}
}
```

It might be nice to do the same for annotations that require members to be set. Notably, the values for annotation members need to be constants, which should simplify the logic.

Here is an example (invoking completion at the `|`):

```java
public class Main {
@MyAnn|
public static void main(String... args) {
System.out.println("Hello, world!");
}

static @interface MyAnnotation {
int myCoolValue();
String myOtherCoolValue();
}
}
```

...becomes...

```java
public class Main {
@MyAnnotation(myCoolValue = 0, myOtherCoolValue = "")
public static void main(String... args) {
System.out.println("Hello, world!");
}

static @interface MyAnnotation {
int myCoolValue();
String myOtherCoolValue();
}
}
```

...providing options to tab through the `0` and the `""` and change those values.

We don't need to collect potential variable/field suggestions, because the values need to be constants. However, I'm pretty sure that enums can be used as annotation member values, so we would need to take that into account.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.