Skip to content

Commit 4d00832

Browse files
committed
[WIP] recover fragment expression as assignment without rhs
When there is this source in a method: ```java { ... "String".var ... ... } ``` jdt.ui expects it to be recovered like this: ```java { ... "String".var = $missing$; ... ``` Where `$missing$` is a fake, empty identifier. Currently, in some cases, the `"String".var` is being completely discarded, and this should improve that. Signed-off-by: David Thompson <[email protected]>
1 parent 69ada6f commit 4d00832

File tree

1 file changed

+7
-0
lines changed
  • org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/parser

1 file changed

+7
-0
lines changed

org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/parser/Parser.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1138,6 +1138,13 @@ public RecoveredElement buildInitialRecoveryState(){
11381138
}
11391139

11401140
if (this.statementRecoveryActivated) {
1141+
if (this.expressionPtr >= 0 && this.expressionStack[0] instanceof FieldReference fr) {
1142+
var snr = new SingleNameReference(new char[0], fr.sourceEnd);
1143+
snr.sourceStart = fr.sourceEnd;
1144+
var assignment = new Assignment(fr, snr, fr.sourceEnd);
1145+
assignment.statementEnd = assignment.sourceEnd;
1146+
element = element.add(assignment, 0);
1147+
}
11411148
if (this.pendingRecoveredType != null &&
11421149
this.scanner.startPosition - 1 <= this.pendingRecoveredType.declarationSourceEnd) {
11431150
// Add the pending type to the AST if this type isn't already added in the AST.

0 commit comments

Comments
 (0)