eclipse-jdt / eclipse-jdt/eclipse.jdt.ui

Wrong code completion in template if a list of generic objects is used

Open
#1,332 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
59
Forks
127
Avg merge
23h 30m
Merged PRs (30d)
35

Description

Assume the following code:
```
package test;

import java.util.ArrayList;
import java.util.List;
import java.util.Map.Entry;

public class OfByOne {
public static void main(String[] args) {
List> listOfEntryStrings = new ArrayList<>();
}
}
```

if one performs a foreach template it looks like this:
```
public static void main(String[] args) {
List> listOfEntryStrings = new ArrayList<>();
for (Entry entry : listOfEntryStrings) {

}
}
```
if one now cycles through to the `args` instead the result is the following invalid code (the type `String` has a extra `>` at the end):

```
public static void main(String[] args) {
List> listOfEntryStrings = new ArrayList<>();
for (String> string : args) {

}
}
```

https://github.com/eclipse-jdt/eclipse.jdt.ui/assets/1331477/1f4dd6d5-5040-4f73-8a8b-a570f62e3009

```
Eclipse SDK

Version: 2024-06 (4.32)
Build id: I20240401-1800
```

Contributor guide

Open the contributing guide

Research direction

Reproduce the foreach template completion with the shown List> example, then cycle to args and compare the generated loop variable type with the valid first result. Trace the template completion path responsible for selecting the iterated element type; done means cycling produces valid String syntax without the extra closing angle bracket.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.