Bug 551064 - ASTParser not able to recover directly in body of type declaration
Summary: ASTParser not able to recover directly in body of type declaration
Status: NEW
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 4.13   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords:
Depends on:
Blocks:
 
Reported: 2019-09-13 16:13 EDT by Roland Grunberg CLA
Modified: 2023-09-04 13:49 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Roland Grunberg CLA 2019-09-13 16:13:01 EDT
Spawned from an issue in https://git.eclipse.org/r/40855/ (Bug 458804)

Given the following 2 source files when using ASTParser#setStatementsRecovery(true) :

(1)
package test;
public class Foo {
	x.
	public void test () {
	}
}

(2)
package test;
public class Foo {
	public void test () {
		x.
	}
}


There is no ASTNode generated for 'x' in (1) while for (2) an ExpressionStatement with a SimpleName element is generated.

Would it be possible to "recover" 'x' in (1) as an ExpressionStatement within an Initializer block, or maybe as an Expression inside a FieldAccess ?
Comment 1 Stephan Herrmann CLA 2019-09-13 16:50:31 EDT
I'm a bit skeptical about this request.

Have you had a look at syntax recovery in the (internal) parser? It would probably have to jump through several hoops to achieve that effect.

If we go by the letter, nobody should expect statements recovery outside a block that can hold statements.

If we would recover it, it should probably be a QualifiedTypeReference since you might be about to declare
   x.C someField;

Would that be OK for your purpose? Or do you definitely need an expression?

Have you checked what happens if you have 'x' without the dot? I think in some situations we'd recover that to
  <missing type> x;
i.e., x would be the name of a field. Any change here would need to be very careful not to break other similar-looking recovery scenarii.
Comment 2 Roland Grunberg CLA 2019-09-17 12:05:46 EDT
(In reply to Stephan Herrmann from comment #1)
> I'm a bit skeptical about this request.
> 
> Have you had a look at syntax recovery in the (internal) parser? It would
> probably have to jump through several hoops to achieve that effect.

Doesn't the internal parser do this already ? I believe with InternalCompletionContext (from JavaContentAssistInvocationContext), there is access to the CompletionOn* type, which is sort of what we want in this case. Basically, any sort of API to get at the token(s) that would be the subject of any completions.

> If we go by the letter, nobody should expect statements recovery outside a
> block that can hold statements.
> 
> If we would recover it, it should probably be a QualifiedTypeReference since
> you might be about to declare
>    x.C someField;
> 
> Would that be OK for your purpose? Or do you definitely need an expression?

I think any ASTNode would be fine.


> Have you checked what happens if you have 'x' without the dot? I think in
> some situations we'd recover that to
>   <missing type> x;
> i.e., x would be the name of a field. Any change here would need to be very
> careful not to break other similar-looking recovery scenarii.

Even without the dot, the nodes recovered are the same as with the dot.
Comment 3 Stephan Herrmann CLA 2019-09-17 12:43:49 EDT
If you see a useful node in the internal AST and if only converting this into a dom ast node is needed, then my worries are irrelevant.
Comment 4 Eclipse Genie CLA 2021-09-07 15:37:34 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.
Comment 5 Stephan Herrmann CLA 2021-09-09 11:12:25 EDT
(In reply to Roland Grunberg from comment #2)
> (In reply to Stephan Herrmann from comment #1)
> > I'm a bit skeptical about this request.
> > 
> > Have you had a look at syntax recovery in the (internal) parser? It would
> > probably have to jump through several hoops to achieve that effect.
> 
> Doesn't the internal parser do this already ? I believe with
> InternalCompletionContext (from JavaContentAssistInvocationContext), there
> is access to the CompletionOn* type, which is sort of what we want in this
> case. Basically, any sort of API to get at the token(s) that would be the
> subject of any completions.

I should have noted, that CompletionParser and ASTParser are disjoint things, so the internal AST seen by ASTParser will never contain any CompletionOn* nodes, and changing that doesn't look like a good idea to me, since completion parsing has its very specific purpose that's different from generally providing an approximation AST from sources with syntax errors.

@Roland do you still want this?
Comment 6 Roland Grunberg CLA 2021-09-13 10:25:26 EDT
Looking back, it does seem like a pretty narrow case and if no one has explicitly complained about it I would either close or leave as low priority.
Comment 7 Eclipse Genie CLA 2023-09-04 13:49:00 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.