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

[code-selection] Selection issues involving enhanced switch

Open
#2,412 2 comments 0 reactions 1 assignee Claimed by @srikanth-sankaran View on GitHub
Dominant language
Java
Stars
237
Forks
195
Avg merge
1d 12h
Merged PRs (30d)
47

Description

Regarding #2299 @srikanth-sankaran suggested to compare codeComplete() with codeSelect().

Within test cases fixed in #2391 I found a few problems of codeSelect() itself:

```java
public void foo(java.io.Serializable o) {
switch(o) {
case Person(var name, var age) : {
/*here*/name
}
}
}
```
selecting on "name" (incomplete statement) produces (via RecoveredElement.updateParseTree()) this method AST (the second "case" is wrong):
```
public void foo(java.io.Serializable o) {
{
{
switch (o) {
case Person(var name, var age) :
case :
}
}
}
}
```

Same problem also in switch *expression*.

With tricky nesting involved:
```java
public void foo(java.io.Serializable o) {
switch(o) {
case Person(var name, var age): {
col.stream().filter(el -> el.equals(/*here*/name))
}
};
}
```
AST drops all added context (is it irrelevant? so dropping might be by intention?):
```
public void foo(java.io.Serializable o) {
{
{
switch (o) {
case Person(var name, var age) :
case :
}
}
}
}
```

And the trickiest for new tests:
```java
public void foo(List col) {
col.stream().filter(el -> {
switch(el) {
case Person(var name, var age): {
/*here*/name
}
};
})
}
```
gives
```
public void foo(List col) {
}
```
ups...

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.