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

Stream chained method call doesn't show up in the AST when there are compiler problems after it

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

Description

For the following code:

```
package tests;

import java.util.List;
import java.util.stream.Stream;

public class TestPostCompletion {

public static void main(String[] args, List x) {
int a = 4;
Stream.iterate(0,i -> ++i).limit(10);
"String".var
}
}
```

which is attempting to do a Post completion for "String", the AST viewer is only showing one statement for the block under main and it is the "int a = 4;". It is not attempting any recovery for the "String".var and not showing the ExpressionStatement that precedes it. There shouldn't be any confusion because it is a complete statement with semi-colon. When the Post completion tries to find the best location, it finds the declaration of a and tries to add another in the middle (invalid code).

If the Stream statement is removed, the block now shows 2 statements with the "String".var being recovered and Post completion works because it can find the "String" node to turn into a statement declaration.

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.