Bug 574803 - [content assist] no content assist in if expression before variable declaration
Summary: [content assist] no content assist in if expression before variable declaration
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 4.20   Edit
Hardware: All All
: P3 major (vote)
Target Milestone: 4.21 M3   Edit
Assignee: Stephan Herrmann CLA
QA Contact:
URL:
Whiteboard:
Keywords: regression
Depends on:
Blocks: 574913
  Show dependency tree
 
Reported: 2021-07-12 09:18 EDT by Julian Honnen CLA
Modified: 2021-08-05 08:48 EDT (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Julian Honnen CLA 2021-07-12 09:18:22 EDT
When adding an if statement before a local variable declaration without any braces yet, content assist is broken on the RHS:

public static void fillAttributes(Object object) throws Exception {
	for (Field field : object.getClass().getFields()) {
		if (field.getType() == |) // no content assist
		Object value = field.get(object);
		System.out.println(value);
	}
}


Tested in Version: 2021-09 (4.21)
Build id: I20210712-0340


This worked in 4.19
Comment 1 Andrey Loskutov CLA 2021-07-24 06:04:29 EDT
Still in I20210723-1800
Comment 2 Stephan Herrmann CLA 2021-07-29 18:23:40 EDT
Problem is: local variable "Object value" creates a syntax at this position (illegal then-statement).

Previously (4.19-), we would never see "Object value", but abort parsing at the cursor.

Now we need to help the parser collecting bits off stacks also in this case.

I have a patch, but still need to sort through effects on other tests.
Comment 3 Eclipse Genie CLA 2021-07-31 10:58:37 EDT
New Gerrit change created: https://git.eclipse.org/r/c/jdt/eclipse.jdt.core/+/183569
Comment 4 Stephan Herrmann CLA 2021-07-31 11:27:07 EDT
(In reply to Eclipse Genie from comment #3)
> New Gerrit change created:
> https://git.eclipse.org/r/c/jdt/eclipse.jdt.core/+/183569

Main idea here: detect cases where the assist node was not attached even while the current method has actual statements.

In this case use the mechanism of RecoveredElement.add() and .updateParseTree().

The tricky part was detecting the assist node *anywhere* within the already constructed AST (to avoid duplicate insertion). Two parts to solving this sub-issue:
* a new AST visitor (based on a new general purpose GenericAstVisitor (like we have in DOM)
* correctly splice CompletionOnBranchStatementLabel into the ASTNode hierarchy to allow it being traversed by the visitor (abstract class BranchStatement is not covered).
Comment 6 Stephan Herrmann CLA 2021-07-31 13:39:44 EDT
(In reply to Eclipse Genie from comment #5)
> Gerrit change https://git.eclipse.org/r/c/jdt/eclipse.jdt.core/+/183569 was
> merged to [master].
> Commit:
> http://git.eclipse.org/c/jdt/eclipse.jdt.core.git/commit/
> ?id=bb441d25c94b5c0cef092b72a93035296af4aff9

Released for 4.21 M3
Comment 7 Andrey Loskutov CLA 2021-08-05 08:48:55 EDT
Verified in I20210804-1800.

The behavior is now as before in 4.19, which was broken too, see bug 575258.